@seayoo-web/scripts 2.5.0 → 2.5.1

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 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.injectFunction = injectFunction;
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,12 +447,13 @@ 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,
456
+ template: templateName,
450
457
  filename: config.deployTo.replace(/^.*\//, ""),
451
458
  code: await this.combineToCode(config.enabledIn, style, script, formattedHTML)
452
459
  });
@@ -458,7 +465,7 @@ class FooterBuilder {
458
465
  collapseWhitespace: true,
459
466
  removeComments: true,
460
467
  minifyJS: true
461
- })).slice(8, -9).replace(/function injectFooter/, "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: true
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
- chokidar.watch(this.codeBaseDir).on("all", (event, path2) => {
506
- if (event !== "addDir") {
507
- if (path2.endsWith(".html")) {
508
- this.buildAndOutput(path2.slice(4).replace(/\\/g, "/"));
509
- } else {
510
- this.buildAndOutput();
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -5,12 +5,16 @@ export declare class FooterBuilder {
5
5
  private dataJsonFile;
6
6
  private injectFunction;
7
7
  private $groups;
8
- constructor({ codeBaseDir, distDir, dataJsonFile, envFilePath, injectFunction, }: {
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;