From 8aca5202f43397e7af53f93047ee96740af0f72c Mon Sep 17 00:00:00 2001 From: Mat Groves Date: Fri, 19 Apr 2024 21:05:44 +0100 Subject: [PATCH] - add skip property and skipChildren - fixed json and test - fixed texture packer still creating individual images - ensure output is removed if the cache key changes --- packages/core/src/Asset.ts | 13 ++++++++++++- packages/core/src/AssetPack.ts | 14 +++++++++----- packages/json/src/index.ts | 2 +- packages/json/test/Json.test.ts | 2 +- packages/manifest/src/pixiManifest.ts | 11 +++++------ packages/texture-packer/src/texturePacker.ts | 3 ++- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/packages/core/src/Asset.ts b/packages/core/src/Asset.ts index fd918e3..a6aff66 100644 --- a/packages/core/src/Asset.ts +++ b/packages/core/src/Asset.ts @@ -21,7 +21,6 @@ export class Asset // file based.. parent: Asset | null = null; children: Asset[] = []; - ignoreChildren = false; // transform based.. transformParent: Asset | null = null; @@ -37,6 +36,7 @@ export class Asset isFolder: boolean; path = ''; + skip = false; private _state: 'deleted' | 'added' | 'modified' | 'normal' = 'added'; private _buffer?: Buffer | null = null; @@ -178,6 +178,17 @@ export class Asset return asset; } + skipChildren() + { + for (let i = 0; i < this.children.length; i++) + { + const child = this.children[i]; + + child.skip = true; + child.skipChildren(); + } + } + getFinalTransformedChildren(asset: Asset = this, finalChildren: Asset[] = []): Asset[] { if (asset.transformChildren.length > 0) diff --git a/packages/core/src/AssetPack.ts b/packages/core/src/AssetPack.ts index 9cc5a90..204dcd7 100644 --- a/packages/core/src/AssetPack.ts +++ b/packages/core/src/AssetPack.ts @@ -73,6 +73,11 @@ export class AssetPack { Logger.info('cache found.'); } + else + { + // to be safe - lets nuke the folder as the cache is empty + fs.removeSync(this._outputPath); + } } // make sure the output folders exists @@ -170,6 +175,8 @@ export class AssetPack const all = assetsToTransform.map((asset) => (async () => { + if (asset.skip) return; + await this._pipeSystem.transform(asset); index++; @@ -200,12 +207,9 @@ export class AssetPack output.push(asset); } - if (!asset.ignoreChildren) + for (let i = 0; i < asset.children.length; i++) { - for (let i = 0; i < asset.children.length; i++) - { - this.deleteAndCollectAssetsToTransform(asset.children[i], output); - } + this.deleteAndCollectAssetsToTransform(asset.children[i], output); } } } diff --git a/packages/json/src/index.ts b/packages/json/src/index.ts index 50ea00e..79e30c5 100644 --- a/packages/json/src/index.ts +++ b/packages/json/src/index.ts @@ -28,7 +28,7 @@ export function json(_options: JsonOptions = {}): AssetPipe const json = JSON.parse(asset.buffer.toString()); const compressedJsonAsset = createNewAssetAt(asset, asset.filename); - compressedJsonAsset.buffer = Buffer.from(JSON.stringify(json, null, 2)); + compressedJsonAsset.buffer = Buffer.from(JSON.stringify(json)); return [compressedJsonAsset]; } diff --git a/packages/json/test/Json.test.ts b/packages/json/test/Json.test.ts index f32a541..e609aed 100644 --- a/packages/json/test/Json.test.ts +++ b/packages/json/test/Json.test.ts @@ -121,6 +121,6 @@ describe('Json', () => const data = readFileSync(`${outputDir}/json/json.json`, 'utf8'); - expect(data.replace(/\\/g, '').trim()).toEqual(`"{"hello":"world","Im":"not broken"}"`); + expect(data.replace(/\\/g, '').trim()).toEqual(`{\"hello\":\"world\",\"Im\":\"not broken\"}`); }); }); diff --git a/packages/manifest/src/pixiManifest.ts b/packages/manifest/src/pixiManifest.ts index 30e8000..042cfc9 100644 --- a/packages/manifest/src/pixiManifest.ts +++ b/packages/manifest/src/pixiManifest.ts @@ -73,6 +73,8 @@ function collectAssets( bundle: PixiManifest, ) { + if (asset.skip) return; + let localBundle = bundle; if (asset.metaData.m || asset.metaData.manifest) @@ -111,13 +113,10 @@ function collectAssets( } } - if (!asset.ignoreChildren) + asset.children.forEach((child) => { - asset.children.forEach((child) => - { - collectAssets(child, options, outputPath, entryPath, bundles, localBundle); - }); - } + collectAssets(child, options, outputPath, entryPath, bundles, localBundle); + }); } function getTexturePackedAssets(assets: Asset[]) diff --git a/packages/texture-packer/src/texturePacker.ts b/packages/texture-packer/src/texturePacker.ts index 1d1df42..1d49b26 100644 --- a/packages/texture-packer/src/texturePacker.ts +++ b/packages/texture-packer/src/texturePacker.ts @@ -96,7 +96,8 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe