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..546b8c0 100644 --- a/packages/core/src/AssetPack.ts +++ b/packages/core/src/AssetPack.ts @@ -73,6 +73,13 @@ export class AssetPack { Logger.info('cache found.'); } + else + { + Logger.warn('cache not found, clearing output folder'); + + // to be safe - lets nuke the folder as the cache is empty + fs.removeSync(this._outputPath); + } } // make sure the output folders exists @@ -170,6 +177,8 @@ export class AssetPack const all = assetsToTransform.map((asset) => (async () => { + if (asset.skip) return; + await this._pipeSystem.transform(asset); index++; @@ -200,12 +209,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..085f136 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/mipmap-compress/src/utils/compressSharp.ts b/packages/mipmap-compress/src/utils/compressSharp.ts index 96698c6..25521ab 100644 --- a/packages/mipmap-compress/src/utils/compressSharp.ts +++ b/packages/mipmap-compress/src/utils/compressSharp.ts @@ -15,12 +15,12 @@ export async function compressSharp( { // optimising the PNG image and using that as the source of the WebP and AVIF images // will result in a smaller file size and increase the speed of the compression. - sharpImage = sharp(await image.sharpImage.png(options.png as PngOptions).toBuffer()); + sharpImage = sharp(await image.sharpImage.png({ ...options.png as PngOptions, force: true }).toBuffer()); compressed.push({ format: '.png', resolution: image.resolution, - sharpImage + sharpImage: sharpImage.clone(), }); } diff --git a/packages/texture-packer/src/packer/createJsons.ts b/packages/texture-packer/src/packer/createJsons.ts index 873401f..058a9e1 100644 --- a/packages/texture-packer/src/packer/createJsons.ts +++ b/packages/texture-packer/src/packer/createJsons.ts @@ -42,7 +42,7 @@ export function createJsons( w: rect.width, h: rect.height }, - rotated: false, + rotated: rect.rot, trimmed: rect.textureData.trimmed, spriteSourceSize: { x: rect.textureData.trimOffsetLeft, 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 const sheet2Exists = existsSync(`${outputDir}/sprites-1.json`); expect(sheet2Exists).toBe(false); + + expect(existsSync(`${outputDir}/sprites`)).toBe(false); }); it('should adjust the size of the textures outputted based on maximumTextureSize', async () => @@ -567,7 +569,7 @@ describe('Texture Packer', () => }); // Mock console.warn - const mockWarn = jest.spyOn(console, 'warn').mockImplementation(); + const mockWarn = jest.spyOn(Logger, 'warn').mockImplementation(); await assetpack.run();