Skip to content

Commit

Permalink
fin docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Jun 26, 2024
1 parent 05c4b12 commit 4308963
Show file tree
Hide file tree
Showing 57 changed files with 880 additions and 568 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"lint-staged": {
"*.{ts,js,mjs}": [
"eslint --cache --fix --max-warnings 0"
"eslint --fix --max-warnings 0"
]
},
"devDependencies": {
Expand Down
8 changes: 6 additions & 2 deletions packages/assetpack/src/manifest/pixiManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ function collectAssets(

if (nonIgnored.length === 0) return;

if (nonIgnored.length === 0) return;

bundleAssets.push({
alias: getShortNames(stripTags(path.relative(entryPath, asset.path)), options),
src: nonIgnored
Expand Down Expand Up @@ -172,5 +170,11 @@ function getShortNames(name: string, options: PixiManifestOptions)
createShortcuts && trimExtensions && allNames.push(path.trimExt(path.basename(name)));
/* eslint-enable @typescript-eslint/no-unused-expressions */

// remove duplicates
const uniqueNames = new Set(allNames);

allNames.length = 0;
uniqueNames.forEach((name) => allNames.push(name));

return allNames;
}
6 changes: 3 additions & 3 deletions packages/assetpack/src/pixi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export function pixiPipes(config: PixiAssetPack)
mipmap({
resolutions: apConfig.resolutions as Record<string, number>,
}),
spineAtlasMipmap({
resolutions: apConfig.resolutions as Record<string, number>,
}),
] as AssetPipe[];

if (apConfig.compression !== false)
{
pipes.push(
compress(apConfig.compression),
spineAtlasMipmap({
resolutions: apConfig.resolutions as Record<string, number>,
}),
spineAtlasCompress(apConfig.compression),
texturePackerCompress(apConfig.compression),
);
Expand Down
11 changes: 0 additions & 11 deletions packages/assetpack/src/texture-packer/packer/createJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ export function createJsons(
};
}

const name = createName(options.textureName, i, bins.length !== 1, options.resolution, options.textureFormat);

let multiPack: string[] | null = null;

if (bins.length > 1 && i === 0)
{
const binsWithoutFirst = bins.slice(1);

multiPack = binsWithoutFirst.map((_, i) => name.replace('-0', `-${i + 1}`).replace('.png', `.json`));
}

json.meta = {
app: 'http://github.com/pixijs/assetpack',
version: '1.0',
Expand Down
106 changes: 94 additions & 12 deletions packages/docs/docs/guide/configuration.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,109 @@
---
sidebar_position: 1
sidebar_position: 0
---

# Configuration
# API Reference

AssetPack uses a config file to define what assets you want to optimise and how you want to optimise them. The config file is a JavaScript file that exports an object with the following properties:

- `entry`: The directory where your raw assets are located.
- `output`: The directory where you want your optimised assets to be outputted to.
- `plugins`: An object containing the plugins you want to use. The key is the name of the plugin, and the value is the plugin itself.
- `ignore`: an optional array of ignore patterns. Any file path matching the patterns will not be processed by assetpack
- `cache`: an optional boolean to enable or disable caching. Defaults to true.
- `logLevel`: an optional string to set the log level. Defaults to 'info'.
- `files`: an optional object to override the settings and tags of any assets. See [Config Overrides](#config-overrides) for more details.
### entry

| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | | Yes |

The directory where your raw assets are located.

### output

| Type | Default | Required |
| -------- | ------- | -------- |
| `string` | | Yes |

The directory where you want your optimised assets to be outputted to.

### ignore

| Type | Default | Required |
| ---------- | ------- | -------- |
| `string[]` | | No |

An optional array of ignore patterns. Any file path matching the patterns will not be processed by assetpack.

### cache

| Type | Default | Required |
| --------- | ------- | -------- |
| `boolean` | `true` | No |

An optional boolean to enable or disable caching.

### cacheLocation

| Type | Default | Required |
| -------- | -------------- | -------- |
| `string` | `'.assetpack'` | No |

An optional string to set the location of the cache.

### logLevel

| Type | Default | Required |
| -------- | -------- | -------- |
| `string` | `'info'` | No |

An optional string to set the log level.

### pipes

| Type | Default | Required |
| -------- | ------- | -------- |
| `Pipe[]` | | No |

An array of pipes to use. For examples of pipes, see [Pipes](/docs/guide/pipes/overview#concepts).

### assetSettings

| Type | Default | Required |
| ---------------- | ------- | -------- |
| `AssetSetting[]` | | No |

| Property | Type | Default | Required |
| -------- | -------- | ------- | -------- |
| files | `string` | | Yes |
| settings | `object` | | No |
| metaData | `object` | | No |

An optional array of asset settings. This allows you to set specific settings for individual assets.

#### Example

```js
// .assetpack.js

export default {
entry: "./raw-assets",
output: "./public",
plugins: {},
entry: './raw-assets',
output: './public',
ignore: ['**/*.html'],
cache: true,
cacheLocation: '.assetpack',
logLevel: 'info',
pipes: [
// Pipes go here
],
assetSettings: [
{
files: ['**/*.png'],
settings: {
compress: {
jpg: true,
png: true,
// all png files will be compressed to avif format but not webp
webp: false,
avif: true,
},
},
},
],
};
```
64 changes: 0 additions & 64 deletions packages/docs/docs/guide/faq.md

This file was deleted.

2 changes: 1 addition & 1 deletion packages/docs/docs/guide/getting-started/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ This will run AssetPack before your build command, and will optimise your assets

## Configuration

- `-c`: The location of the config file to use. Defaults to `.assetpack.js`.
- `-c`: The location of the config file to use. Defaults to `.assetpack.js`. To see a full list of configuration options, see the [API Reference](/docs/guide/configuration).
- `-w`: Watch the assets directory for changes and re-run AssetPack when changes are detected.
68 changes: 68 additions & 0 deletions packages/docs/docs/guide/getting-started/github-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
sidebar_position: 4
title: Github Action
---

# Github Action

:::info
You must enable `cache` in your assetpack configuration to use this feature.

See [API Reference](/docs/guide/configuration#cache) for more information.
:::

AssetPack can be used with GitHub Actions to automate the asset optimisation process and cache the result, improving build times. This guide will show you how to set up a GitHub Action to run AssetPack on your repository.

## Setup

To set up a GitHub Action for AssetPack, you need to create a new workflow file in your repository. Create a new file in the `.github/workflows` directory with the following content:

:::note
This example assumes that your raw assets are located in a directory called `raw-assets` and that you have a `build` script in your `package.json` file that runs AssetPack.

You may need to adjust the paths and commands to match your project structure.
:::

```yaml
name: AssetPack

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install dependencies
run: npm ci

# Cache assets!
- name: Generate hash from file names
id: hash-names
run: echo "NAMES_HASH=$(find ./raw-assets -type f | sort | md5sum | cut -d' ' -f1)" >> $GITHUB_ENV

- name: Cache .assetpack directory
id: cache-directory
uses: actions/cache@v4
with:
path: |
.assetpack
raw-assets
key: ${{ runner.os }}-cache-23-04-24-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('raw-assets/**/*') }}-${{ env.NAMES_HASH }}
restore-keys: |
${{ runner.os }}-cache-23-04-24-${{ hashFiles('**/package-lock.json') }}
# End Cache assets!

# Now do your build
- name: Build
run: npm run build
```
Loading

0 comments on commit 4308963

Please sign in to comment.