Skip to content

Commit

Permalink
Fix linting, fix index exports, fix generate-exports script
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Jan 18, 2024
1 parent 9a6890f commit 5496c22
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 110 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
"import": "./lib/zoom-blur.mjs",
"require": "./lib/zoom-blur.js",
"types": "./lib/zoom-blur.d.ts"
},
"./defaults": {
"import": "./lib/defaults.mjs",
"require": "./lib/defaults.js",
"types": "./lib/defaults.d.ts"
}
},
"main": "lib/index.js",
Expand All @@ -207,7 +212,8 @@
"copy:demoimages": "copyfiles -f tools/demo/images/* deploy/demo/images",
"deploy": "xs deploy",
"release": "xs bump,test,deploy,git-push",
"publish-ci": "xs publish"
"publish-ci": "xs publish",
"generate-exports": "node --no-warnings=ExperimentalWarning scripts/generate-exports.mjs"
},
"pre-commit": [
"lint",
Expand Down Expand Up @@ -254,6 +260,7 @@
"docsGoogleAnalytics": "UA-103772589-3",
"docsTitle": "PixiJS Filters API Documentation",
"docsDescription": "Documentation for PixiJS Filters library",
"docsKeyword": "docs, documentation, pixi, pixijs, filters, webgl, ascii, bloom, convolution, cross-hatch, dotfilter, emboss, pixelate, twist, tiltshift"
"docsKeyword": "docs, documentation, pixi, pixijs, filters, webgl, ascii, bloom, convolution, cross-hatch, dotfilter, emboss, pixelate, twist, tiltshift",
"lint": ["src", "examples", "scripts", "tools/demo/src", "tools/screenshots/*.js"]
}
}
36 changes: 0 additions & 36 deletions scripts/exports.js

This file was deleted.

83 changes: 83 additions & 0 deletions scripts/generate-exports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import fs from 'node:fs';
import path from 'node:path';
import packageJson from '../package.json' assert { type: 'json' };

// Define the directory and file paths
const filtersDirPath = path.resolve('src');
const packageJsonPath = path.resolve('package.json');

// Ensure the exports field exists
packageJson.exports = packageJson.exports ?? {};

packageJson.exports['.'] = {
import: './lib/index.mjs',
require: './lib/index.js',
types: './lib/index.d.ts',
};

// Read all directories in the filters folder
fs.readdirSync(filtersDirPath, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.forEach((dirent) =>
{
// Add each directory to the exports field
const dirName = dirent.name;

packageJson.exports[`./${dirName}`] = {
import: `./lib/${dirName}.mjs`,
require: `./lib/${dirName}.js`,
types: `./lib/${dirName}.d.ts`,
};
});

async function fileExists(filePath)
{
try
{
fs.accessSync(path.resolve(filePath));

return true;
}
catch
{
return false;
}
}

function validateExports(exports)
{
return Promise.all(
Object.entries(exports).map(async ([key, value]) =>
{
const { import: importPath, require: requirePath, types: typesPath } = value;

if (!importPath || !(await fileExists(importPath)))
{
throw new Error(`The import path "${importPath}" for "${key}" does not exist.`);
}

if (!requirePath || !(await fileExists(requirePath)))
{
throw new Error(`The require path "${requirePath}" for "${key}" does not exist.`);
}

if (!typesPath || !(await fileExists(typesPath)))
{
throw new Error(`The types path "${typesPath}" for "${key}" does not exist.`);
}
})
);
}

try
{
await validateExports(packageJson.exports);
// Write the updated package.json back to disk
fs.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
}
catch (error)
{
console.error(`ERROR: ${error.message}\n`);
process.exit(1);
}

61 changes: 0 additions & 61 deletions scripts/rollup-dedupe-vert.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/adjustment/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './AdjustmentFilter.js';
export * from './AdjustmentFilter';
2 changes: 1 addition & 1 deletion src/color-map/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ColorMapFilter.js';
export * from './ColorMapFilter';
2 changes: 1 addition & 1 deletion src/crt/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './CRTFilter.js';
export * from './CRTFilter';
2 changes: 1 addition & 1 deletion src/glitch/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './GlitchFilter.js';
export * from './GlitchFilter';
2 changes: 1 addition & 1 deletion src/kawase-blur/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './KawaseBlurFilter.js';
export * from './KawaseBlurFilter';
2 changes: 1 addition & 1 deletion src/motion-blur/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './MotionBlurFilter.js';
export * from './MotionBlurFilter';
2 changes: 1 addition & 1 deletion src/multi-color-replace/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './MultiColorReplaceFilter.js';
export * from './MultiColorReplaceFilter';
2 changes: 1 addition & 1 deletion src/old-film/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './OldFilmFilter.js';
export * from './OldFilmFilter';
2 changes: 1 addition & 1 deletion src/radial-blur/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './RadialBlurFilter.js';
export * from './RadialBlurFilter';
2 changes: 1 addition & 1 deletion src/reflection/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ReflectionFilter.js';
export * from './ReflectionFilter';
2 changes: 1 addition & 1 deletion src/zoom-blur/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ZoomBlurFilter.js';
export * from './ZoomBlurFilter';
5 changes: 5 additions & 0 deletions tools/demo/src/filters/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"func-names": "off"
}
}

0 comments on commit 5496c22

Please sign in to comment.