-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·116 lines (107 loc) · 4.34 KB
/
build
File metadata and controls
executable file
·116 lines (107 loc) · 4.34 KB
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
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
/**
* 入口文件:view中的html文件,以及被html文件引用的js、css文件
* -a 重新分析文件关系,全量构建
* -m 分析文件关系,生成新的映射文件
* -c commit-hash commit 先判断是否存在map文件,存在则不全量分析。否则全量分析。 根据提交构建
* -f filePath 自定义提交
* */
var fs = require('fs');
var path = require('path');
var clh = require('./increment/change-list-handle');
var gmr = require('./increment/get-reference-relation');
var gulpRun = require('./increment/gup-run');
var smr = require('./increment/analyze-reference-relation');
var proSrcRootPath = require('./doumi_config').proSrcRootPath;
var chalk = require('chalk');
exec();
function exec() {
var arguments = process.argv.splice(2);
var p0 = arguments[0];
var bizCommitHash = arguments[1];
if (arguments.length == 0) {
p0 = '-a';
}
switch (p0) {
case '-a' : //全量构建、不涉及映射关系
let pathConfig = checkOrCreateConfigFile();
console.log(chalk.blue('开始全量构建...'));
gulpRun.run({pathConfig: pathConfig});
break;
case '-c' : //根据提交的changelist构建,先判断是否有映射文件,如果没有则先分析映射关系
if (!bizCommitHash) {
console.log(chalk.red('请提供commit-hash!'));
return;
}
clh.run(bizCommitHash).then(function(targetCommitFile) {
console.log(chalk.blue(' 过滤后的changelist为:'));
console.log(targetCommitFile);
var targetBuildFile = gmr.run(targetCommitFile);
console.log(chalk.blue('最终需要构建的文件列表为:'))
console.log(targetBuildFile);
console.log(chalk.blue('开始build...'));
gulpRun.run(targetBuildFile);
});
break;
case '-f' :
if (!bizCommitHash) {
console.log(chalk.red('请指定文件路径'));
return;
}
var targetFileString = fs.readFileSync(bizCommitHash, {encoding : 'utf8'});
var targetFileArr = clh.filter(targetFileString)
console.log(chalk.blue(' 过滤后的changelist为:'));
console.log(targetFileArr);
var targetBuildFile = gmr.run(targetFileArr);
console.log(chalk.blue('最终需要构建的文件列表为:'))
console.log(targetBuildFile);
console.log(chalk.blue('开始build...'));
gulpRun.run(targetBuildFile);
break;
case '-m' : //全量生成映射关系文件,如果文件之前存在则先删除
smr.analyzeAll();
break;
}
}
function checkOrCreateConfigFile() {
if (fs.existsSync('./build.config.js')) {
try {
let config = require(path.join(process.cwd(), 'build.config.js'));
checkConfigFile(config);
return config;
} catch(e) {
console.log(chalk.yellow('配置文件异常,重新生成新的配置文件!异常的配置文将被重命名为build.config.obsolete.js'));
fs.writeFileSync('./build.config.obsolete.js', fs.readFileSync('./build.config.js'))
createConfigFile();
process.exit(0);
}
} else {
console.log(chalk.yellow('未发现配置文件,即将生成配置文件!'));
createConfigFile();
}
}
function createConfigFile() {
let fileContent = fs.readFileSync(path.join(__dirname, 'build.config.tpl.js'));
fs.writeFileSync('./build.config.js', fileContent);
console.log(chalk.green('配置文件build.config.js创建完成,请进行配置后重新执行构建命令!'));
}
function checkConfigFile(c) {
if (isOk(c.sourcePath.jsWithoutModulePath)
&& isOk(c.sourcePath.jsEntryModulePath)
&& isOk(c.sourcePath.cssPath)
&& isOk(c.sourcePath.lessEntryModulePath)
&& isOk(c.sourcePath.htmlPath)
&& isOk(c.sourcePath.imgPath)
&& isOk(c.sourcePath.otherFilesPath)
&& isOk(c.distDir)) {
} else {
throw '配置文件字段异常,重新生成新的配置文件';
}
}
function isOk(f) {
if (f === null || f == '' || f) {
return true;
}
return false;
}
//日后可增加发送邮件周知。文件内容为change的文件列表以及有影响的文件。