@seayoo-web/scripts 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node.js +73 -59
- package/package.json +1 -1
- package/types/src/footer.d.ts +5 -1
package/dist/node.js
CHANGED
|
@@ -295,7 +295,9 @@ class FooterBuilder {
|
|
|
295
295
|
distDir,
|
|
296
296
|
dataJsonFile,
|
|
297
297
|
envFilePath,
|
|
298
|
-
injectFunction
|
|
298
|
+
injectFunction,
|
|
299
|
+
previewAfterDeploy,
|
|
300
|
+
deployDebug
|
|
299
301
|
}) {
|
|
300
302
|
__publicField(this, "codeBaseDir");
|
|
301
303
|
__publicField(this, "envFilePath");
|
|
@@ -303,11 +305,15 @@ class FooterBuilder {
|
|
|
303
305
|
__publicField(this, "dataJsonFile");
|
|
304
306
|
__publicField(this, "injectFunction");
|
|
305
307
|
__publicField(this, "$groups");
|
|
308
|
+
__publicField(this, "previewAfterDeploy");
|
|
309
|
+
__publicField(this, "deployDebug");
|
|
306
310
|
this.codeBaseDir = codeBaseDir;
|
|
307
311
|
this.envFilePath = envFilePath;
|
|
308
312
|
this.distDir = distDir;
|
|
309
313
|
this.dataJsonFile = dataJsonFile;
|
|
310
|
-
this.
|
|
314
|
+
this.previewAfterDeploy = !!previewAfterDeploy;
|
|
315
|
+
this.deployDebug = !!deployDebug;
|
|
316
|
+
this.injectFunction = injectFunction.replace(/^function[^(]*\(/, "function ABC(");
|
|
311
317
|
this.$groups = readdirSync(codeBaseDir).filter((name) => {
|
|
312
318
|
return statSync(resolve(codeBaseDir, name)).isDirectory();
|
|
313
319
|
});
|
|
@@ -441,13 +447,14 @@ class FooterBuilder {
|
|
|
441
447
|
return [];
|
|
442
448
|
}
|
|
443
449
|
const buildResult = [];
|
|
450
|
+
const templateName = template.replace(/.+\/(.+)\.html$/, "$1");
|
|
444
451
|
for (const config of metaConfig) {
|
|
445
452
|
const formattedHTML = format(html, deepMerge({}, payloadData || {}, config.payload || {})).replace(/<img [^>]*?src=""[^>]+>/gi, "").replace(/<a [^>]*?href=""[^>]+>(.*?)<\/a>/gi, "$1").replace(/<p class="">/gi, "<p>").replace(/(?:<p>\s*<\/p>|<section>\s*<\/section>|<div>\s*<\/div>)/gi, "");
|
|
446
453
|
buildResult.push({
|
|
447
454
|
deployTo: config.deployTo,
|
|
448
455
|
group: template.replace(/\/.*$/, ""),
|
|
449
|
-
template,
|
|
450
|
-
filename: config.deployTo.replace(
|
|
456
|
+
template: templateName,
|
|
457
|
+
filename: config.deployTo.replace(/[\/.]/g, "-").replace(/\-js$/, ".js"),
|
|
451
458
|
code: await this.combineToCode(config.enabledIn, style, script, formattedHTML)
|
|
452
459
|
});
|
|
453
460
|
}
|
|
@@ -458,7 +465,7 @@ class FooterBuilder {
|
|
|
458
465
|
collapseWhitespace: true,
|
|
459
466
|
removeComments: true,
|
|
460
467
|
minifyJS: true
|
|
461
|
-
})).slice(8, -9).replace(/function
|
|
468
|
+
})).slice(8, -9).replace(/function ABC/, "function");
|
|
462
469
|
return `(${func})(${JSON.stringify(enabledIn)},${JSON.stringify(style)},${JSON.stringify(script)},${JSON.stringify(html)})`;
|
|
463
470
|
}
|
|
464
471
|
async upload(deployTo, code, user, key) {
|
|
@@ -467,7 +474,8 @@ class FooterBuilder {
|
|
|
467
474
|
deployTo,
|
|
468
475
|
user,
|
|
469
476
|
key,
|
|
470
|
-
preview:
|
|
477
|
+
preview: this.previewAfterDeploy,
|
|
478
|
+
debug: this.deployDebug
|
|
471
479
|
}).then(() => null).catch((err) => err instanceof Error ? err : new Error(err));
|
|
472
480
|
}
|
|
473
481
|
/**
|
|
@@ -502,13 +510,16 @@ class FooterBuilder {
|
|
|
502
510
|
* - 其他文件变更则触发全量构建
|
|
503
511
|
*/
|
|
504
512
|
startFileWatch() {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
const src = this.codeBaseDir;
|
|
514
|
+
chokidar.watch(src).on("all", (event, path2) => {
|
|
515
|
+
if (event === "addDir") {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const file = path2.startsWith(src) ? path2.slice(src.length + 1) : path2;
|
|
519
|
+
if (file.endsWith(".html")) {
|
|
520
|
+
this.buildAndOutput(file.replace(/\\/g, "/"));
|
|
521
|
+
} else {
|
|
522
|
+
this.buildAndOutput();
|
|
512
523
|
}
|
|
513
524
|
});
|
|
514
525
|
}
|
|
@@ -538,52 +549,55 @@ class FooterBuilder {
|
|
|
538
549
|
res.end();
|
|
539
550
|
return;
|
|
540
551
|
}
|
|
541
|
-
const
|
|
542
|
-
|
|
552
|
+
const templateDeployInfo = url.match(/deploy\/([^/]+)\/([^/]+)\/?\?target=(.+)$/);
|
|
553
|
+
if (!templateDeployInfo) {
|
|
554
|
+
res.writeHead(404, cosHeader);
|
|
555
|
+
res.write("参数错误,应该是 group/template?target=xxx");
|
|
556
|
+
res.end();
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
543
559
|
const user = this.getDeployUserKey();
|
|
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
|
-
}
|
|
560
|
+
const group = templateDeployInfo[1];
|
|
561
|
+
const template = this.getTemplateFile(templateDeployInfo[1], templateDeployInfo[2]);
|
|
562
|
+
const target = templateDeployInfo[3];
|
|
563
|
+
if (!user) {
|
|
564
|
+
res.writeHead(403, cosHeader);
|
|
565
|
+
res.write("请先在根目录添加 .env.local 文件");
|
|
566
|
+
res.end();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (!user.user) {
|
|
570
|
+
res.writeHead(403, cosHeader);
|
|
571
|
+
res.write("请设置 .env.local 文件中 SY_DEPLOY_USER");
|
|
572
|
+
res.end();
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (!user.key) {
|
|
576
|
+
res.writeHead(403, cosHeader);
|
|
577
|
+
res.write("请设置 .env.local 文件中 SY_DEPLOY_KEY");
|
|
578
|
+
res.end();
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const allGroups = this.groups;
|
|
582
|
+
if (!allGroups.includes(group)) {
|
|
583
|
+
res.writeHead(403, cosHeader);
|
|
584
|
+
res.write(`分组错误,没有 ${group}`);
|
|
585
|
+
res.end();
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const allTemplates = this.getAllTemplates();
|
|
589
|
+
if (!allTemplates.includes(template)) {
|
|
590
|
+
res.writeHead(403, cosHeader);
|
|
591
|
+
res.write(`模板错误,没有 ${template}`);
|
|
592
|
+
res.end();
|
|
593
|
+
return;
|
|
579
594
|
}
|
|
580
|
-
if (
|
|
581
|
-
const buildResult = await this.coreBuild(
|
|
582
|
-
const
|
|
583
|
-
const data = buildResult.find((data2) => data2.filename === filename);
|
|
595
|
+
if (target.endsWith(".js")) {
|
|
596
|
+
const buildResult = await this.coreBuild(template);
|
|
597
|
+
const data = buildResult.find((data2) => data2.deployTo === target);
|
|
584
598
|
if (!data) {
|
|
585
599
|
res.writeHead(504, cosHeader);
|
|
586
|
-
res.write(
|
|
600
|
+
res.write(`没有找到文件配置 ${target}`);
|
|
587
601
|
res.end();
|
|
588
602
|
return;
|
|
589
603
|
}
|
|
@@ -593,8 +607,8 @@ class FooterBuilder {
|
|
|
593
607
|
res.end();
|
|
594
608
|
return;
|
|
595
609
|
}
|
|
596
|
-
if (
|
|
597
|
-
const buildResult = await this.coreBuild(
|
|
610
|
+
if (target === "all") {
|
|
611
|
+
const buildResult = await this.coreBuild(template);
|
|
598
612
|
const success = [];
|
|
599
613
|
const failed = [];
|
|
600
614
|
for (const data of buildResult) {
|
|
@@ -617,8 +631,8 @@ class FooterBuilder {
|
|
|
617
631
|
res.end();
|
|
618
632
|
return;
|
|
619
633
|
}
|
|
620
|
-
res.writeHead(
|
|
621
|
-
res.write("
|
|
634
|
+
res.writeHead(400, { "Content-Type": "text/plain", ...cosHeader });
|
|
635
|
+
res.write("参数错误");
|
|
622
636
|
res.end();
|
|
623
637
|
});
|
|
624
638
|
server.listen(port);
|
package/package.json
CHANGED
package/types/src/footer.d.ts
CHANGED
|
@@ -5,12 +5,16 @@ export declare class FooterBuilder {
|
|
|
5
5
|
private dataJsonFile;
|
|
6
6
|
private injectFunction;
|
|
7
7
|
private $groups;
|
|
8
|
-
|
|
8
|
+
private previewAfterDeploy;
|
|
9
|
+
private deployDebug;
|
|
10
|
+
constructor({ codeBaseDir, distDir, dataJsonFile, envFilePath, injectFunction, previewAfterDeploy, deployDebug, }: {
|
|
9
11
|
codeBaseDir: string;
|
|
10
12
|
distDir: string;
|
|
11
13
|
dataJsonFile: string;
|
|
12
14
|
envFilePath: string;
|
|
13
15
|
injectFunction: string;
|
|
16
|
+
previewAfterDeploy?: boolean;
|
|
17
|
+
deployDebug?: boolean;
|
|
14
18
|
});
|
|
15
19
|
get groups(): string[];
|
|
16
20
|
private getDeployUserKey;
|