-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·76 lines (63 loc) · 1.99 KB
/
Copy pathindex.js
File metadata and controls
executable file
·76 lines (63 loc) · 1.99 KB
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
#!/usr/bin/env node
const spawn = require('cross-spawn');
// const path = require('path');
const chalk = require('chalk');
const validateConfig = require('./lib/validateConfig');
const createRcFile = require('./lib/createRcFile');
const getProjectPath = require('./lib/getProjectPath');
const autocomplete = require('./lib/autocomplete');
htz();
async function htz() {
await autocomplete();
const args = process.argv.slice(2);
const command = args[0];
if (!command) {
const projectPath = await validateConfig();
process.exitCode = 0;
return projectPath;
}
if (command === '--setup') {
return undefined;
}
// if (command === 'create-config') {
// const projectPath = await createRcFile(true);
// process.exitCode = 0;
// return projectPath;
// }
if (command === 'reconfigure') {
const projectPath = await createRcFile(true);
process.exitCode = 0;
return projectPath;
}
if (command === 'cwd') {
const [ , action, ...restArgs ] = args;
return runTask(action, restArgs, process.cwd());
}
const projectPath = getProjectPath();
if (!projectPath) {
console.error(
chalk`{red "htz" requires the project dir to be configured in ~/.config/.htzrc.js}\n`,
'Alternatively, you can use "htz cwd <command>" to run commands in the CWD.'
);
process.exitCode = 1;
}
const [ action, ...restArgs ] = args;
runTask(action, restArgs, projectPath);
return undefined;
}
function runTask(action, args, cwd) {
const isGlobalAction = [ 'add', 'remove', 'run', ].includes(action);
const yarnCmd = isGlobalAction ? 'workspaces' : 'workspace';
const cmd = isGlobalAction ? action : `@haaretz/${action}`;
const isWin = process.platform === 'win32';
const spawnArgs = isWin
? [ 'cross-env', [ 'yarn', yarnCmd, cmd, ...args, ], ]
: [ 'yarn', [ yarnCmd, cmd, ...args, ], ];
const yarnWorkspace = spawn(...spawnArgs, {
cwd,
stdio: 'inherit',
});
yarnWorkspace.on('close', code => {
process.exitCode = code;
});
}