@gct-paas/cli 0.1.7 → 0.1.9

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/actions/gen-cdn-lib/gen-cdn-lib.cjs +16 -5
  3. package/dist/actions/gen-cdn-lib/gen-cdn-lib.d.ts +0 -1
  4. package/dist/actions/index.cjs +8 -1
  5. package/dist/actions/index.d.ts +1 -0
  6. package/dist/actions/nginx-start/nginx-start.cjs +68 -0
  7. package/dist/actions/nginx-start/nginx-start.d.ts +16 -0
  8. package/dist/actions/update-catalog-env/update-catalog-env.cjs +4 -10
  9. package/dist/actions/update-catalog-env/update-catalog-env.d.ts +0 -1
  10. package/dist/commands/gen-cdn-lib/gen-cdn-lib.cjs +1 -1
  11. package/dist/commands/index.cjs +2 -0
  12. package/dist/commands/nginx-start/nginx-start.cjs +16 -0
  13. package/dist/commands/nginx-start/nginx-start.d.ts +15 -0
  14. package/dist/constants/index.cjs +11 -0
  15. package/dist/constants/index.d.ts +8 -0
  16. package/dist/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +1 -1
  17. package/es/actions/gen-cdn-lib/gen-cdn-lib.d.ts +0 -1
  18. package/es/actions/gen-cdn-lib/gen-cdn-lib.mjs +16 -22
  19. package/es/actions/index.d.ts +1 -0
  20. package/es/actions/index.mjs +1 -0
  21. package/es/actions/nginx-start/nginx-start.d.ts +16 -0
  22. package/es/actions/nginx-start/nginx-start.mjs +53 -0
  23. package/es/actions/update-catalog-env/update-catalog-env.d.ts +0 -1
  24. package/es/actions/update-catalog-env/update-catalog-env.mjs +4 -27
  25. package/es/commands/gen-cdn-lib/gen-cdn-lib.mjs +1 -1
  26. package/es/commands/index.mjs +2 -0
  27. package/es/commands/nginx-start/nginx-start.d.ts +15 -0
  28. package/es/commands/nginx-start/nginx-start.mjs +9 -0
  29. package/es/constants/index.d.ts +8 -0
  30. package/es/constants/index.mjs +22 -0
  31. package/es/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +1 -1
  32. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.9] - 2026-04-02
11
+
12
+ ### Added
13
+
14
+ - 命令 nginx-start 便捷本地启动 plugin 开发 nginx
15
+
16
+ ## [0.1.8] - 2026-04-02
17
+
18
+ ### Changed
19
+
20
+ - 命令 gen-cdn-lib 改为 tag 默认识别当前运行项目分支映射,也可单独指定
21
+
10
22
  ## [0.1.7] - 2026-04-02
11
23
 
12
24
  ### Added
@@ -9,9 +9,10 @@ var _path = _interopRequireDefault(require("path"));
9
9
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
10
  var _consola = _interopRequireDefault(require("consola"));
11
11
  var _listr = require("listr2");
