-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
75 lines (67 loc) · 2.21 KB
/
install.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
#!/usr/bin/env node
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
var version = '1.0.4'
var args = process.argv.slice(2);
var git = 'https://github.com/NEYouFan/ht-projecttemplate-ios.git';
var params = '';
var flag = false;
args.forEach(function (val, index, array) {
if (val == '-git') {
flag = true;
}else if (flag){
git = val;
flag = false;
}else {
params = params + ' ' + val;
}
});
params = params.replaceAll('=',' ');
if (params == ' -help' || params == ' -h') {
console.log('opions:');
console.log('-h/-help(可选) 显示帮助信息');
console.log('-git(可选) 指定需要生成的模版仓库地址,不填则为默认模版地址');
console.log('-o(可选) 指定输出到工程路径,默认为当前路径');
console.log('-ProductName(必填) 生成工程的项目名称');
console.log('-Prefix(必填) 生成工程的类名前缀');
console.log('-CategoryPrefix(必填) 生成工程的类别里面所有方法的前缀');
console.log('-Author(必填) 生成工程的作者名称');
console.log('-w(可选) 是否覆盖已存在的文件,默认为false');
return;
}
if (params == ' -version' || params == ' -v') {
console.log('ht_tempalte version is:' + version);
return;
}
console.log('params: ' + params);
var exec = require('child_process').exec;
exec('pwd',function(err,stdout,stderr){
});
exec('mkdir HTTempplate',function(err,stdout,stderr){
});
console.log('git cloning... from:' + git);
exec('git clone '+git+' HTTempplate',function(err,stdout,stderr){
console.log(stdout);
if (!err) {
exec('nei template -p ./HTTempplate/HTLocalProjectTemplate/' + params,function(err,stdout,stderr){
if (!err) {
exec('rm -rf HTTempplate',function(err,stdout,stderr){
console.log(stdout);
if (!err) {
console.log('removing HTTempplate...');
console.log('All Done!')
} else {
console.log('err in removing HTTempplate:' + err);
}
});
} else {
console.log('err in nei:' + err);
console.log('stderr is:' + stderr);
}
});
} else {
console.log('err in git cloning:' + err);
}
});