Skip to content

Commit

Permalink
feat: add mIgnore tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Jun 20, 2024
1 parent 85d5a31 commit 56a613c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 22 deletions.
10 changes: 6 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
32 changes: 19 additions & 13 deletions src/manifest/pixiManifest.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,7 +28,7 @@ export interface PixiManifestEntry
};
}

export interface PixiManifestOptions
export interface PixiManifestOptions extends PluginOptions<'mIgnore' | 'manifest'>
{
output?: string;
createShortcuts?: boolean;
Expand All @@ -38,12 +38,16 @@ export interface PixiManifestOptions

export function pixiManifest(_options: PixiManifestOptions = {}): AssetPipe<PixiManifestOptions>
{
const defaultOptions = {
const defaultOptions: PixiManifestOptions = {
output: 'manifest.json',
createShortcuts: false,
trimExtensions: false,
includeMetaData: true,
..._options
..._options,
tags: {
manifest: 'm',
mIgnore: 'mIgnore'
}
};

return {
Expand Down Expand Up @@ -98,7 +102,7 @@ function collectAssets(
outputPath = '',
entryPath = '',
bundles: PixiBundle[],
bundle: PixiBundle,
bundle: PixiBundle
)
{
if (asset.skip) return;
Expand All @@ -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),
Expand All @@ -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 ? {
Expand Down
4 changes: 3 additions & 1 deletion src/spine/spineAtlasCacheBuster.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/spine/spineAtlasManifestMod.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/webfont/sdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
47 changes: 45 additions & 2 deletions test/webfont/Webfont.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: [],
}
],
});

Expand All @@ -266,8 +288,11 @@ describe('Webfont', () =>
output: outputDir,
cache: false,
pipes: [
webfont(), // import is breaking definition file
webfont(),
sdfFont(),
msdfFont(),
mipmap(),
compress(),
pixiManifest(),
]
});
Expand All @@ -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'],
Expand All @@ -298,6 +332,15 @@ describe('Webfont', () =>
}
}
},
{
alias: ['svgFolder/svg.svg'],
src: ['svgFolder/svg.woff2'],
data: {
tags: {
wf: true,
}
}
},
],
});
});
Expand Down

0 comments on commit 56a613c

Please sign in to comment.