-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
759 lines (739 loc) · 32.9 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
'use strict';
exports.name = 'pack';
exports.usage = '<command> [options]';
exports.desc = '默认打包所有,加入app,则只打包app目录的,noapp则不打包app目录的';
exports.register = function(commander){
commander
.option('-e, --verbose', '输出构建日志', Boolean, false)
.option('-c, --complete', '完整打包', Boolean, false)
.option('-f, --force', '强制覆盖远程的里程碑', Boolean, false)
.option('-a, --auto', '自动将当前分支合并到对应分支', Boolean, false)
.option('-p, --app' , '只打包app目录的代码', Boolean, false)
.option('-n, --noapp', '只打包非app即非构建的代码', Boolean,false)
.option('-q, --quick', '快速', Boolean,false)
.action(function(arg0,Command){
var root,
gitRoot,
isGitRoot,
extraPath,
packConfStr,
packConf,
timeoutT,
cmdType,
outputPath,
logPath,
diffFile,
userName,
destBr,
//代码类型
codeType = "app",
version,
command = Command||arg0;
var hashTempPath = "./.hashTemp";
var diffHashPath = "./.diffTemp";
var exec = require('child_process').exec;
doExec("git config --get user.name",function(err,stdout){
userName = stdout;
fis.log.notice("Hi! "+userName);
fis.log.notice("正在打包,请稍候...");
if(checkPath()){
return;
}
checkBranch(function(version,destBr){
initEnv();
getDiffFiles(destBr,function(){
var hasDoAppPack = /(app|weixin|wanle)\/.*\.((?!html|json)\S)+\b/g.exec(diffFile),
hasDoPcPack = /(pc|touch|module|EBooking)\/.*\b/ig.test(diffFile);
if(hasDoAppPack&& !command.noapp){
var _path = codeType;
if(fis.util.exists(extraPath+"output/"+_path)){
try{
fis.util.del(extraPath+"output/"+_path);
}catch(e){
fis.log.notice("删除output/"+_path+"目录失败");
fis.log.notice("请检查你是否打开了该目录!");
return;
}
}
packApp(_path,version,destBr,function(){
if(hasDoPcPack){
packPC(function(){
collectAppRes(_path,function(){
startUpload();
});
});
}else{
collectAppRes(_path,function(){
startUpload();
});
}
});
}else{
if(hasDoPcPack){
packPC(function(){
startUpload();
});
}
}
})
})
})
function getTimestamp(){
var D = new Date(),
_m = D.getMonth()+ 1,
month = _m>9?_m: "0"+_m,
_d = D.getDate(),
date = _d>9?_d: "0"+_d,
_date =""+ (month)+""+ date +Math.ceil(D.getHours()/4);
return _date;
}
function createTag(callback){
var timeStamp = getTimestamp();
fis.log.notice("正在创建里程碑: "+("publish/"+timeStamp).red);
doExec("git tag -l -n publish/"+timeStamp,function(err,output){
var extraParam = "";
if(output !== ""){
var createUser = output.match(/\s+(.*)\s$/)[1];
fis.log.notice("当前里程碑"+("publish/"+timeStamp).red+"已经存在!");
fis.log.notice("即当前时间里已经有人构建过:"+ createUser.red);
if(!(command.force||command.auto)){
fis.log.notice("如果需要覆盖对应的里程碑,请使用 tch pack -f");
return;
}else{
fis.log.notice("正在覆盖对应的里程碑");
extraParam = " -f";
}
}
doExec("git tag publish/"+timeStamp +" "+extraParam+" -m '"+userName+"'",function(err){
doExec("git push "+ extraParam +" origin publish/"+timeStamp,function(err){
if(err){
callback.call(this);
return;
}
fis.log.notice("成功创建里程碑,继续构建!");
callback.call(this);
})
})
})
}
function mergeBr(destBr,srcBr,callback){
doExec("git checkout "+destBr,function(){
doExec("git pull origin "+destBr,function(){
doExec("git merge "+ srcBr,function(err){
doExec("git status -s",function(err,stdout){
if(stdout){
//console.log(stdout);
fis.log.notice("发现下面几个文件存在冲突,请解决:")
var statusArr = stdout.split("\n"),
msg = "";
for(var i = 0, len = statusArr.length -1; i<=len; i++){
var exeArr = /UU\s(\S+)/.exec(statusArr[i]);
if(exeArr){
fis.log.notice(exeArr[1]);
}
}
return;
}
doExec("git push origin "+ destBr,function(){
callback.call(this);
});
})
})
})
});
}
function checkBranch(callback){
fis.log.notice("正在检测分支,请稍候...");
doExec("git status -sb",function(err,stdout,stderr,cb){
var statusArr = stdout.split("\n"),
branchArr = /##\s((daily|weixin|wanle)\/(\d+\.\d+\.\d+))/.exec(statusArr[0]),
devBrArr = /##\s((weixin|wanle)\/develop|develop)/.exec(statusArr[0]);
//如果没有代码未提交,则会有两行,第一行为分支信息,第二行为空行
if(statusArr.length >=3){
fis.log.notice("当前分支还有代码未提交,请提交后再进行操作!");
return;
}
if(typeof arg0 === "string"){
cmdType = arg0;
}
if(branchArr && branchArr[1] && branchArr[3]){
destBr = branchArr[1];
version = branchArr[3];
var realpath = fis.util.realpath("./");
codeType = realpath.split("/").slice(-1)[0];
//如果是daily,则是打包app,否则是打包对应的目录,比如weixin,wanle等
//if(branchArr[2] !== "daily"){
// codeType = branchArr[2];
//}
if(command.verbose){
fis.log.notice("检测到当前目录为"+(codeType+"").red+",正在打包");
fis.log.notice("分支名称为:"+destBr);
}
if(!cmdType){
cmdType = "publish";
fis.log.notice("当前分支为:"+destBr+",默认开启 publish");
}
if(cmdType !== "publish"){
fis.log.notice("发现当前分支为"+destBr.red+",构建命令为 tch pack "+"daily".red);
}
}else if(devBrArr && devBrArr[1]){
var realpath = fis.util.realpath("./");
codeType = realpath.split("/").slice(-1)[0];
destBr = devBrArr[1];
version = "0.0.0";
if(!cmdType){
cmdType = "daily";
fis.log.notice("当前分支为:"+destBr+",默认开启 daily");
}
if(cmdType !== "daily"){
fis.log.notice("发现当前分支为 "+destBr+" 但构建命令为 tch pack "+"publish".red);
fis.log.notice("打包中止");
return;
}
}else{
destBr = /##\s(\S+)/.exec(statusArr[0])[1];
if(command.auto && cmdType === "daily"){
fis.log.notice("检测到自动模式,正在进行合并到develop,请稍候...");
mergeBr("develop",destBr,function(){
destBr = "develop";
version="0.0.0";
callback && callback.call(this,version,destBr);
});
return;
}else{
fis.log.notice("当前分支不为"+"develop".red+"或"+"daily/a.b.c"+"或"+"weixin/develop");
fis.log.notice("打包中止");
return;
}
}
if(!destBr){
fis.log.notice("没有获取到分支名称");
return;
}
doExec("git fetch -p",function(_err){
doExec("git diff --name-only origin/"+destBr+" "+destBr,function(err,output){
if(err) return;
if(output.length > 3){
fis.log.notice("发现有未推送的代码,正在推送...");
doExec("git pull origin "+destBr,function(__err){
if(__err) return;
doExec("git push origin "+destBr,function(___err){
if(___err) return;
_callback();
})
})
return;
}
function _callback(){
if(cmdType === "publish"){
createTag(function(){
callback && callback.call(this,version,destBr);
});
}else{
callback && callback.call(this,version,destBr);
}
}
_callback();
})
})
});
}
function getDiffFiles(branch,callback) {
var self = this;
if (diffFile) {
callback.call(self, diffFile);
return;
}
if (command.complete) {
fis.log.notice("正在全量打包...");
diffFile = fis.util.find("../").join("\n");
//fis.log.notice(diffFile);
callback.call(self, diffFile);
return;
}
exec("git diff --name-only refs/remotes/origin/master refs/remotes/origin/" + branch,
function (err, stdout, stderr, cb) {
var packedFiles = [];
if (command.verbose) {
fis.log.notice("跟master对比,有改动的文件有:");
fis.log.notice(stdout);
}
diffFile = stdout;
callback.call(self, diffFile);
})
}
function getLatestTag(){
doExec("git tag",function(err,stdout,stderr){
if(stdout){
var tagList = stdout.split("\n"),
tagLen = tagList.length;
}
});
}
function packApp(_type,version,destBr,callback){
fis.log.notice("正在打包"+_type+"目录,请稍候...");
doExec("git status -sb",function(err,stdout,stderr,cb){
if(fis.util.exists(diffHashPath)){
fis.util.del(diffHashPath);
}
if(fis.util.exists(hashTempPath)){
fis.util.del(hashTempPath);
}
if(command.quick){
doExec("git checkout "+destBr+" && git pull origin "+destBr,function(){
var releaseCmd = "tch release "+cmdType;
doExec(releaseCmd,function(){
fis.log.notice("构建完成,开始执行复制!");
callback && callback.call(this);
})
})
return;
}
doExec("git checkout master && git pull origin master",function(err,stdout,stderr,cb){
var releaseCmd = "tch release "+cmdType +" -v "+version;
doExec(releaseCmd,function(err,stdout,stderr,cb){
doExec("git checkout "+destBr+" && git pull origin "+destBr,function(){
var releaseCmd = "tch release "+cmdType;
doExec(releaseCmd,function(){
fis.log.notice("构建完成,开始执行复制!");
callback && callback.call(this);
})
})
})
})
})
}
function copyAppFile(arr,appConf,callback){
var self = this;
if(arr.length <1) {
callback.call(self);
return;
}
var args = arguments;
var item = arr.pop();
var prefix = "../output/"+codeType;
var appConfItem;
if(!appConf){
fis.log.notice("没有配置打包配置!");
return;
}
for(var n = 0, nLen = appConf.length -1; n<=nLen; n++){
appConfItem = appConf[n];
if(appConfItem.reg.test(item)){
var execArr = appConfItem.reg.exec(item),
toStr = appConfItem.to,
toPath = toStr[cmdType].replace(/\$(\d+)/g,function($0,$1){
return execArr[$1];
});
fis.util.copy(prefix+item,extraPath+toPath);
writeLog(item);
if(command.verbose){
fis.log.notice("正在复制: "+(prefix+item));
}
process.nextTick(function(){
copyAppFile.apply(self,args);
});
break;
}
}
}
function collectAppRes(type,callback){
if(fis.util.exists(diffHashPath)){
var diffTemp = fis.util.readJSON(diffHashPath),
url,
appConf = packConf.pack[(type||"app")+"Path"],
appConfItem;
if(diffTemp.length >0){
if(command.verbose){
fis.log.notice("app目录的diff差异: ");
fis.log.notice(diffTemp);
}
for(var i = 0,len = diffTemp.length -1; i<=len; i++){
var extraUrl = diffTemp[i].replace(/\/(\w+s)\/tc_.*\.(\w+s)$/,function($0,$1,$2){
var ext = $1 === "js" ?"css":"js";
return $0.replace($1,ext).replace($2,ext);
})
if(diffTemp.indexOf(extraUrl)===-1){
diffTemp.push(extraUrl);
}
}
fis.log.notice("正在复制"+codeType+"目录里的文件到"+cmdType);
copyAppFile(diffTemp,appConf,callback);
}else{
callback.call(this);
}
}else{
callback.call(this);
}
}
function packPC(callback){
if(!callback) callback = function(){};
process.on('uncaughtException', function (err) {
if(command.verbose){
console.log(err);
}
});
getDiffFiles(destBr,function(fileOutput){
var fileArr = fileOutput.split("\n");
for(var i = 0, len = fileArr.length -1; i<=len; i++){
var filePath = fileArr[i];
if(filePath) {
var matchArr = _match(filePath, version,callback);
}
}
})
}
function doExec(cmd,callback){
if(command.verbose){
fis.log.notice("开始执行:"+cmd);
}
exec(cmd,function(){
var args = arguments;
if(command.verbose){
fis.log.notice("执行完成:"+cmd);
}
if(args && args[0]){
fis.log.notice(args[0]);
}
callback && callback.apply(this,args);
});
}
function checkPath(){
setProjectRoot();
root = fis.project.getProjectPath();
isGitRoot = fis.util.isDir("./.git"),
extraPath = isGitRoot?"":"../";
if(!gitRoot){
if(isGitRoot){
fis.log.notice("打包的目录不对,请进入app或者weixin进行打包!");
return true;
gitRoot = fis.util.realpath("./");
}else{
gitRoot = fis.util.realpath(root+"/"+extraPath);
}
}
}
function initEnv(){
outputPath = extraPath+ "output/"+cmdType;
logPath = outputPath+"/path.log";
//删除生成文件夹
try{
fis.util.del(outputPath);
}catch(e){
fis.log.notice("无法删除output目录,如果该目录被打开,则无法被删除!");
fis.log.notice(e);
return;
}
var packConfPath = gitRoot+"/pack.json";
if(fis.util.exists(packConfPath)){
packConfStr = fis.util.read(packConfPath),
packConf = eval('('+packConfStr+')');
}else{
fis.log.notice("pack.json打包配置不存在!");
}
}
function _match(filePath,version,callback){
var arr = packConf.pack.roadpath;
var isBreak = false;
for(var i = 0, len = arr.length -1; i<=len; i++){
var regArr = arr[i].reg,
regX;
if(typeof regArr !== "array"){
regArr = [regArr];
}
for(var n = 0, nLen = regArr.length -1; n<=nLen; n++){
var regItem = regArr[n];
if(typeof regItem === "string"){
regX = new RegExp(regArr[n]);
}else{
regX = regItem;
}
if(regX.test(filePath)){
if(filePath.indexOf(":")>-1){
var _pre = fis.util.realpath("../");
filePath = filePath.replace(_pre,"");
}
if(!fis.util.exists(extraPath+filePath)){
continue;
}
var from = arr[i].from,
_date = getNewDate(filePath);
isBreak = true;
if(from){
lookup(from,{
version: version,
date: _date
},callback);
}else{
lookup([filePath],{
date: _date,
version: version
},callback);
}
break;
}
}
if(isBreak){
break;
}
}
return arr;
}
function getNewDate(filePath){
var _file = fis.file.wrap(extraPath+filePath),
_hash = _file.getHash();
var hashData = getHash()[filePath];
if(hashData && hashData.hash === _hash){
return hashData.date;
}
var cfg = {},
_date = getTimestamp();
cfg[filePath] = {
date: _date,
hash: _hash
};
saveHash(cfg);
return _date;
}
function getHash(){
var tempHashConf = root+"/tempHash.json";
var isExists = fis.util.exists(tempHashConf),
tempHashContent = isExists? fis.util.read(tempHashConf):"{}",
tempHashData = JSON.parse(tempHashContent);
return {
path: tempHashConf,
data:tempHashData
};
}
function saveHash(cfg){
var tempHashJson = getHash(),
tempHashData = tempHashJson.data;
tempHashData = fis.util.merge(tempHashData,cfg);
fis.util.write(tempHashJson.path,JSON.stringify(tempHashData));
}
function uploadFunc(itemCfg,path){
var ftpCfg;
if(!itemCfg.length){
fis.log.notice('全部上传成功!');
return;
}else{
ftpCfg = itemCfg.shift();
}
var FtpDeploy = require('./lib/ftp-deploy'),
config = ftpCfg.server;
config.localRoot = path;
if(cmdType === "publish"){
config.remoteRoot= ftpCfg.to+"/"+getTimestamp();
}else{
config.remoteRoot= ftpCfg.to;
}
var ftpDeploy = new FtpDeploy();
ftpDeploy.on('upload-error', function (data) {
console.log(data.err); // data will also include filename, relativePath, and other goodies
});
ftpDeploy.deploy(config, function(err) {
if (err) {
fis.log.error(err);
}
else {
fis.log.notice('一台服务器已上传!');
uploadFunc(itemCfg,path);
}
});
}
function startUpload(){
fis.log.notice('正在上传,请稍候...');
var output = "../output/"+cmdType;
var merge = require("merge");
var path = fis.util.realpath(output);
var extraFile = fis.util.read("./extra.json"),
extraData = JSON.parse(extraFile);
var ftpCfg,config;
ftpCfg = extraData.ftp[cmdType];
if(!ftpCfg){
var ftpFileConf = fis.util.read("./ftpTemp.json");
if(!ftpFileConf){
fis.log.notice("没有配置ftp的publish账号,请手动上传!");
return;
}
ftpCfg = JSON.parse(ftpFileConf).publish;
}
if(!ftpCfg.length){
ftpCfg = [ftpCfg];
}
uploadFunc(ftpCfg,path);
}
function checkDanger(_file){
var fileContent = _file.getContent(),
dangerConf = packConf && packConf.pack.danger,
dangerExclude = dangerConf.exclude,
dangerMatch = fileContent.match(dangerConf.reg);
if(dangerMatch){
var flag = true;
if(dangerExclude){
var fullFileName = _file.realpath;
dangerExclude.forEach(function(n,i){
if(fullFileName.indexOf(n)>-1){
flag = false;
return;
}
})
}
if(!flag){
return;
}
fis.log.notice(_file+"包含危险字段:"+(dangerMatch.join(",")).red);
if(_file.indexOf("html")>-1){
return;
}else{
return true;
}
}
}
function lookup(fromArr,cfg,callback){
var packArr = packConf.pack.roadpath;
var type = cmdType||"publish";
var isGitRoot = fis.util.isDir("./.git"),
extraPath = isGitRoot?"":"../";
for(var n = 0, nLen = fromArr.length -1; n<=nLen; n++){
var from = fromArr[n];
for(var i = 0, len = packArr.length -1; i<=len; i++){
var packItem = packArr[i],
regStr = packItem.reg,
toStr = packItem.to[type],
domainObj = packItem.domain,
domainStr = domainObj && domainObj[type],
regX;
if(typeof regStr === "string"){
regX = new RegExp(regStr);
}else{
regX = regStr;
}
if(regX.test(from)){
var url = from.replace(regX,domainStr).replace(/{{(\w+)}}/g,function($0,$1){
return cfg[$1];
});
var fromStr = from.replace(regStr,function($0,$1,$2,$3){
packItem["$1"] = $1;
packItem["$2"] = $2;
packItem["$3"] = $3;
return toStr;
}),
fromPath = from.replace(/{{(\w+)}}/g,function($0,$1){
return cfg[$1];
});
var toPath = fromStr.replace(/{{(\w+)}}/g,function($0,$1){
return cfg[$1];
}).replace("$1",packItem["$1"]).replace("$2",packItem["$2"]).replace("$3",packItem["$3"]);
var _file = fis.file.wrap(extraPath+fromPath),
hash = _file.getHash();
var fileContent = _file.getContent();
if(_file._isText){
if(cmdType === "publish" && checkDanger(_file)){
global.isError = true;
}
fileContent = fileContent.replace(/url\(['"]?([^)]+?)['"]?\)|<link[^>]+href=['"]?([^'"]+)['"]?|\ssrc=['"]?([^'"]+)['"]?/g,function($0,$1,$2,$3){
var value = $1||$2||$3,
filePath = _file.dirname+"/"+value,
localFilePath = fis.util.realpath(filePath);
if(!localFilePath){
if(filePath.indexOf("http")>-1){
return $0;
}else{
if(_file.realpath.indexOf("#")===-1 &&
_file.realpath.indexOf(":")===-1
){
fis.log.warning(_file.realpath.bold.red+"存在问题:")
fis.log.warning($1.bold.red+"不存在!");
}
}
return $0;
}
var url = "";
for(var n = 0, nLen = packArr.length -1; n<=nLen;n++){
var _packItem = packArr[n],
_regX = _packItem.reg;
if(_regX.test(localFilePath)){
url = localFilePath.replace(_regX,_packItem.domain[type])
.replace("$1",packItem["$1"]).replace("$2",packItem["$2"])
.replace("$3",packItem["$3"])
.replace(gitRoot+"/","")
.replace(/{{(\w+)}}/g,function($0,$1){
return cfg[$1];
});
break;
}
}
return $0.replace(value,url);
});
}
fis.util.write(extraPath+toPath,fileContent);
if(from.indexOf("img") === -1||_file.ext === ".html"){
if(command.verbose){
fis.log.notice("源文件:"+from);
fis.log.notice("打包后的地址为:"+url);
}
if(timeoutT){
clearTimeout(timeoutT);
}
timeoutT = setTimeout(function(){
//console.log("test");
if(global.isError){
fis.log.notice("打包出现问题,中断!");
return;
}
fis.log.notice("打包时间戳为:"+getTimestamp().red);
fis.log.notice("打包的更多详细内容已经输出到以下文件里:");
fis.log.notice(fis.util.realpath(logPath));
callback.call(this);
},300);
writeLog(from,url);
}
break;
}
}
}
}
function writeLog(from,url){
var srcLine = "源文件:"+from,
destLine = url?"打包后的地址为:"+url +"\r\n":"";
var isExistLog = fis.util.isFile(logPath),
content = srcLine+"\r\n"+destLine+"\r\n";
if(isExistLog){
content += fis.util.read(logPath);
}
fis.util.write(logPath,content);
}
function setProjectRoot(){
var thisPath = fis.util.realpath(process.cwd()),
filename = "tch-conf.js",
confFilePath = thisPath+"/"+filename,
cwd = thisPath,pos = cwd.length;
do {
cwd = cwd.substring(0, pos);
if(fis.util.exists(confFilePath)){
root = cwd;
break;
} else {
confFilePath = false;
pos = cwd.lastIndexOf('/');
}
} while(pos > 0);
if(!root){
root = thisPath+"/app";
}
fis.project.setProjectRoot(root);
}
});
}
exports.commands = function(){
var opts = {
"publish": {
"desc": "打包改动的代码并替换为正式线上的路径"
},
"daily":{
"desc": "打包改动的代码并替换为测试线上的路径"
}
};
return opts;
}