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] 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, + } + } + }, ], }); });