forked from screwdriver-cd/config-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (41 loc) · 1.4 KB
/
index.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
'use strict';
const Yaml = require('js-yaml');
const Hoek = require('hoek');
const Async = require('async');
const phaseValidateStructure = require('./lib/phase/structural');
const phaseFlatten = require('./lib/phase/flatten');
const phaseValidateFunctionality = require('./lib/phase/functional');
const phaseGeneratePermutations = require('./lib/phase/permutation');
/**
* Parse the configuration from a screwdriver.yaml
* @method configParser
* @param {String} yaml Contents of screwdriver.yaml
* @param {Function} callback Function to call when done (error, { workflow, jobs })
*/
module.exports = function configParser(yaml, callback) {
Async.waterfall([
// Convert from YAML to JSON
(next) => {
let parsedYaml;
try {
parsedYaml = Yaml.safeLoad(yaml);
} catch (parseError) {
return next(parseError);
}
return next(null, parsedYaml);
},
// Basic validation
phaseValidateStructure,
// Flatten structures
phaseFlatten,
// Functionality validation
phaseValidateFunctionality,
// Generate Permutations
phaseGeneratePermutations,
// Output in the right format
(doc, next) => next(null, {
jobs: Hoek.reach(doc, 'jobs'),
workflow: Hoek.reach(doc, 'workflow')
})
], callback);
};