-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.js
executable file
·42 lines (37 loc) · 1.07 KB
/
validate.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
#!/usr/bin/env node
'use strict';
const commander = require('commander');
const fs = require('fs');
const index = require('./index');
commander
.usage('[options]')
.option('-j, --json', 'output with JSON')
.option('-f, --file [path]', 'screwdriver command file', './sd-command.yaml')
.parse(process.argv);
/**
* Loads the yaml configuration from a file
* @method loadFile
* @param {String} path File path
* @return {Promise} Promise that resolves to the command as a yaml string
*/
function loadFile(path) {
return new Promise(resolve => {
resolve(fs.readFileSync(path, 'utf8'));
});
}
return loadFile(commander.file)
.then(yamlString => index(yamlString))
.then(result => {
if (result.errors.length > 0) {
console.error(result.errors);
process.exit(1);
} else if (commander.json) {
console.log(JSON.stringify({ valid: true }));
} else {
console.log('true');
}
})
.catch(err => {
console.error(err);
process.exit(1);
});