-
Notifications
You must be signed in to change notification settings - Fork 13
/
verify-one.js
46 lines (36 loc) · 1.13 KB
/
verify-one.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
46
const fs = require('fs');
const unified = require('unified');
const frontmatter = require('remark-frontmatter');
const rpm = require('remark-parse-yaml');
const rp = require('remark-parse');
const minimatch = require('minimatch');
const makeNative = require('./native-compiler');
require('node-json-color-stringify');
const processor = unified()
.use(rp)
.use(frontmatter)
.use(rpm)
.use(makeNative)
.freeze();
if (process.argv.length <= 2) {
process.exitCode = 2;
return;
}
const input = process.argv[2];
const createMatcher = (file) => (pattern) => minimatch(file, pattern, { matchBase: true });
try {
if (!['.*', '!*.md', 'README.md'].some(createMatcher(input))) {
const nativeData = processor
.processSync(fs.readFileSync(input));
if (nativeData.result.hash === '0x0') {
throw new Error('No native hash was specified.');
}
console.log(JSON.colorStringify(nativeData.result, null, 4));
} else {
console.log(`${input} is not a native definition.`);
}
process.exitCode = 0;
} catch (e) {
console.log(e);
process.exitCode = 1;
}