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..bd630dd 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), @@ -118,14 +122,17 @@ function collectAssets( } const bundleAssets = localBundle.assets; - 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!]); + + if (nonIgnored.length === 0) return; + 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/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) 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, + } + } + }, ], }); });