diff --git a/package-lock.json b/package-lock.json index 6665026..7fa7481 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,9 +15,7 @@ "@rollup/plugin-typescript": "^11.0.0", "@types/fs-extra": "^11.0.1", "@types/jest": "^29.4.0", - "chokidar": "^3.5.3", "eslint": "^8.33.0", - "eventemitter3": "^5.0.1", "find-up": "^5.0.0", "fs-extra": "^11.1.0", "husky": "^8.0.3", @@ -3408,6 +3406,10 @@ "resolved": "packages/ffmpeg", "link": true }, + "node_modules/@play-co/assetpack-plugin-image": { + "resolved": "packages/image", + "link": true + }, "node_modules/@play-co/assetpack-plugin-json": { "resolved": "packages/json", "link": true @@ -3416,10 +3418,6 @@ "resolved": "packages/manifest", "link": true }, - "node_modules/@play-co/assetpack-plugin-mipmap-compress": { - "resolved": "packages/mipmap-compress", - "link": true - }, "node_modules/@play-co/assetpack-plugin-spine": { "resolved": "packages/spine", "link": true @@ -3587,6 +3585,14 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/cli-progress": { + "version": "3.11.5", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/clone": { "version": "2.1.1", "dev": true, @@ -4412,6 +4418,7 @@ }, "node_modules/bl": { "version": "4.1.0", + "dev": true, "license": "MIT", "dependencies": { "buffer": "^5.5.0", @@ -4841,6 +4848,7 @@ }, "node_modules/cli-cursor": { "version": "3.1.0", + "dev": true, "license": "MIT", "dependencies": { "restore-cursor": "^3.1.0" @@ -4861,6 +4869,7 @@ }, "node_modules/cli-spinners": { "version": "2.6.1", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -5499,6 +5508,7 @@ }, "node_modules/defaults": { "version": "1.0.4", + "dev": true, "license": "MIT", "dependencies": { "clone": "^1.0.2" @@ -5509,6 +5519,7 @@ }, "node_modules/defaults/node_modules/clone": { "version": "1.0.4", + "dev": true, "license": "MIT", "engines": { "node": ">=0.8" @@ -6053,11 +6064,6 @@ "node": ">=0.10.0" } }, - "node_modules/eventemitter3": { - "version": "5.0.1", - "dev": true, - "license": "MIT" - }, "node_modules/execa": { "version": "5.1.1", "dev": true, @@ -7389,6 +7395,7 @@ }, "node_modules/is-interactive": { "version": "1.0.0", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -7582,6 +7589,7 @@ }, "node_modules/is-unicode-supported": { "version": "0.1.0", + "dev": true, "license": "MIT", "engines": { "node": ">=10" @@ -8931,6 +8939,7 @@ }, "node_modules/log-symbols": { "version": "4.1.0", + "dev": true, "license": "MIT", "dependencies": { "chalk": "^4.1.0", @@ -9342,6 +9351,7 @@ }, "node_modules/mimic-fn": { "version": "2.1.0", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -10286,6 +10296,7 @@ }, "node_modules/onetime": { "version": "5.1.2", + "dev": true, "license": "MIT", "dependencies": { "mimic-fn": "^2.1.0" @@ -10342,6 +10353,7 @@ }, "node_modules/ora": { "version": "5.4.1", + "dev": true, "license": "MIT", "dependencies": { "bl": "^4.1.0", @@ -11503,6 +11515,7 @@ }, "node_modules/restore-cursor": { "version": "3.1.0", + "dev": true, "license": "MIT", "dependencies": { "onetime": "^5.1.0", @@ -12776,6 +12789,7 @@ }, "node_modules/wcwidth": { "version": "1.0.1", + "dev": true, "license": "MIT", "dependencies": { "defaults": "^1.0.3" @@ -13208,6 +13222,25 @@ "@play-co/assetpack-core": ">=0" } }, + "packages/compress": { + "name": "@play-co/assetpack-plugin-compress", + "version": "1.2.2", + "extraneous": true, + "license": "MIT", + "dependencies": { + "fs-extra": "^11.1.0", + "sharp": "^0.33.3" + }, + "devDependencies": { + "@play-co/assetpack-core": "1.2.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@play-co/assetpack-core": ">=0.0.0" + } + }, "packages/core": { "name": "@play-co/assetpack-core", "version": "1.2.2", @@ -13217,12 +13250,12 @@ "@pixi/runner": "^7.0.0", "chalk": "^4.1.2", "chokidar": "^3.5.2", + "cli-progress": "^3.12.0", "clone": "^2.1.2", "fs-extra": "^11.1.0", "merge": "^2.1.1", "minimatch": "5.1.1", "object-hash": "3.0.0", - "ora": "^5.4.1", "readline": "^1.3.0", "string-width": "^4.2.3", "strip-ansi": "^6.0.0", @@ -13230,6 +13263,7 @@ "upath": "^2.0.0" }, "devDependencies": { + "@types/cli-progress": "3.11.5", "@types/clone": "^2.1.1", "@types/object-hash": "^3.0.0" }, @@ -13259,6 +13293,23 @@ "@play-co/assetpack-plugin-manifest": ">=0.0.0" } }, + "packages/image": { + "version": "1.2.2", + "license": "MIT", + "dependencies": { + "fs-extra": "^11.1.0", + "sharp": "^0.33.3" + }, + "devDependencies": { + "@play-co/assetpack-core": "1.2.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@play-co/assetpack-core": ">=0.0.0" + } + }, "packages/json": { "name": "@play-co/assetpack-plugin-json", "version": "1.2.2", @@ -13294,9 +13345,10 @@ "@play-co/assetpack-core": ">=0.0.0" } }, - "packages/mipmap-compress": { - "name": "@play-co/assetpack-plugin-mipmap-compress", + "packages/mipmap": { + "name": "@play-co/assetpack-plugin-mipmap", "version": "1.2.2", + "extraneous": true, "license": "MIT", "dependencies": { "fs-extra": "^11.1.0", @@ -13321,14 +13373,14 @@ }, "devDependencies": { "@play-co/assetpack-core": "1.2.2", - "@play-co/assetpack-plugin-mipmap-compress": "1.2.2" + "@play-co/assetpack-plugin-image": "1.2.2" }, "engines": { "node": ">=16.0.0" }, "peerDependencies": { "@play-co/assetpack-core": ">=0.0.0", - "@play-co/assetpack-plugin-mipmap-compress": ">=0.0.0" + "@play-co/assetpack-plugin-image": ">=0.0.0" } }, "packages/texture-packer": { @@ -13344,14 +13396,14 @@ }, "devDependencies": { "@play-co/assetpack-core": "1.2.2", - "@play-co/assetpack-plugin-mipmap-compress": "1.2.2" + "@play-co/assetpack-plugin-image": "1.2.2" }, "engines": { "node": ">=16.0.0" }, "peerDependencies": { "@play-co/assetpack-core": ">=0.0.0", - "@play-co/assetpack-plugin-mipmap-compress": ">=0.0.0" + "@play-co/assetpack-plugin-image": ">=0.0.0" } }, "packages/texture-packer/node_modules/glob": { diff --git a/package.json b/package.json index 1e8632a..cadad5f 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,7 @@ "@rollup/plugin-typescript": "^11.0.0", "@types/fs-extra": "^11.0.1", "@types/jest": "^29.4.0", - "chokidar": "^3.5.3", "eslint": "^8.33.0", - "eventemitter3": "^5.0.1", "find-up": "^5.0.0", "fs-extra": "^11.1.0", "husky": "^8.0.3", diff --git a/packages/core/package.json b/packages/core/package.json index 92fbba4..304c6f7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -38,7 +38,7 @@ "merge": "^2.1.1", "minimatch": "5.1.1", "object-hash": "3.0.0", - "ora": "^5.4.1", + "cli-progress": "^3.12.0", "readline": "^1.3.0", "string-width": "^4.2.3", "strip-ansi": "^6.0.0", @@ -47,7 +47,8 @@ }, "devDependencies": { "@types/clone": "^2.1.1", - "@types/object-hash": "^3.0.0" + "@types/object-hash": "^3.0.0", + "@types/cli-progress": "3.11.5" }, "engines": { "node": ">=16.0.0" diff --git a/packages/core/src/Asset.ts b/packages/core/src/Asset.ts index 671675d..13bb264 100644 --- a/packages/core/src/Asset.ts +++ b/packages/core/src/Asset.ts @@ -13,7 +13,7 @@ export interface AssetOptions export class Asset { - static defaultOptions: AssetOptions = { + private _defaultOptions: AssetOptions = { path: '', isFolder: false, }; @@ -45,7 +45,7 @@ export class Asset constructor(options: AssetOptions) { - options = { ...Asset.defaultOptions, ...options }; + options = { ...this._defaultOptions, ...options }; this.path = options.path; this.isFolder = options.isFolder as boolean; diff --git a/packages/core/src/AssetIgnore.ts b/packages/core/src/AssetIgnore.ts index 3985fbe..2cd953b 100644 --- a/packages/core/src/AssetIgnore.ts +++ b/packages/core/src/AssetIgnore.ts @@ -4,19 +4,19 @@ import { path } from './utils/path'; export interface AssetIgnoreOptions { ignore: string | string[]; - basePath: string; + entryPath: string; } export class AssetIgnore { private _ignore: string[]; private _ignoreHash: Record = {}; - private _basePath: string; + private _entryPath: string; constructor(options: AssetIgnoreOptions) { this._ignore = (Array.isArray(options.ignore) ? options.ignore : [options.ignore]) as string[]; - this._basePath = options.basePath; + this._entryPath = options.entryPath; } public shouldIgnore(fullPath: string): boolean @@ -28,7 +28,7 @@ export class AssetIgnore _ignoreHash[fullPath] = false; if (_ignore.length > 0) { - const relativePath = path.relative(this._basePath, fullPath); + const relativePath = path.relative(this._entryPath, fullPath); for (let i = 0; i < _ignore.length; i++) { diff --git a/packages/core/src/AssetPack.ts b/packages/core/src/AssetPack.ts index 546b8c0..e8487d6 100644 --- a/packages/core/src/AssetPack.ts +++ b/packages/core/src/AssetPack.ts @@ -11,17 +11,17 @@ import objectHash from 'object-hash'; import { Logger } from './logger/Logger'; import { promiseAllConcurrent } from './utils/promiseAllConcurrent'; import { path } from './utils/path'; +import merge from 'merge'; export class AssetPack { - public static defaultConfig: AssetPackConfig = { + private _defaultConfig: AssetPackConfig = { entry: './static', output: './dist', ignore: [], cache: true, logLevel: 'info', pipes: [], - // files: [] }; readonly config: AssetPackConfig; @@ -33,16 +33,15 @@ export class AssetPack constructor(config: AssetPackConfig = {}) { - config = { ...AssetPack.defaultConfig, ...config }; - this.config = config; - this._entryPath = normalizePath(config.entry as string); - this._outputPath = normalizePath(config.output as string); + this.config = merge.recursive(true, this._defaultConfig, config); + this._entryPath = normalizePath(this.config.entry as string); + this._outputPath = normalizePath(this.config.output as string); Logger.init({ - level: config.logLevel || 'info' + level: this.config.logLevel || 'info', }); - const { pipes, cache, ...configWithoutPlugins } = config; + const { pipes, cache, ...configWithoutPlugins } = this.config; // make a hash.. const cacheName = [objectHash(configWithoutPlugins), ...(pipes as AssetPipe[]).map((pipe) => pipe.name)].join('-'); @@ -105,8 +104,8 @@ export class AssetPack this._assetWatcher = new AssetWatcher({ entryPath: this._entryPath, assetCacheData, - ignore: config.ignore, - assetSettingsData: config.assetSettings as AssetSettings[] || [], + ignore: this.config.ignore, + assetSettingsData: this.config.assetSettings as AssetSettings[] || [], onUpdate: async (root: Asset) => { Logger.report({ @@ -135,11 +134,6 @@ export class AssetPack } } }); - - Logger.report({ - type: 'buildStart', - message: config.entry, - }); } /** diff --git a/packages/core/src/AssetWatcher.ts b/packages/core/src/AssetWatcher.ts index fa2468a..c1bc4f7 100644 --- a/packages/core/src/AssetWatcher.ts +++ b/packages/core/src/AssetWatcher.ts @@ -7,6 +7,7 @@ import { AssetIgnore } from './AssetIgnore'; import type { AssetSettings } from './pipes/PipeSystem'; import { applySettingToAsset } from './utils/applySettingToAsset'; import { path } from './utils/path'; +import { Logger } from './logger/Logger'; export interface AssetWatcherOptions { @@ -26,18 +27,13 @@ interface ChangeData export class AssetWatcher { - static defaultOptions: Omit = { - entryPath: './src/assets', - ignore: [], - }; - private _watcher: chokidar.FSWatcher | undefined; private _assetHash: Record = {}; private _changes: ChangeData[] = []; private _entryPath = ''; - private _root: Asset = new Asset({ path: 'noob', isFolder: true }); + private _root: Asset = new Asset({ path: 'noop', isFolder: true }); private _timeoutId: NodeJS.Timeout | undefined; private _onUpdate: (root: Asset) => Promise; private _updatingPromise: Promise = Promise.resolve(); @@ -45,12 +41,10 @@ export class AssetWatcher private _ignore: AssetIgnore; private _assetSettingsData: AssetSettings[]; private _assetCacheData: Record | undefined | null; - private _inited = false; + private _initialised = false; constructor(options: AssetWatcherOptions) { - options = { ...AssetWatcher.defaultOptions, ...options }; - const entryPath = options.entryPath; this._onUpdate = options.onUpdate; @@ -58,8 +52,8 @@ export class AssetWatcher this._entryPath = entryPath; this._ignore = new AssetIgnore({ - ignore: options.ignore as string[], - basePath: entryPath + ignore: options.ignore as string[] ?? [], + entryPath }); this._assetCacheData = options.assetCacheData; @@ -68,8 +62,13 @@ export class AssetWatcher private _init() { - if (this._inited) return; - this._inited = true; + if (this._initialised) return; + this._initialised = true; + + Logger.report({ + type: 'buildStart', + message: this._entryPath, + }); const asset = new Asset({ path: this._entryPath, @@ -93,14 +92,12 @@ export class AssetWatcher { this._init(); - // logAssetGraph(this._root); - return this._runUpdate(); } async watch() { - let firstRun = !this._inited; + let firstRun = !this._initialised; this._init(); @@ -162,7 +159,7 @@ export class AssetWatcher await this._updatingPromise; } - private _runUpdate() + private async _runUpdate() { return this._onUpdate(this._root).then(() => { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 9ae5d2e..768b0f6 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -1,4 +1,4 @@ -import type { LogLevel } from './logger/logLevel'; +import type { LogLevelKeys } from './logger/logLevel'; import type { AssetPipe } from './pipes/AssetPipe'; import type { AssetSettings } from './pipes/PipeSystem'; @@ -17,7 +17,7 @@ export interface AssetPackConfig * If true cached tree will be used */ cache?: boolean; - logLevel?: LogLevel; + logLevel?: LogLevelKeys; pipes?: (AssetPipe | AssetPipe[])[]; assetSettings?: AssetSettings[]; } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0b09391..e9b80ec 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,21 +1,19 @@ // export * from './AssetPack'; -// export * from './Cache'; -// export * from './config'; +export * from './config'; export * from './logger/Logger'; // export * from './Plugin'; // export * from './Processor'; // export * from './utils'; +export * from './Asset'; export * from './AssetPack'; export * from './config'; -export * from './pipes/PipeSystem'; export * from './pipes/AssetPipe'; +export * from './pipes/PipeSystem'; export * from './pipes/multiPipe'; -export * from './Asset'; export * from './utils/checkExt'; export * from './utils/createNewAssetAt'; -export * from './utils/stripTags'; export * from './utils/merge'; export * from './utils/path'; +export * from './utils/stripTags'; export * from './utils/swapExt'; export * from './utils/findAssetsWithFileName'; - diff --git a/packages/core/src/logger/Logger.ts b/packages/core/src/logger/Logger.ts index 6485f36..8fde31c 100644 --- a/packages/core/src/logger/Logger.ts +++ b/packages/core/src/logger/Logger.ts @@ -1,10 +1,10 @@ import type { ReporterEvent } from './Reporter'; import { Reporter } from './Reporter'; -import type { LogLevel } from './logLevel'; +import type { LogLevelKeys } from './logLevel'; export interface LoggerOptions { - level: LogLevel; + level: LogLevelKeys; } class LoggerClass diff --git a/packages/core/src/logger/Reporter.ts b/packages/core/src/logger/Reporter.ts index f0b6d57..ea3fad1 100644 --- a/packages/core/src/logger/Reporter.ts +++ b/packages/core/src/logger/Reporter.ts @@ -1,13 +1,13 @@ import chalk from 'chalk'; -import type { LogLevel } from './logLevel'; -import { LogLevelEnum } from './logLevel'; -import { persistMessage, resetWindow, setSpinnerStatus, updateSpinner } from './render'; +import type { LogLevelKeys } from './logLevel'; +import { LogLevel } from './logLevel'; +import { persistMessage, resetWindow, startProgress, stopProgress, updateProgress } from './render'; import { prettifyTime } from './utils'; export interface LogEvent { type: 'log'; - level: LogLevel; + level: LogLevelKeys; message: string; } @@ -20,96 +20,69 @@ export interface BuildEvent export type ReporterEvent = LogEvent | BuildEvent; -function getProgressBar(ratio: number) -{ - const size = 40; - const prog = []; - - for (let i = 0; i < size; i++) - { - if (ratio > (i / size)) - { - prog.push('█'); - } - else - { - prog.push('░'); - } - } - - return prog.join(''); -} export class Reporter { - public level: LogLevel = 'info'; + public level: LogLevelKeys = 'info'; private _buildTime = 0; // Exported only for test public report(event: ReporterEvent): void { - const logLevelFilter = LogLevelEnum[this.level || 'info']; + const logLevelFilter = LogLevel[this.level || 'info']; switch (event.type) { case 'buildStart': { - if (logLevelFilter < LogLevelEnum.info) + if (logLevelFilter < LogLevel.info) { break; } this._buildTime = Date.now(); - updateSpinner('Starting Plugins...'); // Clear any previous output resetWindow(); - - /// / persistMessage(`${chalk.blue.bold('›')} ${chalk.blue.bold(`Building: ${event.message}`)}`); - - setSpinnerStatus('success', `AssetPack Initialized`); + persistMessage(chalk.green.bold(`✔ AssetPack Initialized`)); persistMessage(`${chalk.blue.bold('›')} ${chalk.blue.bold(`Building: ${event.message}`)}`); + startProgress(); break; } case 'buildProgress': { - if (logLevelFilter < LogLevelEnum.info) + if (logLevelFilter < LogLevel.info) { break; } // render a bar.. - const progress = parseInt(event.message || '0', 10) / 100; + const progress = parseInt(event.message || '0', 10); - const progressBar = getProgressBar(progress); - - const message = `${progressBar} ${event.message}%`; - - updateSpinner(`${chalk.green(message)}`); + updateProgress(progress); break; } case 'buildSuccess': - if (logLevelFilter < LogLevelEnum.info) + if (logLevelFilter < LogLevel.info) { break; } - setSpinnerStatus('success', 'Build Complete'); + stopProgress(); resetWindow(); - persistMessage(chalk.green.bold(`✔ AssetPack Completed in ${prettifyTime(Date.now() - this._buildTime)}`)); break; case 'buildFailure': - if (logLevelFilter < LogLevelEnum.error) + if (logLevelFilter < LogLevel.error) { break; } + stopProgress(); resetWindow(); - - setSpinnerStatus('error', chalk.red.bold('Build failed.')); + persistMessage(chalk.green.bold(`✖ AssetPack Build Failed`)); break; case 'log': { - if (logLevelFilter < LogLevelEnum[event.level]) + if (logLevelFilter < LogLevel[event.level]) { break; } diff --git a/packages/core/src/logger/logLevel.ts b/packages/core/src/logger/logLevel.ts index adac450..136d472 100644 --- a/packages/core/src/logger/logLevel.ts +++ b/packages/core/src/logger/logLevel.ts @@ -1,4 +1,4 @@ -export enum LogLevelEnum +export enum LogLevel { none = 0, error = 1, @@ -7,4 +7,4 @@ export enum LogLevelEnum verbose = 4, } -export type LogLevel = keyof typeof LogLevelEnum; +export type LogLevelKeys = keyof typeof LogLevel; diff --git a/packages/core/src/logger/render.ts b/packages/core/src/logger/render.ts index 8983601..453d6c4 100644 --- a/packages/core/src/logger/render.ts +++ b/packages/core/src/logger/render.ts @@ -1,7 +1,6 @@ -// @flow import type { Writable } from 'stream'; +import cliProgress from 'cli-progress'; -import ora from 'ora'; import readline from 'readline'; import { countLines } from './utils'; import chalk from 'chalk'; @@ -14,28 +13,11 @@ let lineCount = 0; let errorLineCount = 0; let statusPersisted = false; -const spinner = ora({ - color: 'green', - stream: stdout, - discardStdin: false, - spinner: { - interval: 120, - frames: ['◐', '◓', '◑', '◒'] - } -}); const persistedMessages: string[] = []; export function writeOut(message: string, isError = false) { const processedMessage = `${message}\n`; - const hasSpinner = spinner.isSpinning; - - // Stop spinner so we don't duplicate it - if (hasSpinner) - { - spinner.stop(); - } - const lines = countLines(message); if (isError) @@ -48,12 +30,6 @@ export function writeOut(message: string, isError = false) stdout.write(processedMessage); lineCount += lines; } - - // Restart the spinner - if (hasSpinner) - { - spinner.start(); - } } export function persistMessage(message: string) @@ -64,39 +40,6 @@ export function persistMessage(message: string) writeOut(message); } -export function setSpinnerStatus(type: 'success' | 'error' | 'warn' | 'info', message?: string) -{ - const curMessage = spinner.text.replace(/\n$/, ''); - - if (type === 'error') - { - spinner.fail(chalk.red.bold(message ?? curMessage)); - } - else if (type === 'warn') - { - spinner.warn(chalk.yellow.bold(message ?? curMessage)); - } - else if (type === 'success') - { - spinner.succeed(chalk.green.bold(message ?? curMessage)); - } - else if (type === 'info') - { - spinner.info(chalk.blue.bold(message ?? curMessage)); - } - - lineCount++; -} - -export function updateSpinner(message: string) -{ - spinner.text = `${message}\n`; - if (!spinner.isSpinning) - { - spinner.start(); - } -} - function clearStream(stream: Writable, lines: number) { readline.moveCursor(stream, 0, -lines); @@ -125,3 +68,22 @@ export function resetWindow() writeOut(m); } } + +const progressBar = new cliProgress.SingleBar({ + format: `${chalk.green('{bar}')} {percentage}%`, +}, cliProgress.Presets.rect); + +export function startProgress() +{ + progressBar.start(100, 0); +} + +export function updateProgress(progress: number) +{ + progressBar.update(progress); +} + +export function stopProgress() +{ + progressBar.stop(); +} diff --git a/packages/core/test/AssetIgnore.test.ts b/packages/core/test/AssetIgnore.test.ts index 4048149..51b9247 100644 --- a/packages/core/test/AssetIgnore.test.ts +++ b/packages/core/test/AssetIgnore.test.ts @@ -6,7 +6,7 @@ describe('AssetIgnore', () => { const assetIgnore = new AssetIgnore({ ignore: '**/*.png', - basePath: 'test', + entryPath: 'test', }); expect(assetIgnore.shouldIgnore('test/test.png')).toBe(true); @@ -17,7 +17,7 @@ describe('AssetIgnore', () => { const assetIgnore = new AssetIgnore({ ignore: ['**/*.png', '**/*.json'], - basePath: 'test', + entryPath: 'test', }); expect(assetIgnore.shouldIgnore('test/test.png')).toBe(true); diff --git a/packages/image/README.md b/packages/image/README.md new file mode 100644 index 0000000..a7acdca --- /dev/null +++ b/packages/image/README.md @@ -0,0 +1,42 @@ +# @assetpack/plugin-image + +AssetPack plugin for compressing and mipmapping images into different formats. + +## Installation + +```sh +npm install --save-dev @assetpack/plugin-image +``` + +## Basic Usage + +```js +import { compress, mipmap } from "@assetpack/plugin-image"; + +export default { + ... + plugins: { + ... + mipmap: mipmap(), + compress: compress(), + }, +}; +``` + +## Options + +### compress + +- `tags` - An object containing the tags to use for the plugin. Defaults to `{ nc: "nc" }`. + - `nc` - The tag used to denote that the image should not be compressed. Can be placed on a folder or file. +- jpg: Any settings supported by [sharp](https://sharp.pixelplumbing.com/api-output#jpeg) +- png: Any settings supported by [sharp](https://sharp.pixelplumbing.com/api-output#png) +- webp: Any settings supported by [sharp](https://sharp.pixelplumbing.com/api-output#webp) +- avif: Any settings supported by [sharp](https://sharp.pixelplumbing.com/api-output#avif) + +### mipmap + +- `template`: A template for denoting the resolution of the images. Defaults to `@%%x`. Note you must use `%%` to denote the resolution. +- `resolutions`: An object containing the resolutions that the images will be resized to. Defaults to `{ default: 1, low: 0.5 }`. +- `fixedResolution`: A resolution used if the fix tag is applied e.g. `path/to/image{fix}.png` or `path/to{fix}`. Resolution must match one found in resolutions. Defaults to `default`. +- `tags` - An object containing the tags to use for the plugin. Defaults to `{ fix: "fix" }`. diff --git a/packages/mipmap-compress/jest.config.js b/packages/image/jest.config.js similarity index 100% rename from packages/mipmap-compress/jest.config.js rename to packages/image/jest.config.js diff --git a/packages/mipmap-compress/package.json b/packages/image/package.json similarity index 88% rename from packages/mipmap-compress/package.json rename to packages/image/package.json index 73683b0..488234a 100644 --- a/packages/mipmap-compress/package.json +++ b/packages/image/package.json @@ -1,12 +1,12 @@ { - "name": "@play-co/assetpack-plugin-mipmap-compress", + "name": "@play-co/assetpack-plugin-image", "version": "1.2.2", "description": "", - "homepage": "https://github.com/pixijs/assetpack/tree/master/packages/mipmap-compress/#readme", + "homepage": "https://github.com/pixijs/assetpack/tree/master/packages/image/#readme", "bugs": "https://github.com/pixijs/assetpack/issues", "repository": { "url": "pixijs/assetpack", - "directory": "packages/mipmap-compress" + "directory": "packages/image" }, "license": "MIT", "author": "Zyie", diff --git a/packages/mipmap-compress/rollup.config.mjs b/packages/image/rollup.config.mjs similarity index 100% rename from packages/mipmap-compress/rollup.config.mjs rename to packages/image/rollup.config.mjs diff --git a/packages/image/src/compress.ts b/packages/image/src/compress.ts new file mode 100644 index 0000000..04e8227 --- /dev/null +++ b/packages/image/src/compress.ts @@ -0,0 +1,119 @@ +import type { PluginOptions, Asset, AssetPipe } from '@play-co/assetpack-core'; +import { checkExt, createNewAssetAt } from '@play-co/assetpack-core'; +import type { AvifOptions, JpegOptions, PngOptions, WebpOptions } from 'sharp'; +import sharp from 'sharp'; +import { resolveOptions } from './utils/resolveOptions'; +import { compressSharp } from './utils/compressSharp'; + +type CompressJpgOptions = Omit; +type CompressWebpOptions = Omit; +type CompressAvifOptions = Omit; +type CompressPngOptions = Omit; + +export interface CompressOptions extends PluginOptions<'nc'> +{ + png?: CompressPngOptions | boolean; + webp?: CompressWebpOptions | boolean; + avif?: CompressAvifOptions | boolean; + jpg?: CompressJpgOptions | boolean; +} + +export interface CompressImageData +{ + format: '.avif' | '.png' | '.webp' | '.jpg' | '.jpeg'; + resolution: number; + sharpImage: sharp.Sharp; +} + +export function compress(options: CompressOptions = {}): AssetPipe +{ + const compress = resolveOptions(options, { + png: true, + jpg: true, + webp: false, + avif: false, + }); + + if (compress) + { + compress.jpg = resolveOptions(compress.jpg, { + + }); + compress.png = resolveOptions(compress.png, { + quality: 90, + }); + compress.webp = resolveOptions(compress.webp, { + quality: 80, + }); + compress.avif = resolveOptions(compress.avif, { + + }); + } + + const defaultOptions = { + ...compress, + tags: { + nc: 'nc', + ...options.tags, + } + }; + + return { + folder: true, + name: 'compress', + defaultOptions, + test(asset: Asset, options) + { + return options && checkExt(asset.path, '.png', '.jpg', '.jpeg') && !asset.allMetaData[options.tags.nc as any]; + }, + async transform(asset: Asset, options) + { + const shouldCompress = compress && !asset.metaData[options.tags.nc as any]; + + if (!shouldCompress) + { + return []; + } + + try + { + const image: CompressImageData = { + format: asset.extension as CompressImageData['format'], + resolution: 1, + sharpImage: sharp(asset.buffer), + }; + + const processedImages = await compressSharp(image, options); + + const newAssets = processedImages.map((data) => + { + const end = `${data.format}`; + const filename = asset.filename + .replace(/\.[^/.]+$/, end); + + const newAsset = createNewAssetAt( + asset, + filename + ); + + return newAsset; + }); + + const promises = processedImages.map((image, i) => image.sharpImage.toBuffer().then((buffer) => + { + newAssets[i].buffer = buffer; + })); + + await Promise.all(promises); + + return newAssets; + } + catch (error) + { + throw new Error(`[AssetPack] Failed to compress image: ${asset.path} - ${error}`); + } + }, + + }; +} + diff --git a/packages/image/src/index.ts b/packages/image/src/index.ts new file mode 100644 index 0000000..540b091 --- /dev/null +++ b/packages/image/src/index.ts @@ -0,0 +1,2 @@ +export * from './compress'; +export * from './mipmap'; diff --git a/packages/mipmap-compress/src/mipmapCompress.ts b/packages/image/src/mipmap.ts similarity index 50% rename from packages/mipmap-compress/src/mipmapCompress.ts rename to packages/image/src/mipmap.ts index 1355d4c..7895807 100644 --- a/packages/mipmap-compress/src/mipmapCompress.ts +++ b/packages/image/src/mipmap.ts @@ -1,12 +1,11 @@ -import type { PluginOptions, Asset, AssetPipe } from '@play-co/assetpack-core'; -import { checkExt, createNewAssetAt } from '@play-co/assetpack-core'; -import type { AvifOptions, JpegOptions, PngOptions, WebpOptions } from 'sharp'; +import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; +import { checkExt, createNewAssetAt } from '@play-co/assetpack-core'; import sharp from 'sharp'; -import { resolveOptions } from './utils/resolveOptions'; +import type { CompressImageData } from './compress'; import { mipmapSharp } from './utils/mipmapSharp'; -import { compressSharp } from './utils/compressSharp'; +import { resolveOptions } from './utils/resolveOptions'; -export interface MipmapOptions +export interface MipmapOptions extends PluginOptions<'fix' | T> { /** A template for denoting the resolution of the images. */ template?: string; @@ -16,71 +15,23 @@ export interface MipmapOptions fixedResolution?: string; } -type CompressJpgOptions = Omit; -type CompressWebpOptions = Omit; -type CompressAvifOptions = Omit; -type CompressPngOptions = Omit; - -export interface CompressOptions -{ - png?: CompressPngOptions | boolean; - webp?: CompressWebpOptions | boolean; - avif?: CompressAvifOptions | boolean; - jpg?: CompressJpgOptions | boolean; -} - -export interface MipmapCompressOptions extends PluginOptions<'fix' | 'nc'> -{ - mipmap?: MipmapOptions | boolean; - compress?: CompressOptions | boolean; -} - -export interface MipmapCompressImageData -{ - format: '.avif' | '.png' | '.webp' | '.jpg' | '.jpeg'; - resolution: number; - sharpImage: sharp.Sharp; -} - const defaultMipmapOptions: Required = { template: '@%%x', resolutions: { default: 1, low: 0.5 }, - fixedResolution: 'default' + fixedResolution: 'default', + tags: { + fix: 'fix', + } }; -export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe +export function mipmap(_options: MipmapOptions = {}): AssetPipe { - const mipmap = resolveOptions(_options.mipmap, defaultMipmapOptions); - - const compress = resolveOptions(_options.compress, { - png: true, - jpg: true, - webp: false, - avif: false, - }); - - if (compress) - { - compress.jpg = resolveOptions(compress.jpg, { - - }); - compress.png = resolveOptions(compress.png, { - quality: 90, - }); - compress.webp = resolveOptions(compress.webp, { - quality: 80, - }); - compress.avif = resolveOptions(compress.avif, { - - }); - } + const mipmap = resolveOptions(_options, defaultMipmapOptions); const defaultOptions = { - mipmap, - compress, + ...mipmap, tags: { fix: 'fix', - nc: 'nc', ..._options.tags, } }; @@ -91,28 +42,26 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe< defaultOptions, test(asset: Asset, options) { - return (options.mipmap || options.compress) && checkExt(asset.path, '.png', '.jpg', '.jpeg'); + return options && checkExt(asset.path, '.png', '.jpg', '.jpeg'); }, async transform(asset: Asset, options) { const shouldMipmap = mipmap && !asset.metaData[options.tags.fix as any]; - const shouldCompress = compress && !asset.metaData[options.tags.nc as any]; - let processedImages: MipmapCompressImageData[]; + let processedImages: CompressImageData[]; - const image: MipmapCompressImageData = { - format: asset.extension as MipmapCompressImageData['format'], + const image: CompressImageData = { + format: asset.extension as CompressImageData['format'], resolution: 1, sharpImage: sharp(asset.buffer), }; - // first mipmap if we want.. try { if (shouldMipmap) { - const { resolutions, fixedResolution } = options.mipmap as Required - || defaultOptions.mipmap; + const { resolutions, fixedResolution } = options as Required + || defaultOptions; const fixedResolutions: {[x: string]: number} = {}; @@ -138,28 +87,14 @@ export function mipmapCompress(_options: MipmapCompressOptions = {}): AssetPipe< throw new Error(`[AssetPack] Failed to mipmap image: ${asset.path} - ${error}`); } - try - { - if (shouldCompress) - { - processedImages = (await Promise.all( - processedImages.map((image) => compressSharp(image, options.compress as CompressOptions)) - )).flat(); - } - } - catch (error) - { - throw new Error(`[AssetPack] Failed to compress image: ${asset.path} - ${error}`); - } - // now create our new assets const newAssets = processedImages.map((data) => { let resolution = ''; - if (options.mipmap) + if (options) { - resolution = (options.mipmap as Required).template.replace('%%', `${data.resolution}`); + resolution = (options as Required).template.replace('%%', `${data.resolution}`); resolution = data.resolution === 1 ? '' : resolution; } diff --git a/packages/mipmap-compress/src/utils/compressSharp.ts b/packages/image/src/utils/compressSharp.ts similarity index 85% rename from packages/mipmap-compress/src/utils/compressSharp.ts rename to packages/image/src/utils/compressSharp.ts index f0ebb4c..512841c 100644 --- a/packages/mipmap-compress/src/utils/compressSharp.ts +++ b/packages/image/src/utils/compressSharp.ts @@ -1,12 +1,12 @@ import type { AvifOptions, WebpOptions, JpegOptions, PngOptions } from 'sharp'; -import type { MipmapCompressImageData, CompressOptions } from '../mipmapCompress'; +import type { CompressImageData, CompressOptions } from '../compress'; export async function compressSharp( - image: MipmapCompressImageData, + image: CompressImageData, options: CompressOptions -): Promise +): Promise { - const compressed: MipmapCompressImageData[] = []; + const compressed: CompressImageData[] = []; const sharpImage = image.sharpImage; diff --git a/packages/mipmap-compress/src/utils/mipmapSharp.ts b/packages/image/src/utils/mipmapSharp.ts similarity index 82% rename from packages/mipmap-compress/src/utils/mipmapSharp.ts rename to packages/image/src/utils/mipmapSharp.ts index 641e4ee..a05d9f3 100644 --- a/packages/mipmap-compress/src/utils/mipmapSharp.ts +++ b/packages/image/src/utils/mipmapSharp.ts @@ -1,11 +1,11 @@ -import type { MipmapCompressImageData } from '../mipmapCompress'; +import type { CompressImageData } from '../compress'; export async function mipmapSharp( - image: MipmapCompressImageData, + image: CompressImageData, resolutionHash: {[x: string]: number}, largestResolution: number -): Promise +): Promise { const sharpImage = image.sharpImage; @@ -13,7 +13,7 @@ export async function mipmapSharp( const { width, height } = metadata; - const output: MipmapCompressImageData[] = []; + const output: CompressImageData[] = []; if (width && height) { diff --git a/packages/mipmap-compress/src/utils/resolveOptions.ts b/packages/image/src/utils/resolveOptions.ts similarity index 100% rename from packages/mipmap-compress/src/utils/resolveOptions.ts rename to packages/image/src/utils/resolveOptions.ts diff --git a/packages/mipmap-compress/test/Compress.test.ts b/packages/image/test/Compress.test.ts similarity index 84% rename from packages/mipmap-compress/test/Compress.test.ts rename to packages/image/test/Compress.test.ts index 1031772..3b3944f 100644 --- a/packages/mipmap-compress/test/Compress.test.ts +++ b/packages/image/test/Compress.test.ts @@ -1,9 +1,9 @@ import { AssetPack } from '@play-co/assetpack-core'; import { existsSync } from 'fs-extra'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; -import { mipmapCompress } from '../src/mipmapCompress'; +import { compress } from '../src/compress'; -const pkg = 'mipmap-compress'; +const pkg = 'image'; describe('Compress', () => { @@ -35,14 +35,11 @@ describe('Compress', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ - mipmap: false, - compress: { - png: true, - webp: true, - avif: true, - jpg: true, - }, + compress({ + png: true, + webp: true, + avif: true, + jpg: true, }), ] }); @@ -58,7 +55,7 @@ describe('Compress', () => expect(existsSync(`${outputDir}/testJpg.png`)).toBe(false); }); - it('should compress png with 1 plugin', async () => + it.only('should compress png with 1 plugin', async () => { const testName = 'compress-png-1-plugin'; const inputDir = getInputDir(pkg, testName); @@ -85,16 +82,21 @@ describe('Compress', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ - mipmap: false, - compress: { - png: true, - webp: true, - jpg: true, - avif: true, - }, + compress({ + png: true, + webp: true, + jpg: true, + avif: true, }), - ] + ], + assetSettings: [{ + files: ['**/*.png'], + settings: { + tags: { + nc: 'ncc', + } + } + }] }); await pack.run(); @@ -135,11 +137,9 @@ describe('Compress', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ - compress: { - webp: false, - avif: false, - } + compress({ + webp: false, + avif: false, }) ] }); diff --git a/packages/mipmap-compress/test/Mipmap.test.ts b/packages/image/test/Mipmap.test.ts similarity index 91% rename from packages/mipmap-compress/test/Mipmap.test.ts rename to packages/image/test/Mipmap.test.ts index c94787a..3546993 100644 --- a/packages/mipmap-compress/test/Mipmap.test.ts +++ b/packages/image/test/Mipmap.test.ts @@ -1,9 +1,9 @@ import { AssetPack } from '@play-co/assetpack-core'; import { existsSync } from 'fs-extra'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; -import { mipmapCompress } from '../src/mipmapCompress'; +import { mipmap } from '../src/mipmap'; -const pkg = 'mipmap-compress'; +const pkg = 'image'; describe('Mipmap', () => { @@ -35,14 +35,11 @@ describe('Mipmap', () => }); const opts = { - mipmap: { - resolutions: { - high: 2, - default: 1, - low: 0.5, - } - }, - compress: false + resolutions: { + high: 2, + default: 1, + low: 0.5, + } }; const assetpack = new AssetPack({ @@ -50,7 +47,7 @@ describe('Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress(opts), + mipmap(opts), ] }); @@ -86,7 +83,7 @@ describe('Mipmap', () => folders: [], }); - const mipmap = { + const mipmapOpts = { resolutions: { low: 0.5 }, fixedResolution: 'low' }; @@ -96,7 +93,7 @@ describe('Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ compress: { png: true }, mipmap }), + mipmap(mipmapOpts), ] }); @@ -135,7 +132,7 @@ describe('Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ compress: false }), + mipmap(), ] }); @@ -177,7 +174,7 @@ describe('Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ compress: false }), + mipmap(), ] }); @@ -216,7 +213,7 @@ describe('Mipmap', () => entry: inputDir, output: outputDir, cache: false, - pipes: [mipmapCompress({ compress: false })] + pipes: [mipmap()] }); await assetpack.run(); diff --git a/packages/mipmap-compress/test/resources/dragon.atlas b/packages/image/test/resources/dragon.atlas similarity index 100% rename from packages/mipmap-compress/test/resources/dragon.atlas rename to packages/image/test/resources/dragon.atlas diff --git a/packages/mipmap-compress/test/resources/dragon.json b/packages/image/test/resources/dragon.json similarity index 100% rename from packages/mipmap-compress/test/resources/dragon.json rename to packages/image/test/resources/dragon.json diff --git a/packages/mipmap-compress/test/resources/dragon.png b/packages/image/test/resources/dragon.png similarity index 100% rename from packages/mipmap-compress/test/resources/dragon.png rename to packages/image/test/resources/dragon.png diff --git a/packages/mipmap-compress/test/resources/dragon2.png b/packages/image/test/resources/dragon2.png similarity index 100% rename from packages/mipmap-compress/test/resources/dragon2.png rename to packages/image/test/resources/dragon2.png diff --git a/packages/mipmap-compress/test/resources/jpg-1.jpg b/packages/image/test/resources/jpg-1.jpg similarity index 100% rename from packages/mipmap-compress/test/resources/jpg-1.jpg rename to packages/image/test/resources/jpg-1.jpg diff --git a/packages/mipmap-compress/test/resources/png-1.png b/packages/image/test/resources/png-1.png similarity index 100% rename from packages/mipmap-compress/test/resources/png-1.png rename to packages/image/test/resources/png-1.png diff --git a/packages/mipmap-compress/test/resources/png-2.png b/packages/image/test/resources/png-2.png similarity index 100% rename from packages/mipmap-compress/test/resources/png-2.png rename to packages/image/test/resources/png-2.png diff --git a/packages/mipmap-compress/test/resources/sp-1.png b/packages/image/test/resources/sp-1.png similarity index 100% rename from packages/mipmap-compress/test/resources/sp-1.png rename to packages/image/test/resources/sp-1.png diff --git a/packages/mipmap-compress/test/resources/sp-2.png b/packages/image/test/resources/sp-2.png similarity index 100% rename from packages/mipmap-compress/test/resources/sp-2.png rename to packages/image/test/resources/sp-2.png diff --git a/packages/mipmap-compress/test/resources/sp-3.jpg b/packages/image/test/resources/sp-3.jpg similarity index 100% rename from packages/mipmap-compress/test/resources/sp-3.jpg rename to packages/image/test/resources/sp-3.jpg diff --git a/packages/mipmap-compress/tsconfig.json b/packages/image/tsconfig.json similarity index 98% rename from packages/mipmap-compress/tsconfig.json rename to packages/image/tsconfig.json index 2c8a456..10fc255 100644 --- a/packages/mipmap-compress/tsconfig.json +++ b/packages/image/tsconfig.json @@ -1,5 +1,4 @@ { "extends": "../../tsconfig.json", "include": ["src/**/*", "types/**/*", "test/**/*"], - } diff --git a/packages/manifest/test/Manifest.test.ts b/packages/manifest/test/Manifest.test.ts index f7cf8df..311499d 100644 --- a/packages/manifest/test/Manifest.test.ts +++ b/packages/manifest/test/Manifest.test.ts @@ -1,7 +1,7 @@ import { AssetPack } from '@play-co/assetpack-core'; import { audio } from '@play-co/assetpack-plugin-ffmpeg'; +import { compress, mipmap } from '@play-co/assetpack-plugin-image'; import { pixiManifest } from '@play-co/assetpack-plugin-manifest'; -import { mipmapCompress } from '@play-co/assetpack-plugin-mipmap-compress'; import { spineAtlasMipmap } from '@play-co/assetpack-plugin-spine'; import { texturePacker } from '@play-co/assetpack-plugin-texture-packer'; import { existsSync, readJSONSync } from 'fs-extra'; @@ -123,13 +123,12 @@ describe('Manifest', () => }), audio(), spineAtlasMipmap(), - mipmapCompress({ - compress: { - png: true, - jpg: true, - webp: true, - avif: false, - } + mipmap(), + compress({ + png: true, + jpg: true, + webp: true, + avif: false, }), pixiManifest(), ] @@ -328,12 +327,11 @@ describe('Manifest', () => }, }), audio(), + mipmap(), spineAtlasMipmap(), - mipmapCompress({ - compress: { - webp: true, - png: true, - } + compress({ + webp: true, + png: true, }), pixiManifest({ createShortcuts: true, @@ -596,12 +594,11 @@ describe('Manifest', () => }, }), audio(), + mipmap(), spineAtlasMipmap(), - mipmapCompress({ - compress: { - webp: true, - png: true, - } + compress({ + webp: true, + png: true, }), pixiManifest({ createShortcuts: true, @@ -742,11 +739,10 @@ describe('Manifest', () => }), audio(), spineAtlasMipmap(), - mipmapCompress({ - compress: { - webp: true, - png: true, - } + mipmap(), + compress({ + webp: true, + png: true, }), pixiManifest({ createShortcuts: false, diff --git a/packages/mipmap-compress/README.md b/packages/mipmap-compress/README.md deleted file mode 100644 index 61e6ef0..0000000 --- a/packages/mipmap-compress/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# @assetpack/plugin-mipmap - -AssetPack plugin for generating mipmaps -By default this plugin will generate `@1x` and `@0.5x` resolutions for all images. - -This plugin also supports generating mipmaps for Spine atlas files with the `spineAtlasMipmap` plugin. - -## Installation - -```sh -npm install --save-dev @assetpack/plugin-mipmap -``` - -## Basic Usage - -```js -import { mipmap, spineAtlasMipmap } from "@assetpack/plugin-mipmap"; - -export default { - ... - plugins: { - ... - mipmap: mipmap(), - spine: spineAtlasMipmap(), - }, -}; -``` - -## Options - -- `template`: A template for denoting the resolution of the images. Defaults to `@%%x`. Note you must use `%%` to denote the resolution. -- `resolutions`: An object containing the resolutions that the images will be resized to. Defaults to `{ default: 1, low: 0.5 }`. -- `fixedResolution`: A resolution used if the fix tag is applied e.g. `path/to/image{fix}.png` or `path/to{fix}`. Resolution must match one found in resolutions. Defaults to `default`. -- `tags` - An object containing the tags to use for the plugin. Defaults to `{ fix: "fix" }`. diff --git a/packages/mipmap-compress/src/index.ts b/packages/mipmap-compress/src/index.ts deleted file mode 100644 index e0b9ed8..0000000 --- a/packages/mipmap-compress/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './mipmapCompress'; diff --git a/packages/spine/package.json b/packages/spine/package.json index 22f10aa..02abc18 100644 --- a/packages/spine/package.json +++ b/packages/spine/package.json @@ -33,11 +33,11 @@ }, "devDependencies": { "@play-co/assetpack-core": "1.2.2", - "@play-co/assetpack-plugin-mipmap-compress": "1.2.2" + "@play-co/assetpack-plugin-image": "1.2.2" }, "peerDependencies": { "@play-co/assetpack-core": ">=0.0.0", - "@play-co/assetpack-plugin-mipmap-compress": ">=0.0.0" + "@play-co/assetpack-plugin-image": ">=0.0.0" }, "engines": { "node": ">=16.0.0" diff --git a/packages/spine/src/spineAtlasCompress.ts b/packages/spine/src/spineAtlasCompress.ts index 3e017fa..e1f3fb7 100644 --- a/packages/spine/src/spineAtlasCompress.ts +++ b/packages/spine/src/spineAtlasCompress.ts @@ -1,6 +1,6 @@ import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; import { checkExt, createNewAssetAt, swapExt } from '@play-co/assetpack-core'; -import type { CompressOptions } from '@play-co/assetpack-plugin-mipmap-compress'; +import type { CompressOptions } from '@play-co/assetpack-plugin-image'; import { AtlasView } from './AtlasView'; export type SpineAtlasCompressOptions = PluginOptions<'nc'> & CompressOptions; diff --git a/packages/spine/src/spineAtlasMipmap.ts b/packages/spine/src/spineAtlasMipmap.ts index e062631..d86e0a4 100644 --- a/packages/spine/src/spineAtlasMipmap.ts +++ b/packages/spine/src/spineAtlasMipmap.ts @@ -1,8 +1,8 @@ import type { Asset, PluginOptions } from '@play-co/assetpack-core'; import { checkExt, type AssetPipe, createNewAssetAt } from '@play-co/assetpack-core'; -import type { MipmapOptions } from '@play-co/assetpack-plugin-mipmap-compress'; +import type { MipmapOptions } from '@play-co/assetpack-plugin-image'; -export type SpineOptions = PluginOptions<'fix' | 'nc'> & MipmapOptions; +export type SpineOptions = PluginOptions<'fix'> & MipmapOptions; export function spineAtlasMipmap(_options?: SpineOptions): AssetPipe { diff --git a/packages/spine/test/spineAtlasAll.test.ts b/packages/spine/test/spineAtlasAll.test.ts index 40a6bde..4ef2034 100644 --- a/packages/spine/test/spineAtlasAll.test.ts +++ b/packages/spine/test/spineAtlasAll.test.ts @@ -1,5 +1,5 @@ import { AssetPack } from '@play-co/assetpack-core'; -import { mipmapCompress } from '@play-co/assetpack-plugin-mipmap-compress'; +import { compress, mipmap } from '@play-co/assetpack-plugin-image'; import { readFileSync } from 'fs-extra'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCompress } from '../src/spineAtlasCompress'; @@ -41,15 +41,13 @@ describe('Spine Atlas All', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ - mipmap: { - resolutions: { default: 1, low: 0.5 }, - }, - compress: { - png: true, - jpg: true, - webp: true, - } + compress({ + png: true, + webp: true, + jpg: true, + }), + mipmap({ + resolutions: { default: 1, low: 0.5 }, }), spineAtlasMipmap({ resolutions: { default: 1, low: 0.5 }, diff --git a/packages/spine/test/spineAtlasCompress.test.ts b/packages/spine/test/spineAtlasCompress.test.ts index a4c2ab9..d37ecbe 100644 --- a/packages/spine/test/spineAtlasCompress.test.ts +++ b/packages/spine/test/spineAtlasCompress.test.ts @@ -1,5 +1,5 @@ import { AssetPack } from '@play-co/assetpack-core'; -import { mipmapCompress } from '@play-co/assetpack-plugin-mipmap-compress';// assetpack-plugin-mipmap-compress'; +import { compress } from '@play-co/assetpack-plugin-image'; import { readFileSync } from 'fs-extra'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; import { spineAtlasCompress } from '../src/spineAtlasCompress'; @@ -40,13 +40,10 @@ describe('Spine Atlas Compress', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ - mipmap: false, - compress: { - png: true, - jpg: true, - webp: true, - } + compress({ + png: true, + jpg: true, + webp: true, }), spineAtlasCompress({ png: true, diff --git a/packages/spine/test/spineAtlasMipmap.test.ts b/packages/spine/test/spineAtlasMipmap.test.ts index 1d0f417..2e5799d 100644 --- a/packages/spine/test/spineAtlasMipmap.test.ts +++ b/packages/spine/test/spineAtlasMipmap.test.ts @@ -1,7 +1,7 @@ import { AssetPack } from '@play-co/assetpack-core'; import { existsSync } from 'fs-extra'; import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test'; -import { mipmapCompress } from '@play-co/assetpack-plugin-mipmap-compress'; +import { mipmap } from '@play-co/assetpack-plugin-image'; import { spineAtlasMipmap } from '../src/spineAtlasMipmap'; const pkg = 'spine'; @@ -55,7 +55,7 @@ describe('Atlas Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress(opts), + mipmap(opts.mipmap), spineAtlasMipmap(opts.mipmap), ] }); @@ -101,7 +101,7 @@ describe('Atlas Mipmap', () => folders: [], }); - const mipmap = { + const mipmapOpts = { resolutions: { low: 0.5 }, fixedResolution: 'low' }; @@ -111,8 +111,8 @@ describe('Atlas Mipmap', () => output: outputDir, cache: false, pipes: [ - spineAtlasMipmap(mipmap), - mipmapCompress({ compress: { png: true }, mipmap }), + spineAtlasMipmap(mipmapOpts), + mipmap(mipmapOpts), ] }); @@ -155,7 +155,7 @@ describe('Atlas Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ compress: false }), + mipmap(), spineAtlasMipmap(), ] }); @@ -200,7 +200,7 @@ describe('Atlas Mipmap', () => output: outputDir, cache: false, pipes: [ - mipmapCompress({ compress: false }), + mipmap(), spineAtlasMipmap(), ] }); diff --git a/packages/texture-packer/package.json b/packages/texture-packer/package.json index 5a3d8dd..e48ae25 100644 --- a/packages/texture-packer/package.json +++ b/packages/texture-packer/package.json @@ -37,11 +37,11 @@ }, "devDependencies": { "@play-co/assetpack-core": "1.2.2", - "@play-co/assetpack-plugin-mipmap-compress": "1.2.2" + "@play-co/assetpack-plugin-image": "1.2.2" }, "peerDependencies": { "@play-co/assetpack-core": ">=0.0.0", - "@play-co/assetpack-plugin-mipmap-compress": ">=0.0.0" + "@play-co/assetpack-plugin-image": ">=0.0.0" }, "engines": { "node": ">=16.0.0" diff --git a/packages/texture-packer/src/texturePackerCompress.ts b/packages/texture-packer/src/texturePackerCompress.ts index 591ef89..9a5728f 100644 --- a/packages/texture-packer/src/texturePackerCompress.ts +++ b/packages/texture-packer/src/texturePackerCompress.ts @@ -1,6 +1,6 @@ import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core'; import { checkExt, createNewAssetAt, swapExt } from '@play-co/assetpack-core'; -import type { CompressOptions } from '@play-co/assetpack-plugin-mipmap-compress'; +import type { CompressOptions } from '@play-co/assetpack-plugin-image'; export type TexturePackerCompressOptions = PluginOptions<'tps' | 'nc'> & CompressOptions; diff --git a/packages/texture-packer/test/texturePackerCompress.test.ts b/packages/texture-packer/test/texturePackerCompress.test.ts index cdddb4b..470cc71 100644 --- a/packages/texture-packer/test/texturePackerCompress.test.ts +++ b/packages/texture-packer/test/texturePackerCompress.test.ts @@ -1,5 +1,5 @@ import { AssetPack } from '@play-co/assetpack-core'; -import { mipmapCompress } from '@play-co/assetpack-plugin-mipmap-compress'; +import { compress } from '@play-co/assetpack-plugin-image'; import { texturePacker, texturePackerCompress } from '@play-co/assetpack-plugin-texture-packer'; import { readJSONSync } from 'fs-extra'; import type { File } from '../../../shared/test/index'; @@ -43,7 +43,7 @@ describe('Texture Packer Compression', () => genFolder(testName); - const compress = { + const compressOpt = { png: true, jpg: true, webp: true, @@ -59,14 +59,8 @@ describe('Texture Packer Compression', () => resolutions: { default: 1 }, }, }), - mipmapCompress({ - compress: { - png: true, - jpg: true, - webp: true, - } - }), - texturePackerCompress(compress), + compress(compressOpt), + texturePackerCompress(compressOpt), ] });