-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.js
More file actions
49 lines (44 loc) · 1.38 KB
/
Copy pathcheck.js
File metadata and controls
49 lines (44 loc) · 1.38 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
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const ROOT = __dirname;
const mustExist = [
'server.js',
'runner-launch.js',
'public/index.html',
'public/app.js',
'public/script-search.js',
'public/run-session-store.js',
'public/style.css',
'config/scripts.json'
];
let ok = true;
for (const rel of mustExist) {
const abs = path.join(ROOT, rel);
if (!fs.existsSync(abs)) {
console.error(`[FAIL] Missing: ${rel}`);
ok = false;
} else {
console.log(`[ OK ] ${rel}`);
}
}
for (const rel of ['server.js', 'runner-launch.js', 'public/app.js', 'public/script-search.js', 'public/run-session-store.js']) {
try {
new vm.Script(fs.readFileSync(path.join(ROOT, rel), 'utf8'), { filename: rel });
console.log(`[ OK ] Syntax: ${rel}`);
} catch (error) {
console.error(`[FAIL] Syntax: ${rel}\n${error.stack || error.message}`);
ok = false;
}
}
try {
const config = JSON.parse(fs.readFileSync(path.join(ROOT, 'config/scripts.json'), 'utf8'));
if (!config || !Array.isArray(config.groups) || !Array.isArray(config.scripts)) {
throw new Error('expected an object containing groups[] and scripts[]');
}
console.log(`[ OK ] Config: ${config.groups.length} groups, ${config.scripts.length} scripts`);
} catch (error) {
console.error(`[FAIL] config/scripts.json: ${error.message}`);
ok = false;
}
process.exit(ok ? 0 : 1);