forked from zallek/swagger-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateRulesIndex.js
executable file
·40 lines (33 loc) · 1.09 KB
/
generateRulesIndex.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
#!/usr/bin/env node
/* eslint no-var: 0, prefer-template: 0, func-names:0, prefer-arrow-callback:0 */
var path = require('path');
var fs = require('fs');
var BREAK_RULES_DIR = path.join(__dirname, 'src/rules/break');
var SMOOTH_RULES_DIR = path.join(__dirname, 'src/rules/smooth');
var RULES_INDEX_PATH = path.join(__dirname, 'src/rules/index.js');
var breakRulesIds = fs.readdirSync(BREAK_RULES_DIR).map(function (file) {
return file.slice(0, -3);
});
var smoothRulesIds = fs.readdirSync(SMOOTH_RULES_DIR).map(function (file) {
return file.slice(0, -3);
});
// Generate JS code
var rulesIndex = (
'/**\n' +
' Generated File\n' +
' Do not manually modify, use `npm run build:genRulesIndex` instead.\n' +
'**/\n\n' +
'export default {\n' +
' break: {\n' +
breakRulesIds.map(function (id) {
return ' \'' + id + '\': require(\'./break/' + id + '.js\'),\n';
}).join('') +
' },\n' +
' smooth: {\n' +
smoothRulesIds.map(function (id) {
return ' \'' + id + '\': require(\'./smooth/' + id + '.js\'),\n';
}).join('') +
' },\n' +
'};\n'
);
fs.writeFileSync(RULES_INDEX_PATH, rulesIndex, 'utf8');