roundel 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/check.js +31 -5
- package/package.json +1 -1
package/dist/check.js
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
1
2
|
import { resolve } from 'node:path';
|
|
2
3
|
import { pathToFileURL } from 'node:url';
|
|
3
4
|
import { contributions, PluginError, register, reset, validate } from './plugin.js';
|
|
4
5
|
export const EXIT_OK = 0;
|
|
5
6
|
export const EXIT_RUNTIME = 1;
|
|
6
7
|
export const EXIT_USAGE = 2;
|
|
8
|
+
const USAGE = 'usage: roundel check <plugin-file>\n';
|
|
9
|
+
const HELP = `${USAGE}
|
|
10
|
+
Load a plugin file, validate it against the family schema, register it, and report what
|
|
11
|
+
roundel does with it. Exit 0 when it contributes, 1 on a refusal (with a code and a fix), 2 on
|
|
12
|
+
a usage error.
|
|
13
|
+
|
|
14
|
+
-h, --help show this help
|
|
15
|
+
-V, --version print the version
|
|
16
|
+
`;
|
|
17
|
+
function version() {
|
|
18
|
+
return JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
19
|
+
}
|
|
20
|
+
function target(arg, write) {
|
|
21
|
+
if (arg === '--help' || arg === '-h') {
|
|
22
|
+
write(HELP);
|
|
23
|
+
return EXIT_OK;
|
|
24
|
+
}
|
|
25
|
+
if (arg === '--version' || arg === '-V') {
|
|
26
|
+
write(`${version()}\n`);
|
|
27
|
+
return EXIT_OK;
|
|
28
|
+
}
|
|
29
|
+
if (arg === undefined || arg.startsWith('-')) {
|
|
30
|
+
write(arg === undefined ? USAGE : `unknown option ${arg}\n${USAGE}`);
|
|
31
|
+
return EXIT_USAGE;
|
|
32
|
+
}
|
|
33
|
+
return arg;
|
|
34
|
+
}
|
|
7
35
|
function refuse(code, message, fix, write) {
|
|
8
36
|
write(`${code}: ${message}\n fix: ${fix}\n`);
|
|
9
37
|
return EXIT_RUNTIME;
|
|
@@ -20,11 +48,9 @@ export async function check(argv, write) {
|
|
|
20
48
|
}
|
|
21
49
|
}
|
|
22
50
|
async function inspect(argv, write) {
|
|
23
|
-
const file = argv[0];
|
|
24
|
-
if (file ===
|
|
25
|
-
|
|
26
|
-
return EXIT_USAGE;
|
|
27
|
-
}
|
|
51
|
+
const file = target(argv[0], write);
|
|
52
|
+
if (typeof file === 'number')
|
|
53
|
+
return file;
|
|
28
54
|
const loaded = (await import(pathToFileURL(resolve(file)).href));
|
|
29
55
|
const plugin = loaded.default ?? loaded;
|
|
30
56
|
reset();
|
package/package.json
CHANGED