Skip to content

Commit

Permalink
fix(core): linting (#18)
Browse files Browse the repository at this point in the history
* - add spine cache buster
- add sprite sheet cache buster
- tests

* cache id is now takes into account all pipe options
add test

* docs

* Update packages/spine/test/spineAtlasAll.test.ts

* remove only

* fix test and merge bits

* rename

* - update manifest plugin to remove specific logic
- add a manifest modifier for texture packer
- add a manifest modifier for spine atlas

* fix options

* fix options

* fin name

* fix tests

* fix:(core): linting

* merge

---------

Co-authored-by: Mat Groves <[email protected]>
  • Loading branch information
Zyie and GoodBoyDigital authored Apr 29, 2024
1 parent ef71c06 commit c74d163
Show file tree
Hide file tree
Showing 75 changed files with 193 additions and 162 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build:force": "nx run-many --target=build --all --parallel --skip-nx-cache",
"clean": "rimraf packages/*/{dist,.testInput,.testOutput,.assetpack}",
"lint": "eslint --cache packages shared --ext .js,.ts,.mjs --max-warnings 0",
"lint:fix": "npm run lint -- --fix",
"prepare": "husky install",
"prerelease": "npm run lint && npm run build:force",
"release": "lerna publish --no-private --exact --force-publish",
Expand Down
1 change: 0 additions & 1 deletion packages/cache-buster/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
Expand Down
3 changes: 2 additions & 1 deletion packages/cache-buster/src/cacheBuster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AssetPipe, Asset } from '@play-co/assetpack-core';
import { createNewAssetAt, swapExt } from '@play-co/assetpack-core';

import type { Asset, AssetPipe } from '@play-co/assetpack-core';

/**
* Cache buster asset pipe. This pipe will add a hash to the end of the filename
* the hash is calculated from the contents of the file.
Expand Down
2 changes: 1 addition & 1 deletion packages/cache-buster/test/cacheBuster.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Asset, AssetPack, path } from '@play-co/assetpack-core';
import { existsSync } from 'fs-extra';
import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test';
import { cacheBuster } from '../src';
import { Asset, AssetPack, path } from '@play-co/assetpack-core';

const pkg = 'cache-buster';

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable no-console */
import type { AssetPackConfig } from '@play-co/assetpack-core';
import chalk from 'chalk';
import { Command } from 'commander';
import findUp from 'find-up';
import { createRequire } from 'module';
import path from 'path';
import { pathToFileURL } from 'url';
import { createRequire } from 'module';

import type { AssetPackConfig } from '@play-co/assetpack-core';

const require = createRequire(import.meta.url);

Expand Down
1 change: 0 additions & 1 deletion packages/core/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extractTagsFromFileName } from './utils/extractTagsFromFileName';
import { getHash } from './utils/getHash';
import fs from 'fs-extra';
import { Logger } from './logger/Logger';
import { extractTagsFromFileName } from './utils/extractTagsFromFileName';
import { getHash } from './utils/getHash';
import { path } from './utils/path';

export interface AssetOptions
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/AssetCache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Asset } from './Asset';
import fs from 'fs-extra';
import { path } from './utils/path';

import type { Asset } from './Asset';

