forked from devfile/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-api-reference.js
35 lines (33 loc) · 1.68 KB
/
generate-api-reference.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
'use strict'
const { Bootprint } = require('bootprint/index')
const bootprintJsonSchema = require('bootprint-json-schema')
const bootprintConfig = require('./reference-generator/config.js')
const fs = require('fs');
fs.readdir('./docs/modules/user-guide/attachments/jsonschemas/', (err, files) => {
if (err) throw err;
files.forEach((version) => {
var glob = require('glob-fs')();
var schemas = glob.readdirSync('./docs/modules/user-guide/attachments/jsonschemas/' + version + '/devfile*.json');
if (! schemas.empty) {
var schemaPath = schemas[0]
var apiReferencePath = './docs/modules/user-guide/attachments/api-reference/' + version + '/'
console.log("Generating Api reference:\n - from schema: " + schemaPath + '\n - to folder: ' + apiReferencePath)
new Bootprint(bootprintJsonSchema, bootprintConfig)
.run(schemaPath, apiReferencePath)
.then((result) => {
try {
fs.mkdirSync(`./docs/modules/user-guide/examples/api-reference/${version}/`, { recursive: true })
} catch(e) { console.error(e)}
fs.writeFileSync(
`./docs/modules/user-guide/examples/api-reference/${version}/body.html`,
`
<a href="_attachments/jsonschemas/${version}/devfile.json">Download current the JSON Schema</a>
<iframe src="../_attachments/api-reference/${version}/index.html" style="border:none;width: 100%;min-height:50em;height:-webkit-fill-available;"></iframe>
`)
}
, (err) => {
throw err
})
}
});
});