From c384a9dd335aa0e32f7da548c94a65a9c92b2384 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:29:38 +0100 Subject: [PATCH 1/7] fix: multi pipe not calling all hooks --- package-lock.json | 263 ++++++++++++++-------------- package.json | 10 +- src/core/pipes/AssetPipe.ts | 4 +- src/core/pipes/multiPipe.ts | 28 +++ src/texture-packer/texturePacker.ts | 2 +- 5 files changed, 170 insertions(+), 137 deletions(-) diff --git a/package-lock.json b/package-lock.json index f813d79..6c4dd80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,11 +17,11 @@ "chokidar": "^3.6.0", "cli-progress": "^3.12.0", "clone": "^2.1.2", - "commander": "^12.0.0", + "commander": "^12.1.0", "find-up": "^7.0.0", - "fluent-ffmpeg": "^2.1.2", + "fluent-ffmpeg": "^2.1.3", "fs-extra": "^11.2.0", - "glob": "^10.3.12", + "glob": "^10.4.1", "maxrects-packer": "^2.7.3", "merge": "^2.1.1", "minimatch": "9.0.4", @@ -29,7 +29,7 @@ "object-hash": "3.0.0", "otf2svg": "^1.0.2", "readline": "^1.3.0", - "sharp": "~0.33.3", + "sharp": "~0.33.4", "string-width": "^7.1.0", "strip-ansi": "^7.1.0", "svg2ttf": "^6.0.3", @@ -49,7 +49,7 @@ "@types/object-hash": "^3.0.6", "@types/svg2ttf": "^5.0.3", "husky": "^8.0.3", - "lint-staged": "^15.2.2", + "lint-staged": "^15.2.7", "typescript": "^5.4.5", "vitest": "^1.6.0" } @@ -1654,9 +1654,9 @@ "dev": true }, "node_modules/@img/sharp-darwin-arm64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.3.tgz", - "integrity": "sha512-FaNiGX1MrOuJ3hxuNzWgsT/mg5OHG/Izh59WW2mk1UwYHUwtfbhk5QNKYZgxf0pLOhx9ctGiGa2OykD71vOnSw==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.4.tgz", + "integrity": "sha512-p0suNqXufJs9t3RqLBO6vvrgr5OhgbWp76s5gTRvdmxmuv9E1rcaqGUsl3l4mKVmXPkTkTErXediAui4x+8PSA==", "cpu": [ "arm64" ], @@ -1679,9 +1679,9 @@ } }, "node_modules/@img/sharp-darwin-x64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.3.tgz", - "integrity": "sha512-2QeSl7QDK9ru//YBT4sQkoq7L0EAJZA3rtV+v9p8xTKl4U1bUqTIaCnoC7Ctx2kCjQgwFXDasOtPTCT8eCTXvw==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.4.tgz", + "integrity": "sha512-0l7yRObwtTi82Z6ebVI2PnHT8EB2NxBgpK2MiKJZJ7cz32R4lxd001ecMhzzsZig3Yv9oclvqqdV93jo9hy+Dw==", "cpu": [ "x64" ], @@ -1872,9 +1872,9 @@ } }, "node_modules/@img/sharp-linux-arm": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.3.tgz", - "integrity": "sha512-Q7Ee3fFSC9P7vUSqVEF0zccJsZ8GiiCJYGWDdhEjdlOeS9/jdkyJ6sUSPj+bL8VuOYFSbofrW0t/86ceVhx32w==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.4.tgz", + "integrity": "sha512-RUgBD1c0+gCYZGCCe6mMdTiOFS0Zc/XrN0fYd6hISIKcDUbAW5NtSQW9g/powkrXYm6Vzwd6y+fqmExDuCdHNQ==", "cpu": [ "arm" ], @@ -1897,9 +1897,9 @@ } }, "node_modules/@img/sharp-linux-arm64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.3.tgz", - "integrity": "sha512-Zf+sF1jHZJKA6Gor9hoYG2ljr4wo9cY4twaxgFDvlG0Xz9V7sinsPp8pFd1XtlhTzYo0IhDbl3rK7P6MzHpnYA==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.4.tgz", + "integrity": "sha512-2800clwVg1ZQtxwSoTlHvtm9ObgAax7V6MTAB/hDT945Tfyy3hVkmiHpeLPCKYqYR1Gcmv1uDZ3a4OFwkdBL7Q==", "cpu": [ "arm64" ], @@ -1922,9 +1922,9 @@ } }, "node_modules/@img/sharp-linux-s390x": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.3.tgz", - "integrity": "sha512-vFk441DKRFepjhTEH20oBlFrHcLjPfI8B0pMIxGm3+yilKyYeHEVvrZhYFdqIseSclIqbQ3SnZMwEMWonY5XFA==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.4.tgz", + "integrity": "sha512-h3RAL3siQoyzSoH36tUeS0PDmb5wINKGYzcLB5C6DIiAn2F3udeFAum+gj8IbA/82+8RGCTn7XW8WTFnqag4tQ==", "cpu": [ "s390x" ], @@ -1933,7 +1933,7 @@ "linux" ], "engines": { - "glibc": ">=2.28", + "glibc": ">=2.31", "node": "^18.17.0 || ^20.3.0 || >=21.0.0", "npm": ">=9.6.5", "pnpm": ">=7.1.0", @@ -1947,9 +1947,9 @@ } }, "node_modules/@img/sharp-linux-x64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.3.tgz", - "integrity": "sha512-Q4I++herIJxJi+qmbySd072oDPRkCg/SClLEIDh5IL9h1zjhqjv82H0Seupd+q2m0yOfD+/fJnjSoDFtKiHu2g==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.4.tgz", + "integrity": "sha512-GoR++s0XW9DGVi8SUGQ/U4AeIzLdNjHka6jidVwapQ/JebGVQIpi52OdyxCNVRE++n1FCLzjDovJNozif7w/Aw==", "cpu": [ "x64" ], @@ -1972,9 +1972,9 @@ } }, "node_modules/@img/sharp-linuxmusl-arm64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.3.tgz", - "integrity": "sha512-qnDccehRDXadhM9PM5hLvcPRYqyFCBN31kq+ErBSZtZlsAc1U4Z85xf/RXv1qolkdu+ibw64fUDaRdktxTNP9A==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.4.tgz", + "integrity": "sha512-nhr1yC3BlVrKDTl6cO12gTpXMl4ITBUZieehFvMntlCXFzH2bvKG76tBL2Y/OqhupZt81pR7R+Q5YhJxW0rGgQ==", "cpu": [ "arm64" ], @@ -1997,9 +1997,9 @@ } }, "node_modules/@img/sharp-linuxmusl-x64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.3.tgz", - "integrity": "sha512-Jhchim8kHWIU/GZ+9poHMWRcefeaxFIs9EBqf9KtcC14Ojk6qua7ghKiPs0sbeLbLj/2IGBtDcxHyjCdYWkk2w==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.4.tgz", + "integrity": "sha512-uCPTku0zwqDmZEOi4ILyGdmW76tH7dm8kKlOIV1XC5cLyJ71ENAAqarOHQh0RLfpIpbV5KOpXzdU6XkJtS0daw==", "cpu": [ "x64" ], @@ -2022,15 +2022,15 @@ } }, "node_modules/@img/sharp-wasm32": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.3.tgz", - "integrity": "sha512-68zivsdJ0koE96stdUfM+gmyaK/NcoSZK5dV5CAjES0FUXS9lchYt8LAB5rTbM7nlWtxaU/2GON0HVN6/ZYJAQ==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.4.tgz", + "integrity": "sha512-Bmmauh4sXUsUqkleQahpdNXKvo+wa1V9KhT2pDA4VJGKwnKMJXiSTGphn0gnJrlooda0QxCtXc6RX1XAU6hMnQ==", "cpu": [ "wasm32" ], "optional": true, "dependencies": { - "@emnapi/runtime": "^1.1.0" + "@emnapi/runtime": "^1.1.1" }, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0", @@ -2043,9 +2043,9 @@ } }, "node_modules/@img/sharp-win32-ia32": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.3.tgz", - "integrity": "sha512-CyimAduT2whQD8ER4Ux7exKrtfoaUiVr7HG0zZvO0XTFn2idUWljjxv58GxNTkFb8/J9Ub9AqITGkJD6ZginxQ==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.4.tgz", + "integrity": "sha512-99SJ91XzUhYHbx7uhK3+9Lf7+LjwMGQZMDlO/E/YVJ7Nc3lyDFZPGhjwiYdctoH2BOzW9+TnfqcaMKt0jHLdqw==", "cpu": [ "ia32" ], @@ -2064,9 +2064,9 @@ } }, "node_modules/@img/sharp-win32-x64": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.3.tgz", - "integrity": "sha512-viT4fUIDKnli3IfOephGnolMzhz5VaTvDRkYqtZxOMIoMQ4MrAziO7pT1nVnOt2FAm7qW5aa+CCc13aEY6Le0g==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.4.tgz", + "integrity": "sha512-3QLocdTRVIrFNye5YocZl+KKpYKP+fksi1QhmOArgx7GyhIbQp/WrJRu176jm8IxromS7RIkzMiMINVdBtC8Aw==", "cpu": [ "x64" ], @@ -7429,7 +7429,10 @@ "node_modules/async": { "version": "3.2.5", "resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz", - "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==" + "integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==", + "dev": true, + "optional": true, + "peer": true }, "node_modules/at-least-node": { "version": "1.0.0", @@ -7963,11 +7966,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -8712,9 +8715,9 @@ "dev": true }, "node_modules/commander": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", - "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", "engines": { "node": ">=18" } @@ -11235,9 +11238,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -11473,17 +11476,22 @@ "dev": true }, "node_modules/fluent-ffmpeg": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz", - "integrity": "sha512-IZTB4kq5GK0DPp7sGQ0q/BWurGHffRtQQwVkiqDgeO6wYJLLV5ZhgNOQ65loZxxuPMKZKZcICCUnaGtlxBiR0Q==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.3.tgz", + "integrity": "sha512-Be3narBNt2s6bsaqP6Jzq91heDgOEaDCJAXcE3qcma/EJBSy5FB4cvO31XBInuAuKBx8Kptf8dkhjK0IOru39Q==", "dependencies": { - "async": ">=0.2.9", + "async": "^0.2.9", "which": "^1.1.1" }, "engines": { - "node": ">=0.8.0" + "node": ">=18" } }, + "node_modules/fluent-ffmpeg/node_modules/async": { + "version": "0.2.10", + "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", + "integrity": "sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==" + }, "node_modules/fluent-ffmpeg/node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -12185,21 +12193,21 @@ } }, "node_modules/glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", + "version": "10.4.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", + "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", "dependencies": { "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", - "minimatch": "^9.0.1", - "minipass": "^7.0.4", - "path-scurry": "^1.10.2" + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "path-scurry": "^1.11.1" }, "bin": { "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -13773,9 +13781,9 @@ } }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.0.tgz", + "integrity": "sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==", "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -15699,12 +15707,15 @@ } }, "node_modules/lilconfig": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.0.0.tgz", - "integrity": "sha512-K2U4W2Ff5ibV7j7ydLr+zLAkIg5JJ4lPn1Ltsdt+Tz/IjQ8buJ55pZAxoP34lqIiwtF9iAvtLv3JGv7CAyAg+g==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.2.tgz", + "integrity": "sha512-eop+wDAvpItUys0FWkHIKeC9ybYrTGbU41U5K7+bttZZeohvnY7M9dZ5kB21GNWiFT2q1OoPTvncPCgSOVO5ow==", "dev": true, "engines": { "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antonk52" } }, "node_modules/lines-and-columns": { @@ -15723,21 +15734,21 @@ } }, "node_modules/lint-staged": { - "version": "15.2.2", - "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.2.2.tgz", - "integrity": "sha512-TiTt93OPh1OZOsb5B7k96A/ATl2AjIZo+vnzFZ6oHK5FuTk63ByDtxGQpHm+kFETjEWqgkF95M8FRXKR/LEBcw==", - "dev": true, - "dependencies": { - "chalk": "5.3.0", - "commander": "11.1.0", - "debug": "4.3.4", - "execa": "8.0.1", - "lilconfig": "3.0.0", - "listr2": "8.0.1", - "micromatch": "4.0.5", - "pidtree": "0.6.0", - "string-argv": "0.3.2", - "yaml": "2.3.4" + "version": "15.2.7", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.2.7.tgz", + "integrity": "sha512-+FdVbbCZ+yoh7E/RosSdqKJyUM2OEjTciH0TFNkawKgvFp1zbGlEC39RADg+xKBG1R4mhoH2j85myBQZ5wR+lw==", + "dev": true, + "dependencies": { + "chalk": "~5.3.0", + "commander": "~12.1.0", + "debug": "~4.3.4", + "execa": "~8.0.1", + "lilconfig": "~3.1.1", + "listr2": "~8.2.1", + "micromatch": "~4.0.7", + "pidtree": "~0.6.0", + "string-argv": "~0.3.2", + "yaml": "~2.4.2" }, "bin": { "lint-staged": "bin/lint-staged.js" @@ -15749,15 +15760,6 @@ "url": "https://opencollective.com/lint-staged" } }, - "node_modules/lint-staged/node_modules/commander": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", - "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", - "dev": true, - "engines": { - "node": ">=16" - } - }, "node_modules/lint-staged/node_modules/execa": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", @@ -15881,16 +15883,16 @@ } }, "node_modules/listr2": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/listr2/-/listr2-8.0.1.tgz", - "integrity": "sha512-ovJXBXkKGfq+CwmKTjluEqFi3p4h8xvkxGQQAQan22YCgef4KZ1mKGjzfGh6PL6AW5Csw0QiQPNuQyH+6Xk3hA==", + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/listr2/-/listr2-8.2.1.tgz", + "integrity": "sha512-irTfvpib/rNiD637xeevjO2l3Z5loZmuaRi0L0YE5LfijwVY96oyVn0DFD3o/teAok7nfobMG1THvvcHh/BP6g==", "dev": true, "dependencies": { "cli-truncate": "^4.0.0", "colorette": "^2.0.20", "eventemitter3": "^5.0.1", "log-update": "^6.0.0", - "rfdc": "^1.3.0", + "rfdc": "^1.3.1", "wrap-ansi": "^9.0.0" }, "engines": { @@ -16464,12 +16466,12 @@ "integrity": "sha512-O/SUXauVN4x6RaEJFqSPcXNtLFL+QzJHKZlyDVYFwcDDRVca3Fa/37QXXC+4zAGGa4YhHrHxKXuuHvLDIQECtA==" }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", + "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -16535,9 +16537,9 @@ } }, "node_modules/minipass": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.0.tgz", - "integrity": "sha512-oGZRv2OT1lO2UF1zUcwdTb3wqUwI0kBGTgt/T7OdSj6M6N5m3o5uPf0AIW6lVxGGoiWUR7e2AwTE+xiwK8WQig==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "engines": { "node": ">=16 || 14 >=14.17" } @@ -17634,15 +17636,15 @@ "dev": true }, "node_modules/path-scurry": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", - "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -19033,9 +19035,9 @@ } }, "node_modules/rfdc": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.1.tgz", - "integrity": "sha512-r5a3l5HzYlIC68TpmYKlxWjmOP6wiPJ1vWv2HeLhNsRZMrCkxeqxiHlQ21oXmQ4F3SiryXBHhAD7JZqvOJjFmg==", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", "dev": true }, "node_modules/rgb2hex": { @@ -19431,9 +19433,9 @@ } }, "node_modules/sharp": { - "version": "0.33.3", - "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.3.tgz", - "integrity": "sha512-vHUeXJU1UvlO/BNwTpT0x/r53WkLUVxrmb5JTgW92fdFCFk0ispLMAeu/jPO2vjkXM1fYUi3K7/qcLF47pwM1A==", + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.4.tgz", + "integrity": "sha512-7i/dt5kGl7qR4gwPRD2biwD2/SvBn3O04J77XKFgL2OnZtQw+AG9wnuS/csmu80nPRHLYE9E41fyEiG8nhH6/Q==", "hasInstallScript": true, "dependencies": { "color": "^4.2.3", @@ -19448,8 +19450,8 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-darwin-arm64": "0.33.3", - "@img/sharp-darwin-x64": "0.33.3", + "@img/sharp-darwin-arm64": "0.33.4", + "@img/sharp-darwin-x64": "0.33.4", "@img/sharp-libvips-darwin-arm64": "1.0.2", "@img/sharp-libvips-darwin-x64": "1.0.2", "@img/sharp-libvips-linux-arm": "1.0.2", @@ -19458,15 +19460,15 @@ "@img/sharp-libvips-linux-x64": "1.0.2", "@img/sharp-libvips-linuxmusl-arm64": "1.0.2", "@img/sharp-libvips-linuxmusl-x64": "1.0.2", - "@img/sharp-linux-arm": "0.33.3", - "@img/sharp-linux-arm64": "0.33.3", - "@img/sharp-linux-s390x": "0.33.3", - "@img/sharp-linux-x64": "0.33.3", - "@img/sharp-linuxmusl-arm64": "0.33.3", - "@img/sharp-linuxmusl-x64": "0.33.3", - "@img/sharp-wasm32": "0.33.3", - "@img/sharp-win32-ia32": "0.33.3", - "@img/sharp-win32-x64": "0.33.3" + "@img/sharp-linux-arm": "0.33.4", + "@img/sharp-linux-arm64": "0.33.4", + "@img/sharp-linux-s390x": "0.33.4", + "@img/sharp-linux-x64": "0.33.4", + "@img/sharp-linuxmusl-arm64": "0.33.4", + "@img/sharp-linuxmusl-x64": "0.33.4", + "@img/sharp-wasm32": "0.33.4", + "@img/sharp-win32-ia32": "0.33.4", + "@img/sharp-win32-x64": "0.33.4" } }, "node_modules/sharp/node_modules/semver": { @@ -23132,10 +23134,13 @@ "dev": true }, "node_modules/yaml": { - "version": "2.3.4", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", - "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==", + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.5.tgz", + "integrity": "sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg==", "dev": true, + "bin": { + "yaml": "bin.mjs" + }, "engines": { "node": ">= 14" } diff --git a/package.json b/package.json index 5a85d79..ca4df4e 100644 --- a/package.json +++ b/package.json @@ -59,11 +59,11 @@ "chokidar": "^3.6.0", "cli-progress": "^3.12.0", "clone": "^2.1.2", - "commander": "^12.0.0", + "commander": "^12.1.0", "find-up": "^7.0.0", - "fluent-ffmpeg": "^2.1.2", + "fluent-ffmpeg": "^2.1.3", "fs-extra": "^11.2.0", - "glob": "^10.3.12", + "glob": "^10.4.1", "maxrects-packer": "^2.7.3", "merge": "^2.1.1", "minimatch": "9.0.4", @@ -71,7 +71,7 @@ "object-hash": "3.0.0", "otf2svg": "^1.0.2", "readline": "^1.3.0", - "sharp": "~0.33.3", + "sharp": "~0.33.4", "string-width": "^7.1.0", "strip-ansi": "^7.1.0", "svg2ttf": "^6.0.3", @@ -88,7 +88,7 @@ "@types/object-hash": "^3.0.6", "@types/svg2ttf": "^5.0.3", "husky": "^8.0.3", - "lint-staged": "^15.2.2", + "lint-staged": "^15.2.7", "typescript": "^5.4.5", "vitest": "^1.6.0" }, diff --git a/src/core/pipes/AssetPipe.ts b/src/core/pipes/AssetPipe.ts index 690a2ca..f88232e 100644 --- a/src/core/pipes/AssetPipe.ts +++ b/src/core/pipes/AssetPipe.ts @@ -35,7 +35,7 @@ export interface AssetPipe> * @param asser - the root asset * @param processor - Processor that called the function. */ - start?(asset: Asset, options: DeepRequired, pipeSystem: PipeSystem): void + start?(asset: Asset, options: DeepRequired, pipeSystem: PipeSystem): Promise /** * Returns a boolean on whether or not the process should affect this tree. @@ -56,6 +56,6 @@ export interface AssetPipe> * @param asset - the root asset * @param processor - Processor that called the function. */ - finish?(asset: Asset, options: DeepRequired, pipeSystem: PipeSystem): void + finish?(asset: Asset, options: DeepRequired, pipeSystem: PipeSystem): Promise } diff --git a/src/core/pipes/multiPipe.ts b/src/core/pipes/multiPipe.ts index 59f40c3..cd37265 100644 --- a/src/core/pipes/multiPipe.ts +++ b/src/core/pipes/multiPipe.ts @@ -36,6 +36,20 @@ export function multiPipe(options: MultiPipeOptions): AssetPipe[] = []; @@ -55,6 +69,20 @@ export function multiPipe(options: MultiPipeOptions): AssetPipe Date: Wed, 19 Jun 2024 13:32:01 +0100 Subject: [PATCH 2/7] feat: add global `copy` tag --- src/core/pipes/PipeSystem.ts | 10 + src/webfont/sdf.ts | 5 +- test/core/Assetpack.test.ts | 42 ++++ test/manifest/Manifest.test.ts | 418 ++++++++++++++++++--------------- 4 files changed, 286 insertions(+), 189 deletions(-) diff --git a/src/core/pipes/PipeSystem.ts b/src/core/pipes/PipeSystem.ts index 2e8e55f..3939317 100644 --- a/src/core/pipes/PipeSystem.ts +++ b/src/core/pipes/PipeSystem.ts @@ -1,3 +1,4 @@ +import { finalCopyPipe } from './finalCopyPipe.js'; import { mergePipeOptions } from './mergePipeOptions.js'; import { multiPipe } from './multiPipe.js'; @@ -72,6 +73,15 @@ export class PipeSystem pipeIndex++; + // if the asset has the copy tag on it, then the only pipe that should be run is the final copy pipe + // this is to ensure that the asset is copied to the output directory without any other processing + if (asset.allMetaData.copy && pipe !== finalCopyPipe) + { + await this._transform(asset, pipeIndex); + + return; + } + const options = mergePipeOptions(pipe, asset); if (options !== false && pipe.transform && pipe.test?.(asset, options)) diff --git a/src/webfont/sdf.ts b/src/webfont/sdf.ts index c6d561e..cbe8527 100644 --- a/src/webfont/sdf.ts +++ b/src/webfont/sdf.ts @@ -12,7 +12,7 @@ export interface SDFFontOptions extends PluginOptions<'font' | 'nc' | 'fix'> font?: Omit; } -export function signedFont( +function signedFont( defaultOptions: SDFFontOptions ): AssetPipe { @@ -45,8 +45,7 @@ export function signedFont( const newTextureAsset = createNewAssetAt(asset, newTextureName); // don't compress! - newTextureAsset.metaData[options.tags.nc] = true; - newTextureAsset.metaData[options.tags.fix] = true; + newTextureAsset.metaData.copy = true; assets.push(newTextureAsset); diff --git a/test/core/Assetpack.test.ts b/test/core/Assetpack.test.ts index e54e18c..30c9bde 100644 --- a/test/core/Assetpack.test.ts +++ b/test/core/Assetpack.test.ts @@ -241,6 +241,48 @@ describe('Core', () => expect(existsSync(join(outputDir, 'scripts/test.json'))).toBe(false); }); + it('should copy assets when copy tag is used', async () => + { + const testName = 'copy-tag'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + createFolder( + pkg, + { + name: testName, + files: [], + folders: [{ + name: 'scripts{copy}', + files: [{ + name: 'json.json', + content: assetPath('json/json.json'), + }], + folders: [], + }, + { + name: 'scripts2', + files: [{ + name: 'json{copy}.json', + content: assetPath('json/json.json'), + }], + folders: [], + }], + }); + + const assetpack = new AssetPack({ + entry: inputDir, + output: outputDir, + cache: false, + ignore: ['**/scripts/**/*'], + }); + + await assetpack.run(); + + expect(existsSync(join(outputDir, 'scripts/json.json'))).toBe(true); + expect(existsSync(join(outputDir, 'scripts2/json.json'))).toBe(true); + }); + it('should provide the correct options overrides to the plugin', async () => { const testName = 'plugin-options-override'; diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 0c6b8aa..96dfbbf 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -7,23 +7,17 @@ import { compress, mipmap } from '../../src/image/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { spineAtlasManifestMod, spineAtlasMipmap } from '../../src/spine/index.js'; import { texturePacker, texturePackerManifestMod } from '../../src/texture-packer/index.js'; -import { - assetPath, - createFolder, - getCacheDir, - getInputDir, - getOutputDir -} from '../utils/index.js'; +import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; import type { File } from '../utils/index.js'; const pkg = 'manifest'; -function genSprites() +function genSprites(total = 10) { const sprites: File[] = []; - for (let i = 0; i < 10; i++) + for (let i = 0; i < total; i++) { sprites.push({ name: `sprite${i}.png`, @@ -116,7 +110,8 @@ describe('Manifest', () => } const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: useCache, pipes: [ @@ -137,13 +132,13 @@ describe('Manifest', () => pixiManifest(), spineAtlasManifestMod(), texturePackerManifestMod(), - ] + ], }); await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[1]).toEqual({ name: 'bundle', @@ -182,10 +177,7 @@ describe('Manifest', () => }, { alias: ['bundle/tps-0'], - src: [ - 'bundle/tps-0@0.5x.json', - 'bundle/tps-0.json', - ], + src: ['bundle/tps-0@0.5x.json', 'bundle/tps-0.json'], data: { tags: { tps: true, @@ -195,10 +187,7 @@ describe('Manifest', () => }, { alias: ['bundle/tps-1'], - src: [ - 'bundle/tps-1@0.5x.json', - 'bundle/tps-1.json', - ], + src: ['bundle/tps-1@0.5x.json', 'bundle/tps-1.json'], data: { tags: { tps: true, @@ -229,18 +218,153 @@ describe('Manifest', () => alias: ['spine/dragon.json'], src: ['spine/dragon.json'], data: { - tags: {} + tags: {}, }, }, { alias: ['spine/dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + data: { + tags: { + spine: true, + }, + }, + }, + ], + }); + }, 30000); + + it('should copy over files and add them to manifest', async () => + { + const testName = 'manifest-copy'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + const useCache = false; + + createFolder(pkg, { + name: testName, + files: [], + + folders: [ + { + name: 'defaultFolder', + files: [ + { + name: 'json{copy}.json', + content: assetPath('json/json.json'), + }, + ], + folders: [ + { + name: 'tps{copy}', + files: genSprites(3), + folders: [], + }, + { + name: 'mip', + files: genSprites(3), + folders: [], + }, + ], + }, + ], + }); + + const assetpack = new AssetPack({ + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: useCache, + pipes: [ + mipmap(), + compress({ + png: true, + jpg: true, + webp: true, + avif: false, + }), + pixiManifest(), + ], + }); + + await assetpack.run(); + + // load the manifest json + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; + + expect(manifest.bundles[0]).toEqual({ + name: 'default', + assets: [ + { + alias: ['defaultFolder/json.json'], + src: ['defaultFolder/json.json'], + data: { + tags: { + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/mip/sprite0.png'], + src: [ + 'defaultFolder/mip/sprite0@0.5x.webp', + 'defaultFolder/mip/sprite0@0.5x.png', + 'defaultFolder/mip/sprite0.webp', + 'defaultFolder/mip/sprite0.png', + ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/mip/sprite1.png'], src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', + 'defaultFolder/mip/sprite1@0.5x.webp', + 'defaultFolder/mip/sprite1@0.5x.png', + 'defaultFolder/mip/sprite1.webp', + 'defaultFolder/mip/sprite1.png', ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/mip/sprite2.png'], + src: [ + 'defaultFolder/mip/sprite2@0.5x.webp', + 'defaultFolder/mip/sprite2@0.5x.png', + 'defaultFolder/mip/sprite2.webp', + 'defaultFolder/mip/sprite2.png', + ], + data: { + tags: {}, + }, + }, + { + alias: ['defaultFolder/tps/sprite0.png'], + src: ['defaultFolder/tps/sprite0.png'], data: { tags: { - spine: true, + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/tps/sprite1.png'], + src: ['defaultFolder/tps/sprite1.png'], + data: { + tags: { + copy: true, + }, + }, + }, + { + alias: ['defaultFolder/tps/sprite2.png'], + src: ['defaultFolder/tps/sprite2.png'], + data: { + tags: { + copy: true, }, }, }, @@ -323,7 +447,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -342,7 +467,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: true, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -358,77 +483,39 @@ describe('Manifest', () => name: 'default', assets: [ { - alias: [ - 'folder/json.json', - 'json.json', - ], - src: [ - 'folder/json.json' - ] + alias: ['folder/json.json', 'json.json'], + src: ['folder/json.json'], }, { - alias: [ - 'folder/json.json5', - 'json.json5', - ], - src: [ - 'folder/json.json5' - ] + alias: ['folder/json.json5', 'json.json5'], + src: ['folder/json.json5'], }, { - alias: [ - 'folder/sprite.png', - 'folder/sprite', - 'sprite.png', - 'sprite' - ], + alias: ['folder/sprite.png', 'folder/sprite', 'sprite.png', 'sprite'], src: [ 'folder/sprite@0.5x.webp', 'folder/sprite@0.5x.png', 'folder/sprite.webp', 'folder/sprite.png', - ] + ], }, { - alias: [ - 'folder2/1.mp3', - 'folder2/1', - ], - src: [ - 'folder2/1.ogg', - 'folder2/1.mp3', - ] + alias: ['folder2/1.mp3', 'folder2/1'], + src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: [ - 'folder2/folder3/1.mp3', - 'folder2/folder3/1', - ], - src: [ - 'folder2/folder3/1.ogg', - 'folder2/folder3/1.mp3', - ] + alias: ['folder2/folder3/1.mp3', 'folder2/folder3/1'], + src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { - alias: [ - 'spine/dragon.json', - 'dragon.json', - ], - src: [ - 'spine/dragon.json' - ] + alias: ['spine/dragon.json', 'dragon.json'], + src: ['spine/dragon.json'], }, { - alias: [ - 'spine/dragon.atlas', - 'dragon.atlas', - ], - src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', - ] - } - ] + alias: ['spine/dragon.atlas', 'dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + }, + ], }); }); @@ -464,7 +551,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -477,7 +565,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: false, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -487,23 +575,16 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ - name: 'default', assets: [ { - alias: [ - 'spine/dragon.atlas', - 'dragon.atlas' - ], - src: [ - 'spine/dragon.atlas' - ] - } - ] - + alias: ['spine/dragon.atlas', 'dragon.atlas'], + src: ['spine/dragon.atlas'], + }, + ], }); }); @@ -582,7 +663,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), cache: false, output: outputDir, pipes: [ @@ -601,7 +683,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: true, trimExtensions: false, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -611,7 +693,7 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ name: 'default', @@ -728,7 +810,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -747,7 +830,7 @@ describe('Manifest', () => pixiManifest({ createShortcuts: false, trimExtensions: true, - includeMetaData: false + includeMetaData: false, }), spineAtlasManifestMod(), texturePackerManifestMod(), @@ -757,78 +840,45 @@ describe('Manifest', () => await assetpack.run(); // load the manifest json - const manifest = sortObjectProperties((await fs.readJSONSync(`${outputDir}/manifest.json`))) as any; + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)) as any; expect(manifest.bundles[0]).toEqual({ name: 'default', assets: [ { - alias: [ - 'folder/json.json' - ], - src: [ - 'folder/json.json' - ] + alias: ['folder/json.json'], + src: ['folder/json.json'], }, { - alias: [ - 'folder/json.json5' - ], - src: [ - 'folder/json.json5' - ] + alias: ['folder/json.json5'], + src: ['folder/json.json5'], }, { - alias: [ - 'folder/sprite.png', - 'folder/sprite' - ], + alias: ['folder/sprite.png', 'folder/sprite'], src: [ 'folder/sprite@0.5x.webp', 'folder/sprite@0.5x.png', 'folder/sprite.webp', 'folder/sprite.png', - ] + ], }, { - alias: [ - 'folder2/1.mp3', - 'folder2/1' - ], - src: [ - 'folder2/1.ogg', - 'folder2/1.mp3', - ] + alias: ['folder2/1.mp3', 'folder2/1'], + src: ['folder2/1.ogg', 'folder2/1.mp3'], }, { - alias: [ - 'folder2/folder3/1.mp3', - 'folder2/folder3/1', - ], - src: [ - 'folder2/folder3/1.ogg', - 'folder2/folder3/1.mp3', - ] + alias: ['folder2/folder3/1.mp3', 'folder2/folder3/1'], + src: ['folder2/folder3/1.ogg', 'folder2/folder3/1.mp3'], }, { - alias: [ - 'spine/dragon.json' - ], - src: [ - 'spine/dragon.json' - ] + alias: ['spine/dragon.json'], + src: ['spine/dragon.json'], }, { - alias: [ - 'spine/dragon.atlas' - ], - src: [ - 'spine/dragon@0.5x.atlas', - 'spine/dragon.atlas', - ] - } - ] - + alias: ['spine/dragon.atlas'], + src: ['spine/dragon@0.5x.atlas', 'spine/dragon.atlas'], + }, + ], }); }); @@ -856,7 +906,8 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ @@ -907,12 +958,13 @@ describe('Manifest', () => }); const assetpack = new AssetPack({ - entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), output: outputDir, cache: false, pipes: [ pixiManifest({ - includeMetaData: false + includeMetaData: false, }), ], }); @@ -923,59 +975,53 @@ describe('Manifest', () => bundles: [ { name: 'default', - assets: [] + assets: [], }, { name: 'sound2', assets: [ { - alias: [ - 'sound2/2.mp3' - ], - src: [ - 'sound2/2.mp3' - ] - } - ] + alias: ['sound2/2.mp3'], + src: ['sound2/2.mp3'], + }, + ], }, { name: 'sound', assets: [ { - alias: [ - 'sound/1.mp3' - ], - src: [ - 'sound/1.mp3' - ] - } - ] - } - ] + alias: ['sound/1.mp3'], + src: ['sound/1.mp3'], + }, + ], + }, + ], }); }); }); function sortObjectProperties(obj: any) { - return Object.keys(obj).sort().reduce((acc: any, key: string) => - { - const value = obj[key]; - - if (typeof value === 'object' && !Array.isArray(value) && value !== null) + return Object.keys(obj) + .sort() + .reduce((acc: any, key: string) => { - acc[key] = sortObjectProperties(value); - } - else - { - if (Array.isArray(value)) + const value = obj[key]; + + if (typeof value === 'object' && !Array.isArray(value) && value !== null) { - value.sort(); + acc[key] = sortObjectProperties(value); } + else + { + if (Array.isArray(value)) + { + value.sort(); + } - acc[key] = value; - } + acc[key] = value; + } - return acc; - }, {}); + return acc; + }, {}); } From 56a613c67a940bbb8e046cd44764e25555f98ac3 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:47:21 +0100 Subject: [PATCH 3/7] feat: add mIgnore tag --- .eslintrc.cjs | 10 ++++--- src/manifest/pixiManifest.ts | 32 +++++++++++--------- src/spine/spineAtlasCacheBuster.ts | 4 ++- src/spine/spineAtlasManifestMod.ts | 4 ++- src/webfont/sdf.ts | 4 ++- test/webfont/Webfont.test.ts | 47 ++++++++++++++++++++++++++++-- 6 files changed, 79 insertions(+), 22 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index a7ae364..f455dbe 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,15 +5,17 @@ module.exports = { ecmaVersion: 2020, sourceType: "module", }, + plugins: ['import'], rules: { "spaced-comment": [1, "always", { markers: ["/"] }], "@typescript-eslint/triple-slash-reference": [1, { path: "always" }], - "@typescript-eslint/consistent-type-imports": [ - 1, - { disallowTypeAnnotations: false }, - ], "@typescript-eslint/type-annotation-spacing": 1, "@typescript-eslint/no-non-null-assertion": 0, + "@typescript-eslint/consistent-type-imports": + ["error", { disallowTypeAnnotations: false }], + "import/consistent-type-specifier-style": ["error", "prefer-top-level"], + "import/no-duplicates": ["error"], + "camelcase": 0, }, overrides: [ { diff --git a/src/manifest/pixiManifest.ts b/src/manifest/pixiManifest.ts index 9fc4f2e..6d07d36 100644 --- a/src/manifest/pixiManifest.ts +++ b/src/manifest/pixiManifest.ts @@ -1,10 +1,10 @@ import fs from 'fs-extra'; -import { - type Asset, - type AssetPipe, - path, - type PipeSystem, - stripTags +import { path, stripTags } from '../core/index.js'; + +import type { + Asset, + AssetPipe, + PipeSystem, PluginOptions } from '../core/index.js'; export interface PixiBundle @@ -28,7 +28,7 @@ export interface PixiManifestEntry }; } -export interface PixiManifestOptions +export interface PixiManifestOptions extends PluginOptions<'mIgnore' | 'manifest'> { output?: string; createShortcuts?: boolean; @@ -38,12 +38,16 @@ export interface PixiManifestOptions export function pixiManifest(_options: PixiManifestOptions = {}): AssetPipe { - const defaultOptions = { + const defaultOptions: PixiManifestOptions = { output: 'manifest.json', createShortcuts: false, trimExtensions: false, includeMetaData: true, - ..._options + ..._options, + tags: { + manifest: 'm', + mIgnore: 'mIgnore' + } }; return { @@ -98,7 +102,7 @@ function collectAssets( outputPath = '', entryPath = '', bundles: PixiBundle[], - bundle: PixiBundle, + bundle: PixiBundle ) { if (asset.skip) return; @@ -107,7 +111,7 @@ function collectAssets( let localBundle = bundle; - if (asset.metaData.m || asset.metaData.manifest) + if (asset.metaData[options.tags!.manifest!]) { localBundle = { name: stripTags(asset.filename), @@ -121,11 +125,13 @@ function collectAssets( const finalAssets = asset.getFinalTransformedChildren(); - if (asset.transformChildren.length > 0) + if (asset.transformChildren.length > 0 && !asset.inheritedMetaData[options.tags!.mIgnore!]) { + const nonIgnored = finalAssets.filter((finalAsset) => !finalAsset.inheritedMetaData[options.tags!.mIgnore!]); + bundleAssets.push({ alias: getShortNames(stripTags(path.relative(entryPath, asset.path)), options), - src: finalAssets + src: nonIgnored .map((finalAsset) => path.relative(outputPath, finalAsset.path)) .sort((a, b) => b.localeCompare(a)), data: options.includeMetaData ? { diff --git a/src/spine/spineAtlasCacheBuster.ts b/src/spine/spineAtlasCacheBuster.ts index 8c12799..2e17ab3 100644 --- a/src/spine/spineAtlasCacheBuster.ts +++ b/src/spine/spineAtlasCacheBuster.ts @@ -1,7 +1,9 @@ import fs from 'fs-extra'; -import { type Asset, type AssetPipe, checkExt, findAssets } from '../core/index.js'; +import { checkExt, findAssets } from '../core/index.js'; import { AtlasView } from './AtlasView.js'; +import type { Asset, AssetPipe } from '../core/index.js'; + /** * This should be used after the cache buster plugin in the pipes. * As it relies on the cache buster plugin to have already cache busted all files. diff --git a/src/spine/spineAtlasManifestMod.ts b/src/spine/spineAtlasManifestMod.ts index 83bf87d..2a99cd5 100644 --- a/src/spine/spineAtlasManifestMod.ts +++ b/src/spine/spineAtlasManifestMod.ts @@ -1,7 +1,9 @@ import fs from 'fs-extra'; -import { type Asset, type AssetPipe, findAssets, path } from '../core/index.js'; +import { findAssets, path } from '../core/index.js'; import { AtlasView } from './AtlasView.js'; +import type { Asset, AssetPipe } from '../core/index.js'; + export interface SpineManifestOptions { output?: string; diff --git a/src/webfont/sdf.ts b/src/webfont/sdf.ts index cbe8527..fa308ca 100644 --- a/src/webfont/sdf.ts +++ b/src/webfont/sdf.ts @@ -45,7 +45,9 @@ function signedFont( const newTextureAsset = createNewAssetAt(asset, newTextureName); // don't compress! - newTextureAsset.metaData.copy = true; + newTextureAsset.metaData[options.tags.nc] = true; + newTextureAsset.metaData[options.tags.fix] = true; + newTextureAsset.metaData.mIgnore = true; assets.push(newTextureAsset); diff --git a/test/webfont/Webfont.test.ts b/test/webfont/Webfont.test.ts index f694367..7c7ef5b 100644 --- a/test/webfont/Webfont.test.ts +++ b/test/webfont/Webfont.test.ts @@ -2,6 +2,8 @@ import fs from 'fs-extra'; import { existsSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; import { AssetPack } from '../../src/core/index.js'; +import { compress } from '../../src/image/compress.js'; +import { mipmap } from '../../src/image/mipmap.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { msdfFont, sdfFont, webfont } from '../../src/webfont/index.js'; import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; @@ -228,7 +230,7 @@ describe('Webfont', () => expect(existsSync(`${outputDir}/sdf.1.png`)).toBe(true); }); - it.skip('should generate manifest correctly', async () => + it('should generate manifest correctly', async () => { const testName = 'webfont-manifest'; const inputDir = getInputDir(pkg, testName); @@ -258,6 +260,26 @@ describe('Webfont', () => ], folders: [], }, + { + name: 'msdfFolder{msdf}', + files: [ + { + name: 'ttf.ttf', + content: assetPath('font/Roboto-Regular.ttf'), + }, + ], + folders: [], + }, + { + name: 'svgFolder{wf}', + files: [ + { + name: 'svg.svg', + content: assetPath('font/Roboto-Regular.svg'), + }, + ], + folders: [], + } ], }); @@ -266,8 +288,11 @@ describe('Webfont', () => output: outputDir, cache: false, pipes: [ - webfont(), // import is breaking definition file + webfont(), sdfFont(), + msdfFont(), + mipmap(), + compress(), pixiManifest(), ] }); @@ -289,6 +314,15 @@ describe('Webfont', () => } } }, + { + alias: ['msdfFolder/ttf.ttf'], + src: ['msdfFolder/ttf.fnt'], + data: { + tags: { + msdf: true, + } + } + }, { alias: ['sdfFolder/ttf.ttf'], src: ['sdfFolder/ttf.fnt'], @@ -298,6 +332,15 @@ describe('Webfont', () => } } }, + { + alias: ['svgFolder/svg.svg'], + src: ['svgFolder/svg.woff2'], + data: { + tags: { + wf: true, + } + } + }, ], }); }); From dfd8c949fb8d53bd45985ca809938c560e994024 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:50:40 +0100 Subject: [PATCH 4/7] feat: multi-pack spritesheets --- src/pixi/index.ts | 2 - src/texture-packer/index.ts | 1 - src/texture-packer/packer/createJsons.ts | 56 +++--- src/texture-packer/texturePacker.ts | 1 + .../texturePackerCacheBuster.ts | 20 ++- src/texture-packer/texturePackerCompress.ts | 35 +++- .../texturePackerManifestMod.ts | 167 ------------------ test/manifest/Manifest.test.ts | 31 ++-- .../texturePackerCacheBuster.test.ts | 90 ++++++++-- .../texturePackerManifest.test.ts | 32 ++-- 10 files changed, 169 insertions(+), 266 deletions(-) delete mode 100644 src/texture-packer/texturePackerManifestMod.ts diff --git a/src/pixi/index.ts b/src/pixi/index.ts index 1afbc7c..54b22cd 100644 --- a/src/pixi/index.ts +++ b/src/pixi/index.ts @@ -12,7 +12,6 @@ import { spineAtlasMipmap } from '../spine/spineAtlasMipmap.js'; import { texturePacker } from '../texture-packer/texturePacker.js'; import { texturePackerCacheBuster } from '../texture-packer/texturePackerCacheBuster.js'; import { texturePackerCompress } from '../texture-packer/texturePackerCompress.js'; -import { texturePackerManifestMod } from '../texture-packer/texturePackerManifestMod.js'; import { webfont } from '../webfont/webfont.js'; import type { FfmpegOptions } from '../ffmpeg/ffmpeg.js'; @@ -109,7 +108,6 @@ export function pixiAssetPackPipes(config: PixiAssetPack) pipes.push( pixiManifest(manifestOptions), - texturePackerManifestMod(manifestOptions), spineAtlasManifestMod(manifestOptions), ); diff --git a/src/texture-packer/index.ts b/src/texture-packer/index.ts index 8958b40..477af01 100644 --- a/src/texture-packer/index.ts +++ b/src/texture-packer/index.ts @@ -1,4 +1,3 @@ export * from './texturePacker.js'; export * from './texturePackerCacheBuster.js'; export * from './texturePackerCompress.js'; -export * from './texturePackerManifestMod.js'; diff --git a/src/texture-packer/packer/createJsons.ts b/src/texture-packer/packer/createJsons.ts index f42d0ee..c920fd0 100644 --- a/src/texture-packer/packer/createJsons.ts +++ b/src/texture-packer/packer/createJsons.ts @@ -15,12 +15,12 @@ export function createJsons( width: number, height: number, options: { - textureName: string, - resolution: number, - textureFormat: 'png' | 'jpg', - nameStyle: 'short' | 'relative', - removeFileExtension: boolean - } + textureName: string; + resolution: number; + textureFormat: 'png' | 'jpg'; + nameStyle: 'short' | 'relative'; + removeFileExtension: boolean; + }, ) { const bins = packer.bins; @@ -32,7 +32,7 @@ export function createJsons( const bin = bins[i]; const json: any = { - frames: {} + frames: {}, }; for (let j = 0; j < bin.rects.length; j++) @@ -44,7 +44,7 @@ export function createJsons( x: rect.x, y: rect.y, w: rect.width, - h: rect.height + h: rect.height, }, rotated: rect.rot, trimmed: rect.textureData.trimmed, @@ -52,42 +52,42 @@ export function createJsons( x: rect.textureData.trimOffsetLeft, y: rect.textureData.trimOffsetTop, w: rect.width, - h: rect.height + h: rect.height, }, sourceSize: { w: rect.textureData.originalWidth, - h: rect.textureData.originalHeight - } + h: rect.textureData.originalHeight, + }, }; } + const name = createName(options.textureName, i, bins.length !== 1, options.resolution, options.textureFormat); + + let multiPack: string[] | null = null; + + if (bins.length > 1 && i === 0) + { + const binsWithoutFirst = bins.slice(1); + + multiPack = binsWithoutFirst.map((_, i) => name.replace('-0', `-${i + 1}`).replace('.png', `.json`)); + } + json.meta = { app: 'http://github.com/pixijs/assetpack', version: '1.0', - image: createName( - options.textureName, - i, - bins.length !== 1, - options.resolution, - options.textureFormat - ), + image: name, format: 'RGBA8888', size: { w: width, - h: height + h: height, }, - scale: options.resolution + scale: options.resolution, + related_multi_packs: multiPack, }; jsons.push({ - name: createName( - options.textureName, - i, - bins.length !== 1, - options.resolution, - 'json' - ), - json + name: createName(options.textureName, i, bins.length !== 1, options.resolution, 'json'), + json, }); } diff --git a/src/texture-packer/texturePacker.ts b/src/texture-packer/texturePacker.ts index eb08ce0..d494b10 100644 --- a/src/texture-packer/texturePacker.ts +++ b/src/texture-packer/texturePacker.ts @@ -159,6 +159,7 @@ export function texturePacker(_options: TexturePackerOptions = {}): AssetPipe asset.getFinalTransformedChildren()[0]); - jsonAssets.forEach((jsonAsset) => + // loop through all the json files back to front + for (let i = jsonAssets.length - 1; i >= 0; i--) { // we are going to replace the textures in the atlas file with the new cache busted textures // as we do this, the hash of the atlas file will change, so we need to update the path // and also remove the original file. - + const jsonAsset = jsonAssets[i]; const originalHash = jsonAsset.hash; const originalPath = jsonAsset.path; @@ -75,15 +76,24 @@ export function texturePackerCacheBuster( json.meta.image = cacheBustedTexture.filename; - jsonAsset.buffer = Buffer.from(JSON.stringify(json)); + if (json.meta.related_multi_packs) + { + json.meta.related_multi_packs = (json.meta.related_multi_packs as string[]).map((pack) => + { + const foundAssets = findAssets((asset) => + asset.filename === pack, asset, true); - jsonAsset.path = jsonAsset.path.replace(originalHash, jsonAsset.hash); + return foundAssets[0].getFinalTransformedChildren()[0].filename; + }); + } + jsonAsset.buffer = Buffer.from(JSON.stringify(json)); + jsonAsset.path = jsonAsset.path.replace(originalHash, jsonAsset.hash); fs.removeSync(originalPath); // rewrite.. fs.writeFileSync(jsonAsset.path, jsonAsset.buffer); - }); + } textureJsonFilesToFix.length = 0; } diff --git a/src/texture-packer/texturePackerCompress.ts b/src/texture-packer/texturePackerCompress.ts index d7cdecb..54b85fa 100644 --- a/src/texture-packer/texturePackerCompress.ts +++ b/src/texture-packer/texturePackerCompress.ts @@ -5,7 +5,9 @@ import type { CompressOptions } from '../image/compress.js'; export type TexturePackerCompressOptions = PluginOptions<'tps' | 'nc'> & Omit; -export function texturePackerCompress(_options?: TexturePackerCompressOptions): AssetPipe +export function texturePackerCompress( + _options?: TexturePackerCompressOptions, +): AssetPipe { const defaultOptions = { ...{ @@ -17,8 +19,8 @@ export function texturePackerCompress(_options?: TexturePackerCompressOptions): tags: { tps: 'tps', nc: 'nc', - ..._options?.tags - } + ..._options?.tags, + }, }; return { @@ -26,17 +28,19 @@ export function texturePackerCompress(_options?: TexturePackerCompressOptions): defaultOptions, test(asset: Asset, options) { - return (asset.allMetaData[options.tags.tps] + return ( + asset.allMetaData[options.tags.tps] && !asset.allMetaData[options.tags.nc] - && checkExt(asset.path, '.json')); + && checkExt(asset.path, '.json') + ); }, async transform(asset: Asset, options) { const formats = []; - if (options.avif)formats.push('avif'); - if (options.png)formats.push('png'); - if (options.webp)formats.push('webp'); + if (options.avif) formats.push('avif'); + if (options.png) formats.push('png'); + if (options.webp) formats.push('webp'); const json = JSON.parse(asset.buffer.toString()); @@ -49,8 +53,21 @@ export function texturePackerCompress(_options?: TexturePackerCompressOptions): json.meta.image = swapExt(json.meta.image, extension); const newAsset = createNewAssetAt(asset, newFileName); + const newJson = JSON.parse(JSON.stringify(json)); + + if (newJson.meta.related_multi_packs) + { + newJson.meta.related_multi_packs = (newJson.meta.related_multi_packs as string[]).map((pack) => + swapExt(pack, `${extension}.json`), + ); + } + + newAsset.buffer = Buffer.from(JSON.stringify(newJson, null, 2)); - newAsset.buffer = Buffer.from(JSON.stringify(json, null, 2)); + if (!newJson.meta.related_multi_packs) + { + newAsset.metaData.mIgnore = true; + } return newAsset; }); diff --git a/src/texture-packer/texturePackerManifestMod.ts b/src/texture-packer/texturePackerManifestMod.ts deleted file mode 100644 index b6b53aa..0000000 --- a/src/texture-packer/texturePackerManifestMod.ts +++ /dev/null @@ -1,167 +0,0 @@ -import fs from 'fs-extra'; -import { findAssets, Logger, path } from '../core/index.js'; - -import type { Asset, AssetPipe, PluginOptions } from '../core/index.js'; - -export interface TexturePackerManifestOptions extends PluginOptions<'tps'> -{ - output?: string; -} - -/** - * This pipe will modify the manifest generated by 'pixiManifest'. It will remove the entry - * in the manifest - which groups all the textures and jsons under one asset and replace it with - * the assets representing individual pages of the sprite sheet. - * - * Once done, it rewrites the manifest. - * - * This should be added after the `pixiManifest` pipe. - * - * ensure that the same output path is passed to the pipe as the `pixiManifest` pipe. Otherwise - * the manifest will not be found. - * - * As this pipe needs to know about all the textures in the texture files most of the work is done - * in the finish method. - * - * Kind of like applying a patch at the end of the manifest process. - * - * @param _options - * @returns - */ -export function texturePackerManifestMod( - _options: TexturePackerManifestOptions = {} -): AssetPipe -{ - const defaultOptions = { - output: 'manifest.json', - ..._options, - tags: { - tps: 'tps', - ..._options.tags, - }, - }; - - return { - folder: false, - name: 'texture-packer-manifest', - defaultOptions, - - async finish(asset: Asset, options, pipeSystem) - { - const manifestLocation = options.output; - - const newFileName = path.dirname(manifestLocation) === '.' - ? path.joinSafe(pipeSystem.outputPath, manifestLocation) : manifestLocation; - - if (!fs.existsSync(newFileName)) - { - // eslint-disable-next-line max-len - Logger.warn(`[AssetPack][texture-packer-manifest] Texture Packer Manifest could not find the manifest: ${newFileName}. Please ensure that the 'pixiManifest' output and the 'texturePackerManifest' output are the same.`); - - return; - } - - const manifest = fs.readJsonSync(newFileName); - - // used to make sure we don't process the same asset twice. - const duplicateHash: Record = {}; - - const originalJsonAssets = findAssets((asset) => - asset.metaData[options.tags.tps] && !asset.transformParent, asset, true); - - originalJsonAssets.forEach((originalJsonAsset) => - { - // if we have already processed this asset then skip it. - if (duplicateHash[originalJsonAsset.path]) return; - - duplicateHash[originalJsonAsset.path] = true; - - // now get all the final assets that were created for this sprite sheet. - // this will include all the variations of the textures and the jsons. - const finalJsonAssets = originalJsonAsset.getFinalTransformedChildren(); - - // next find the manifestAsset data that was added by the manifest - this is the data that - // we need to remove and replace with the new data for each PAGE of the sprite sheet. - const jsonManifestPath = path.relative(pipeSystem.outputPath, finalJsonAssets[0].path); - - const { manifestAsset, bundle } = findManifestAsset(manifest, jsonManifestPath); - - const texturePackedAssets = getTexturePackedAssets(finalJsonAssets); - - // now we need to get the pages of the sprite sheet and update the manifest with the new pages. - texturePackedAssets.forEach((pages, pageIndex) => - { - bundle.assets.push({ - // use the same alias as the original asset but add the page index to it. - // we don't control what the alias is so we use whats here. - alias: manifestAsset.alias.map((alias: string) => - getAlias(alias, pageIndex, texturePackedAssets.length > 1) - ), - src: pages - .map((finalAsset) => path.relative(pipeSystem.outputPath, finalAsset.path)) - .sort((a, b) => b.localeCompare(a)), - data: manifestAsset.data - }); - }); - - // to wrap up remove the original manifest asset from the bundle. - bundle.assets.splice(bundle.assets.indexOf(manifestAsset), 1); - }); - - // write the new manifest. - fs.writeJSONSync(newFileName, manifest, { spaces: 2 }); - - return; - } - }; -} - -function getTexturePackedAssets(assets: Asset[]) -{ - // first get the jsons.. - const jsonAssets = assets.filter((asset) => asset.extension === '.json'); - - const groupAssets: Asset[][] = []; - - for (let i = 0; i < jsonAssets.length; i++) - { - const jsonAsset = jsonAssets[i]; - - groupAssets[jsonAsset.transformData.page] ??= []; - - groupAssets[jsonAsset.transformData.page].push(jsonAsset); - } - - return groupAssets; -} - -function findManifestAsset(manifest: any, assetPath: string): {bundle: any, manifestAsset: any} -{ - for (let i = 0; i < manifest.bundles.length; i++) - { - const bundle = manifest.bundles[i]; - const assets = bundle.assets; - - const manifestAsset = assets.find((asset: {src: string[]}) => - - asset.src.includes(assetPath) - ); - - if (manifestAsset) - { - return { bundle, manifestAsset }; - } - } - - return { bundle: null, manifestAsset: null }; -} - -function getAlias(alias: string, pageIndex: number, multiPage: boolean) -{ - if (multiPage) - { - return `${alias}-${pageIndex}`; - } - - return alias; -} diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 96dfbbf..a3dac26 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -6,7 +6,7 @@ import { audio } from '../../src/ffmpeg/index.js'; import { compress, mipmap } from '../../src/image/index.js'; import { pixiManifest } from '../../src/manifest/index.js'; import { spineAtlasManifestMod, spineAtlasMipmap } from '../../src/spine/index.js'; -import { texturePacker, texturePackerManifestMod } from '../../src/texture-packer/index.js'; +import { texturePacker, texturePackerCompress } from '../../src/texture-packer/index.js'; import { assetPath, createFolder, getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; import type { File } from '../utils/index.js'; @@ -115,13 +115,13 @@ describe('Manifest', () => output: outputDir, cache: useCache, pipes: [ + audio(), + spineAtlasMipmap(), texturePacker({ resolutionOptions: { maximumTextureSize: 512, }, }), - audio(), - spineAtlasMipmap(), mipmap(), compress({ png: true, @@ -129,9 +129,9 @@ describe('Manifest', () => webp: true, avif: false, }), + texturePackerCompress(), pixiManifest(), spineAtlasManifestMod(), - texturePackerManifestMod(), ], }); @@ -176,18 +176,11 @@ describe('Manifest', () => }, }, { - alias: ['bundle/tps-0'], - src: ['bundle/tps-0@0.5x.json', 'bundle/tps-0.json'], - data: { - tags: { - tps: true, - m: true, - }, - }, - }, - { - alias: ['bundle/tps-1'], - src: ['bundle/tps-1@0.5x.json', 'bundle/tps-1.json'], + alias: ['bundle/tps'], + src: ['bundle/tps-0@0.5x.webp.json', + 'bundle/tps-0@0.5x.png.json', + 'bundle/tps-0.webp.json', + 'bundle/tps-0.png.json'], data: { tags: { tps: true, @@ -232,7 +225,7 @@ describe('Manifest', () => }, ], }); - }, 30000); + }); it('should copy over files and add them to manifest', async () => { @@ -470,7 +463,6 @@ describe('Manifest', () => includeMetaData: false, }), spineAtlasManifestMod(), - texturePackerManifestMod(), ], }); @@ -568,7 +560,6 @@ describe('Manifest', () => includeMetaData: false, }), spineAtlasManifestMod(), - texturePackerManifestMod(), ], }); @@ -686,7 +677,6 @@ describe('Manifest', () => includeMetaData: false, }), spineAtlasManifestMod(), - texturePackerManifestMod(), ], }); @@ -833,7 +823,6 @@ describe('Manifest', () => includeMetaData: false, }), spineAtlasManifestMod(), - texturePackerManifestMod(), ], }); diff --git a/test/texture-packer/texturePackerCacheBuster.test.ts b/test/texture-packer/texturePackerCacheBuster.test.ts index 8b04212..1ff9b36 100644 --- a/test/texture-packer/texturePackerCacheBuster.test.ts +++ b/test/texture-packer/texturePackerCacheBuster.test.ts @@ -3,8 +3,10 @@ import { glob } from 'glob'; import { describe, expect, it } from 'vitest'; import { cacheBuster } from '../../src/cache-buster/index.js'; import { AssetPack } from '../../src/core/index.js'; +import { compress } from '../../src/image/compress.js'; import { texturePacker } from '../../src/texture-packer/texturePacker.js'; import { texturePackerCacheBuster } from '../../src/texture-packer/texturePackerCacheBuster.js'; +import { texturePackerCompress } from '../../src/texture-packer/texturePackerCompress.js'; import { createTPSFolder } from '../utils/createTPSFolder.js'; import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; @@ -28,6 +30,7 @@ describe('Texture Packer Cache Buster', () => texturePacker({ resolutionOptions: { resolutions: { default: 1 }, + maximumTextureSize: 512, }, }), cacheBuster(), @@ -41,9 +44,9 @@ describe('Texture Packer Cache Buster', () => const files = await glob(globPath); // need two sets of files - expect(files.length).toBe(2); - expect(files.filter((file) => file.endsWith('.json')).length).toBe(1); - expect(files.filter((file) => file.endsWith('.png')).length).toBe(1); + expect(files.length).toBe(4); + expect(files.filter((file) => file.endsWith('.json')).length).toBe(2); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(2); const jsonFiles = files.filter((file) => file.endsWith('.json')); const pngFiles = files.filter((file) => file.endsWith('.png')); @@ -53,18 +56,81 @@ describe('Texture Packer Cache Buster', () => { const rawJson = fs.readJSONSync(jsonFile); - const checkFiles = (fileList: string[]) => + expect(pngFiles.includes(`${outputDir}/${rawJson.meta.image}`)).toBe(true); + + // check if json has related_multi_packs + if (rawJson.meta.related_multi_packs) + { + const relatedMultiPacks = rawJson.meta.related_multi_packs as string[]; + + expect(relatedMultiPacks.length).toBe(1); + expect(jsonFiles.includes(`${outputDir}/${relatedMultiPacks[0]}`)).toBe(true); + } + }); + }); + + it('should create compressed sprite sheet and correctly update json', async () => + { + const testName = 'tp-cache-bust-compress'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + createTPSFolder(testName, pkg); + + const assetpack = new AssetPack({ + entry: inputDir, cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: false, + pipes: [ + texturePacker({ + resolutionOptions: { + resolutions: { default: 1 }, + maximumTextureSize: 512, + }, + }), + compress(), + texturePackerCompress(), + cacheBuster(), + texturePackerCacheBuster() + ] + }); + + await assetpack.run(); + + const globPath = `${outputDir}/*.{json,png,webp}`; + const files = await glob(globPath); + + expect(files.length).toBe(8); + expect(files.filter((file) => file.endsWith('.json')).length).toBe(4); + expect(files.filter((file) => file.endsWith('.png')).length).toBe(2); + expect(files.filter((file) => file.endsWith('.webp')).length).toBe(2); + + const jsonFiles = files.filter((file) => file.endsWith('.json')); + const pngFiles = files.filter((file) => file.endsWith('.png')); + const webpFiles = files.filter((file) => file.endsWith('.webp')); + + // check that the files are correct + jsonFiles.forEach((jsonFile) => + { + const rawJson = fs.readJSONSync(jsonFile); + + if (rawJson.meta.image.includes('.webp')) { - fileList.forEach((file) => - { - // remove the outputDir - file = file.replace(`${outputDir}/`, ''); + expect(webpFiles.includes(`${outputDir}/${rawJson.meta.image}`)).toBe(true); + } + else + { + expect(pngFiles.includes(`${outputDir}/${rawJson.meta.image}`)).toBe(true); + } - expect(rawJson.meta.image).toEqual(file); - }); - }; + // check if json has related_multi_packs + if (rawJson.meta.related_multi_packs) + { + const relatedMultiPacks = rawJson.meta.related_multi_packs as string[]; - checkFiles(pngFiles); + expect(relatedMultiPacks.length).toBe(1); + expect(jsonFiles.includes(`${outputDir}/${relatedMultiPacks[0]}`)).toBe(true); + } }); }); }); diff --git a/test/texture-packer/texturePackerManifest.test.ts b/test/texture-packer/texturePackerManifest.test.ts index b36ee2f..f7c626e 100644 --- a/test/texture-packer/texturePackerManifest.test.ts +++ b/test/texture-packer/texturePackerManifest.test.ts @@ -1,9 +1,9 @@ import fs from 'fs-extra'; import { describe, expect, it } from 'vitest'; import { AssetPack } from '../../src/core/index.js'; +import { compress } from '../../src/image/compress.js'; import { pixiManifest } from '../../src/manifest/index.js'; -import { texturePacker } from '../../src/texture-packer/index.js'; -import { texturePackerManifestMod } from '../../src/texture-packer/texturePackerManifestMod.js'; +import { texturePacker, texturePackerCompress } from '../../src/texture-packer/index.js'; import { createTPSFolder } from '../utils/createTPSFolder.js'; import { getCacheDir, getInputDir, getOutputDir } from '../utils/index.js'; @@ -30,7 +30,6 @@ describe('Texture Packer Compression', () => }, }), pixiManifest(), - texturePackerManifestMod(), ] }); @@ -70,12 +69,13 @@ describe('Texture Packer Compression', () => pipes: [ texturePacker({ resolutionOptions: { - resolutions: { default: 1 }, - maximumTextureSize: 512 + resolutions: { default: 1, low: 0.5 }, + maximumTextureSize: 512, }, }), + compress(), + texturePackerCompress(), pixiManifest(), - texturePackerManifestMod(), ] }); @@ -86,10 +86,13 @@ describe('Texture Packer Compression', () => expect(manifest.bundles[0].assets).toEqual([ { alias: [ - 'sprites-0' + 'sprites' ], src: [ - 'sprites-0.json' + 'sprites-0@0.5x.webp.json', + 'sprites-0@0.5x.png.json', + 'sprites-0.webp.json', + 'sprites-0.png.json', ], data: { tags: { @@ -97,19 +100,6 @@ describe('Texture Packer Compression', () => } } }, - { - alias: [ - 'sprites-1' - ], - src: [ - 'sprites-1.json' - ], - data: { - tags: { - tps: true - } - } - } ]); }); }); From 3d23204ae90946ac056877d88d36f20ee08971ee Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:54:13 +0100 Subject: [PATCH 5/7] update --- test/webfont/Webfont.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/webfont/Webfont.test.ts b/test/webfont/Webfont.test.ts index 7c7ef5b..b924fc9 100644 --- a/test/webfont/Webfont.test.ts +++ b/test/webfont/Webfont.test.ts @@ -343,5 +343,5 @@ describe('Webfont', () => }, ], }); - }); + }, 10000); }); From dccffe9d9f2c4e2b0a62d2beb1a1b894977c3771 Mon Sep 17 00:00:00 2001 From: Zyie <24736175+Zyie@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:34:51 +0100 Subject: [PATCH 6/7] add test --- src/manifest/pixiManifest.ts | 3 +- test/manifest/Manifest.test.ts | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/manifest/pixiManifest.ts b/src/manifest/pixiManifest.ts index 6d07d36..bd630dd 100644 --- a/src/manifest/pixiManifest.ts +++ b/src/manifest/pixiManifest.ts @@ -122,13 +122,14 @@ function collectAssets( } const bundleAssets = localBundle.assets; - const finalAssets = asset.getFinalTransformedChildren(); if (asset.transformChildren.length > 0 && !asset.inheritedMetaData[options.tags!.mIgnore!]) { const nonIgnored = finalAssets.filter((finalAsset) => !finalAsset.inheritedMetaData[options.tags!.mIgnore!]); + if (nonIgnored.length === 0) return; + bundleAssets.push({ alias: getShortNames(stripTags(path.relative(entryPath, asset.path)), options), src: nonIgnored diff --git a/test/manifest/Manifest.test.ts b/test/manifest/Manifest.test.ts index 96dfbbf..29ae8a8 100644 --- a/test/manifest/Manifest.test.ts +++ b/test/manifest/Manifest.test.ts @@ -998,6 +998,58 @@ describe('Manifest', () => ], }); }); + + it('should ignore files with the mIgnore tag', async () => + { + const testName = 'manifest-ignore'; + const inputDir = getInputDir(pkg, testName); + const outputDir = getOutputDir(pkg, testName); + + createFolder(pkg, { + name: testName, + files: [ + { + name: '1.png', + content: assetPath('image/sp-1.png'), + }, + { + name: '2{mIgnore}.png', + content: assetPath('image/sp-1.png'), + }, + ], + folders: [], + }); + + const assetpack = new AssetPack({ + entry: inputDir, + cacheLocation: getCacheDir(pkg, testName), + output: outputDir, + cache: false, + pipes: [ + pixiManifest({ + includeMetaData: false, + }), + ], + }); + + await assetpack.run(); + + const manifest = sortObjectProperties(await fs.readJSONSync(`${outputDir}/manifest.json`)); + + expect(manifest).toEqual({ + bundles: [ + { + name: 'default', + assets: [ + { + alias: ['1.png'], + src: ['1.png'], + }, + ], + }, + ], + }); + }); }); function sortObjectProperties(obj: any) From a8ebc80f7594de3b8420e05b0d10e942218f7798 Mon Sep 17 00:00:00 2001 From: Mat Groves Date: Mon, 24 Jun 2024 15:23:25 +0100 Subject: [PATCH 7/7] tweak create jsons --- src/texture-packer/packer/createJsons.ts | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/texture-packer/packer/createJsons.ts b/src/texture-packer/packer/createJsons.ts index c920fd0..8c8144c 100644 --- a/src/texture-packer/packer/createJsons.ts +++ b/src/texture-packer/packer/createJsons.ts @@ -61,28 +61,17 @@ export function createJsons( }; } - const name = createName(options.textureName, i, bins.length !== 1, options.resolution, options.textureFormat); - - let multiPack: string[] | null = null; - - if (bins.length > 1 && i === 0) - { - const binsWithoutFirst = bins.slice(1); - - multiPack = binsWithoutFirst.map((_, i) => name.replace('-0', `-${i + 1}`).replace('.png', `.json`)); - } - json.meta = { app: 'http://github.com/pixijs/assetpack', version: '1.0', - image: name, + image: createName(options.textureName, i, bins.length !== 1, options.resolution, options.textureFormat), format: 'RGBA8888', size: { w: width, h: height, }, scale: options.resolution, - related_multi_packs: multiPack, + related_multi_packs: null, }; jsons.push({ @@ -91,5 +80,16 @@ export function createJsons( }); } + // before we leave, lets connect all the jsons to the first json.. + + const firstJsonMeta = jsons[0].json.meta; + + firstJsonMeta.related_multi_packs = []; + + for (let i = 1; i < jsons.length; i++) + { + firstJsonMeta.related_multi_packs.push(jsons[i].name); + } + return jsons; }