-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-config.js
More file actions
41 lines (36 loc) · 1.26 KB
/
validate-config.js
File metadata and controls
41 lines (36 loc) · 1.26 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
#!/usr/bin/env node
/**
* Validates config/layne.json and exits with code 1 if there are errors.
* Run via: npm run validate-config
*/
import { readFile } from 'fs/promises';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { validateConfig } from '../src/config-validator.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const configPath = join(__dirname, '..', 'config', 'layne.json');
let raw;
try {
raw = JSON.parse(await readFile(configPath, 'utf8'));
} catch (err) {
if (err.code === 'ENOENT') {
console.error(`✗ config/layne.json not found at ${configPath}`);
} else if (err instanceof SyntaxError) {
console.error(`✗ config/layne.json is not valid JSON: ${err.message}`);
} else {
console.error(`✗ Failed to read config/layne.json: ${err.message}`);
}
process.exit(1);
}
const result = validateConfig(raw);
if (result.valid) {
const repoCount = Object.keys(raw).filter(k => k !== '$global').length;
console.log(`✓ config/layne.json is valid (${repoCount} repo(s) configured)`);
process.exit(0);
} else {
console.error(`✗ config/layne.json has ${result.errors.length} error(s):\n`);
for (const err of result.errors) {
console.error(` • ${err}`);
}
process.exit(1);
}