Skip to content

Commit

Permalink
feat: add global copy tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Jun 19, 2024
1 parent c384a9d commit 85d5a31
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 189 deletions.
10 changes: 10 additions & 0 deletions src/core/pipes/PipeSystem.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { finalCopyPipe } from './finalCopyPipe.js';
import { mergePipeOptions } from './mergePipeOptions.js';
import { multiPipe } from './multiPipe.js';

Expand Down Expand Up @@ -72,6 +73,15 @@ export class PipeSystem

pipeIndex++;

// if the asset has the copy tag on it, then the only pipe that should be run is the final copy pipe
// this is to ensure that the asset is copied to the output directory without any other processing
if (asset.allMetaData.copy && pipe !== finalCopyPipe)
{
await this._transform(asset, pipeIndex);

return;
}

const options = mergePipeOptions(pipe, asset);

if (options !== false && pipe.transform && pipe.test?.(asset, options))
Expand Down
5 changes: 2 additions & 3 deletions src/webfont/sdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SDFFontOptions extends PluginOptions<'font' | 'nc' | 'fix'>
font?: Omit<BitmapFontOptions, 'outputType' | 'fieldType'>;
}

export function signedFont(
function signedFont(
defaultOptions: SDFFontOptions
): AssetPipe<SDFFontOptions>
{
Expand Down Expand Up @@ -45,8 +45,7 @@ export function signedFont(
const newTextureAsset = createNewAssetAt(asset, newTextureName);

// don't compress!
newTextureAsset.metaData[options.tags.nc] = true;
newTextureAsset.metaData[options.tags.fix] = true;
newTextureAsset.metaData.copy = true;

assets.push(newTextureAsset);

Expand Down
42 changes: 42 additions & 0 deletions test/core/Assetpack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,48 @@ describe('Core', () =>
expect(existsSync(join(outputDir, 'scripts/test.json'))).toBe(false);
});

it('should copy assets when copy tag is used', async () =>
{
const testName = 'copy-tag';
const inputDir = getInputDir(pkg, testName);
const outputDir = getOutputDir(pkg, testName);

createFolder(
pkg,
{
name: testName,
files: [],
folders: [{
name: 'scripts{copy}',
files: [{
name: 'json.json',
content: assetPath('json/json.json'),
}],
folders: [],
},
{
name: 'scripts2',
files: [{
name: 'json{copy}.json',
content: assetPath('json/json.json'),
}],
folders: [],
}],
});

const assetpack = new AssetPack({
entry: inputDir,
output: outputDir,
cache: false,
ignore: ['**/scripts/**/*'],
});

await assetpack.run();

expect(existsSync(join(outputDir, 'scripts/json.json'))).toBe(true);
expect(existsSync(join(outputDir, 'scripts2/json.json'))).toBe(true);
});

it('should provide the correct options overrides to the plugin', async () =>
{
const testName = 'plugin-options-override';
Expand Down
Loading

0 comments on commit 85d5a31

Please sign in to comment.