-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.js
62 lines (61 loc) · 2.09 KB
/
configuration.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
const beautify = require('js-beautify').html
const fs = require('fs')
const HTML = require('./html.js')
const template = fs.readFileSync('./configuration-template.html').toString()
module.exports = (rootPath, moduleName, documentationPath, properties) => {
if (!properties || !properties.length) {
return
}
let title
if (moduleName === '@userdashboard/dashboard') {
title = 'Dashboard'
} else if (moduleName === '@userdashboard/organizations') {
title = 'Organizations module'
} else if (moduleName === '@userdashboard/maxmind-geoip') {
title = 'MaxMind GeoIP module'
} else if (moduleName === '@userdashboard/stripe-connect') {
title = 'Stripe Connect module'
} else if (moduleName === '@userdashboard/stripe-subscriptions') {
title = 'Stripe Subscriptions module'
}
const sorted = [].concat(properties)
sorted.sort((a, b) => {
return a.raw > b.raw ? 1 : -1
})
const data = []
for (const property of sorted) {
const description = property.description
const unset = property.default || ''
let value = property.value || ''
if (value.indexOf(',') > -1) {
value = value.split(',').join(', ')
}
data.push({
object: 'variable',
name: property.raw,
description,
default: unset,
value
})
}
if (!data.length) {
return
}
const doc = HTML.parse(template)
doc.getElementsByTagName('title')[0].child = [{
node: 'text',
text: `${title} configuration`
}]
doc.getElementsByTagName('h1')[0].child = [{
node: 'text',
text: `${title} configuration`
}]
const navbarTemplate = doc.getElementById('navbar')
doc.getElementById('navigation').child = navbarTemplate.child
navbarTemplate.parentNode.removeChild(navbarTemplate)
HTML.renderList(doc, data, 'variable-row-template', 'variables-table')
const html = beautify(doc.toString(), { indent_size: 2, space_in_empty_paren: true })
const configurationFile = moduleName.split('/').pop() + '-configuration.html'
fs.writeFileSync(`${documentationPath}/${configurationFile}`, html)
console.log('writing configuration file', configurationFile)
}