-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 1.22 KB
/
index.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
'use strict';
const FS = require('q-io/fs');
const fs = require('fs');
const path = require('path');
const rule = require('./rule.js').rule;
const mock = require('./mock.js').mock;
const reset = require('./reset.js').reset;
const action = process.argv[2];
const dest = process.argv[3];
const rootPath= fs.realpathSync('.') + '/mock/views' // 获取根目录
const pathFileObj = {}; // 存储路径-json文件名
function walk(handler, dest) {
FS.listTree(dest || rootPath)
.then(data => data.filter(item => path.parse(item).ext === '.js')) //留下js文件
.then(data => data.map(item => {
item = path.parse(item);
delete item.root;
delete item.ext;
delete item.base;
return item;
})) // 存入路径-文件名
.then(data => {
data.forEach(handler)
}) // 处理
.fail(err => console.log(err));
}
module.exports = function (action, dest) {
switch(action) {
case 'mock':
walk(mock, dest);
break;
case 'init':
walk(rule, dest);
break;
case 'reset':
walk(reset, dest);
break;
default:
break;
}
};