diff --git a/package-lock.json b/package-lock.json index e7e559f..888acbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17682,7 +17682,9 @@ "devDependencies": { "@play-co/assetpack-core": "1.4.3", "@play-co/assetpack-plugin-image": "1.4.3", - "@play-co/assetpack-plugin-manifest": "1.4.3" + "@play-co/assetpack-plugin-manifest": "1.4.3", + "glob": "^8.0.3", + "glob-promise": "^6.0.0" }, "engines": { "node": ">=16.0.0" @@ -17692,6 +17694,65 @@ "@play-co/assetpack-plugin-image": ">=0.0.0" } }, + "packages/spine/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "packages/spine/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "packages/spine/node_modules/glob-promise": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/glob-promise/-/glob-promise-6.0.5.tgz", + "integrity": "sha512-uUzvxo60yo/vMLXZHCNAlfdM5U5A07jCnUO8xTK44Z0Vc58poGDXhDx8ju1DmPdprOORh+4Lpog64hl+AJ5piA==", + "dev": true, + "dependencies": { + "@types/glob": "^8.0.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "type": "individual", + "url": "https://github.com/sponsors/ahmadnassri" + }, + "peerDependencies": { + "glob": "^8.0.3" + } + }, + "packages/spine/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "packages/texture-packer": { "name": "@play-co/assetpack-plugin-texture-packer", "version": "1.4.3", diff --git a/packages/manifest/test/Manifest.test.ts b/packages/manifest/test/Manifest.test.ts index c19b962..512438e 100644 --- a/packages/manifest/test/Manifest.test.ts +++ b/packages/manifest/test/Manifest.test.ts @@ -631,11 +631,11 @@ describe('Manifest', () => ], }, { - alias: ['folder2/1.mp3', '1.mp3'], + alias: ['folder2/1.mp3'], src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: ['folder2/folder3/1.mp3', '1.mp3'], + alias: ['folder2/folder3/1.mp3'], src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { @@ -761,8 +761,7 @@ describe('Manifest', () => assets: [ { alias: [ - 'folder/json.json', - 'folder/json' + 'folder/json.json' ], src: [ 'folder/json.json' @@ -770,8 +769,7 @@ describe('Manifest', () => }, { alias: [ - 'folder/json.json5', - 'folder/json' + 'folder/json.json5' ], src: [ 'folder/json.json5' @@ -811,8 +809,7 @@ describe('Manifest', () => }, { alias: [ - 'spine/dragon.json', - 'spine/dragon' + 'spine/dragon.json' ], src: [ 'spine/dragon.json' @@ -820,8 +817,7 @@ describe('Manifest', () => }, { alias: [ - 'spine/dragon.atlas', - 'spine/dragon' + 'spine/dragon.atlas' ], src: [ 'spine/dragon@0.5x.atlas', diff --git a/packages/spine/package.json b/packages/spine/package.json index ce277e6..7830269 100644 --- a/packages/spine/package.json +++ b/packages/spine/package.json @@ -34,7 +34,9 @@ "devDependencies": { "@play-co/assetpack-core": "1.4.3", "@play-co/assetpack-plugin-image": "1.4.3", - "@play-co/assetpack-plugin-manifest": "1.4.3" + "@play-co/assetpack-plugin-manifest": "1.4.3", + "glob": "^8.0.3", + "glob-promise": "^6.0.0" }, "peerDependencies": { "@play-co/assetpack-core": ">=0.0.0", diff --git a/packages/spine/test/spineAtlasAll.test.ts b/packages/spine/test/spineAtlasAll.test.ts index 6f4c95a..1227ab9 100644 --- a/packages/spine/test/spineAtlasAll.test.ts +++ b/packages/spine/test/spineAtlasAll.test.ts @@ -1,4 +1,5 @@ -import { existsSync, readFileSync } from 'fs-extra'; +import { readFileSync } from 'fs-extra'; +import glob from 'glob-promise'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCacheBuster } from '../src/spineAtlasCacheBuster'; import { spineAtlasCompress } from '../src/spineAtlasCompress'; @@ -128,37 +129,62 @@ describe('Spine Atlas All', () => }); await assetpack.run(); + const globPath = `${outputDir}/*.{atlas,png,webp}`; + const files = await glob(globPath); - [ - { - atlas: `dragon-ZmGiUA@0.5x.webp.atlas`, - png1: `dragon-7mmX8g@0.5x.webp`, - png2: `dragon2-k_22pw@0.5x.webp` - }, - { - atlas: `dragon-spj8.webp.atlas`, - png1: `dragon-rSwKOg.webp`, - png2: `dragon2-ws3uhw.webp` - }, - { - atlas: `dragon-wstH@0.5x.png.atlas`, - png1: `dragon-3--s@0.5x.png`, - png2: `dragon2-vflfww@0.5x.png` - }, - { - atlas: `dragon-O471eg.png.atlas`, - png1: `dragon-vezElA.png`, - png2: `dragon2-3UnJNw.png` - } - ].forEach(({ atlas, png1, png2 }) => + // need two sets of files + expect(files.length).toBe(12); + expect(files.filter((file) => file.endsWith('.atlas')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.webp')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.jpg')).length).toBe(0); + + const atlasFiles = files.filter((file) => file.endsWith('.atlas')); + const pngFiles = files.filter((file) => file.endsWith('.png')); + const webpFiles = files.filter((file) => file.endsWith('.webp')); + + // check that the files are correct + atlasFiles.forEach((atlasFile) => { - const rawAtlas = readFileSync(`${outputDir}/${atlas}`); + const rawAtlas = readFileSync(atlasFile); + const isHalfSize = atlasFile.includes('@0.5x'); + const isWebp = atlasFile.includes('.webp'); + const isPng = atlasFile.includes('.png'); + + const checkFiles = (fileList: string[], isHalfSize: boolean, isFileType: boolean) => + { + fileList.forEach((file) => + { + // remove the outputDir + file = file.replace(`${outputDir}/`, ''); + const isFileHalfSize = file.includes('@0.5x'); + const isFileFileType = file.includes(isWebp ? '.webp' : '.png'); + const shouldExist = isHalfSize === isFileHalfSize && isFileType === isFileFileType; - expect(rawAtlas.includes(png1)).toBeTruthy(); - expect(rawAtlas.includes(png2)).toBeTruthy(); + expect(rawAtlas.includes(file)).toBe(shouldExist); + }); + }; - expect(existsSync(`${outputDir}/${png1}`)).toBeTruthy(); - expect(existsSync(`${outputDir}/${png2}`)).toBeTruthy(); + if (isHalfSize) + { + if (isWebp) + { + checkFiles(webpFiles, true, true); + } + else if (isPng) + { + checkFiles(pngFiles, true, true); + } + } + else + if (isWebp) + { + checkFiles(webpFiles, false, true); + } + else if (isPng) + { + checkFiles(pngFiles, false, true); + } }); }); }); diff --git a/packages/spine/test/spineAtlasCacheBuster.test.ts b/packages/spine/test/spineAtlasCacheBuster.test.ts index f8f9aa7..6164abb 100644 --- a/packages/spine/test/spineAtlasCacheBuster.test.ts +++ b/packages/spine/test/spineAtlasCacheBuster.test.ts @@ -1,4 +1,5 @@ import { readFileSync } from 'fs-extra'; +import glob from 'glob-promise'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCacheBuster } from '../src/spineAtlasCacheBuster'; import { AssetPack } from '@play-co/assetpack-core'; @@ -47,9 +48,34 @@ describe('Spine Atlas Cache Buster', () => await assetpack.run(); - const rawAtlas = readFileSync(`${outputDir}/dragon-qmTByg.atlas`); + const globPath = `${outputDir}/*.{atlas,png}`; + const files = await glob(globPath); - expect(rawAtlas.includes('dragon-iSqGPQ')).toBeTruthy(); - expect(rawAtlas.includes('dragon2-6ebkeA')).toBeTruthy(); + // need two sets of files + expect(files.length).toBe(3); + expect(files.filter((file) => file.endsWith('.atlas')).length).toBe(1); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(2); + + const atlasFiles = files.filter((file) => file.endsWith('.atlas')); + const pngFiles = files.filter((file) => file.endsWith('.png')); + + // check that the files are correct + atlasFiles.forEach((atlasFile) => + { + const rawAtlas = readFileSync(atlasFile); + + const checkFiles = (fileList: string[]) => + { + fileList.forEach((file) => + { + // remove the outputDir + file = file.replace(`${outputDir}/`, ''); + + expect(rawAtlas.includes(file)).toBe(true); + }); + }; + + checkFiles(pngFiles); + }); }); });