Skip to content

Commit

Permalink
chore(scripts): use zx built-in minimist to parse options (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Dec 27, 2024
1 parent 61f321b commit ad60129
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
33 changes: 20 additions & 13 deletions scripts/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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
});
}
}
}
Expand All @@ -63,7 +70,7 @@ async function update() {

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

if (dryRun) {
if (dryrun) {
continue;
}

Expand Down
15 changes: 9 additions & 6 deletions scripts/reset.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#!/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`;
}

await $`rm -rf node_modules`;

if (metapackage) {
if (flags.metapackage) {
await $`npm i`;
} else {
for (const root of ROOTS) {
Expand Down

0 comments on commit ad60129

Please sign in to comment.