12
+ var _constants = require("../../constants/index.cjs");
13
+ var _utils = require("../../utils/index.cjs");
12
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
15
  class GenCdnLibAction {
14
- packages = ["@gct-paas/api", "@gct-paas/core", "@gct-paas/core-mobile", "@gct-paas/core-pad", "@gct-paas/core-web", "@gct-paas/design", "@gct-paas/design-mobile", "@gct-paas/design-pad", "@gct-paas/design-web", "@gct-paas/native", "@gct-paas/render", "@gct-paas/render-mobile", "@gct-paas/render-pad", "@gct-paas/render-web", "@gct-paas/schema", "@gct-paas/v-ben"];
15
16
  /**
16
17
  * 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
17
18
  */
@@ -57,11 +58,21 @@ class GenCdnLibAction {
57
58
  }
58
59
  _consola.default.info("\u6B63\u5728\u8BFB\u53D6 import-map.json...");
59
60
  const importMap = _fsExtra.default.readJSONSync(importMapJsonPath);
60
- const tasks = new _listr.Listr(this.packages.map(pkg => ({
61
- title: `${pkg}@${opts.tag}`,
61
+ let tag = opts.tag;
62
+ if (!tag) {
63
+ const branch = await (0, _utils.getBranchName)();
64
+ if (branch) {
65
+ tag = _constants.branch_2_tag[branch];
66
+ }
67
+ if (!tag) {
68
+ tag = "latest";
69
+ }
70
+ }
71
+ const tasks = new _listr.Listr(_constants.lib_packages.map(pkg => ({
72
+ title: `${pkg}@${tag}`,
62
73
  task: async (_, task) => {
63
- task.title = `${pkg}@${opts.tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
64
- const pkgInfo = await _pacote.default.manifest(`${pkg}@${opts.tag}`, {
74
+ task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
75
+ const pkgInfo = await _pacote.default.manifest(`${pkg}@${tag}`, {
65
76
  registry: opts.registry,
66
77
  cache: cacheDir
67
78
  });
@@ -6,7 +6,6 @@ import { IGenCdnLibOptions } from '../../interface';
6
6
  * @class GenCdnLibAction
7
7
  */
8
8
  export declare class GenCdnLibAction {
9
- private packages;
10
9
  /**
11
10
  * 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
12
11
  */
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "InitGitAction", {
21
21
  return _initGit.InitGitAction;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "NginxStartAction", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _nginxStart.NginxStartAction;
28
+ }
29
+ });
24
30
  Object.defineProperty(exports, "RestoreFilesAction", {
25
31
  enumerable: true,
26
32
  get: function () {
@@ -37,4 +43,5 @@ var _genApi = require("./gen-api/gen-api.cjs");
37
43
  var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
38
44
  var _initGit = require("./init-git/init-git.cjs");
39
45
  var _restoreFiles = require("./restore-files/restore-files.cjs");
40
- var _updateCatalogEnv = require("./update-catalog-env/update-catalog-env.cjs");
46
+ var _updateCatalogEnv = require("./update-catalog-env/update-catalog-env.cjs");
47
+ var _nginxStart = require("./nginx-start/nginx-start.cjs");
@@ -3,3 +3,4 @@ export { GenCdnLibAction } from './gen-cdn-lib/gen-cdn-lib';
3
3
  export { InitGitAction } from './init-git/init-git';
4
4
  export { RestoreFilesAction } from './restore-files/restore-files';
5
5
  export { UpdateCatalogEnvAction } from './update-catalog-env/update-catalog-env';
6
+ export { NginxStartAction } from './nginx-start/nginx-start';
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NginxStartAction = void 0;
7
+ var _nodeChild_process = require("node:child_process");
8
+ var _nodeFs = require("node:fs");
9
+ var _nodePath = require("node:path");
10
+ var _consola = require("consola");
11
+ function sleep(ms) {
12
+ return new Promise(resolve2 => setTimeout(resolve2, ms));
13
+ }
14
+ class NginxStartAction {
15
+ nginxDir;
16
+ constructor(nginxDir) {
17
+ this.nginxDir = nginxDir ?? (0, _nodePath.resolve)(process.cwd(), "configs/nginx");
18
+ }
19
+ /**
20
+ * 停止已运行的 nginx 进程
21
+ * Windows 使用 taskkill 强制终止,其他平台使用 nginx -s stop
22
+ * 若 nginx 未运行则忽略错误
23
+ */
24
+ async stopNginxIfRunning() {
25
+ try {
26
+ if (process.platform === "win32") {
27
+ (0, _nodeChild_process.execSync)("taskkill /F /IM nginx.exe", {
28
+ stdio: "pipe"
29
+ });
30
+ } else {
31
+ (0, _nodeChild_process.execSync)(`nginx -p "${this.nginxDir}" -s stop`, {
32
+ stdio: "pipe"
33
+ });
34
+ }
35
+ _consola.consola.info("\u5DF2\u505C\u6B62\u73B0\u6709 nginx \u8FDB\u7A0B\uFF0C\u7B49\u5F85 1 \u79D2...");
36
+ await sleep(1e3);
37
+ } catch {
38
+ _consola.consola.info("nginx \u672A\u8FD0\u884C\uFF0C\u8DF3\u8FC7\u505C\u6B62\u6B65\u9AA4");
39
+ }
40
+ }
41
+ /**
42
+ * 启动 nginx
43
+ * Windows 下 nginx 不会自动 daemonize,使用 spawn detached 模式后台启动
44
+ */
45
+ startNginx() {
46
+ (0, _nodeFs.mkdirSync)((0, _nodePath.resolve)(this.nginxDir, "logs"), {
47
+ recursive: true
48
+ });
49
+ (0, _nodeFs.mkdirSync)((0, _nodePath.resolve)(this.nginxDir, "temp"), {
50
+ recursive: true
51
+ });
52
+ const nginxDirNormalized = this.nginxDir.split(_nodePath.sep).join("/");
53
+ const child = (0, _nodeChild_process.spawn)("nginx", ["-p", nginxDirNormalized, "-c", "nginx.conf"], {
54
+ cwd: process.cwd(),
55
+ stdio: "ignore",
56
+ detached: true
57
+ });
58
+ child.unref();
59
+ }
60
+ async run() {
61
+ _consola.consola.start("\u5F00\u59CB\u542F\u52A8 nginx...");
62
+ await this.stopNginxIfRunning();
63
+ _consola.consola.start("\u6B63\u5728\u542F\u52A8 nginx...");
64
+ this.startNginx();
65
+ _consola.consola.success("nginx \u542F\u52A8\u6267\u884C\u5B8C\u6BD5");
66
+ }
67
+ }
68
+ exports.NginxStartAction = NginxStartAction;
@@ -0,0 +1,16 @@
1
+ export declare class NginxStartAction {
2
+ private readonly nginxDir;
3
+ constructor(nginxDir?: string);
4
+ /**
5
+ * 停止已运行的 nginx 进程
6
+ * Windows 使用 taskkill 强制终止,其他平台使用 nginx -s stop
7
+ * 若 nginx 未运行则忽略错误
8
+ */
9
+ private stopNginxIfRunning;
10
+ /**
11
+ * 启动 nginx
12
+ * Windows 下 nginx 不会自动 daemonize,使用 spawn detached 模式后台启动
13
+ */
14
+ private startNginx;
15
+ run(): Promise<void>;
16
+ }
@@ -11,17 +11,13 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
11
  var _jsYaml = _interopRequireDefault(require("js-yaml"));
12
12
  var _utils = require("../../utils/index.cjs");
13
13
  var _path = _interopRequireDefault(require("path"));
14
+ var _constants = require("../../constants/index.cjs");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- const envMap = {
16
- "paas-dev": "dev",
17
- "paas-test": "test"
18
- };
19
16
  class UpdateCatalogEnvAction {
20
- packages = ["@gct-paas/api", "@gct-paas/core", "@gct-paas/core-mobile", "@gct-paas/core-pad", "@gct-paas/core-web", "@gct-paas/design", "@gct-paas/design-mobile", "@gct-paas/design-pad", "@gct-paas/design-web", "@gct-paas/native", "@gct-paas/render", "@gct-paas/render-mobile", "@gct-paas/render-pad", "@gct-paas/render-web", "@gct-paas/schema", "@gct-paas/v-ben"];
21
17
  async run() {
22
18
  _consola.consola.start("\u4FEE\u6539 pnpm catalog \u914D\u7F6E...");
23
19
  const branch = await (0, _utils.getBranchName)();
24
- const tag = envMap[branch];
20
+ const tag = _constants.branch_2_tag[branch];
25
21
  if (!tag) {
26
22
  _consola.consola.info(`\u5F53\u524D\u5206\u652F ${branch} \u4E0D\u5339\u914D\u4EFB\u4F55\u73AF\u5883\u6807\u7B7E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E`);
27
23
  return;
@@ -33,12 +29,10 @@ class UpdateCatalogEnvAction {
33
29
  _consola.consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
34
30
  return;
35
31
  }
36
- const tasks = new _listr.Listr(this.packages.map(pkg => ({
32
+ const pkgsToUpdate = _constants.lib_packages.filter(pkg => pkg in catalogCfg);
33
+ const tasks = new _listr.Listr(pkgsToUpdate.map(pkg => ({
37
34
  title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
38
35
  task: async (_, task) => {
39
- if (!catalogCfg[pkg]) {
40
- return;
41
- }
42
36
  task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
43
37
  try {
44
38
  const pkgInfo = await _pacote.default.manifest(`${pkg}@${tag}`);
@@ -1,4 +1,3 @@
1
1
  export declare class UpdateCatalogEnvAction {
2
- private packages;
3
2
  run(): Promise<void>;
4
3
  }
@@ -7,7 +7,7 @@ exports.GenCdnLibCommand = void 0;
7
7
  var _actions = require("../../actions/index.cjs");
8
8
  class GenCdnLibCommand {
9
9
  load(program) {
10
- program.command("gen-cdn-lib").description("\u751F\u6210 cdn \u5E93\u6587\u4EF6").option("--tag <tag>", "\u6307\u5B9A\u4E0B\u8F7D\u7684\u7248\u672C\u6807\u7B7E(latest | dev | beta | alpha)\uFF0C\u9ED8\u8BA4\u4E3A latest", "latest").option("--dir <dir>", "\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u9ED8\u8BA4\u4E3A\u5F53\u524D\u6267\u884C\u76EE\u5F55").option("--jsonPath <jsonPath>", "\u6307\u5B9A import-map.json \u6587\u4EF6\u8DEF\u5F84\uFF0C\u672A\u5236\u5B9A\u9ED8\u8BA4\u4F7F\u7528\u6307\u5B9A\u7684 dir \u76EE\u5F55\u4E0B\u7684 import-map.json \u6587\u4EF6").option("--clean", "\u662F\u5426\u6E05\u7406\u8F93\u51FA\u76EE\u5F55\u540E\u518D\u751F\u6210").option("--registry <registry>", "\u6307\u5B9A npm registry \u5730\u5740\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4 registry").option("--cache <cache>", "\u6307\u5B9A pacote \u7F13\u5B58\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4\u7F13\u5B58\u76EE\u5F55").option("--cleanCache", "\u6E05\u7406\u7F13\u5B58\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u4E3A false", false).option("--noFiles", "\u662F\u5426\u53EA\u751F\u6210 import-map.json \u6587\u4EF6\u800C\u4E0D\u4E0B\u8F7D\u5305\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u4E3A false", false).action(this.action.bind(this));
10
+ program.command("gen-cdn-lib").description("\u751F\u6210 cdn \u5E93\u6587\u4EF6").option("--tag <tag>", "\u6307\u5B9A\u4E0B\u8F7D\u7684\u7248\u672C\u6807\u7B7E(latest | dev | beta | alpha)\uFF0C\u9ED8\u8BA4\u4E3A latest").option("--dir <dir>", "\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u9ED8\u8BA4\u4E3A\u5F53\u524D\u6267\u884C\u76EE\u5F55").option("--jsonPath <jsonPath>", "\u6307\u5B9A import-map.json \u6587\u4EF6\u8DEF\u5F84\uFF0C\u672A\u5236\u5B9A\u9ED8\u8BA4\u4F7F\u7528\u6307\u5B9A\u7684 dir \u76EE\u5F55\u4E0B\u7684 import-map.json \u6587\u4EF6").option("--clean", "\u662F\u5426\u6E05\u7406\u8F93\u51FA\u76EE\u5F55\u540E\u518D\u751F\u6210").option("--registry <registry>", "\u6307\u5B9A npm registry \u5730\u5740\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4 registry").option("--cache <cache>", "\u6307\u5B9A pacote \u7F13\u5B58\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4\u7F13\u5B58\u76EE\u5F55").option("--cleanCache", "\u6E05\u7406\u7F13\u5B58\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u4E3A false", false).option("--noFiles", "\u662F\u5426\u53EA\u751F\u6210 import-map.json \u6587\u4EF6\u800C\u4E0D\u4E0B\u8F7D\u5305\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u4E3A false", false).action(this.action.bind(this));
11
11
  }
12
12
  async action(args) {
13
13
  await new _actions.GenCdnLibAction().run(args);
@@ -10,6 +10,7 @@ var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
10
10
  var _initGit = require("./init-git/init-git.cjs");
11
11
  var _restoreFiles = require("./restore-files/restore-files.cjs");
12
12
  var _updateCatalogEnv = require("./update-catalog-env/update-catalog-env.cjs");
13
+ var _nginxStart = require("./nginx-start/nginx-start.cjs");
13
14
  class CommandLoader {
14
15
  static load(program) {
15
16
  new _genApi.GenApiCommand().load(program);
@@ -17,6 +18,7 @@ class CommandLoader {
17
18
  new _initGit.InitGitCommand().load(program);
18
19
  new _restoreFiles.RestoreFilesCommand().load(program);
19
20
  new _updateCatalogEnv.UpdateCatalogEnvCommand().load(program);
21
+ new _nginxStart.NginxStartCommand().load(program);
20
22
  this.handleInvalidCommand(program);
21
23
  }
22
24
  static handleInvalidCommand(program) {
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NginxStartCommand = void 0;
7
+ var _actions = require("../../actions/index.cjs");
8
+ class NginxStartCommand {
9
+ load(program) {
10
+ program.command("nginx-start").description("\u542F\u52A8 nginx\uFF08\u9700\u5C06 nginx \u53EF\u6267\u884C\u6587\u4EF6\u6DFB\u52A0\u5230\u7CFB\u7EDF PATH\uFF09").option("-d, --dir <path>", "nginx \u914D\u7F6E\u76EE\u5F55\uFF08\u9ED8\u8BA4\uFF1A<cwd>/configs/nginx\uFF09").action(this.action.bind(this));
11
+ }
12
+ async action(options) {
13
+ await new _actions.NginxStartAction(options.dir).run();
14
+ }
15
+ }
16
+ exports.NginxStartCommand = NginxStartCommand;
@@ -0,0 +1,15 @@
1
+ import { Command } from 'commander';
2
+ import { ICommand } from '../../interface';
3
+ /**
4
+ * 插件开发本地调试 nginx 启动命令
5
+ *
6
+ * @export
7
+ * @class NginxStartCommand
8
+ * @implements {ICommand}
9
+ */
10
+ export declare class NginxStartCommand implements ICommand {
11
+ load(program: Command): void;
12
+ action(options: {
13
+ dir?: string;
14
+ }): Promise<void>;
15
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.lib_packages = exports.branch_2_tag = void 0;
7
+ const lib_packages = exports.lib_packages = ["@gct-paas/api", "@gct-paas/core", "@gct-paas/core-mobile", "@gct-paas/core-pad", "@gct-paas/core-web", "@gct-paas/design", "@gct-paas/design-mobile", "@gct-paas/design-pad", "@gct-paas/design-web", "@gct-paas/native", "@gct-paas/render", "@gct-paas/render-mobile", "@gct-paas/render-pad", "@gct-paas/render-web", "@gct-paas/schema", "@gct-paas/v-ben"];
8
+ const branch_2_tag = exports.branch_2_tag = {
9
+ "paas-dev": "dev",
10
+ "paas-test": "test"
11
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description: 底包清单
3
+ */
4
+ export declare const lib_packages: string[];
5
+ /**
6
+ * @description: 环境标签映射,key 是分支名,value 是 npm 发包的标签
7
+ */
8
+ export declare const branch_2_tag: Record<string, string>;
@@ -11,7 +11,7 @@ export interface IGenCdnLibOptions {
11
11
  * @default 'latest'
12
12
  * @type {string}
13
13
  */
14
- tag: string;
14
+ tag?: string;
15
15
  /**
16
16
  * 要输出的 extras 资源目录,未指定时默认为当前执行目录
17
17
  *
@@ -6,7 +6,6 @@ import { IGenCdnLibOptions } from '../../interface';
6
6
  * @class GenCdnLibAction
7
7
  */
8
8
  export declare class GenCdnLibAction {
9
- private packages;
10
9
  /**
11
10
  * 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
12
11
  */
@@ -3,25 +3,9 @@ import path from "path";
3
3
  import fse from "fs-extra";
4
4
  import log from "consola";
5
5
  import { Listr } from "listr2";
6
+ import { branch_2_tag, lib_packages } from "../../constants/index.mjs";
7
+ import { getBranchName } from "../../utils/index.mjs";
6
8
  export class GenCdnLibAction {
7
- packages = [
8
- "@gct-paas/api",
9
- "@gct-paas/core",
10
- "@gct-paas/core-mobile",
11
- "@gct-paas/core-pad",
12
- "@gct-paas/core-web",
13
- "@gct-paas/design",
14
- "@gct-paas/design-mobile",
15
- "@gct-paas/design-pad",
16
- "@gct-paas/design-web",
17
- "@gct-paas/native",
18
- "@gct-paas/render",
19
- "@gct-paas/render-mobile",
20
- "@gct-paas/render-pad",
21
- "@gct-paas/render-web",
22
- "@gct-paas/schema",
23
- "@gct-paas/v-ben"
24
- ];
25
9
  /**
26
10
  * 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
27
11
  */
@@ -65,12 +49,22 @@ export class GenCdnLibAction {
65
49
  }
66
50
  log.info("\u6B63\u5728\u8BFB\u53D6 import-map.json...");
67
51
  const importMap = fse.readJSONSync(importMapJsonPath);
52
+ let tag = opts.tag;
53
+ if (!tag) {
54
+ const branch = await getBranchName();
55
+ if (branch) {
56
+ tag = branch_2_tag[branch];
57
+ }
58
+ if (!tag) {
59
+ tag = "latest";
60
+ }
61
+ }
68
62
  const tasks = new Listr(
69
- this.packages.map((pkg) => ({
70
- title: `${pkg}@${opts.tag}`,
63
+ lib_packages.map((pkg) => ({
64
+ title: `${pkg}@${tag}`,
71
65
  task: async (_, task) => {
72
- task.title = `${pkg}@${opts.tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
73
- const pkgInfo = await pacote.manifest(`${pkg}@${opts.tag}`, {
66
+ task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
67
+ const pkgInfo = await pacote.manifest(`${pkg}@${tag}`, {
74
68
  registry: opts.registry,
75
69
  cache: cacheDir
76
70
  });
@@ -3,3 +3,4 @@ export { GenCdnLibAction } from './gen-cdn-lib/gen-cdn-lib';
3
3
  export { InitGitAction } from './init-git/init-git';
4
4
  export { RestoreFilesAction } from './restore-files/restore-files';
5
5
  export { UpdateCatalogEnvAction } from './update-catalog-env/update-catalog-env';
6
+ export { NginxStartAction } from './nginx-start/nginx-start';
@@ -3,3 +3,4 @@ export { GenCdnLibAction } from "./gen-cdn-lib/gen-cdn-lib.mjs";
3
3
  export { InitGitAction } from "./init-git/init-git.mjs";
4
4
  export { RestoreFilesAction } from "./restore-files/restore-files.mjs";
5
5
  export { UpdateCatalogEnvAction } from "./update-catalog-env/update-catalog-env.mjs";
6
+ export { NginxStartAction } from "./nginx-start/nginx-start.mjs";
@@ -0,0 +1,16 @@
1
+ export declare class NginxStartAction {
2
+ private readonly nginxDir;
3
+ constructor(nginxDir?: string);
4
+ /**
5
+ * 停止已运行的 nginx 进程
6
+ * Windows 使用 taskkill 强制终止,其他平台使用 nginx -s stop
7
+ * 若 nginx 未运行则忽略错误
8
+ */
9
+ private stopNginxIfRunning;
10
+ /**
11
+ * 启动 nginx
12
+ * Windows 下 nginx 不会自动 daemonize,使用 spawn detached 模式后台启动
13
+ */
14
+ private startNginx;
15
+ run(): Promise<void>;
16
+ }
@@ -0,0 +1,53 @@
1
+ import { execSync, spawn } from "node:child_process";
2
+ import { mkdirSync } from "node:fs";
3
+ import { resolve, sep } from "node:path";
4
+ import { consola } from "consola";
5
+ function sleep(ms) {
6
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
7
+ }
8
+ export class NginxStartAction {
9
+ nginxDir;
10
+ constructor(nginxDir) {
11
+ this.nginxDir = nginxDir ?? resolve(process.cwd(), "configs/nginx");
12
+ }
13
+ /**
14
+ * 停止已运行的 nginx 进程
15
+ * Windows 使用 taskkill 强制终止,其他平台使用 nginx -s stop
16
+ * 若 nginx 未运行则忽略错误
17
+ */
18
+ async stopNginxIfRunning() {
19
+ try {
20
+ if (process.platform === "win32") {
21
+ execSync("taskkill /F /IM nginx.exe", { stdio: "pipe" });
22
+ } else {
23
+ execSync(`nginx -p "${this.nginxDir}" -s stop`, { stdio: "pipe" });
24
+ }
25
+ consola.info("\u5DF2\u505C\u6B62\u73B0\u6709 nginx \u8FDB\u7A0B\uFF0C\u7B49\u5F85 1 \u79D2...");
26
+ await sleep(1e3);
27
+ } catch {
28
+ consola.info("nginx \u672A\u8FD0\u884C\uFF0C\u8DF3\u8FC7\u505C\u6B62\u6B65\u9AA4");
29
+ }
30
+ }
31
+ /**
32
+ * 启动 nginx
33
+ * Windows 下 nginx 不会自动 daemonize,使用 spawn detached 模式后台启动
34
+ */
35
+ startNginx() {
36
+ mkdirSync(resolve(this.nginxDir, "logs"), { recursive: true });
37
+ mkdirSync(resolve(this.nginxDir, "temp"), { recursive: true });
38
+ const nginxDirNormalized = this.nginxDir.split(sep).join("/");
39
+ const child = spawn("nginx", ["-p", nginxDirNormalized, "-c", "nginx.conf"], {
40
+ cwd: process.cwd(),
41
+ stdio: "ignore",
42
+ detached: true
43
+ });
44
+ child.unref();
45
+ }
46
+ async run() {
47
+ consola.start("\u5F00\u59CB\u542F\u52A8 nginx...");
48
+ await this.stopNginxIfRunning();
49
+ consola.start("\u6B63\u5728\u542F\u52A8 nginx...");
50
+ this.startNginx();
51
+ consola.success("nginx \u542F\u52A8\u6267\u884C\u5B8C\u6BD5");
52
+ }
53
+ }
@@ -1,4 +1,3 @@
1
1
  export declare class UpdateCatalogEnvAction {
2
- private packages;
3
2
  run(): Promise<void>;
4
3
  }
@@ -5,33 +5,12 @@ import fse from "fs-extra";
5
5
  import jsYaml from "js-yaml";
6
6
  import { getBranchName } from "../../utils/index.mjs";
7
7
  import path from "path";
8
- const envMap = {
9
- "paas-dev": "dev",
10
- "paas-test": "test"
11
- };
8
+ import { branch_2_tag, lib_packages } from "../../constants/index.mjs";
12
9
  export class UpdateCatalogEnvAction {
13
- packages = [
14
- "@gct-paas/api",
15
- "@gct-paas/core",
16
- "@gct-paas/core-mobile",
17
- "@gct-paas/core-pad",
18
- "@gct-paas/core-web",
19
- "@gct-paas/design",
20
- "@gct-paas/design-mobile",
21
- "@gct-paas/design-pad",
22
- "@gct-paas/design-web",
23
- "@gct-paas/native",
24
- "@gct-paas/render",
25
- "@gct-paas/render-mobile",
26
- "@gct-paas/render-pad",
27
- "@gct-paas/render-web",
28
- "@gct-paas/schema",
29
- "@gct-paas/v-ben"
30
- ];
31
10
  async run() {
32
11
  consola.start("\u4FEE\u6539 pnpm catalog \u914D\u7F6E...");
33
12
  const branch = await getBranchName();
34
- const tag = envMap[branch];
13
+ const tag = branch_2_tag[branch];
35
14
  if (!tag) {
36
15
  consola.info(`\u5F53\u524D\u5206\u652F ${branch} \u4E0D\u5339\u914D\u4EFB\u4F55\u73AF\u5883\u6807\u7B7E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E`);
37
16
  return;
@@ -43,13 +22,11 @@ export class UpdateCatalogEnvAction {
43
22
  consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
44
23
  return;
45
24
  }
25
+ const pkgsToUpdate = lib_packages.filter((pkg) => pkg in catalogCfg);
46
26
  const tasks = new Listr(
47
- this.packages.map((pkg) => ({
27
+ pkgsToUpdate.map((pkg) => ({
48
28
  title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
49
29
  task: async (_, task) => {
50
- if (!catalogCfg[pkg]) {
51
- return;
52
- }
53
30
  task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
54
31
  try {
55
32
  const pkgInfo = await pacote.manifest(`${pkg}@${tag}`);
@@ -1,7 +1,7 @@
1
1
  import { GenCdnLibAction } from "../../actions/index.mjs";
2
2
  export class GenCdnLibCommand {
3
3
  load(program) {
4
- program.command("gen-cdn-lib").description("\u751F\u6210 cdn \u5E93\u6587\u4EF6").option("--tag <tag>", "\u6307\u5B9A\u4E0B\u8F7D\u7684\u7248\u672C\u6807\u7B7E(latest | dev | beta | alpha)\uFF0C\u9ED8\u8BA4\u4E3A latest", "latest").option("--dir <dir>", "\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u9ED8\u8BA4\u4E3A\u5F53\u524D\u6267\u884C\u76EE\u5F55").option("--jsonPath <jsonPath>", "\u6307\u5B9A import-map.json \u6587\u4EF6\u8DEF\u5F84\uFF0C\u672A\u5236\u5B9A\u9ED8\u8BA4\u4F7F\u7528\u6307\u5B9A\u7684 dir \u76EE\u5F55\u4E0B\u7684 import-map.json \u6587\u4EF6").option("--clean", "\u662F\u5426\u6E05\u7406\u8F93\u51FA\u76EE\u5F55\u540E\u518D\u751F\u6210").option("--registry <registry>", "\u6307\u5B9A npm registry \u5730\u5740\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4 registry").option("--cache <cache>", "\u6307\u5B9A pacote \u7F13\u5B58\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4\u7F13\u5B58\u76EE\u5F55").option("--cleanCache", "\u6E05\u7406\u7F13\u5B58\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u4E3A false", false).option("--noFiles", "\u662F\u5426\u53EA\u751F\u6210 import-map.json \u6587\u4EF6\u800C\u4E0D\u4E0B\u8F7D\u5305\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u4E3A false", false).action(this.action.bind(this));
4
+ program.command("gen-cdn-lib").description("\u751F\u6210 cdn \u5E93\u6587\u4EF6").option("--tag <tag>", "\u6307\u5B9A\u4E0B\u8F7D\u7684\u7248\u672C\u6807\u7B7E(latest | dev | beta | alpha)\uFF0C\u9ED8\u8BA4\u4E3A latest").option("--dir <dir>", "\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u9ED8\u8BA4\u4E3A\u5F53\u524D\u6267\u884C\u76EE\u5F55").option("--jsonPath <jsonPath>", "\u6307\u5B9A import-map.json \u6587\u4EF6\u8DEF\u5F84\uFF0C\u672A\u5236\u5B9A\u9ED8\u8BA4\u4F7F\u7528\u6307\u5B9A\u7684 dir \u76EE\u5F55\u4E0B\u7684 import-map.json \u6587\u4EF6").option("--clean", "\u662F\u5426\u6E05\u7406\u8F93\u51FA\u76EE\u5F55\u540E\u518D\u751F\u6210").option("--registry <registry>", "\u6307\u5B9A npm registry \u5730\u5740\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4 registry").option("--cache <cache>", "\u6307\u5B9A pacote \u7F13\u5B58\u76EE\u5F55\uFF0C\u672A\u6307\u5B9A\u65F6\u4F7F\u7528\u9ED8\u8BA4\u7F13\u5B58\u76EE\u5F55").option("--cleanCache", "\u6E05\u7406\u7F13\u5B58\u76EE\u5F55\uFF0C\u9ED8\u8BA4\u4E3A false", false).option("--noFiles", "\u662F\u5426\u53EA\u751F\u6210 import-map.json \u6587\u4EF6\u800C\u4E0D\u4E0B\u8F7D\u5305\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u4E3A false", false).action(this.action.bind(this));
5
5
  }
6
6
  async action(args) {
7
7
  await new GenCdnLibAction().run(
@@ -4,6 +4,7 @@ import { GenCdnLibCommand } from "./gen-cdn-lib/gen-cdn-lib.mjs";
4
4
  import { InitGitCommand } from "./init-git/init-git.mjs";
5
5
  import { RestoreFilesCommand } from "./restore-files/restore-files.mjs";
6
6
  import { UpdateCatalogEnvCommand } from "./update-catalog-env/update-catalog-env.mjs";
7
+ import { NginxStartCommand } from "./nginx-start/nginx-start.mjs";
7
8
  export class CommandLoader {
8
9
  static load(program) {
9
10
  new GenApiCommand().load(program);
@@ -11,6 +12,7 @@ export class CommandLoader {
11
12
  new InitGitCommand().load(program);
12
13
  new RestoreFilesCommand().load(program);
13
14
  new UpdateCatalogEnvCommand().load(program);
15
+ new NginxStartCommand().load(program);
14
16
  this.handleInvalidCommand(program);
15
17
  }
16
18
  static handleInvalidCommand(program) {
@@ -0,0 +1,15 @@
1
+ import { Command } from 'commander';
2
+ import { ICommand } from '../../interface';
3
+ /**
4
+ * 插件开发本地调试 nginx 启动命令
5
+ *
6
+ * @export
7
+ * @class NginxStartCommand
8
+ * @implements {ICommand}
9
+ */
10
+ export declare class NginxStartCommand implements ICommand {
11
+ load(program: Command): void;
12
+ action(options: {
13
+ dir?: string;
14
+ }): Promise<void>;
15
+ }
@@ -0,0 +1,9 @@
1
+ import { NginxStartAction } from "../../actions/index.mjs";
2
+ export class NginxStartCommand {
3
+ load(program) {
4
+ program.command("nginx-start").description("\u542F\u52A8 nginx\uFF08\u9700\u5C06 nginx \u53EF\u6267\u884C\u6587\u4EF6\u6DFB\u52A0\u5230\u7CFB\u7EDF PATH\uFF09").option("-d, --dir <path>", "nginx \u914D\u7F6E\u76EE\u5F55\uFF08\u9ED8\u8BA4\uFF1A<cwd>/configs/nginx\uFF09").action(this.action.bind(this));
5
+ }
6
+ async action(options) {
7
+ await new NginxStartAction(options.dir).run();
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description: 底包清单
3
+ */
4
+ export declare const lib_packages: string[];
5
+ /**
6
+ * @description: 环境标签映射,key 是分支名,value 是 npm 发包的标签
7
+ */
8
+ export declare const branch_2_tag: Record<string, string>;
@@ -0,0 +1,22 @@
1
+ export const lib_packages = [
2
+ "@gct-paas/api",
3
+ "@gct-paas/core",
4
+ "@gct-paas/core-mobile",
5
+ "@gct-paas/core-pad",
6
+ "@gct-paas/core-web",
7
+ "@gct-paas/design",
8
+ "@gct-paas/design-mobile",
9
+ "@gct-paas/design-pad",
10
+ "@gct-paas/design-web",
11
+ "@gct-paas/native",
12
+ "@gct-paas/render",
13
+ "@gct-paas/render-mobile",
14
+ "@gct-paas/render-pad",
15
+ "@gct-paas/render-web",
16
+ "@gct-paas/schema",
17
+ "@gct-paas/v-ben"
18
+ ];
19
+ export const branch_2_tag = {
20
+ "paas-dev": "dev",
21
+ "paas-test": "test"
22
+ };
@@ -11,7 +11,7 @@ export interface IGenCdnLibOptions {
11
11
  * @default 'latest'
12
12
  * @type {string}
13
13
  */
14
- tag: string;
14
+ tag?: string;
15
15
  /**
16
16
  * 要输出的 extras 资源目录,未指定时默认为当前执行目录
17
17
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "bin": {