forked from rstackjs/rstack-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (39 loc) · 1.25 KB
/
Copy pathindex.ts
File metadata and controls
48 lines (39 loc) · 1.25 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
import { color, logger } from 'rslog';
import { parseArgs } from '../cli/args.ts';
import { printCommandHelp } from '../cli/help.ts';
import { installHooks } from './install.ts';
export const runSetupCLI = async (args: string[]): Promise<void> => {
const { values } = parseArgs({
args,
options: {
help: { type: 'boolean', short: 'h' },
'hooks-dir': { type: 'string', multiple: true },
},
allowPositionals: false,
strict: true,
});
const hooksDirs = values.hooksDir;
if (hooksDirs && hooksDirs.length > 1) {
throw new Error('The --hooks-dir option cannot be specified more than once.');
}
const hooksDir = hooksDirs?.[0];
if (values.help) {
await printCommandHelp('setup');
return;
}
const result = installHooks({ hooksDir });
if (result.status === 'installed' || result.status === 'unchanged') {
return;
}
if (result.status === 'skipped') {
if (result.message) {
logger.warn(`Git hooks setup skipped: ${color.yellow(result.message)}.`);
return;
}
const reason =
result.reason === 'disabled' ? 'disabled by RSTACK_HOOKS' : 'not a Git repository';
logger.info(`Git hooks setup skipped: ${color.yellow(reason)}.`);
return;
}
throw new Error(result.message);
};