-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.js
34 lines (29 loc) · 890 Bytes
/
build.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
const fs = require('fs');
const async = require('async');
const templates = [
'change_password',
'create',
'delete',
'get_user',
'login',
'verify'
];
const getScript = (type, done) => {
async.reduce(templates, {}, (scripts, name, cb) => {
fs.readFile(`./src/scripts/${type}/${name}.js`, 'utf8', (err, text) =>
cb(err, Object.assign(scripts, { [name]: text})))
}, done);
};
const processDirs = (dirs, done) => {
async.reduce(dirs, {}, (result, type, cb) => {
getScript(type, (err, data) =>
cb(err, Object.assign(result, { [type]: data})))
}, done);
}
const buildAll = () => {
fs.readdir('./src/scripts', (err, dirs) => processDirs(dirs, (err, result) => {
if (err) return console.error(err);
fs.appendFile(`./dbscripts.json`, JSON.stringify(result, null, ' '), (e) => console.log(e || 'Completed successfully'));
}));
};
buildAll();