-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
executable file
·87 lines (76 loc) · 2.54 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env node
// @ts-check
import { program } from 'commander';
import path, { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'fs';
import { execSync } from 'node:child_process';
const __dirname = dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'),
);
program.version(packageJson.version);
program
.command('dev')
.description('develop npm package(s) of current repo.')
.argument('[rootPath]', 'root path where to find packages')
.option(
'-w, --watch <string>',
'specify watch files/dir, use "," to separate',
)
.option('-s, --start <string>', 'specify dev commands')
.action(async (rootPath, { watch, start }) => {
global.NPT_CURRENT_WATCH_PATH = watch;
global.NPT_CURRENT_START_PATH = start;
(await import('../dist/index.js')).dev(rootPath);
});
program
.command('link')
.description('link npm package(s) of current repo.')
.argument('[rootPath]', 'root path where to find packages')
.action(async (rootPath) => {
(await import('../dist/index.js')).link(rootPath);
});
program
.command('add')
.description('add linked npm package(s) to current project.')
.argument('[pckNames]', 'specify package names to add, split with ","')
.action(async (pckNames) => {
(await import('../dist/index.js')).add(pckNames);
});
program
.command('list')
.description('list linked packages or added path.')
.argument('[pckName]', 'list all the added path of a linked package')
.option('-a, --all', 'list all the relations')
.option('-p, --packages', 'list all the packages that are linked')
.action(async (pckName, { packages, all }) => {
(await import('../dist/index.js')).list(pckName, all, packages);
});
program
.command('remove')
.description('remove the linked packages of current repo.')
.argument('[pckNames]', 'specify package names to be removed, split with ","')
.action(async (pckNames) => {
(await import('../dist/index.js')).remove(pckNames);
});
program
.command('unlink')
.description('unlink packages.')
.argument(
'[pckNames]',
'specify package names to be unlinked, split with ","',
)
.action(async (pckNames) => {
(await import('../dist/index.js')).unlink(pckNames);
});
program
.command('upgrade')
.description('upgrade to latest version.')
.action(() => {
execSync('pnpm add -g npm-package-devtool@latest', { stdio: 'inherit' });
});
program.parse(process.argv).opts();
if (!program.args.length) {
program.help();
}