diff --git a/scripts/deps.js b/scripts/deps.js index 4d63670..65f75d2 100755 --- a/scripts/deps.js +++ b/scripts/deps.js @@ -2,26 +2,25 @@ // npm run deps update -import {$} from 'zx'; +import {$, minimist, path} from 'zx'; import {roots, json} from './nx.js'; import process from 'node:process'; -const not = (actor) => (...args) => !actor(...args); -const FLAGS = (arg) => /^-/.test(arg); - -const command = process.argv[2]; -const args = process.argv.slice(3).filter(not(FLAGS)); -const flags = process.argv.slice(3).filter(FLAGS); - +const argvPos = process.argv.findIndex(a => a.endsWith(path.parse(import.meta.url).base)) + 1; +const flags = minimist(process.argv.slice(argvPos), { + boolean: ['commit', 'dryrun'], + alias: { + 'dry-run': 'dryrun', + }, +}); +const [command, ...deps] = flags._; switch (command) { case 'update': await update(); break; default: throw 'Unknown command ' + command; } async function update() { - const dryRun = flags.includes('--dry-run'); - const commit = flags.includes('--commit'); - const deps = args.slice(); + const { dryrun, commit } = flags; const projects = await roots(); const work = []; @@ -39,7 +38,15 @@ async function update() { const dependencies = pkg[key] || {}; if (dependencies[name] && dependencies[name] !== '*') { - work.push({pkg: pkg.name, name, key, mode, root, prev: dependencies[name], next: version}); + work.push({ + pkg: pkg.name, + name, + key, + mode, + root, + prev: dependencies[name], + next: version + }); } } } @@ -63,7 +70,7 @@ async function update() { console.log(log.join('\n')); - if (dryRun) { + if (dryrun) { continue; } diff --git a/scripts/reset.js b/scripts/reset.js index a08f041..c6f8839 100755 --- a/scripts/reset.js +++ b/scripts/reset.js @@ -1,13 +1,16 @@ #!/usr/bin/env node -import {$} from 'zx'; +import {$, minimist} from 'zx'; import {roots} from './nx.js'; -import process from "node:process"; +import process from 'node:process'; -const FLAGS = process.argv.slice(2).filter((arg) => /^-/.test(arg)); const ROOTS = await roots(); - -const metapackage = FLAGS.includes('--metapackage') || FLAGS.includes('-u'); +const flags = minimist(process.argv.slice(2), { + boolean: 'metapackage', + alias: { + u: 'metapackage', + }, +}); for (const root of ROOTS) { await $`rm -rf ${root}/node_modules`; @@ -15,7 +18,7 @@ for (const root of ROOTS) { await $`rm -rf node_modules`; -if (metapackage) { +if (flags.metapackage) { await $`npm i`; } else { for (const root of ROOTS) {