-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstaged.ts
More file actions
81 lines (70 loc) · 2.24 KB
/
Copy pathstaged.ts
File metadata and controls
81 lines (70 loc) · 2.24 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
77
78
79
80
81
import lintStaged from 'lint-staged';
import { parseArgs } from './cli/args.ts';
import { printCommandHelp } from './cli/help.ts';
import { loadRstackConfig } from './config.ts';
export type StagedSyncTaskGenerator = (
stagedFileNames: readonly string[],
) => string | string[];
export type StagedAsyncTaskGenerator = (
stagedFileNames: readonly string[],
) => Promise<string | string[]>;
export type StagedTaskGenerator =
StagedSyncTaskGenerator | StagedAsyncTaskGenerator;
export type StagedFunctionTask = {
title: string;
task: (stagedFileNames: readonly string[]) => void | Promise<void>;
};
export type StagedTask =
| string
| StagedFunctionTask
| StagedTaskGenerator
| (string | StagedTaskGenerator)[];
export type StagedConfig = Record<string, StagedTask> | StagedTaskGenerator;
export async function runStagedCLI(args: string[]): Promise<void> {
const { values } = parseArgs({
args,
options: {
'allow-empty': { type: 'boolean' },
concurrent: { type: 'string', short: 'p' },
cwd: { type: 'string' },
debug: { type: 'boolean', short: 'd' },
help: { type: 'boolean', short: 'h' },
'no-stash': { type: 'boolean' },
quiet: { type: 'boolean', short: 'q' },
relative: { type: 'boolean', short: 'r' },
verbose: { type: 'boolean', short: 'v' },
},
allowPositionals: false,
strict: true,
});
if (values.help) {
await printCommandHelp('staged');
return;
}
const { configs } = await loadRstackConfig();
const stagedConfig = configs.staged;
if (!stagedConfig) {
throw new Error(
'No define.staged config found. Add define.staged({ "*": "your-command" }) to rstack config file',
);
}
// Let child commands detect that they are running through `rs staged`.
process.env.RSTACK_STAGED = '1';
const success = await lintStaged({
allowEmpty: values.allowEmpty,
concurrent:
values.concurrent === undefined
? undefined
: (JSON.parse(values.concurrent) as boolean | number),
config: stagedConfig,
cwd: values.cwd,
debug: values.debug,
quiet: values.quiet,
relative: values.relative,
stash: values.noStash ? false : undefined,
verbose: values.verbose,
});
if (!success) {
process.exitCode = 1;
}
}