forked from wenzhixin/bootstrap-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-api.js
103 lines (90 loc) · 2.59 KB
/
check-api.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// eslint-disable-next-line no-global-assign
require = require('esm')(module)
const fs = require('fs')
const chalk = require('chalk')
const Constants = require('../src/constants/index.js').default
class API {
constructor () {
this.init()
this.check()
}
check () {
const file = `../site/docs/api/${this.file}`
const md = {}
const content = fs.readFileSync(file).toString()
const lines = content.split('## ')
const outLines = lines.slice(0, 1)
console.log('-------------------------')
console.log(`Checking file: ${file}`)
console.log('-------------------------')
for (const item of lines.slice(1)) {
md[item.split('\n')[0]] = item
}
const mds = Object.keys(md)
for (const [i, key] of this.options.entries()) {
if (md[key]) {
outLines.push(md[key])
const details = md[key].split('\n\n- ')
for (let i = 0; i < this.attributes.length; i++) {
const name = this.attributes[i]
if (this.ignore && this.ignore[key] && this.ignore[key].includes(name)) {
continue
}
if (!details[i + 1] || details[i + 1].indexOf(`**${name}:**`) === -1) {
console.log(chalk.red(`[${key}] missing '${name}'`))
}
}
} else {
outLines.push(key + '\n\n')
}
}
fs.writeFile(file, outLines.join('## '), () => {})
}
}
class TableOptions extends API {
init () {
this.file = 'table-options.md'
this.options = Object.keys(Constants.DEFAULTS).filter(it => {
return !/^(on|format)[A-Z]/.test(it)
})
this.options.unshift('-')
this.attributes = ['Attribute', 'Type', 'Detail', 'Default', 'Example']
this.ignore = {
totalRows: ['Example'],
totalNotFiltered: ['Example']
}
}
}
class ColumnOptions extends API {
init () {
this.file = 'column-options.md'
this.options = Object.keys(Constants.COLUMN_DEFAULTS)
this.attributes = ['Attribute', 'Type', 'Detail', 'Default', 'Example']
}
}
class Methods extends API {
init () {
this.file = 'methods.md'
this.options = Constants.METHODS
this.attributes = ['Parameter', 'Detail']//, 'Example']
}
}
class Events extends API {
init () {
this.file = 'events.md'
this.options = Object.values(Constants.EVENTS)
this.attributes = ['jQuery Event', 'Parameter', 'Detail']
}
}
class Localizations extends API {
init () {
this.file = 'localizations.md'
this.options = Object.keys(Constants.LOCALES.en)
this.attributes = ['Parameter', 'Default']
}
}
new TableOptions()
new ColumnOptions()
new Methods()
new Events()
new Localizations()