diff options
author | Cashew <52880648+Scrub1492@users.noreply.github.com> | 2023-12-29 10:26:33 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-29 03:26:33 +0000 |
commit | 39eeed805044388591bdb45a790414495a7bf321 (patch) | |
tree | 557f99043102aba83f323610097f668f2c48814c /dev/bin/build.js | |
parent | 1e254fd1d4423b984e176547ef36a14383bbd7f5 (diff) |
remove getArgs in favor of node:util.parseArgs (#476)
* remove getArgs
* kebab-case to camelCase
* update app/deployment
Diffstat (limited to 'dev/bin/build.js')
-rw-r--r-- | dev/bin/build.js | 56 |
1 files changed, 37 insertions, 19 deletions
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) { |