From afe76719ed77e6aa971dbe843e9edb0f17809d10 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:53:53 +0100 Subject: [PATCH 1/2] feat: add global `copy` tag (#33) --- src/core/pipes/PipeSystem.ts | 10 + src/webfont/sdf.ts | 5 +- test/core/Assetpack.test.ts | 42 ++++ test/manifest/Manifest.test.ts | 418 ++++++++++++++++++--------------- 4 files changed, 286 insertions(+), 189 deletions(-) diff --git a/src/core/pipes/PipeSystem.ts b/src/core/pipes/PipeSystem.ts index 2e8e55f..3939317 100644 --- a/src/core/pipes/PipeSystem.ts +++ b/src/core/pipes/PipeSystem.ts @@ -1,3 +1,4 @@ +import { finalCopyPipe } from './finalCopyPipe.js'; import { mergePipeOptions } from './mergePipeOptions.js'; import { multiPipe } from './multiPipe.js'; @@ -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)) diff --git a/src/webfont/sdf.ts b/src/webfont/sdf.ts index c6d561e..cbe8527 100644 --- a/src/webfont/sdf.ts +++ b/src/webfont/sdf.ts @@ -12,7 +12,7 @@ export interface SDFFontOptions extends PluginOptions<'font' | 'nc' | 'fix'> font?: Omit; } -export function signedFont( +function signedFont( defaultOptions: SDFFontOptions ): AssetPipe { @@ -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); diff --git a/test/core/Assetpack.test.ts b/test/core/Assetpack.test.ts index e54e18c..30c9bde 100644 --- a/test/core/Assetpack.test.ts +++ b/test/core/Assetpack.test.ts @@ -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'; diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 0c6b8aa..96dfbbf 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -7,23 +7,17 @@ import { compress, mipmap } from '../../src/image/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { spineAtlasManifestMod, spineAtlasMipmap } from '../../src/spine/index.js'; import { texturePacker, texturePackerManifestMod } from '../../src/texture-packer/index.js'; -import { - assetPath, - createFolder, - getCacheDir, - getInputDir, - getOutputDir -} from '../utils/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; import type { File } from '../utils/index.js'; const pkg = 'manifest'; -function genSprites() +function genSprites(total = 10) { const sprites: File[] = []; - for (let i = 0; i < 10; i++) + for (let i = 0; i < total; i++) { sprites.push({ name: `sprite${i}.png`, @@ -116,7 +110,8 @@ describe('Manifest', () => } const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: useCache, pipes: [ @@ -137,13 +132,13 @@ describe('Manifest', () => pixiManifest(), spineAtlasManifestMod(), texturePackerManifestMod(), - ] + ], }); await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[1]).toEqual({ name: 'bundle', @@ -182,10 +177,7 @@ describe('Manifest', () => }, { alias: ['bundle/tps-0'], - src: [ - 'bundle/tps-0@0.5x.json', - 'bundle/tps-0.json', - ], + src: ['bundle/tps-0@0.5x.json', 'bundle/tps-0.json'], data: { tags: { tps: true, @@ -195,10 +187,7 @@ describe('Manifest', () => }, { alias: ['bundle/tps-1'], - src: [ - 'bundle/tps-1@0.5x.json', - 'bundle/tps-1.json', - ], + src: ['bundle/tps-1@0.5x.json', 'bundle/tps-1.json'], data: { tags: { tps: true, @@ -229,18 +218,153 @@ describe('Manifest', () => alias: ['spine/dragon.json'], src: ['spine/dragon.json'], data: { - tags: {} + tags: {}, }, }, { alias: ['spine/dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + data: { + tags: { + spine: true, + }, + }, + }, + ], + }); + }, 30000); + + it('should copy over files and add them to manifest', async () => + { + const testName = 'manifest-copy'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + const useCache = false; + + createFolder(pkg, { + name: testName, + files: [], + + folders: [ + { + name: 'defaultFolder', + files: [ + { + name: 'json{copy}.json', + content: assetPath('json/json.json'), + }, + ], + folders: [ + { + name: 'tps{copy}', + files: genSprites(3), + folders: [], + }, + { + name: 'mip', + files: genSprites(3), + folders: [], + }, + ], + }, + ], + }); + + const assetpack = new AssetPack({ + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: useCache, + pipes: [ + mipmap(), + compress({ + png: true, + jpg: true, + webp: true, + avif: false, + }), + pixiManifest(), + ], + }); + + await assetpack.run(); + + // load the manifest json + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; + + expect(manifest.bundles[0]).toEqual({ + name: 'default', + assets: [ + { + alias: ['defaultFolder/json.json'], + src: ['defaultFolder/json.json'], + data: { + tags: { + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/mip/sprite0.png'], + src: [ + 'defaultFolder/mip/sprite0@0.5x.webp', + 'defaultFolder/mip/sprite0@0.5x.png', + 'defaultFolder/mip/sprite0.webp', + 'defaultFolder/mip/sprite0.png', + ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/mip/sprite1.png'], src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', + 'defaultFolder/mip/sprite1@0.5x.webp', + 'defaultFolder/mip/sprite1@0.5x.png', + 'defaultFolder/mip/sprite1.webp', + 'defaultFolder/mip/sprite1.png', ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/mip/sprite2.png'], + src: [ + 'defaultFolder/mip/sprite2@0.5x.webp', + 'defaultFolder/mip/sprite2@0.5x.png', + 'defaultFolder/mip/sprite2.webp', + 'defaultFolder/mip/sprite2.png', + ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/tps/sprite0.png'], + src: ['defaultFolder/tps/sprite0.png'], data: { tags: { - spine: true, + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/tps/sprite1.png'], + src: ['defaultFolder/tps/sprite1.png'], + data: { + tags: { + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/tps/sprite2.png'], + src: ['defaultFolder/tps/sprite2.png'], + data: { + tags: { + copy: true, }, }, }, @@ -323,7 +447,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -342,7 +467,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: true, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -358,77 +483,39 @@ describe('Manifest', () => name: 'default', assets: [ { - alias: [ - 'folder/json.json', - 'json.json', - ], - src: [ - 'folder/json.json' - ] + alias: ['folder/json.json', 'json.json'], + src: ['folder/json.json'], }, { - alias: [ - 'folder/json.json5', - 'json.json5', - ], - src: [ - 'folder/json.json5' - ] + alias: ['folder/json.json5', 'json.json5'], + src: ['folder/json.json5'], }, { - alias: [ - 'folder/sprite.png', - 'folder/sprite', - 'sprite.png', - 'sprite' - ], + alias: ['folder/sprite.png', 'folder/sprite', 'sprite.png', 'sprite'], src: [ 'folder/sprite@0.5x.webp', 'folder/sprite@0.5x.png', 'folder/sprite.webp', 'folder/sprite.png', - ] + ], }, { - alias: [ - 'folder2/1.mp3', - 'folder2/1', - ], - src: [ - 'folder2/1.ogg', - 'folder2/1.mp3', - ] + alias: ['folder2/1.mp3', 'folder2/1'], + src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: [ - 'folder2/folder3/1.mp3', - 'folder2/folder3/1', - ], - src: [ - 'folder2/folder3/1.ogg', - 'folder2/folder3/1.mp3', - ] + alias: ['folder2/folder3/1.mp3', 'folder2/folder3/1'], + src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { - alias: [ - 'spine/dragon.json', - 'dragon.json', - ], - src: [ - 'spine/dragon.json' - ] + alias: ['spine/dragon.json', 'dragon.json'], + src: ['spine/dragon.json'], }, { - alias: [ - 'spine/dragon.atlas', - 'dragon.atlas', - ], - src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', - ] - } - ] + alias: ['spine/dragon.atlas', 'dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + }, + ], }); }); @@ -464,7 +551,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -477,7 +565,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: false, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -487,23 +575,16 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ - name: 'default', assets: [ { - alias: [ - 'spine/dragon.atlas', - 'dragon.atlas' - ], - src: [ - 'spine/dragon.atlas' - ] - } - ] - + alias: ['spine/dragon.atlas', 'dragon.atlas'], + src: ['spine/dragon.atlas'], + }, + ], }); }); @@ -582,7 +663,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), cache: false, output: outputDir, pipes: [ @@ -601,7 +683,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: false, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -611,7 +693,7 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ name: 'default', @@ -728,7 +810,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -747,7 +830,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: false, trimExtensions: true, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -757,78 +840,45 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ name: 'default', assets: [ { - alias: [ - 'folder/json.json' - ], - src: [ - 'folder/json.json' - ] + alias: ['folder/json.json'], + src: ['folder/json.json'], }, { - alias: [ - 'folder/json.json5' - ], - src: [ - 'folder/json.json5' - ] + alias: ['folder/json.json5'], + src: ['folder/json.json5'], }, { - alias: [ - 'folder/sprite.png', - 'folder/sprite' - ], + alias: ['folder/sprite.png', 'folder/sprite'], src: [ 'folder/sprite@0.5x.webp', 'folder/sprite@0.5x.png', 'folder/sprite.webp', 'folder/sprite.png', - ] + ], }, { - alias: [ - 'folder2/1.mp3', - 'folder2/1' - ], - src: [ - 'folder2/1.ogg', - 'folder2/1.mp3', - ] + alias: ['folder2/1.mp3', 'folder2/1'], + src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: [ - 'folder2/folder3/1.mp3', - 'folder2/folder3/1', - ], - src: [ - 'folder2/folder3/1.ogg', - 'folder2/folder3/1.mp3', - ] + alias: ['folder2/folder3/1.mp3', 'folder2/folder3/1'], + src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { - alias: [ - 'spine/dragon.json' - ], - src: [ - 'spine/dragon.json' - ] + alias: ['spine/dragon.json'], + src: ['spine/dragon.json'], }, { - alias: [ - 'spine/dragon.atlas' - ], - src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', - ] - } - ] - + alias: ['spine/dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + }, + ], }); }); @@ -856,7 +906,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -907,12 +958,13 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ pixiManifest({ - includeMetaData: false + includeMetaData: false, }), ], }); @@ -923,59 +975,53 @@ describe('Manifest', () => bundles: [ { name: 'default', - assets: [] + assets: [], }, { name: 'sound2', assets: [ { - alias: [ - 'sound2/2.mp3' - ], - src: [ - 'sound2/2.mp3' - ] - } - ] + alias: ['sound2/2.mp3'], + src: ['sound2/2.mp3'], + }, + ], }, { name: 'sound', assets: [ { - alias: [ - 'sound/1.mp3' - ], - src: [ - 'sound/1.mp3' - ] - } - ] - } - ] + alias: ['sound/1.mp3'], + src: ['sound/1.mp3'], + }, + ], + }, + ], }); }); }); function sortObjectProperties(obj: any) { - return Object.keys(obj).sort().reduce((acc: any, key: string) => - { - const value = obj[key]; - - if (typeof value === 'object' && !Array.isArray(value) && value !== null) + return Object.keys(obj) + .sort() + .reduce((acc: any, key: string) => { - acc[key] = sortObjectProperties(value); - } - else - { - if (Array.isArray(value)) + const value = obj[key]; + + if (typeof value === 'object' && !Array.isArray(value) && value !== null) { - value.sort(); + acc[key] = sortObjectProperties(value); } + else + { + if (Array.isArray(value)) + { + value.sort(); + } - acc[key] = value; - } + acc[key] = value; + } - return acc; - }, {}); + return acc; + }, {}); } From 9c48d84ad5a0a310322ed531a8fe2e5ea4546a08 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:57:49 +0100 Subject: [PATCH 2/2] feat: add mIgnore tag (#34) --- .eslintrc.cjs | 10 +++--- src/manifest/pixiManifest.ts | 35 ++++++++++++-------- src/spine/spineAtlasCacheBuster.ts | 4 ++- src/spine/spineAtlasManifestMod.ts | 4 ++- src/webfont/sdf.ts | 4 ++- test/manifest/Manifest.test.ts | 52 ++++++++++++++++++++++++++++++ test/webfont/Webfont.test.ts | 47 +++++++++++++++++++++++++-- 7 files changed, 133 insertions(+), 23 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index a7ae364..f455dbe 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,15 +5,17 @@ module.exports = { ecmaVersion: 2020, sourceType: "module", }, + plugins: ['import'], rules: { "spaced-comment": [1, "always", { markers: ["/"] }], "@typescript-eslint/triple-slash-reference": [1, { path: "always" }], - "@typescript-eslint/consistent-type-imports": [ - 1, - { disallowTypeAnnotations: false }, - ], "@typescript-eslint/type-annotation-spacing": 1, "@typescript-eslint/no-non-null-assertion": 0, + "@typescript-eslint/consistent-type-imports": + ["error", { disallowTypeAnnotations: false }], + "import/consistent-type-specifier-style": ["error", "prefer-top-level"], + "import/no-duplicates": ["error"], + "camelcase": 0, }, overrides: [ { diff --git a/src/manifest/pixiManifest.ts b/src/manifest/pixiManifest.ts index 9fc4f2e..bd630dd 100644 --- a/src/manifest/pixiManifest.ts +++ b/src/manifest/pixiManifest.ts @@ -1,10 +1,10 @@ import fs from 'fs-extra'; -import { - type Asset, - type AssetPipe, - path, - type PipeSystem, - stripTags +import { path, stripTags } from '../core/index.js'; + +import type { + Asset, + AssetPipe, + PipeSystem, PluginOptions } from '../core/index.js'; export interface PixiBundle @@ -28,7 +28,7 @@ export interface PixiManifestEntry }; } -export interface PixiManifestOptions +export interface PixiManifestOptions extends PluginOptions<'mIgnore' | 'manifest'> { output?: string; createShortcuts?: boolean; @@ -38,12 +38,16 @@ export interface PixiManifestOptions export function pixiManifest(_options: PixiManifestOptions = {}): AssetPipe { - const defaultOptions = { + const defaultOptions: PixiManifestOptions = { output: 'manifest.json', createShortcuts: false, trimExtensions: false, includeMetaData: true, - ..._options + ..._options, + tags: { + manifest: 'm', + mIgnore: 'mIgnore' + } }; return { @@ -98,7 +102,7 @@ function collectAssets( outputPath = '', entryPath = '', bundles: PixiBundle[], - bundle: PixiBundle, + bundle: PixiBundle ) { if (asset.skip) return; @@ -107,7 +111,7 @@ function collectAssets( let localBundle = bundle; - if (asset.metaData.m || asset.metaData.manifest) + if (asset.metaData[options.tags!.manifest!]) { localBundle = { name: stripTags(asset.filename), @@ -118,14 +122,17 @@ function collectAssets( } const bundleAssets = localBundle.assets; - const finalAssets = asset.getFinalTransformedChildren(); - if (asset.transformChildren.length > 0) + if (asset.transformChildren.length > 0 && !asset.inheritedMetaData[options.tags!.mIgnore!]) { + const nonIgnored = finalAssets.filter((finalAsset) => !finalAsset.inheritedMetaData[options.tags!.mIgnore!]); + + if (nonIgnored.length === 0) return; + bundleAssets.push({ alias: getShortNames(stripTags(path.relative(entryPath, asset.path)), options), - src: finalAssets + src: nonIgnored .map((finalAsset) => path.relative(outputPath, finalAsset.path)) .sort((a, b) => b.localeCompare(a)), data: options.includeMetaData ? { diff --git a/src/spine/spineAtlasCacheBuster.ts b/src/spine/spineAtlasCacheBuster.ts index 8c12799..2e17ab3 100644 --- a/src/spine/spineAtlasCacheBuster.ts +++ b/src/spine/spineAtlasCacheBuster.ts @@ -1,7 +1,9 @@ import fs from 'fs-extra'; -import { type Asset, type AssetPipe, checkExt, findAssets } from '../core/index.js'; +import { checkExt, findAssets } from '../core/index.js'; import { AtlasView } from './AtlasView.js'; +import type { Asset, AssetPipe } from '../core/index.js'; + /** * This should be used after the cache buster plugin in the pipes. * As it relies on the cache buster plugin to have already cache busted all files. diff --git a/src/spine/spineAtlasManifestMod.ts b/src/spine/spineAtlasManifestMod.ts index 83bf87d..2a99cd5 100644 --- a/src/spine/spineAtlasManifestMod.ts +++ b/src/spine/spineAtlasManifestMod.ts @@ -1,7 +1,9 @@ import fs from 'fs-extra'; -import { type Asset, type AssetPipe, findAssets, path } from '../core/index.js'; +import { findAssets, path } from '../core/index.js'; import { AtlasView } from './AtlasView.js'; +import type { Asset, AssetPipe } from '../core/index.js'; + export interface SpineManifestOptions { output?: string; diff --git a/src/webfont/sdf.ts b/src/webfont/sdf.ts index cbe8527..fa308ca 100644 --- a/src/webfont/sdf.ts +++ b/src/webfont/sdf.ts @@ -45,7 +45,9 @@ function signedFont( const newTextureAsset = createNewAssetAt(asset, newTextureName); // don't compress! - newTextureAsset.metaData.copy = true; + newTextureAsset.metaData[options.tags.nc] = true; + newTextureAsset.metaData[options.tags.fix] = true; + newTextureAsset.metaData.mIgnore = true; assets.push(newTextureAsset); diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 96dfbbf..29ae8a8 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -998,6 +998,58 @@ describe('Manifest', () => ], }); }); + + it('should ignore files with the mIgnore tag', async () => + { + const testName = 'manifest-ignore'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + createFolder(pkg, { + name: testName, + files: [ + { + name: '1.png', + content: assetPath('image/sp-1.png'), + }, + { + name: '2{mIgnore}.png', + content: assetPath('image/sp-1.png'), + }, + ], + folders: [], + }); + + const assetpack = new AssetPack({ + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: false, + pipes: [ + pixiManifest({ + includeMetaData: false, + }), + ], + }); + + await assetpack.run(); + + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)); + + expect(manifest).toEqual({ + bundles: [ + { + name: 'default', + assets: [ + { + alias: ['1.png'], + src: ['1.png'], + }, + ], + }, + ], + }); + }); }); function sortObjectProperties(obj: any) diff --git a/test/webfont/Webfont.test.ts b/test/webfont/Webfont.test.ts index f694367..7c7ef5b 100644 --- a/test/webfont/Webfont.test.ts +++ b/test/webfont/Webfont.test.ts @@ -2,6 +2,8 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; import { AssetPack } from '../../src/core/index.js'; +import { compress } from '../../src/image/compress.js'; +import { mipmap } from '../../src/image/mipmap.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { msdfFont, sdfFont, webfont } from '../../src/webfont/index.js'; import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; @@ -228,7 +230,7 @@ describe('Webfont', () => expect(existsSync(`${outputDir}/sdf.1.png`)).toBe(true); }); - it.skip('should generate manifest correctly', async () => + it('should generate manifest correctly', async () => { const testName = 'webfont-manifest'; const inputDir = getInputDir(pkg, testName); @@ -258,6 +260,26 @@ describe('Webfont', () => ], folders: [], }, + { + name: 'msdfFolder{msdf}', + files: [ + { + name: 'ttf.ttf', + content: assetPath('font/Roboto-Regular.ttf'), + }, + ], + folders: [], + }, + { + name: 'svgFolder{wf}', + files: [ + { + name: 'svg.svg', + content: assetPath('font/Roboto-Regular.svg'), + }, + ], + folders: [], + } ], }); @@ -266,8 +288,11 @@ describe('Webfont', () => output: outputDir, cache: false, pipes: [ - webfont(), // import is breaking definition file + webfont(), sdfFont(), + msdfFont(), + mipmap(), + compress(), pixiManifest(), ] }); @@ -289,6 +314,15 @@ describe('Webfont', () => } } }, + { + alias: ['msdfFolder/ttf.ttf'], + src: ['msdfFolder/ttf.fnt'], + data: { + tags: { + msdf: true, + } + } + }, { alias: ['sdfFolder/ttf.ttf'], src: ['sdfFolder/ttf.fnt'], @@ -298,6 +332,15 @@ describe('Webfont', () => } } }, + { + alias: ['svgFolder/svg.svg'], + src: ['svgFolder/svg.woff2'], + data: { + tags: { + wf: true, + } + } + }, ], }); });