@gct-paas/cli 0.1.8 → 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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.9] - 2026-04-02
11
+
12
+ ### Added
13
+
14
+ - 命令 nginx-start 便捷本地启动 plugin 开发 nginx
15
+
10
16
  ## [0.1.8] - 2026-04-02
11
17
 
12
18
  ### Changed
@@ -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
+ }
@@ -29,12 +29,10 @@ class UpdateCatalogEnvAction {
29
29
  _consola.consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
30
30
  return;
31
31
  }
32
- const tasks = new _listr.Listr(_constants.lib_packages.map(pkg => ({
32
+ const pkgsToUpdate = _constants.lib_packages.filter(pkg => pkg in catalogCfg);
33
+ const tasks = new _listr.Listr(pkgsToUpdate.map(pkg => ({
33
34
  title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
34
35
  task: async (_, task) => {
35
- if (!catalogCfg[pkg]) {
36
- return;
37
- }
38
36
  task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
39
37
  try {
40
38
  const pkgInfo = await _pacote.default.manifest(`${pkg}@${tag}`);
@@ -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
+ }
@@ -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
+ }
@@ -22,13 +22,11 @@ export class UpdateCatalogEnvAction {
22
22
  consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
23
23
  return;
24
24
  }
25
+ const pkgsToUpdate = lib_packages.filter((pkg) => pkg in catalogCfg);
25
26
  const tasks = new Listr(
26
- lib_packages.map((pkg) => ({
27
+ pkgsToUpdate.map((pkg) => ({
27
28
  title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
28
29
  task: async (_, task) => {
29
- if (!catalogCfg[pkg]) {
30
- return;
31
- }
32
30
  task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
33
31
  try {
34
32
  const pkgInfo = await pacote.manifest(`${pkg}@${tag}`);
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gct-paas/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "paas 平台核心包",
6
6
  "bin": {