-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-lint.ts
More file actions
70 lines (58 loc) · 2.19 KB
/
Copy pathrun-lint.ts
File metadata and controls
70 lines (58 loc) · 2.19 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
import { log } from '@clack/prompts';
import { replacePlaceholders } from '@calycode/utils';
import { addPrintOutputFlag, printOutputDir, withErrorHandler } from '../utils/index';
import { runLintXano } from '../features/lint-xano';
import { findProjectRoot } from '../utils/commands/project-root-finder';
// [ ] CORE
async function runLinter(printOutput: boolean = false, core) {
const globalConfig = await core.loadGlobalConfig();
const context = globalConfig.currentContext;
const startDir = process.cwd();
const { instanceConfig, workspaceConfig, branchConfig } = await core.getCurrentContextConfig({
startDir,
context,
});
if (!instanceConfig || !workspaceConfig || !branchConfig) {
log.error(
'Missing instance, workspace, or branch context. Please use setup-instance and switch-context.'
);
process.exit(1);
}
const inputDir = replacePlaceholders(instanceConfig.process.output, {
'@': await findProjectRoot(),
instance: instanceConfig.name,
workspace: workspaceConfig.name,
branch: branchConfig.label,
});
if (!inputDir) throw new Error('Input YAML file is required');
const outputDir = replacePlaceholders(instanceConfig.lint.output, {
'@': await findProjectRoot(),
instance: instanceConfig.name,
workspace: workspaceConfig.name,
branch: branchConfig.label,
});
const now = new Date();
const ts = now.toISOString().replace(/[:.]/g, '-');
const outputPath = `${outputDir}/report-${ts}.json`;
const ruleConfig = instanceConfig.lint.rules;
log.info(
`Lint ${instanceConfig.name} > ${workspaceConfig.name} > ${branchConfig.label} in progress.`
);
await runLintXano({ inputDir, ruleConfig, outputFile: outputPath });
printOutputDir(printOutput, outputDir);
}
// [ ] CLI
function registerLintCommand(program, core) {
const cmd = program
.command('lint')
.description(
'Lint backend logic, based on provided local file. Remote and dynamic sources are WIP...'
);
addPrintOutputFlag(cmd);
cmd.action(
withErrorHandler(async (opts) => {
await runLinter(opts.printOutput, core);
})
);
}
export { registerLintCommand };