/
generateDocs.js
63 lines (61 loc) · 1.78 KB
/
generateDocs.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
54
55
56
57
58
59
60
61
62
63
'use strict'
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const toc = require('markdown-toc');
let doc = ''
let resourceDir = 'json/resources/'
fs.readdirAsync(resourceDir)
.then((files) => {
doc += '# Resources\n'
let filePromises = []
files.forEach((f) => {
filePromises.push(fs.readJsonAsync(resourceDir + f))
})
return filePromises
})
.mapSeries((f) => {
let groupName = f[Object.keys(f)[0]].Name.split('::')[1]
doc += '## ' + groupName + '\n'
for (let item in f) {
doc += buildBlock(f[item])
}
})
.then(() => {
return fs.readJsonAsync('json/properties/properties.json')
})
.then((properties) => {
doc += '# Resource Attribute Properties\n'
for (let item in properties) {
doc += buildBlock(properties[item])
}
})
.then(() => {
let finalTOC = toc(doc).content;
doc = finalTOC + '\n\n' + doc;
return fs.writeFileAsync('doc.md', doc)
})
.then((result) => {
console.log('Complete.')
})
.catch((e) => {
console.error('failed.')
console.error(e)
})
function buildBlock(content) {
let block = '### ' + content.Name + '\n'
block += '#### Properties\n'
for(let prop in content.Properties) {
let type = content.Properties[prop].Type
if(type !== 'String' && type !== 'Boolean' && type !== 'Number' && type !== 'Map' && type !== 'Object' && type !== 'Date') {
type = '[' + type + '](#' + type.toLowerCase() + ')'
//console.log(type)
}
block += '##### ' + prop + '\n'
block += content.Properties[prop].Description + '\n\n'
block += '| Array | Type | Required |\n'
block += '|----------|----------|----------|\n'
block += '|' + content.Properties[prop].Array + '|' + type + '|' + content.Properties[prop].Required + '|\n\n'
}
block += '\n'
return block
}