Skip to content

Commit

Permalink
Showing 5 changed files with 74 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -29,6 +29,6 @@
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/prefer-as-const": "warn"
},
"ignorePatterns": ["scripts/*.js", "src/*.config.js", "tests/fixtures"],
"ignorePatterns": ["tests/fixtures"],
"plugins": ["@typescript-eslint"]
}
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@
"storage"
],
"bin": {
"make-index": "scripts/make-index.js"
"make-index": "scripts/make-index.js",
"build": "scripts/build.js"
},
"type": "module",
"homepage": "https://github.com/zen-fs/core",
@@ -45,9 +46,9 @@
"format:check": "prettier --check .",
"lint": "eslint src tests && tsc -p tsconfig.json --noEmit",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
"build": "node scripts/build.js",
"build": "node scripts/build.js --globalName=ZenFS",
"build:docs": "typedoc --out docs --name ZenFS src/index.ts",
"dev": "node scripts/build.js --watch",
"dev": "npm run build -- --watch",
"prepublishOnly": "npm run build"
},
"dependencies": {
@@ -58,6 +59,7 @@
"readable-stream": "^4.5.2"
},
"devDependencies": {
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.1",
"@typescript-eslint/eslint-plugin": "^5.55.0",
69 changes: 50 additions & 19 deletions scripts/build.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,46 +1,77 @@
import { build, context } from 'esbuild';
import { execSync } from 'node:child_process';
import { parseArgs } from 'node:util';
import { rmSync } from 'node:fs';
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import $package from '../package.json' assert { type: 'json' };

const options = parseArgs({
config: {
const main = $package.main;

let buildCount = 0;

const { watch, keep, quiet, globalName, entryPoints } = parseArgs({
options: {
watch: { short: 'w', type: 'boolean', default: false },
keep: { short: 'k', type: 'boolean', default: false },
quiet: { short: 'q', type: 'boolean', default: false },
globalName: { type: 'string' },
entryPoints: { type: 'string', default: [main], multiple: true },
},
strict: false,
}).values;

async function exportsOf(name) {
const mod = await import(name);
return Object.keys(mod).filter(key => key != 'default');
}

function start() {
if (!keep) {
rmSync('dist', { force: true, recursive: true });
}

if (watch && !quiet) {
console.log(`------------ Building #${++buildCount}`);
}

execSync('npx tsc -p tsconfig.json', { stdio: 'inherit' });
}

const config = {
entryPoints: ['src/index.ts'],
entryPoints,
target: 'esnext',
globalName: 'ZenFS',
globalName,
outfile: 'dist/browser.min.js',
sourcemap: true,
keepNames: true,
bundle: true,
minify: true,
platform: 'browser',
plugins: [
globalExternals({
'@zenfs/core': {
varName: 'ZenFS',
namedExports: await exportsOf('@zenfs/core'),
},
}),
{
name: 'tsc',
name: 'tsc+counter',
setup({ onStart, onEnd }) {
let buildCount = 0;
onStart(async () => {
try {
console.log(`------------ Building #${++buildCount}`);
execSync('npx tsc -p tsconfig.json', { stdio: 'inherit' });
} finally {
}
});
onEnd(() => {
console.log(`--------------- Built #${buildCount}`);
});
onStart(start);

if (watch && !quiet) {
onEnd(() => {
console.log(`--------------- Built #${buildCount}`);
});
}
},
},
],
};

if (options.watch) {
console.log('Watching for changes...');
if (watch) {
if (!quiet) {
console.log('Watching for changes...');
}
const ctx = await context(config);
await ctx.watch();
} else {
10 changes: 4 additions & 6 deletions scripts/make-index.js
Original file line number Diff line number Diff line change
@@ -5,10 +5,7 @@ import { join } from 'path/posix';
import { resolve } from 'path';
import { minimatch } from 'minimatch';

const {
values: options,
positionals: [root],
} = parseArgs({
const { values: options, positionals } = parseArgs({
options: {
help: { short: 'h', type: 'boolean', default: false },
ignore: { short: 'i', type: 'string', multiple: true, default: [] },
@@ -17,9 +14,10 @@ const {
verbose: { type: 'boolean', default: false },
},
allowPositionals: true,
strict: true,
});

const root = positionals.at(-1) == 'make-index' ? '.' : positionals.at(-1);

if (options.help) {
console.log(`make-index <path> [...options]
path: The path to create a listing for
@@ -76,7 +74,7 @@ function makeListing(path, seen = new Set()) {
return null;
}

let entries = {};
const entries = {};
for (const file of readdirSync(path)) {
const full = join(path, file);
if (options.ignore.some(pattern => minimatch(full, pattern))) {

0 comments on commit 2a22dc7

Please sign in to comment.