-
Notifications
You must be signed in to change notification settings - Fork 22
/
verify
executable file
·50 lines (37 loc) · 1.04 KB
/
verify
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
50
#!/usr/bin/env node
require('coffee-script/register');
require('babel-core/register')();
const parser = require('./src');
const exec = require('child_process').exec;
const fs = require('fs');
function runQuery(content) {
const result = parser.deparse(parser.parse(content).query);
const json1 = parser.clean(parser.parse(content).query);
const json2 = parser.clean(parser.parse(result).query);
const same = parser.verify(content);
if (same) {
console.log('OK');
} else {
console.log('NOT OK');
fs.writeFileSync('a.json', JSON.stringify(json1, null, ' '));
fs.writeFileSync('b.json', JSON.stringify(json2, null, ' '));
exec('diff -C10 a.json b.json', (error, stdout, stderr) => {
if (error) {
console.log(error);
}
console.log(stdout);
});
}
}
if (process.argv[2]) {
runQuery(process.argv[2]);
} else {
var content = '';
process.stdin.resume();
process.stdin.on('data', (buf) => {
content += buf.toString();
});
process.stdin.on('end', () => {
runQuery(content);
});
}