Skip to content

Commit

Permalink
simplify zxi script
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 12, 2024
1 parent 68a204f commit ef2d19c
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions scripts/zxi.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { delimiter, dirname, normalize } = path;
const { dirname, resolve } = path;
const { pathExists } = fs;
const { cwd, env } = process;
const { _: args } = argv;
const { cyan, green } = chalk;
const ROOT = cwd();
const CD = args.includes('cd');
const TIME = args.includes('time');

Expand All @@ -13,28 +12,21 @@ if (TIME) args.splice(args.indexOf('time'), 1);
const FILE = args.shift();
const DIR = dirname(FILE);

$.preferLocal = true;
$.verbose = true;

if (await pathExists(`${ DIR }/package.json`)) {
cd(DIR);

// after fixing the npm bug, use `--prefix ${ DIR }` instead of extra `cd`
// https://github.com/npm/cli/issues/4819
await $`npm install \
await $({ cwd: DIR })`npm install \
--no-audit \
--no-fund \
--lockfile-version=3 \
--loglevel=error \
--force \
`;

const BIN = normalize(`${ cwd() }/node_modules/.bin`);

if (await pathExists(BIN)) env.PATH = `${ BIN }${ delimiter }${ env.PATH }`;
$.preferLocal = [resolve(DIR), cwd()];
}

if (!CD) cd(ROOT);
} else if (CD) cd(DIR);
if (CD) cd(DIR);

env.FORCE_COLOR = '1';

Expand Down

0 comments on commit ef2d19c

Please sign in to comment.