diff --git a/packages/core/src/Asset.ts b/packages/core/src/Asset.ts index 550ed23..e3902d0 100644 --- a/packages/core/src/Asset.ts +++ b/packages/core/src/Asset.ts @@ -31,6 +31,7 @@ export class Asset metaData: Record = {}; inheritedMetaData: Record = {}; allMetaData: Record = {}; + transformData: Record = {}; settings?: Record; @@ -62,6 +63,7 @@ export class Asset asset.parent = this; asset.inheritedMetaData = { ...this.inheritedMetaData, ...this.metaData }; + asset.transformData = { ...this.transformData }; asset.allMetaData = { ...asset.inheritedMetaData, ...asset.metaData }; } @@ -84,6 +86,7 @@ export class Asset asset.transformParent = this; asset.inheritedMetaData = { ...this.inheritedMetaData, ...this.metaData }; + asset.transformData = { ...this.transformData }; asset.allMetaData = { ...asset.inheritedMetaData, ...asset.metaData }; diff --git a/packages/core/src/pipes/mergePipeOptions.ts b/packages/core/src/pipes/mergePipeOptions.ts index 93741e1..24b55e9 100644 --- a/packages/core/src/pipes/mergePipeOptions.ts +++ b/packages/core/src/pipes/mergePipeOptions.ts @@ -1,9 +1,11 @@ +import { merge } from '../utils/merge'; + import type { Asset } from '../Asset'; -import type { AssetPipe } from './AssetPipe'; +import type { AssetPipe, PluginOptions } from './AssetPipe'; -export function mergePipeOptions(pipe: AssetPipe, asset: Asset): T +export function mergePipeOptions>(pipe: AssetPipe, asset: Asset): T { if (!asset.settings) return pipe.defaultOptions; - return { ...pipe.defaultOptions, ...asset.settings }; + return merge.recursive(pipe.defaultOptions, asset.settings); } diff --git a/packages/ffmpeg/src/audio.ts b/packages/ffmpeg/src/audio.ts index 160e16d..f66fa17 100644 --- a/packages/ffmpeg/src/audio.ts +++ b/packages/ffmpeg/src/audio.ts @@ -34,5 +34,7 @@ export function audio(_options?: FfmpegOptions): AssetPipe const audio = ffmpeg(merge(true, defaultOptions, _options)); + audio.name = 'audio'; + return audio; } diff --git a/packages/spine/src/spineAtlasCompress.ts b/packages/spine/src/spineAtlasCompress.ts index 1ea8dfd..f398e9a 100644 --- a/packages/spine/src/spineAtlasCompress.ts +++ b/packages/spine/src/spineAtlasCompress.ts @@ -11,7 +11,7 @@ export function spineAtlasCompress(_options?: SpineAtlasCompressOptions): AssetP const defaultOptions = { ..._options, tags: { - tps: 'nc', + nc: 'nc', ..._options?.tags } }; diff --git a/packages/texture-packer/src/texturePacker.ts b/packages/texture-packer/src/texturePacker.ts index 2bc4b03..f3e9345 100644 --- a/packages/texture-packer/src/texturePacker.ts +++ b/packages/texture-packer/src/texturePacker.ts @@ -6,7 +6,7 @@ import { createNewAssetAt, Logger, path, stripTags } from '@play-co/assetpack-co import type { PackTexturesOptions, TexturePackerFormat } from './packer/packTextures'; import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; -export interface TexturePackerOptions extends PluginOptions<'tps' | 'fix' | 'jpg' | 'nc' > +export interface TexturePackerOptions extends PluginOptions<'tps' | 'fix' | 'jpg' > { texturePacker?: Partial; resolutionOptions?: { @@ -66,7 +66,6 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe; /** * This should be used after the cache buster plugin in the pipes. @@ -17,9 +19,16 @@ import type { Asset } from '@play-co/assetpack-core'; * @param _options * @returns */ -export function texturePackerCacheBuster(): AssetPipe +export function texturePackerCacheBuster( + _options: TexturePackerCacheBustOptions = {} +): AssetPipe { - const defaultOptions = {}; + const defaultOptions = { + tags: { + tps: 'tps', + ..._options.tags, + }, + }; const textureJsonFilesToFix: Asset[] = []; @@ -27,9 +36,9 @@ export function texturePackerCacheBuster(): AssetPipe folder: false, name: 'texture-packer-cache-buster', defaultOptions, - test(asset: Asset, _options) + test(asset: Asset, options) { - return asset.allMetaData.tps && checkExt(asset.path, '.json'); + return asset.allMetaData[options.tags.tps] && checkExt(asset.path, '.json'); }, async transform(asset: Asset, _options) diff --git a/packages/texture-packer/src/texturePackerManifestMod.ts b/packages/texture-packer/src/texturePackerManifestMod.ts index 954ca7b..844476c 100644 --- a/packages/texture-packer/src/texturePackerManifestMod.ts +++ b/packages/texture-packer/src/texturePackerManifestMod.ts @@ -1,9 +1,9 @@ import fs from 'fs-extra'; import { type AssetPipe, findAssets, path } from '@play-co/assetpack-core'; -import type { Asset } from '@play-co/assetpack-core'; +import type { Asset, PluginOptions } from '@play-co/assetpack-core'; -export interface TexturePackerManifestOptions +export interface TexturePackerManifestOptions extends PluginOptions<'tps'> { output?: string; } @@ -34,7 +34,11 @@ export function texturePackerManifestMod( { const defaultOptions = { output: 'manifest.json', - ..._options + ..._options, + tags: { + tps: 'tps', + ..._options.tags, + }, }; return { @@ -63,7 +67,7 @@ export function texturePackerManifestMod( const duplicateHash: Record = {}; const originalJsonAssets = findAssets((asset) => - asset.metaData.tps && !asset.transformParent, asset, true); + asset.metaData[options.tags.tps] && !asset.transformParent, asset, true); originalJsonAssets.forEach((originalJsonAsset) => { @@ -120,9 +124,9 @@ function getTexturePackedAssets(assets: Asset[]) { const jsonAsset = jsonAssets[i]; - groupAssets[jsonAsset.allMetaData.page] ??= []; + groupAssets[jsonAsset.transformData.page] ??= []; - groupAssets[jsonAsset.allMetaData.page].push(jsonAsset); + groupAssets[jsonAsset.transformData.page].push(jsonAsset); } return groupAssets; diff --git a/packages/webfont/src/sdf.ts b/packages/webfont/src/sdf.ts index 84fcf28..4b30884 100644 --- a/packages/webfont/src/sdf.ts +++ b/packages/webfont/src/sdf.ts @@ -6,7 +6,7 @@ import { checkExt, createNewAssetAt, stripTags } from '@play-co/assetpack-core'; import type { BitmapFontOptions } from 'msdf-bmfont-xml'; import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; -export interface SDFFontOptions extends PluginOptions<'sdf'> +export interface SDFFontOptions extends PluginOptions<'font' | 'nc' | 'fix'> { name: string, type: BitmapFontOptions['fieldType'], @@ -23,7 +23,7 @@ export function signedFont( defaultOptions, test(asset: Asset, options) { - return asset.allMetaData[options.type] && checkExt(asset.path, '.ttf'); + return asset.allMetaData[options.tags.font] && checkExt(asset.path, '.ttf'); }, async transform(asset: Asset, options) { @@ -46,8 +46,8 @@ export function signedFont( const newTextureAsset = createNewAssetAt(asset, newTextureName); // don't compress! - newTextureAsset.metaData.nc = true; - newTextureAsset.metaData.fix = true; + newTextureAsset.metaData[options.tags.nc] = true; + newTextureAsset.metaData[options.tags.fix] = true; assets.push(newTextureAsset); @@ -72,16 +72,28 @@ export function sdfFont(options: Partial = {}): AssetPipe return signedFont({ name: 'sdf-font', type: 'sdf', - ...options + ...options, + tags: { + font: 'sdf', + nc: 'nc', + fix: 'fix', + ...options.tags + } }); } -export function msdfFont(options?: Partial): AssetPipe +export function msdfFont(options: Partial = {}): AssetPipe { return signedFont({ name: 'msdf-font', type: 'msdf', ...options, + tags: { + font: 'msdf', + nc: 'nc', + fix: 'fix', + ...options.tags + } }); } diff --git a/packages/webfont/src/webfont.ts b/packages/webfont/src/webfont.ts index 9687d94..a789424 100644 --- a/packages/webfont/src/webfont.ts +++ b/packages/webfont/src/webfont.ts @@ -1,14 +1,17 @@ import { fonts } from './fonts'; import { checkExt, createNewAssetAt, path } from '@play-co/assetpack-core'; -import type { Asset, AssetPipe } from '@play-co/assetpack-core'; +import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; -export function webfont(): AssetPipe +export type WebfontOptions = PluginOptions<'wf'>; + +export function webfont(_options?: Partial): AssetPipe { - const defaultOptions = { + const defaultOptions: WebfontOptions = { tags: { wf: 'wf', - } + ..._options?.tags + }, }; return { @@ -17,7 +20,7 @@ export function webfont(): AssetPipe defaultOptions, test(asset: Asset, options) { - return asset.metaData[options.tags.wf as any] && checkExt(asset.path, '.otf', '.ttf', '.svg'); + return asset.allMetaData[options.tags.wf] && checkExt(asset.path, '.otf', '.ttf', '.svg'); }, async transform(asset: Asset) {