-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgood-fences.js
executable file
·45 lines (37 loc) · 1.64 KB
/
good-fences.js
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
#! /usr/bin/env node
// @ts-check
/**
* `./index` is generated via `napi build` or `yarn build` along with `.node`
* It contains js/ts friendly definitions of rust code annotated with `#[napi]`
*/
const { goodFences, GoodFencesResultType } = require('./index');
const { program } = require('commander');
program
.option('-p, --project <string> ', 'tsconfig.json file path, defaults to `./tsconfig.json`', './tsconfig.paths.json')
.option('-o, --output <string>', 'path to write found violations')
.option('--baseUrl <string>', "Overrides `compilerOptions.baseUrl` property read from '--project' argument", '.')
.option('--ignoreExternalFences', 'Ignore external fences (e.g. those in `node_modules`)', false)
.option('--ignoredDirs [pathRegexs...]', 'Directories matching given regular expressions are excluded from fence evaluation (e.g. `--ignoreDirs lib` will not evaluate source files in all dirs named `lib`', [])
.arguments('<path> [morePaths...]')
program.parse(process.argv);
const options = program.opts();
const args = program.args;
const result = goodFences({
paths: args ?? ['packages', 'shared'],
project: options.project,
baseUrl: options.baseUrl,
errOutputPath: options.output,
ignoreExternalFences: options.ignoreExternalFences ? 1 : 0,
ignoredDirs: options.ignoredDirs,
});
result.forEach(r => {
if (r.resultType !== GoodFencesResultType.Violation) {
console.log(r.detailedMessage);
}
if (r.resultType === GoodFencesResultType.Violation) {
console.error(r.detailedMessage);
}
});
if (result.find(r => r.resultType === GoodFencesResultType.Violation)) {
process.exit(1);
}