-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
106 lines (90 loc) · 2.41 KB
/
base.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
104
105
106
var files = [];
var path = require('path');
var fs = require('fs');
var minimist = require('minimist');
var root = 'projects'; //项目总目录
var argv = minimist(process.argv.slice(2), {
string: ['src', 'mode','ph','kkwap']
});
var src = argv.src;
var mode = argv.mode;
var isProd = argv.mode === 'prod'; //运行模式
//var publicPath = (argv.ph != '' && argv.ph) ? true : false
var publicPath = argv.ph
// var kkwap = (argv.kkwap != '' && argv.kkwap) ? true : false
var ScanDir = function(path) {
var that = this
if (fs.statSync(path).isFile()) {
return files.push(path)
}
try {
fs.readdirSync(path).forEach(function(file) {
ScanDir.call(that, path + '/' + file)
})
} catch (e) {}
};
var projectList = fs.readdirSync('./'+root);
if (projectList.indexOf(src) < 0) {
console.error('project not found');
process.exit();
}
var project = path.join(__dirname,root,src);
var pageConfigFile = path.join(project,'src','page.js');
var isExists = fs.existsSync(pageConfigFile);
if(!isExists){
console.error('page.js not found!');
process.exit()
}
// var pageConfig = JSON.parse(fs.readFileSync(pageConfigFile,'utf-8')).pageList;
var pageConfig = require(pageConfigFile);
ScanDir(path.join(project,'src'));
var sourceList = {
jsList:{},
imgList:{},
scssList:{},
cssList:{},
htmlList:{}
};
var jsStr = 'src/js/',strLen = jsStr.length;
files.map((item,i)=>{
var extname = path.extname(item);
var basename = path.basename(item,extname);
switch(extname){
case '.js':
var temp = item.substring(item.indexOf(jsStr)+strLen);
var entryJs = temp.substring(0,temp.indexOf(extname));
sourceList.jsList[entryJs] = item;
break;
case '.gif':
sourceList.imgList[basename] = item;
break;
case '.jpg':
sourceList.imgList[basename] = item;
break;
case '.png':
sourceList.imgList[basename] = item;
break;
case '.jpeg':
sourceList.imgList[basename] = item;
break;
case '.scss':
sourceList.scssList[basename] = item;
break;
case '.css':
sourceList.cssList[basename] = item;
break;
case '.html':
sourceList.htmlList[basename] = item;
break;
}
});
module.exports = {
projectName: src,
sourceList: sourceList,
pageConfig: pageConfig,
isProd: isProd,
root: root,
publicPath: publicPath,
mode: mode
/* kkwap : kkwap*/
};