Skip to content

Commit ad60129

Browse files
authored
chore(scripts): use zx built-in minimist to parse options (#39)
1 parent 61f321b commit ad60129

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

scripts/deps.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

33
// npm run deps update
44

5-
import {$} from 'zx';
5+
import {$, minimist, path} from 'zx';
66
import {roots, json} from './nx.js';
77
import process from 'node:process';
88

9-
const not = (actor) => (...args) => !actor(...args);
10-
const FLAGS = (arg) => /^-/.test(arg);
11-
12-
const command = process.argv[2];
13-
const args = process.argv.slice(3).filter(not(FLAGS));
14-
const flags = process.argv.slice(3).filter(FLAGS);
15-
9+
const argvPos = process.argv.findIndex(a => a.endsWith(path.parse(import.meta.url).base)) + 1;
10+
const flags = minimist(process.argv.slice(argvPos), {
11+
boolean: ['commit', 'dryrun'],
12+
alias: {
13+
'dry-run': 'dryrun',
14+
},
15+
});
16+
const [command, ...deps] = flags._;
1617
switch (command) {
1718
case 'update': await update(); break;
1819
default: throw 'Unknown command ' + command;
1920
}
2021

2122
async function update() {
22-
const dryRun = flags.includes('--dry-run');
23-
const commit = flags.includes('--commit');
24-
const deps = args.slice();
23+
const { dryrun, commit } = flags;
2524
const projects = await roots();
2625

2726
const work = [];
@@ -39,7 +38,15 @@ async function update() {
3938
const dependencies = pkg[key] || {};
4039

4140
if (dependencies[name] && dependencies[name] !== '*') {
42-
work.push({pkg: pkg.name, name, key, mode, root, prev: dependencies[name], next: version});
41+
work.push({
42+
pkg: pkg.name,
43+
name,
44+
key,
45+
mode,
46+
root,
47+
prev: dependencies[name],
48+
next: version
49+
});
4350
}
4451
}
4552
}
@@ -63,7 +70,7 @@ async function update() {
6370

6471
console.log(log.join('\n'));
6572

66-
if (dryRun) {
73+
if (dryrun) {
6774
continue;
6875
}
6976

scripts/reset.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#!/usr/bin/env node
22

3-
import {$} from 'zx';
3+
import {$, minimist} from 'zx';
44
import {roots} from './nx.js';
5-
import process from "node:process";
5+
import process from 'node:process';
66

7-
const FLAGS = process.argv.slice(2).filter((arg) => /^-/.test(arg));
87
const ROOTS = await roots();
9-
10-
const metapackage = FLAGS.includes('--metapackage') || FLAGS.includes('-u');
8+
const flags = minimist(process.argv.slice(2), {
9+
boolean: 'metapackage',
10+
alias: {
11+
u: 'metapackage',
12+
},
13+
});
1114

1215
for (const root of ROOTS) {
1316
await $`rm -rf ${root}/node_modules`;
1417
}
1518

1619
await $`rm -rf node_modules`;
1720

18-
if (metapackage) {
21+
if (flags.metapackage) {
1922
await $`npm i`;
2023
} else {
2124
for (const root of ROOTS) {

0 commit comments

Comments
 (0)