forked from dodevops/cloudcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkdoc.js
53 lines (50 loc) · 1.8 KB
/
mkdoc.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
47
48
49
50
51
52
53
/**
* mkdoc.js - Create the README.md file to match the current features
*/
const handlebars = require('handlebars')
const YAML = require('yaml')
const fs = require('fs').promises
const bluebird = require('bluebird')
const sortRegexp = new RegExp("_(.+)")
// Build feature objects
bluebird
.reduce(
['feature', 'flavour'],
(docObjects, part) => {
return fs
.readdir(part)
.then(partNames => {
return bluebird.reduce(
partNames,
(docObject, partName) => {
return fs.readFile(`${part}/${partName}/${part}.yaml`, { encoding: 'utf8' }).then(featureDescriptor => {
let docPartName = partName
if (sortRegexp.test(partName)) {
const matches = partName.match(sortRegexp)
docPartName = matches[1]
}
docObject[docPartName] = YAML.parse(featureDescriptor)
return docObject
})
},
{}
)
})
.then(docObject => {
docObjects[part] = docObject
return docObjects
})
},
{}
)
.then(docObjects => {
return fs.readFile('README.md.handlebars', { encoding: 'utf8' }).then(readmeTemplateSource => {
const readmeTemplate = handlebars.compile(readmeTemplateSource)
return readmeTemplate({
docObjects: docObjects
})
})
})
.then(readme => {
return fs.writeFile('README.md', readme)
})