@seayoo-web/scripts 2.5.1 → 2.5.3

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/index.js CHANGED
@@ -73,6 +73,7 @@ function getBuildEnv(command, mode, onlyBuild, requireSentryToken, ignoreSentryT
73
73
  const s = `${EnvPrefix}SENTRY_AUTH_TOKEN`;
74
74
  const u = `${EnvPrefix}DEPLOY_USER`;
75
75
  const k = `${EnvPrefix}DEPLOY_KEY`;
76
+ const p = `${EnvPrefix}_SERVER_PORT`;
76
77
  const paths = process.cwd().replace(/\\/g, "/").split("/");
77
78
  const execDirWithPackage = paths.slice(-2).join("/");
78
79
  const execDir = paths.slice(-1)[0];
@@ -87,6 +88,8 @@ function getBuildEnv(command, mode, onlyBuild, requireSentryToken, ignoreSentryT
87
88
  process.exit(1);
88
89
  }
89
90
  envConfig.page = execDirWithPackage;
91
+ const port = +envs[p];
92
+ if (port) envConfig.port = port;
90
93
  if (onlyBuild) {
91
94
  return envConfig;
92
95
  }
@@ -157,6 +160,10 @@ function definePageBuildConfig(option) {
157
160
  ...optionReset
158
161
  } = option || {};
159
162
  const { alias, ...resolveReset } = resolve;
163
+ if (server.port) {
164
+ console.warn(`ServerPort 不允许直接修改,请使用环境变量 ${EnvPrefix}_SERVER_PORT 设置`);
165
+ delete server.port;
166
+ }
160
167
  return async function({ command, mode }) {
161
168
  var _a, _b, _c;
162
169
  const justBuild = mode === "build";
@@ -268,6 +275,7 @@ function definePageBuildConfig(option) {
268
275
  },
269
276
  server: {
270
277
  open: true,
278
+ port: envs.port,
271
279
  ...server
272
280
  },
273
281
  ...optionReset,
package/dist/node.js CHANGED
@@ -454,7 +454,7 @@ class FooterBuilder {
454
454
  deployTo: config.deployTo,
455
455
  group: template.replace(/\/.*$/, ""),
456
456
  template: templateName,
457
- filename: config.deployTo.replace(/^.*\//, ""),
457
+ filename: config.deployTo.replace(/[\/.]/g, "-").replace(/\-js$/, ".js"),
458
458
  code: await this.combineToCode(config.enabledIn, style, script, formattedHTML)
459
459
  });
460
460
  }
@@ -549,52 +549,55 @@ class FooterBuilder {
549
549
  res.end();
550
550
  return;
551
551
  }
552
- const fileDeployInfo = url.match(/deploy\/([^/]+)\/([^/]+)\/([^/]+)$/);
553
- const templateDeployInfo = url.match(/deploy\/([^/]+)\/([^/]+)$/);
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
+ }
554
559
  const user = this.getDeployUserKey();
555
- if (fileDeployInfo || templateDeployInfo) {
556
- if (!user) {
557
- res.writeHead(403, cosHeader);
558
- res.write("请先在根目录添加 .env.local 文件");
559
- res.end();
560
- return;
561
- }
562
- if (!user.user) {
563
- res.writeHead(403, cosHeader);
564
- res.write("请设置 .env.local 文件中 SY_DEPLOY_USER");
565
- res.end();
566
- return;
567
- }
568
- if (!user.key) {
569
- res.writeHead(403, cosHeader);
570
- res.write("请设置 .env.local 文件中 SY_DEPLOY_KEY");
571
- res.end();
572
- return;
573
- }
574
- const group = (fileDeployInfo == null ? void 0 : fileDeployInfo[1]) || (templateDeployInfo == null ? void 0 : templateDeployInfo[1]) || "";
575
- const allGroups = this.groups;
576
- if (!allGroups.includes(group)) {
577
- res.writeHead(403, cosHeader);
578
- res.write(`分组错误,没有 ${group}`);
579
- res.end();
580
- return;
581
- }
582
- const template = fileDeployInfo ? this.getTemplateFile(fileDeployInfo[1], fileDeployInfo[2]) : templateDeployInfo ? this.getTemplateFile(templateDeployInfo[1], templateDeployInfo[2]) : "";
583
- const allTemplates = this.getAllTemplates();
584
- if (!allTemplates.includes(template)) {
585
- res.writeHead(403, cosHeader);
586
- res.write(`模板错误,没有 ${template}`);
587
- res.end();
588
- return;
589
- }
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;
590
594
  }
591
- if (fileDeployInfo) {
592
- const buildResult = await this.coreBuild(this.getTemplateFile(fileDeployInfo[1], fileDeployInfo[2]));
593
- const filename = `${fileDeployInfo[3].replace(/\.js$/, "")}.js`;
594
- 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);
595
598
  if (!data) {
596
599
  res.writeHead(504, cosHeader);
597
- res.write(`没有找到文件 ${filename}`);
600
+ res.write(`没有找到文件配置 ${target}`);
598
601
  res.end();
599
602
  return;
600
603
  }
@@ -604,8 +607,8 @@ class FooterBuilder {
604
607
  res.end();
605
608
  return;
606
609
  }
607
- if (templateDeployInfo) {
608
- const buildResult = await this.coreBuild(this.getTemplateFile(templateDeployInfo[1], templateDeployInfo[2]));
610
+ if (target === "all") {
611
+ const buildResult = await this.coreBuild(template);
609
612
  const success = [];
610
613
  const failed = [];
611
614
  for (const data of buildResult) {
@@ -628,8 +631,8 @@ class FooterBuilder {
628
631
  res.end();
629
632
  return;
630
633
  }
631
- res.writeHead(404, { "Content-Type": "text/plain", ...cosHeader });
632
- res.write("Api Not Found");
634
+ res.writeHead(400, { "Content-Type": "text/plain", ...cosHeader });
635
+ res.write("参数错误");
633
636
  res.end();
634
637
  });
635
638
  server.listen(port);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/scripts",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "scripts for seayoo web repos",
5
5
  "type": "module",
6
6
  "source": "index.ts",
@@ -74,6 +74,7 @@
74
74
  },
75
75
  "scripts": {
76
76
  "build": "vite build && tsc --emitDeclarationOnly",
77
+ "type-check": "tsc --noEmit",
77
78
  "prepublish": "pnpm build"
78
79
  }
79
80
  }
@@ -19,6 +19,8 @@ interface IBuildEnvs {
19
19
  deployUser: string;
20
20
  /** 部署的 key */
21
21
  deployKey: string;
22
+ /** 本地开发服务器的端口 */
23
+ port?: number;
22
24
  /** 从 vite 读取到的环境变量 */
23
25
  viteEnvs: Record<string, string>;
24
26
  }