summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md6
-rw-r--r--dev/bin/build.js56
-rw-r--r--dev/util.js68
-rw-r--r--package.json2
4 files changed, 41 insertions, 91 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3b48236f..28d02c0b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -51,9 +51,9 @@ Several command line arguments are available for these scripts:
- `--all` - Builds all targets specified in [manifest-variants.json](dev/data/manifest-variants.json).
- `--default` - Restores the default manifest file.
- `--manifest <target>` - Overwrites `ext/manifest.json` with the manifest variant for the specified build target.
-- `--dry-run` - Runs the full build process (excluding zip building), checking that the configuration is valid.
-- `--dry-run-build-zip` - If `--dry-run` is also specified, zip building will also be performed in memory; no files are created.
-- `--yomitan-version <version>` - Sets the version number in the extension manifest. Defaults to 0.0.0.0 if not set.
+- `--dryRun` - Runs the full build process (excluding zip building), checking that the configuration is valid.
+- `--dryRunBuildZip` - If `--dryRun` is also specified, zip building will also be performed in memory; no files are created.
+- `--version <version>` - Sets the version number in the extension manifest. Defaults to 0.0.0.0 if not set.
If no arguments are specified, the command is equivalent to `build.bat --all`.
diff --git a/dev/bin/build.js b/dev/bin/build.js
index deb82618..5d7e4f0d 100644
--- a/dev/bin/build.js
+++ b/dev/bin/build.js
@@ -25,7 +25,8 @@ import path from 'path';
import readline from 'readline';
import {buildLibs} from '../build-libs.js';
import {ManifestUtil} from '../manifest-util.js';
-import {getAllFiles, getArgs, testMain} from '../util.js';
+import {getAllFiles, testMain} from '../util.js';
+import {parseArgs} from 'util';
const dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -218,24 +219,42 @@ function ensureFilesExist(directory, files) {
}
}
-
/**
* @param {string[]} argv
*/
export async function main(argv) {
- const args = getArgs(argv, new Map(/** @type {[key: string, value: (boolean|null|number|string|string[])][]} */ ([
- ['all', false],
- ['default', false],
- ['manifest', null],
- ['dry-run', false],
- ['dry-run-build-zip', false],
- ['yomitan-version', '0.0.0.0'],
- [null, []]
- ])));
-
- const dryRun = /** @type {boolean} */ (args.get('dry-run'));
- const dryRunBuildZip = /** @type {boolean} */ (args.get('dry-run-build-zip'));
- const yomitanVersion = /** @type {string} */ (args.get('yomitan-version'));
+ /** @type {import('util').ParseArgsConfig['options']} */
+ const parseArgsConfigOptions = {
+ all: {
+ type: 'boolean',
+ default: false
+ },
+ default: {
+ type: 'boolean',
+ default: false
+ },
+ manifest: {
+ type: 'string'
+ },
+ dryRun: {
+ type: 'boolean',
+ default: false
+ },
+ dryRunBuildZip: {
+ type: 'boolean',
+ default: false
+ },
+ version: {
+ type: 'string',
+ default: '0.0.0.0'
+ }
+ };
+
+ const {values: args} = parseArgs({args: argv, options: parseArgsConfigOptions});
+
+ const dryRun = /** @type {boolean} */ (args.dryRun);
+ const dryRunBuildZip = /** @type {boolean} */ (args.dryRunBuildZip);
+ const yomitanVersion = /** @type {string} */ (args.version);
const manifestUtil = new ManifestUtil();
@@ -247,14 +266,13 @@ export async function main(argv) {
try {
await buildLibs();
const variantNames = /** @type {string[]} */ ((
- argv.length === 0 || args.get('all') ?
- manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) :
- args.get(null)
+ argv.length === 0 || args.all ?
+ manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) : []
));
await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion);
} finally {
// Restore manifest
- const manifestName = /** @type {?string} */ ((!args.get('default') && args.get('manifest') !== null) ? args.get('manifest') : null);
+ const manifestName = /** @type {?string} */ ((!args.default && typeof args.manifest !== 'undefined') ? args.manifest : null);
const restoreManifest = manifestUtil.getManifest(manifestName);
process.stdout.write('Restoring manifest...\n');
if (!dryRun) {
diff --git a/dev/util.js b/dev/util.js
index 731b5456..ff1c0120 100644
--- a/dev/util.js
+++ b/dev/util.js
@@ -22,74 +22,6 @@ import path from 'path';
import {parseJson} from './json.js';
/**
- * @param {string[]} args
- * @param {Map<?string, (boolean|null|number|string|string[])>} argMap
- * @returns {Map<?string, (boolean|null|number|string|string[])>}
- */
-export function getArgs(args, argMap) {
- let key = null;
- let canKey = true;
- let onKey = false;
- for (const arg of args) {
- onKey = false;
-
- if (canKey && arg.startsWith('--')) {
- if (arg.length === 2) {
- canKey = false;
- key = null;
- onKey = false;
- } else {
- key = arg.substring(2);
- onKey = true;
- }
- }
-
- const target = argMap.get(key);
-
- switch (typeof target) {
- case 'boolean':
- argMap.set(key, true);
- key = null;
- break;
- case 'number':
- argMap.set(key, target + 1);
- key = null;
- break;
- case 'string':
- if (!onKey) {
- argMap.set(key, arg);
- key = null;
- }
- break;
- case 'object':
- if (target === null) {
- if (!onKey) {
- argMap.set(key, arg);
- key = null;
- }
- return argMap;
- } else if (Array.isArray(target)) {
- if (!onKey) {
- target.push(arg);
- key = null;
- }
- return argMap;
- } else {
- console.error(`Unknown argument: ${arg}`);
- key = null;
- }
- break;
- default:
- console.error(`Unknown argument: ${arg}`);
- key = null;
- break;
- }
- }
-
- return argMap;
-}
-
-/**
* @param {string} baseDirectory
* @param {?(fileName: string, isDirectory: boolean) => boolean} predicate
* @returns {string[]}
diff --git a/package.json b/package.json
index b9de0673..bca8ac8a 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
"test-ts-test": "npx tsc --noEmit --project test/jsconfig.json",
"test-code": "vitest run",
"test-code-write": "vitest run --config test/data/vitest.write.config.json",
- "test-build": "node ./dev/bin/build.js --dry-run --all",
+ "test-build": "node ./dev/bin/build.js --dryRun --all",
"license-report": "license-report --output=html --only=prod --fields=name --fields=installedVersion --fields=licenseType --fields=link --html.cssFile=dev/data/legal-npm.css > ext/legal-npm.html",
"license-report-markdown": "license-report --output=markdown --only=prod --fields=name --fields=installedVersion --fields=licenseType --fields=link"
},