2017-02-15 00:43:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var RuleCompiler = require('./rule-compiler.js');
|
|
|
|
|
|
|
|
if (process.argv.length < 3) {
|
|
|
|
console.log('Usage: node cli.js <rules script>');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var rules = [];
|
|
|
|
var caps = {};
|
|
|
|
var tags = {};
|
2017-03-15 04:21:12 +00:00
|
|
|
var err = RuleCompiler.compile(fs.readFileSync(process.argv[2]).toString(),rules,caps,tags);
|
2017-02-15 00:43:22 +00:00
|
|
|
|
|
|
|
if (err) {
|
2017-03-15 04:21:12 +00:00
|
|
|
console.error('ERROR parsing '+process.argv[2]+' line '+err[0]+' column '+err[1]+': '+err[2]);
|
2017-02-15 00:43:22 +00:00
|
|
|
process.exit(1);
|
|
|
|
} else {
|
2017-03-15 04:21:12 +00:00
|
|
|
let capsArray = [];
|
|
|
|
let capabilitiesByName = {};
|
|
|
|
for(let n in caps) {
|
|
|
|
capsArray.push(caps[n]);
|
|
|
|
capabilitiesByName[n] = caps[n].id;
|
|
|
|
}
|
|
|
|
let tagsArray = [];
|
|
|
|
for(let n in tags) {
|
|
|
|
let t = tags[n];
|
|
|
|
tagsArray.push({
|
|
|
|
'id': t.id,
|
|
|
|
'default': t['default']||null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-15 00:43:22 +00:00
|
|
|
console.log(JSON.stringify({
|
2017-03-15 04:21:12 +00:00
|
|
|
config: {
|
|
|
|
rules: rules,
|
|
|
|
capabilities: capsArray,
|
|
|
|
tags: tagsArray
|
|
|
|
},
|
|
|
|
capabilitiesByName: capabilitiesByName,
|
|
|
|
tagsByName: tags
|
|
|
|
},null,1));
|
|
|
|
|
2017-02-15 00:43:22 +00:00
|
|
|
process.exit(0);
|
|
|
|
}
|