export interface AssetCacheOptions
{
cacheName?: string;
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/AssetPack.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import fs from 'fs-extra';
import type { Asset } from './Asset';
import type { AssetPipe } from './pipes/AssetPipe';
import merge from 'merge';
import { AssetCache } from './AssetCache';
import { AssetWatcher } from './AssetWatcher';
import type { AssetSettings } from './pipes/PipeSystem';
import { PipeSystem } from './pipes/PipeSystem';
import { finalCopyPipe } from './pipes/finalCopyPipe';
import type { AssetPackConfig } from './config';
import { Logger } from './logger/Logger';
import { promiseAllConcurrent } from './utils/promiseAllConcurrent';
import { path } from './utils/path';
import merge from 'merge';
import { finalCopyPipe } from './pipes/finalCopyPipe';
import { PipeSystem } from './pipes/PipeSystem';
import { generateCacheName } from './utils/generateCacheName';
import { path } from './utils/path';
import { promiseAllConcurrent } from './utils/promiseAllConcurrent';

import type { Asset } from './Asset';
import type { AssetPackConfig } from './config';
import type { AssetPipe } from './pipes/AssetPipe';
import type { AssetSettings } from './pipes/PipeSystem';

export class AssetPack
{
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/AssetWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import chokidar from 'chokidar';
import fs from 'fs-extra';
import { Asset } from './Asset';
import chokidar from 'chokidar';
import type { CachedAsset } from './AssetCache';
import { syncAssetsWithCache } from './utils/syncAssetsWithCache';
import { AssetIgnore } from './AssetIgnore';
import type { AssetSettings } from './pipes/PipeSystem';
import { Logger } from './logger/Logger';
import { applySettingToAsset } from './utils/applySettingToAsset';
import { path } from './utils/path';
import { Logger } from './logger/Logger';
import { syncAssetsWithCache } from './utils/syncAssetsWithCache';

import type { CachedAsset } from './AssetCache';
import type { AssetSettings } from './pipes/PipeSystem';

export interface AssetWatcherOptions
{
Expand Down
12 changes: 4 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// export * from './AssetPack';
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 './config';
export * from './logger/Logger';
export * from './pipes/AssetPipe';
export * from './pipes/PipeSystem';
export * from './pipes/multiPipe';
export * from './pipes/PipeSystem';
export * from './utils/checkExt';
export * from './utils/createNewAssetAt';
export * from './utils/findAssets';
export * from './utils/merge';
export * from './utils/path';
export * from './utils/stripTags';
export * from './utils/swapExt';
export * from './utils/findAssets';
3 changes: 2 additions & 1 deletion packages/core/src/logger/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ReporterEvent } from './Reporter';
import { Reporter } from './Reporter';

import type { LogLevelKeys } from './logLevel';
import type { ReporterEvent } from './Reporter';

export interface LoggerOptions
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/logger/Reporter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import chalk from 'chalk';
import type { LogLevelKeys } from './logLevel';
import { LogLevel } from './logLevel';
import { persistMessage, resetWindow, startProgress, stopProgress, updateProgress } from './render';
import { prettifyTime } from './utils';

import type { LogLevelKeys } from './logLevel';

export interface LogEvent
{
type: 'log';
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/logger/render.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Writable } from 'stream';
import chalk from 'chalk';
import cliProgress from 'cli-progress';

import readline from 'readline';
import { countLines } from './utils';
import chalk from 'chalk';

import type { Writable } from 'stream';

const stdout = process.stdout;
const stderr = process.stderr;
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/pipes/PipeSystem.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Asset } from '../Asset';
import type { AssetPipe } from './AssetPipe';
import { mergePipeOptions } from './mergePipeOptions';
import { multiPipe } from './multiPipe';

import type { Asset } from '../Asset';
import type { AssetPipe } from './AssetPipe';

export interface PipeSystemOptions
{
pipes: (AssetPipe | AssetPipe[])[];
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/pipes/finalCopyPipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs-extra';
import type { Asset } from '../Asset';
import { createNewAssetAt } from '../utils/createNewAssetAt';

import type { Asset } from '../Asset';
import type { AssetPipe } from './AssetPipe';

export const finalCopyPipe: AssetPipe<object> = {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/pipes/multiPipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { mergePipeOptions } from './mergePipeOptions';

import type { Asset } from '../Asset';
import type { AssetPipe } from './AssetPipe';
import type { PipeSystem } from './PipeSystem';
import { mergePipeOptions } from './mergePipeOptions';

export interface MultiPipeOptions
{
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/utils/applySettingToAsset.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Asset } from '../Asset';
import type { AssetSettings } from '../pipes/PipeSystem';
import minimatch from 'minimatch';
import { merge } from './merge';
import { path } from './path';

import type { Asset } from '../Asset';
import type { AssetSettings } from '../pipes/PipeSystem';

export function applySettingToAsset(asset: Asset, settings: AssetSettings[], entryPath: string)
{
const relativePath = path.relative(entryPath, asset.path);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/generateCacheName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AssetPackConfig } from '../config';
import objectHash from 'object-hash';

import type { AssetPackConfig } from '../config';

/**
* Returns a unique name based on the hash generated from the config
* this takes into account the following:
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/logAssetGraph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Asset } from '../Asset';
import { path } from './path';

import type { Asset } from '../Asset';

const stateColorMap = {
normal: 'white',
added: 'green',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import upath from 'upath';

export const path = upath;
1 change: 1 addition & 0 deletions packages/core/src/utils/syncAssetsWithCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Asset } from '../Asset';

import type { CachedAsset } from '../AssetCache';

export function syncAssetsWithCache(assetHash: Record<string, Asset>, cachedData: Record<string, CachedAsset>)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/AssetWatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assetPath, createFolder, getInputDir } from '../../../shared/test';
import { Asset } from '../src/Asset';
import { AssetWatcher } from '../src/AssetWatcher';
import { AssetCache } from '../src/AssetCache';
import { AssetWatcher } from '../src/AssetWatcher';
import { logAssetGraph } from '../src/utils/logAssetGraph';

const pkg = 'core';
Expand Down
5 changes: 3 additions & 2 deletions packages/core/test/Assetpack.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { existsSync, removeSync, writeJSONSync } from 'fs-extra';
import { join } from 'path';
import type { MockAssetPipe } from '../../../shared/test/index';
import { assetPath, createFolder, createAssetPipe, getInputDir, getOutputDir } from '../../../shared/test/index';
import { assetPath, createAssetPipe, createFolder, getInputDir, getOutputDir } from '../../../shared/test/index';
import { AssetPack } from '../src/AssetPack';
import { logAssetGraph } from '../src/utils/logAssetGraph';

import type { MockAssetPipe } from '../../../shared/test/index';
import type { AssetPipe } from '../src/pipes/AssetPipe';

const pkg = 'core';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/PipeSystem.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Asset } from '../src/Asset';
import type { AssetPipe } from '../src/pipes/AssetPipe';
import { PipeSystem } from '../src/pipes/PipeSystem';

import type { AssetPipe } from '../src/pipes/AssetPipe';

describe('PipeSystem', () =>
{
it('should transform an asset', async () =>
Expand Down
7 changes: 4 additions & 3 deletions packages/core/test/Utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { MockAssetPipe } from '../../../shared/test/index';
import { createFolder, createAssetPipe, getInputDir, getOutputDir } from '../../../shared/test/index';
import type { Asset } from '../src/Asset';
import { createAssetPipe, createFolder, getInputDir, getOutputDir } from '../../../shared/test/index';
import { AssetPack } from '../src/AssetPack';
import { extractTagsFromFileName } from '../src/utils/extractTagsFromFileName';
import { generateCacheName } from '../src/utils/generateCacheName';

import type { MockAssetPipe } from '../../../shared/test/index';
import type { Asset } from '../src/Asset';

describe('Utils', () =>
{
const pkg = 'core';
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createAssetPipe } from '../../../shared/test';
import { AssetPack } from '../src';

import type { AssetPackConfig } from '../src/config';

describe('AssetPack Config', () =>
Expand Down
1 change: 0 additions & 1 deletion packages/ffmpeg/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
Expand Down
5 changes: 3 additions & 2 deletions packages/ffmpeg/src/audio.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ffmpeg } from './ffmpeg';
import { merge } from '@play-co/assetpack-core';
import type { AssetPipe } from '@play-co/assetpack-core';

import type { FfmpegOptions } from './ffmpeg';
import { ffmpeg } from './ffmpeg';
import type { AssetPipe } from '@play-co/assetpack-core';

export function audio(_options?: FfmpegOptions): AssetPipe
{
Expand Down
7 changes: 4 additions & 3 deletions packages/ffmpeg/src/ffmpeg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { AssetPipe, Asset } from '@play-co/assetpack-core';
import { checkExt, createNewAssetAt, path } from '@play-co/assetpack-core';
import fluentFfmpeg from 'fluent-ffmpeg';
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
import fs from 'fs-extra';
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
import { checkExt, createNewAssetAt, path } from '@play-co/assetpack-core';

import type { Asset, AssetPipe } from '@play-co/assetpack-core';

fluentFfmpeg.setFfmpegPath(ffmpegPath.path);

Expand Down
2 changes: 1 addition & 1 deletion packages/ffmpeg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './ffmpeg';
export * from './audio';
export * from './ffmpeg';
4 changes: 2 additions & 2 deletions packages/ffmpeg/test/Audio.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetPack } from '@play-co/assetpack-core';
import { audio } from '@play-co/assetpack-plugin-ffmpeg';
import { existsSync } from 'fs-extra';
import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test';
import { AssetPack } from '@play-co/assetpack-core';
import { audio } from '@play-co/assetpack-plugin-ffmpeg';

const pkg = 'ffmpeg';

Expand Down
1 change: 0 additions & 1 deletion packages/image/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
Expand Down
9 changes: 5 additions & 4 deletions packages/image/src/compress.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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';
import { resolveOptions } from './utils/resolveOptions';
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';

type CompressJpgOptions = Omit<JpegOptions, 'force'>;
type CompressWebpOptions = Omit<WebpOptions, 'force'>;
Expand Down
9 changes: 5 additions & 4 deletions packages/image/src/mipmap.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core';
import { checkExt, createNewAssetAt } from '@play-co/assetpack-core';
import sharp from 'sharp';
import type { CompressImageData } from './compress';
import { mipmapSharp } from './utils/mipmapSharp';
import { resolveOptions } from './utils/resolveOptions';
import { checkExt, createNewAssetAt } from '@play-co/assetpack-core';

import type { CompressImageData } from './compress';
import type { Asset, AssetPipe, PluginOptions } from '@play-co/assetpack-core';

export interface MipmapOptions<T extends string = ''> extends PluginOptions<'fix' | T>
{
Expand Down Expand Up @@ -46,7 +47,7 @@ export function mipmap(_options: MipmapOptions = {}): AssetPipe<MipmapOptions>
},
async transform(asset: Asset, options)
{
const shouldMipmap = mipmap && !asset.metaData[options.tags.fix as any];
const shouldMipmap = mipmap && !asset.metaData[options.tags.fix as any];

let processedImages: CompressImageData[];

Expand Down
2 changes: 1 addition & 1 deletion packages/image/src/utils/compressSharp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AvifOptions, WebpOptions, JpegOptions, PngOptions } from 'sharp';
import type { AvifOptions, JpegOptions, PngOptions, WebpOptions } from 'sharp';
import type { CompressImageData, CompressOptions } from '../compress';

export async function compressSharp(
Expand Down
Loading

0 comments on commit c74d163

Please sign in to comment.