diff --git a/packages/assetpack/src/core/Asset.ts b/packages/assetpack/src/core/Asset.ts index 57dcd3e..e60fee5 100644 --- a/packages/assetpack/src/core/Asset.ts +++ b/packages/assetpack/src/core/Asset.ts @@ -30,9 +30,7 @@ export class Asset metaData: Record = {}; inheritedMetaData: Record = {}; - allMetaData: Record = {}; transformData: Record = {}; - manifestData: Record = {}; settings?: Record; @@ -64,7 +62,6 @@ export class Asset asset.parent = this; asset.inheritedMetaData = { ...this.inheritedMetaData, ...this.metaData }; - asset.allMetaData = { ...asset.inheritedMetaData, ...asset.metaData }; asset.transformData = { ...this.transformData, ...asset.transformData }; } @@ -88,12 +85,16 @@ export class Asset asset.transformParent = this; asset.inheritedMetaData = { ...this.inheritedMetaData, ...this.metaData }; - asset.allMetaData = { ...asset.inheritedMetaData, ...asset.metaData }; asset.transformData = { ...this.transformData, ...asset.transformData }; asset.settings = this.settings; } + get allMetaData() + { + return { ...this.inheritedMetaData, ...this.metaData }; + } + get state() { return this._state; @@ -254,20 +255,38 @@ export class Asset } /** - * Update the manifest data with certain keys from the metaData - * @param keys - keys to apply from the metaData to the manifestData + * Get the public meta data for this asset + * This will exclude any internal data */ - applyManifestData(keys: string[]) + getPublicMetaData(internalPipeData: Record) { - for (let i = 0; i < keys.length; i++) + const internalKeys = new Set(Object.keys(internalPipeData)); + const metaData = Object.keys(this.allMetaData).reduce((result: Record, key) => { - const key = keys[i]; + if (!internalKeys.has(key)) + { + result[key] = this.allMetaData[key]; + } + + return result; + }, {} as Record); - if (this.metaData[key] !== undefined) + return metaData; + } + + getInternalMetaData(internalPipeData: Record) + { + const res: Record = {}; + + Object.keys(internalPipeData).forEach((key) => + { + if (this.allMetaData[key]) { - this.manifestData[key] = this.metaData[key]; + res[key] = this.allMetaData[key]; } - } + }); + + return res; } } diff --git a/packages/assetpack/src/core/pipes/AssetPipe.ts b/packages/assetpack/src/core/pipes/AssetPipe.ts index 26e203d..1662ba3 100644 --- a/packages/assetpack/src/core/pipes/AssetPipe.ts +++ b/packages/assetpack/src/core/pipes/AssetPipe.ts @@ -17,7 +17,7 @@ export type DeepRequired = T extends Primitive }; export interface PluginOptions {} -export interface AssetPipe, TAGS extends string = string, DATA_TAGS extends string = string> +export interface AssetPipe, TAGS extends string = string, INTERNAL_TAGS extends string = string> { /** Whether the process runs on a folder */ folder?: boolean; @@ -32,10 +32,9 @@ export interface AssetPipe, TAGS extends string = st tags?: Record; /** - * Any tags here will be placed in the manifests `data` object - * This can be used to pass data to loaders more easily + * Any tags here will not be placed in the manifest data. */ - dataTags?: Record; + internalTags?: Record; /** * Called once at the start. diff --git a/packages/assetpack/src/core/pipes/PipeSystem.ts b/packages/assetpack/src/core/pipes/PipeSystem.ts index 470e61e..6b14e85 100644 --- a/packages/assetpack/src/core/pipes/PipeSystem.ts +++ b/packages/assetpack/src/core/pipes/PipeSystem.ts @@ -28,6 +28,11 @@ export class PipeSystem assetSettings: AssetSettings[] = []; + internalMetaData: Record = { + copy: 'copy', + ignore: 'ignore', + }; + constructor(options: PipeSystemOptions) { const pipes = []; @@ -49,6 +54,7 @@ export class PipeSystem options.pipes.flat().forEach((pipe) => { this.pipeHash[pipe.name] = pipe; + this.internalMetaData = { ...this.internalMetaData, ...Object.values(pipe.internalTags ?? pipe.tags ?? {}).reduce((acc, tag) => ({ ...acc, [tag]: true }), {}) }; }); this.pipes = pipes; @@ -88,8 +94,6 @@ export class PipeSystem { asset.transformName = pipe.name; asset.transformChildren = []; - // apply the dataTags of the pipe to the asset so it can be used by pixi and other loaders - asset.applyManifestData(Object.values(pipe.dataTags ?? {})); const assets = await pipe.transform(asset, options, this); diff --git a/packages/assetpack/src/image/compress.ts b/packages/assetpack/src/image/compress.ts index 92ba323..12be771 100644 --- a/packages/assetpack/src/image/compress.ts +++ b/packages/assetpack/src/image/compress.ts @@ -67,7 +67,7 @@ export function compress(options: CompressOptions = {}): AssetPipe @@ -45,6 +84,7 @@ export function pixiManifest(_options: PixiManifestOptions = {}): AssetPipe['tags'] + tags: AssetPipe['tags'], + internalTags: Record ) { if (asset.skip) return; @@ -137,21 +179,28 @@ function collectAssets( if (finalManifestAssets.length === 0) return; + const metadata = { + tags: { ...asset.getInternalMetaData(internalTags) }, + ...asset.getPublicMetaData(internalTags) + } as Record; + + if (options.legacyMetaDataOutput) + { + metadata.tags = asset.allMetaData; + } + bundleAssets.push({ alias: getShortNames(stripTags(path.relative(entryPath, asset.path)), options), src: finalManifestAssets .map((finalAsset) => path.relative(outputPath, finalAsset.path)) .sort((a, b) => b.localeCompare(a)), - data: options.includeMetaData ? { - tags: asset.allMetaData, - ...asset.manifestData - } : undefined + data: options.includeMetaData ? metadata : undefined }); } asset.children.forEach((child) => { - collectAssets(child, options, outputPath, entryPath, bundles, localBundle, tags); + collectAssets(child, options, outputPath, entryPath, bundles, localBundle, tags, internalTags); }); // for all assets.. check for atlas and remove them from the bundle.. diff --git a/packages/assetpack/src/webfont/sdf.ts b/packages/assetpack/src/webfont/sdf.ts index 8bfc490..5749f09 100644 --- a/packages/assetpack/src/webfont/sdf.ts +++ b/packages/assetpack/src/webfont/sdf.ts @@ -14,7 +14,7 @@ export interface SDFFontOptions extends PluginOptions function signedFont( defaultOptions: SDFFontOptions -): AssetPipe +): AssetPipe { return { folder: false, @@ -25,9 +25,6 @@ function signedFont( nc: 'nc', fix: 'fix', }, - dataTags: { - family: 'family', - }, test(asset: Asset) { return asset.allMetaData[this.tags!.font] && checkExt(asset.path, '.ttf'); @@ -37,7 +34,7 @@ function signedFont( const newFileName = stripTags(asset.filename.replace(/\.(ttf)$/i, '')); // set the family name to the filename if it doesn't exist - asset.manifestData.family = asset.metaData.family ?? path.trimExt(asset.filename); + asset.metaData.family ??= path.trimExt(asset.filename); const { font, textures } = await GenerateFont(asset.path, { ...options.font, filename: newFileName, diff --git a/packages/assetpack/src/webfont/webfont.ts b/packages/assetpack/src/webfont/webfont.ts index 1fcd451..8802402 100644 --- a/packages/assetpack/src/webfont/webfont.ts +++ b/packages/assetpack/src/webfont/webfont.ts @@ -3,7 +3,7 @@ import { fonts } from './fonts.js'; import type { Asset, AssetPipe } from '../core/index.js'; -export function webfont(): AssetPipe +export function webfont(): AssetPipe { return { folder: false, @@ -12,9 +12,6 @@ export function webfont(): AssetPipe tags: { wf: 'wf', }, - dataTags: { - family: 'family', - }, test(asset: Asset) { return asset.allMetaData[this.tags!.wf] && checkExt(asset.path, '.otf', '.ttf', '.svg'); @@ -48,7 +45,7 @@ export function webfont(): AssetPipe newAsset.buffer = buffer; // set the family name to the filename if it doesn't exist - asset.manifestData.family = asset.metaData.family ?? path.trimExt(asset.filename); + asset.metaData.family ??= path.trimExt(asset.filename); return [newAsset]; } diff --git a/packages/assetpack/test/manifest/Manifest.test.ts b/packages/assetpack/test/manifest/Manifest.test.ts index cd29400..bfbae6d 100644 --- a/packages/assetpack/test/manifest/Manifest.test.ts +++ b/packages/assetpack/test/manifest/Manifest.test.ts @@ -218,6 +218,7 @@ describe('Manifest', () => alias: ['spine/dragon.atlas'], src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], data: { + spine: true, tags: { spine: true, }, diff --git a/packages/assetpack/test/spine/spineAtlasManifest.test.ts b/packages/assetpack/test/spine/spineAtlasManifest.test.ts index 2a24b3d..f546e62 100644 --- a/packages/assetpack/test/spine/spineAtlasManifest.test.ts +++ b/packages/assetpack/test/spine/spineAtlasManifest.test.ts @@ -78,6 +78,7 @@ describe('Atlas Manifest', () => 'dragon.atlas' ], data: { + spine: true, tags: { spine: true } @@ -182,6 +183,7 @@ describe('Atlas Manifest', () => 'dragon.atlas' ], data: { + spine: true, tags: { spine: true } @@ -206,6 +208,7 @@ describe('Atlas Manifest', () => 'nested/dragon.atlas' ], data: { + spine: true, tags: { spine: true } diff --git a/packages/assetpack/test/webfont/Webfont.test.ts b/packages/assetpack/test/webfont/Webfont.test.ts index 1593a7c..ea7e695 100644 --- a/packages/assetpack/test/webfont/Webfont.test.ts +++ b/packages/assetpack/test/webfont/Webfont.test.ts @@ -293,7 +293,7 @@ describe('Webfont', () => msdfFont(), mipmap(), compress(), - pixiManifest(), + pixiManifest({ legacyMetaDataOutput: false }), ] });