-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex
833 lines (815 loc) · 24.5 KB
/
index
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
#!/usr/bin/env node
const fs = require("fs-extra");
if (fs.existsSync("./package-lock.json")) fs.removeSync("./package-lock.json");
console.time("全自动化工具完成");
let allCount = 0;
let start = process.argv[2] ? new Date(process.argv[2]) : null;
const DATE_TODAY = new Date(
new Date().getFullYear(),
new Date().getMonth(),
new Date().getDate()
);
const DATE_TOMORROW = new Date(
new Date().getFullYear(),
new Date().getMonth(),
new Date().getDate() + 1
);
const COMMON_IGNORE = [
".vscode/**/*",
"Docs/**/*",
"README.MD",
"index.html",
"node_modules/**/*",
"**/node_modules/**/*",
"完整包/**/*",
"更新包/**/*",
"开发需求文档/**/*",
".gitignore",
"package.json",
"config.json",
"index",
"pickup"
];
const path = require("path");
const exec = require("child_process").exec;
const spawn = require("child_process").spawn;
const fextract = require("files-extractor");
const STATUS = fextract.STATUS;
const autoConfig = require("./config");
const CODE_VERSION = "V" + autoConfig.version;
const LAST_VERSION = "V" + autoConfig.lastVersion;
let VERSION_LIST = {
last: autoConfig.versionList[autoConfig.lastVersion]
};
autoConfig.versionList[
autoConfig.version
] = DATE_TOMORROW.toLocaleDateString().replace(/\-/g, "/");
fs.writeFileSync("./config.json", JSON.stringify(autoConfig, null, 2));
start =
start == null && VERSION_LIST.last
? (start = new Date(VERSION_LIST.last))
: null;
const PRODUCT_NAME = autoConfig.product_name;
const eventproxy = require("eventproxy");
const async = require("async");
const AUTO_MODE = {
PUBLISH_ONLY: "PublishOnly",
UPDATE_ONLY: "UpdateOnly",
COMPLETE_ONLY: "CompleteOnly",
ALL: "ALL"
};
console.info(
`全自动化工具运行中...模式${autoConfig.mode}...网站版本${CODE_VERSION}`
);
/**
* Pad start string with 0
*
* @param {String} value
* @param {Number} length
* @param {String} pad
* @returns {String}
*/
const pad = String.prototype.padStart
? function(value, length, pad) {
return String.prototype.padStart.call(String(value), length, pad || "0");
}
: function(value, length, pad) {
value = String(value);
length = length >> 0;
pad = pad || "0";
if (value.length > length) {
return value;
} else {
length = length - value.length;
if (length > pad.length) {
pad += pad.repeat(length / pad.length);
}
return pad.slice(0, length) + value;
}
};
/**
* Format date
*
* @param {Date} date
* @returns {String}
*/
const formatDate = function(date, easy = false) {
let year = date.getFullYear();
let month = pad(date.getMonth() + 1, 2);
let day = pad(date.getDate(), 2);
let hour = pad(date.getHours(), 2);
let minutes = pad(date.getMinutes(), 2);
let seconds = pad(date.getSeconds(), 2);
return easy
? `${year}${month}${day}`
: `${year}-${month}-${day} ${hour}.${minutes}.${seconds}`;
};
const getDirObj = function(opts) {
// console.info(opts.start.toISOString(),opts.end.toISOString());
let originDirName = formatDate(opts.start) + " & " + formatDate(opts.end);
let codeVersion =
opts.output === "更新包"
? `${LAST_VERSION}to${CODE_VERSION}`
: CODE_VERSION;
let terminDirName =
opts.terminDirName ||
`${PRODUCT_NAME.replace(
"源码包",
opts.tag + opts.output
)}-${codeVersion}-${formatDate(opts.end, true)}`;
let originDirPath = path.join(__dirname, opts.output, originDirName);
let terminDirPath = originDirPath.replace(originDirName, terminDirName);
return {
originDirName: originDirName,
terminDirName: terminDirName,
originDirPath: originDirPath,
terminDirPath: terminDirPath
};
};
let optsCodeDiff = {
start: start || DATE_TODAY,
end: DATE_TOMORROW,
output: "更新包",
types: "mtime",
ignore: [
"网站发布/**/*",
"**/dist/**/*",
"**/obj/**",
"**/bin/**",
"**/*.user",
"**/log/**",
"**/Web.config"
],
tag: "源码"
};
let optsUpdate = {
start: start || DATE_TODAY,
end: DATE_TOMORROW,
output: "更新包",
types: "mtime",
ignore: ["WHQJAdmin/**/*", "WHQJFront/**/*", "**/log/**", "**/Web.config"],
tag: "发布"
};
const optsCode = {
start: new Date(2017, 0, 1),
end: DATE_TOMORROW,
dot: true,
output: "完整包",
ignore: [
"网站发布/WHQJFront/index.html",
".git/**/*",
".svn/**/*",
"**/.vs/**/*",
"**/Game.*/obj/**",
"**/Game.*/bin/**",
"**/*.user",
"**/dist/**/*"
],
tag: ""
};
const optsAgent = {
start: new Date(2017, 0, 1),
end: DATE_TOMORROW,
files: "网站发布/WHQJFront/?(bin|Card)/**/*",
output: "网站发布",
terminDirName: "WHQJAgent"
};
const optsAPI = {
start: new Date(2017, 0, 1),
end: DATE_TOMORROW,
files: "网站发布/WHQJFront/?(bin|WS)/**/*",
output: "网站发布",
terminDirName: "WHQJAPI"
};
let NEED_PUBLISH_PROJS = [
{
name: "WHQJFront",
path: path.join(
__dirname,
"./WHQJFront/WebProjects/Game.Web/Game.Web.csproj"
)
},
{
name: "WHQJAdmin",
path: path.join(
__dirname,
"./WHQJAdmin/WebProjects/Game.Web/Game.Web.csproj"
)
}
];
const buildConfig = {
spread: [
{
execStr: "npm i",
condition: !fs.existsSync(
path.join(
__dirname,
"./WHQJFront/WebProjects/Game.Web/Spread/node_modules"
)
),
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Spread/")
}
},
{
execStr: "npm run build",
condition: true,
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Spread/")
}
},
{
execStr: "npm run auto",
condition: true,
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Spread/")
}
}
],
card: [
{
execStr: "npm i",
condition: !fs.existsSync(
path.join(
__dirname,
"./WHQJFront/WebProjects/Game.Web/Card/node_modules"
)
),
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Card/")
}
},
{
execStr: "npm run product",
condition: true,
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Card/")
}
},
{
execStr: "npm run auto",
condition: true,
options: {
cwd: path.join(__dirname, "./WHQJFront/WebProjects/Game.Web/Card/")
}
}
]
};
const codeDiffExtract = function(cb) {
console.time("源码更新");
allCount++;
let subCount = 0;
let diffDirObj = getDirObj(optsCodeDiff);
COMMON_IGNORE.forEach(ignore => {
optsCodeDiff.ignore.push(ignore);
});
if (fs.existsSync(diffDirObj.terminDirPath)) {
subCount++;
fs.removeSync(diffDirObj.terminDirPath);
console.info(`Step_${allCount}_${subCount} [源码更新]清理`);
}
let x = fextract(optsCodeDiff);
x.on("message", msg => {
switch (msg.status) {
case STATUS.FAILED:
console.error(msg.data);
return cb(err);
case STATUS.WARNING:
console.warn(msg.data);
break;
case STATUS.BOOTSTRAP:
subCount++;
console.info(`Step_${allCount}_${subCount} [源码更新]文件提取启动 `);
console.time("Files Search");
break;
case STATUS.SEARCHED:
subCount++;
console.timeEnd("Files Search");
console.info(`Step_${allCount}_${subCount} [源码更新]文件搜索完成 `);
console.time("Files Filter");
break;
case STATUS.FILTERED:
subCount++;
console.timeEnd("Files Filter");
console.info(`Step_${allCount}_${subCount} [源码更新]文件过滤完成 `);
console.time("Files Extract");
break;
case STATUS.EXTRACTED:
subCount++;
let result = null;
console.timeEnd("Files Extract");
console.info(`Step_${allCount}_${subCount} [源码更新]文件提取完成 `);
if (fs.existsSync(diffDirObj.originDirPath)) {
subCount++;
fs.copySync(diffDirObj.originDirPath, diffDirObj.terminDirPath, {
preserveTimestamps: true
});
console.info(
`Step_${allCount}_${subCount} [源码更新]文件夹重命名成功 {${
diffDirObj.originDirName
}} > {${diffDirObj.terminDirName}} `
);
fs.removeSync(diffDirObj.originDirPath);
result = diffDirObj.terminDirPath;
}
cb(null, result);
break;
}
});
};
const publishDiffExtract = function(cb) {
console.time("发布更新");
allCount++;
let subCount = 0;
let diffDirObj = getDirObj(optsUpdate);
COMMON_IGNORE.forEach(ignore => {
optsUpdate.ignore.push(ignore);
});
if (fs.existsSync(diffDirObj.terminDirPath)) {
fs.removeSync(diffDirObj.terminDirPath);
subCount++;
console.info(`Step_${allCount}_${subCount} [发布更新]清理`);
}
mvList = [];
let x = fextract(optsUpdate);
x.on("message", msg => {
switch (msg.status) {
case STATUS.FAILED:
console.error(msg.data);
return cb(err);
case STATUS.WARNING:
console.warn(msg.data);
break;
case STATUS.BOOTSTRAP:
subCount++;
console.info(`Step_${allCount}_${subCount} [发布更新]文件提取启动 `);
console.time("Files Search");
break;
case STATUS.SEARCHED:
console.timeEnd("Files Search");
subCount++;
console.info(`Step_${allCount}_${subCount} [发布更新]文件搜索完成 `);
console.time("Files Filter");
break;
case STATUS.FILTERED:
console.timeEnd("Files Filter");
if (Array.isArray(msg.data)) {
msg.data.forEach(p => {
if (p.indexOf("网站发布") > -1)
mvList.push({
origin: path.join(diffDirObj.originDirPath, p),
termin: path
.join(diffDirObj.originDirPath, p)
.replace("\\网站发布", "")
});
});
}
subCount++;
console.info(`Step_${allCount}_${subCount} [发布更新]文件过滤完成 `);
console.time("Files Extract");
break;
case STATUS.EXTRACTED:
console.timeEnd("Files Extract");
subCount++;
console.info(`Step_${allCount}_${subCount} [发布更新]文件提取完成 `);
let epUpdateStep4 = new eventproxy();
epUpdateStep4.once("updateStep4", function() {
let result = null;
if (fs.existsSync(diffDirObj.originDirPath)) {
fs.copySync(diffDirObj.originDirPath, diffDirObj.terminDirPath, {
preserveTimestamps: true
});
subCount++;
console.info(
`Step_${allCount}_${subCount} [发布更新]文件夹重命名成功 {${
diffDirObj.originDirName
}} > {${diffDirObj.terminDirName}} `
);
fs.removeSync(diffDirObj.originDirPath);
result = diffDirObj.terminDirPath;
}
fs.remove(path.join(diffDirObj.terminDirPath, "./网站发布"), function(
err
) {
if (err) console.error(err);
subCount++;
console.info(
`Step_${allCount}_${subCount} [发布更新]文件整理完成 `
);
cb(null, result);
});
});
if (mvList.length > 0) {
let epUpdateStep4_1 = new eventproxy();
epUpdateStep4_1.after("mvList", mvList.length, function() {
epUpdateStep4.emit("updateStep4", true);
});
mvList.forEach(function(obj) {
fs.move(obj.origin, obj.termin, function(err) {
epUpdateStep4_1.emit("mvList", true);
});
});
} else {
epUpdateStep4.emit("updateStep4", false);
}
break;
}
});
};
const codeExtract = function(cb) {
console.time("源码完整");
allCount++;
let subCount = 1;
let diffDirObj = getDirObj(optsCode);
COMMON_IGNORE.forEach(ignore => {
optsCode.ignore.push(ignore);
});
if (fs.existsSync(diffDirObj.terminDirPath)) {
fs.removeSync(diffDirObj.terminDirPath);
console.info(`Step_${allCount}_${subCount} [源码完整]清理`);
}
let x = fextract(optsCode);
x.on("message", msg => {
switch (msg.status) {
case STATUS.FAILED:
console.error(msg.data);
return cb(err);
case STATUS.WARNING:
console.warn(msg.data);
break;
case STATUS.BOOTSTRAP:
subCount++;
console.info(`Step_${allCount}_${subCount} [源码完整]文件提取启动 `);
console.time("Files Search");
break;
case STATUS.SEARCHED:
subCount++;
console.timeEnd("Files Search");
console.info(`Step_${allCount}_${subCount} [源码完整]文件搜索完成 `);
console.time("Files Filter");
break;
case STATUS.FILTERED:
subCount++;
console.timeEnd("Files Filter");
console.info(`Step_${allCount}_${subCount} [源码完整]文件过滤完成 `);
console.time("Files Extract");
break;
case STATUS.EXTRACTED:
subCount++;
let result = null;
console.timeEnd("Files Extract");
console.info(`Step_${allCount}_${subCount} [源码完整]文件提取完成 `);
if (fs.existsSync(diffDirObj.originDirPath)) {
subCount++;
fs.copySync(diffDirObj.originDirPath, diffDirObj.terminDirPath, {
preserveTimestamps: true
});
console.info(
`Step_${allCount}_${subCount} [源码完整]文件夹重命名成功 {${
diffDirObj.originDirName
}} > {${diffDirObj.terminDirName}} `
);
fs.removeSync(diffDirObj.originDirPath);
result = diffDirObj.terminDirPath;
}
cb(null, result);
break;
}
});
};
const buildDist = function(buildCfg, cb) {
if (buildCfg.length > 0) {
let epBuildList = new eventproxy();
epBuildList.after("builded", buildCfg.length, function(builded) {
cb(true);
});
async.eachSeries(
buildCfg,
(cfg, ecb) => {
if (cfg.condition) {
console.info(`${cfg.execStr} on ${cfg.options.cwd} start`);
exec(cfg.execStr, cfg.options, (err, stdout, stderr) => {
console.info(`${cfg.execStr} on ${cfg.options.cwd} end`);
ecb();
epBuildList.emit("builded", true);
});
} else {
ecb();
epBuildList.emit("builded", false);
}
},
err => {
if (err) console.err(err);
}
);
} else {
cb(false);
}
};
const copyRoomCard = function(cb) {
let dirObj = getDirObj(optsAgent);
let copy = [];
let x = fextract(optsAgent);
x.on("message", msg => {
switch (msg.status) {
case STATUS.FAILED:
console.error(msg.data);
return cb(err);
case STATUS.WARNING:
console.warn(msg.data);
break;
case STATUS.BOOTSTRAP:
case STATUS.SEARCHED:
case STATUS.FILTERED:
if (Array.isArray(msg.data)) {
msg.data.forEach(p => {
let obj = {
src: path.join(dirObj.originDirPath, p),
dest: path.join(
dirObj.originDirPath,
p.replace("网站发布/WHQJFront/", "")
)
};
copy.push(obj);
});
}
break;
case STATUS.EXTRACTED:
let result = null;
let epRCReady = eventproxy();
epRCReady.once("ready", ready => {
if (fs.existsSync(dirObj.originDirPath)) {
fs.removeSync(path.join(dirObj.originDirPath, "./网站发布"));
fs.copySync(dirObj.originDirPath, dirObj.terminDirPath, {
preserveTimestamps: true
});
fs.removeSync(dirObj.originDirPath);
result = {
name: dirObj.terminDirName,
path: dirObj.terminDirPath
};
cb(null, result);
}
});
if (copy.length > 0) {
copy.push({
src: path.join(__dirname, "./网站发布/WHQJFront/index.html"),
dest: path.join(dirObj.originDirPath, "./index.html")
});
copy.push({
src: path.join(__dirname, "./网站发布/WHQJFront/Web.config"),
dest: path.join(dirObj.originDirPath, "./Web.config")
});
let epRCMove = eventproxy();
epRCMove.after("moved", copy.length, moved => {
epRCReady.emit("ready", true);
});
copy.forEach(obj => {
fs.copySync(obj.src, obj.dest, {
preserveTimestamps: true
});
epRCMove.emit("moved", true);
});
} else {
epRCReady.emit("ready", true);
}
break;
}
});
};
const copyAPI = function(cb) {
let dirObj = getDirObj(optsAPI);
let copy = [];
let x = fextract(optsAPI);
x.on("message", msg => {
switch (msg.status) {
case STATUS.FAILED:
console.error(msg.data);
return cb(err);
case STATUS.WARNING:
console.warn(msg.data);
break;
case STATUS.BOOTSTRAP:
case STATUS.SEARCHED:
case STATUS.FILTERED:
if (Array.isArray(msg.data)) {
msg.data.forEach(p => {
let obj = {
src: path.join(dirObj.originDirPath, p),
dest: path.join(
dirObj.originDirPath,
p.replace("网站发布/WHQJFront/", "")
)
};
copy.push(obj);
});
}
break;
case STATUS.EXTRACTED:
let result = null;
let epRCReady = eventproxy();
epRCReady.once("ready", ready => {
if (fs.existsSync(dirObj.originDirPath)) {
fs.removeSync(path.join(dirObj.originDirPath, "./网站发布"));
fs.copySync(dirObj.originDirPath, dirObj.terminDirPath, {
preserveTimestamps: true
});
fs.removeSync(dirObj.originDirPath);
result = {
name: dirObj.terminDirName,
path: dirObj.terminDirPath
};
cb(null, result);
}
});
if (copy.length > 0) {
copy.push({
src: path.join(__dirname, "./网站发布/WHQJFront/Web.config"),
dest: path.join(dirObj.originDirPath, "./Web.config")
});
let epRCMove = eventproxy();
epRCMove.after("moved", copy.length, moved => {
epRCReady.emit("ready", true);
});
copy.forEach(obj => {
fs.copySync(obj.src, obj.dest, {
preserveTimestamps: true
});
epRCMove.emit("moved", true);
});
} else {
epRCReady.emit("ready", true);
}
break;
}
});
};
if (fs.existsSync(path.join(__dirname, "./网站发布"))) {
console.time("项目清理");
fs.removeSync(path.join(__dirname, "./网站发布"));
console.timeEnd("项目清理");
}
console.time("项目发布");
let epPublish = new eventproxy();
epPublish.after("publish", NEED_PUBLISH_PROJS.length, publish => {
if (autoConfig.mode !== AUTO_MODE.PUBLISH_ONLY) {
let epUpdate = new eventproxy();
epUpdate.once("updated", function(updated) {
if (autoConfig.mode !== AUTO_MODE.UPDATE_ONLY) {
codeExtract(function(err, codePath) {
allCount++;
let subCount = 0;
if (codePath && fs.existsSync(codePath + ".zip")) {
subCount++;
fs.removeSync(codePath + ".zip");
console.info(`Step_${allCount}_${subCount} [完整包]清理`);
}
console.time("完整包打包");
subCount++;
console.info(
`Step_${allCount}_${subCount} [完整包]打包开始 ${codePath}.zip`
);
let cmd7z = "7z a -tzip " + codePath + ".zip " + codePath;
exec(cmd7z, (err, stdout, stderr) => {
if (err) console.info(err);
subCount++;
console.info(
`Step_${allCount}_${subCount} [完整包]打包完成,正在为你打开更新包文件夹`
);
console.timeEnd("完整包打包");
exec("start " + path.join(__dirname, optsCode.output));
console.timeEnd("全自动化工具完成");
});
});
} else {
console.timeEnd("全自动化工具完成");
}
});
console.info(`Step_0 项目发布完成`);
console.timeEnd("项目发布");
if (autoConfig.mode !== AUTO_MODE.COMPLETE_ONLY) {
codeDiffExtract(function(err, codeDiffPath) {
console.timeEnd("源码更新");
let paths = [];
if (codeDiffPath) paths.push(codeDiffPath);
publishDiffExtract(function(err, publishDiffPath) {
console.timeEnd("发布更新");
if (publishDiffPath) paths.push(publishDiffPath);
if (paths.length > 0) {
console.time("更新包打包");
allCount++;
let subCount = 0;
let zipPath = paths[0].replace("发布", "").replace("源码", "");
if (fs.existsSync(zipPath + ".zip")) {
subCount++;
fs.removeSync(zipPath + ".zip");
console.info(`Step_${allCount}_${subCount} [更新包]清理`);
}
subCount++;
console.info(
`Step_${allCount}_${subCount} [更新包]打包开始 ${zipPath}.zip`
);
let cmd7z = "7z a -tzip " + zipPath + ".zip " + paths.join(" ");
exec(cmd7z, (err, stdout, stderr) => {
if (err) console.info(err);
subCount++;
console.info(
`Step_${allCount}_${subCount} [更新包]打包完成,正在为你打开更新包文件夹`
);
console.timeEnd("更新包打包");
epUpdate.emit("updated", true);
exec("start " + path.join(__dirname, optsCodeDiff.output));
});
} else {
console.info("[更新包]无需打包,因为没有需要更新的文件!");
epUpdate.emit("updated", false);
}
});
});
} else {
epUpdate.emit("updated", false);
}
} else {
console.timeEnd("全自动化工具完成");
}
});
let projCount = 0;
function publishExec(proj) {
let pOutPath = path.join(__dirname, "./网站发布/" + proj.name);
let MSBuild_Publish =
"MSBuild " +
proj.path +
" /t:_WPPCopyWebApplication /p:Configuration=Release /p:WebProjectOutputDir=" +
pOutPath;
exec(
MSBuild_Publish,
{
encoding: "utf8",
timeout: 0,
maxBuffer: 5000 * 1024, // 默认 200 * 1024
killSignal: "SIGTERM"
},
(err, stdout, stderr) => {
projCount++;
console.info(`Step_0_${projCount} 项目[${proj.name}] 发布完成!`);
if (err) {
console.info(`Step_0_${projCount} 项目[${proj.name}] 编译出错!`);
}
if (proj.name === "WHQJFront" && autoConfig.otherRoomCard) {
copyRoomCard(function(err, result) {
if (err) {
console.error(err);
return;
}
projCount++;
console.info(`Step_0_${projCount} 项目[${result.name}] 发布完成!`);
if (autoConfig.otherAPI) {
copyAPI(function(err, result) {
if (err) {
console.error(err);
return;
}
projCount++;
console.info(
`Step_0_${projCount} 项目[${result.name}] 发布完成!`
);
epPublish.emit("publish", true);
});
} else {
epPublish.emit("publish", true);
}
});
} else {
epPublish.emit("publish", true);
}
}
);
}
console.info(`Step_0 项目发布启动`);
if (Object.keys(autoConfig.prebuild).length > 0) {
let epPreBuild = new eventproxy();
epPreBuild.after(
"prebuilded",
Object.keys(autoConfig.prebuild).length,
prebuilded => {
projCount++;
console.info(`Step_0_${projCount} 项目[预发布] 编译完成!`);
async.each(NEED_PUBLISH_PROJS, publishExec);
}
);
Object.keys(autoConfig.prebuild).forEach(k => {
if (autoConfig.prebuild[k]) {
buildDist(buildConfig[k], builded => {
epPreBuild.emit("prebuilded", true);
});
} else {
epPreBuild.emit("prebuilded", false);
}
});
} else {
async.each(NEED_PUBLISH_PROJS, publishExec);
}
// console.info(opts);
// process.exec("fextract -s "+ opts.start.toISOString() + " -e "+ opts.end.toISOString(),(err,stdout,stderr)=>{
// console.info(stdout);
// });