@gct-paas/cli 0.1.6 → 0.1.8
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 +14 -0
- package/dist/actions/gen-cdn-lib/gen-cdn-lib.cjs +16 -5
- package/dist/actions/gen-cdn-lib/gen-cdn-lib.d.ts +0 -1
- package/dist/actions/index.cjs +15 -1
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/restore-files/restore-files.cjs +19 -0
- package/dist/actions/restore-files/restore-files.d.ts +3 -0
- package/dist/actions/update-catalog-env/update-catalog-env.cjs +57 -0
- package/dist/actions/update-catalog-env/update-catalog-env.d.ts +3 -0
- package/dist/commands/gen-cdn-lib/gen-cdn-lib.cjs +1 -1
- package/dist/commands/index.cjs +4 -0
- package/dist/commands/restore-files/restore-files.cjs +16 -0
- package/dist/commands/restore-files/restore-files.d.ts +6 -0
- package/dist/commands/update-catalog-env/update-catalog-env.cjs +16 -0
- package/dist/commands/update-catalog-env/update-catalog-env.d.ts +6 -0
- package/dist/constants/index.cjs +11 -0
- package/dist/constants/index.d.ts +8 -0
- package/dist/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +1 -1
- package/dist/utils/git-util/git-util.cjs +25 -0
- package/dist/utils/git-util/git-util.d.ts +7 -0
- package/dist/utils/index.cjs +16 -0
- package/dist/utils/index.d.ts +1 -0
- package/es/actions/gen-cdn-lib/gen-cdn-lib.d.ts +0 -1
- package/es/actions/gen-cdn-lib/gen-cdn-lib.mjs +16 -22
- package/es/actions/index.d.ts +2 -0
- package/es/actions/index.mjs +2 -0
- package/es/actions/restore-files/restore-files.d.ts +3 -0
- package/es/actions/restore-files/restore-files.mjs +13 -0
- package/es/actions/update-catalog-env/update-catalog-env.d.ts +3 -0
- package/es/actions/update-catalog-env/update-catalog-env.mjs +48 -0
- package/es/bin.mjs +0 -0
- package/es/commands/gen-cdn-lib/gen-cdn-lib.mjs +1 -1
- package/es/commands/index.mjs +4 -0
- package/es/commands/restore-files/restore-files.d.ts +6 -0
- package/es/commands/restore-files/restore-files.mjs +9 -0
- package/es/commands/update-catalog-env/update-catalog-env.d.ts +6 -0
- package/es/commands/update-catalog-env/update-catalog-env.mjs +9 -0
- package/es/constants/index.d.ts +8 -0
- package/es/constants/index.mjs +22 -0
- package/es/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +1 -1
- package/es/utils/git-util/git-util.d.ts +7 -0
- package/es/utils/git-util/git-util.mjs +21 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.mjs +1 -0
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.8] - 2026-04-02
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- 命令 gen-cdn-lib 改为 tag 默认识别当前运行项目分支映射,也可单独指定
|
|
15
|
+
|
|
16
|
+
## [0.1.7] - 2026-04-02
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- 命令 init-git 初始化项目获取到本地后的配置
|
|
21
|
+
- 命令 update-catalog-env 根据分支修改 pnpm catalog 配置,使具体分支使用对应环境的底包
|
|
22
|
+
- 命令 restore-files 还原指定的已经修改的文件列表,目前还原修改的 pnpm-workspace.yaml 文件
|
|
23
|
+
|
|
10
24
|
## [0.1.3] - 2025-06-16
|
|
11
25
|
|
|
12
26
|
### 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
|
-
|
|
61
|
-
|
|
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}@${
|
|
64
|
-
const pkgInfo = await _pacote.default.manifest(`${pkg}@${
|
|
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
|
});
|
package/dist/actions/index.cjs
CHANGED
|
@@ -21,6 +21,20 @@ Object.defineProperty(exports, "InitGitAction", {
|
|
|
21
21
|
return _initGit.InitGitAction;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "RestoreFilesAction", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _restoreFiles.RestoreFilesAction;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "UpdateCatalogEnvAction", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _updateCatalogEnv.UpdateCatalogEnvAction;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
24
36
|
var _genApi = require("./gen-api/gen-api.cjs");
|
|
25
37
|
var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
|
|
26
|
-
var _initGit = require("./init-git/init-git.cjs");
|
|
38
|
+
var _initGit = require("./init-git/init-git.cjs");
|
|
39
|
+
var _restoreFiles = require("./restore-files/restore-files.cjs");
|
|
40
|
+
var _updateCatalogEnv = require("./update-catalog-env/update-catalog-env.cjs");
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { GenApiAction } from './gen-api/gen-api';
|
|
2
2
|
export { GenCdnLibAction } from './gen-cdn-lib/gen-cdn-lib';
|
|
3
3
|
export { InitGitAction } from './init-git/init-git';
|
|
4
|
+
export { RestoreFilesAction } from './restore-files/restore-files';
|
|
5
|
+
export { UpdateCatalogEnvAction } from './update-catalog-env/update-catalog-env';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RestoreFilesAction = void 0;
|
|
7
|
+
var _consola = require("consola");
|
|
8
|
+
var _simpleGit = _interopRequireDefault(require("simple-git"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const FILES_TO_RESTORE = ["pnpm-workspace.yaml"];
|
|
11
|
+
class RestoreFilesAction {
|
|
12
|
+
async run() {
|
|
13
|
+
const git = (0, _simpleGit.default)(process.cwd());
|
|
14
|
+
_consola.consola.start(`\u8FD8\u539F\u6587\u4EF6: ${FILES_TO_RESTORE.join(", ")}`);
|
|
15
|
+
await git.checkout(FILES_TO_RESTORE);
|
|
16
|
+
_consola.consola.success("\u6587\u4EF6\u8FD8\u539F\u5B8C\u6210");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.RestoreFilesAction = RestoreFilesAction;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UpdateCatalogEnvAction = void 0;
|
|
7
|
+
var _pacote = _interopRequireDefault(require("pacote"));
|
|
8
|
+
var _consola = require("consola");
|
|
9
|
+
var _listr = require("listr2");
|
|
10
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
11
|
+
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
12
|
+
var _utils = require("../../utils/index.cjs");
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
var _constants = require("../../constants/index.cjs");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
class UpdateCatalogEnvAction {
|
|
17
|
+
async run() {
|
|
18
|
+
_consola.consola.start("\u4FEE\u6539 pnpm catalog \u914D\u7F6E...");
|
|
19
|
+
const branch = await (0, _utils.getBranchName)();
|
|
20
|
+
const tag = _constants.branch_2_tag[branch];
|
|
21
|
+
if (!tag) {
|
|
22
|
+
_consola.consola.info(`\u5F53\u524D\u5206\u652F ${branch} \u4E0D\u5339\u914D\u4EFB\u4F55\u73AF\u5883\u6807\u7B7E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const catalogPath = _path.default.join(process.cwd(), "pnpm-workspace.yaml");
|
|
26
|
+
const pnpmConfig = _jsYaml.default.load(await _fsExtra.default.readFile(catalogPath, "utf-8"));
|
|
27
|
+
const catalogCfg = pnpmConfig.catalog;
|
|
28
|
+
if (!catalogCfg) {
|
|
29
|
+
_consola.consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const tasks = new _listr.Listr(_constants.lib_packages.map(pkg => ({
|
|
33
|
+
title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
|
|
34
|
+
task: async (_, task) => {
|
|
35
|
+
if (!catalogCfg[pkg]) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
|
|
39
|
+
try {
|
|
40
|
+
const pkgInfo = await _pacote.default.manifest(`${pkg}@${tag}`);
|
|
41
|
+
catalogCfg[pkg] = pkgInfo.version;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const err = error;
|
|
44
|
+
throw new Error(`\u65E0\u6CD5\u83B7\u53D6 ${pkg}@${tag} \u7684\u7248\u672C\u4FE1\u606F\uFF0C\u53EF\u80FD\u662F\u5305\u4E0D\u5B58\u5728\u6216\u7F51\u7EDC\u95EE\u9898: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
})), {
|
|
48
|
+
concurrent: true
|
|
49
|
+
});
|
|
50
|
+
await tasks.run();
|
|
51
|
+
await _fsExtra.default.writeFile(catalogPath, _jsYaml.default.dump(pnpmConfig, {
|
|
52
|
+
indent: 2
|
|
53
|
+
}), "utf-8");
|
|
54
|
+
_consola.consola.success("pnpm catalog \u914D\u7F6E\u4FEE\u6539\u5B8C\u6210");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.UpdateCatalogEnvAction = UpdateCatalogEnvAction;
|
|
@@ -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"
|
|
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);
|
package/dist/commands/index.cjs
CHANGED
|
@@ -8,11 +8,15 @@ var _consola = require("consola");
|
|
|
8
8
|
var _genApi = require("./gen-api/gen-api.cjs");
|
|
9
9
|
var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
|
|
10
10
|
var _initGit = require("./init-git/init-git.cjs");
|
|
11
|
+
var _restoreFiles = require("./restore-files/restore-files.cjs");
|
|
12
|
+
var _updateCatalogEnv = require("./update-catalog-env/update-catalog-env.cjs");
|
|
11
13
|
class CommandLoader {
|
|
12
14
|
static load(program) {
|
|
13
15
|
new _genApi.GenApiCommand().load(program);
|
|
14
16
|
new _genCdnLib.GenCdnLibCommand().load(program);
|
|
15
17
|
new _initGit.InitGitCommand().load(program);
|
|
18
|
+
new _restoreFiles.RestoreFilesCommand().load(program);
|
|
19
|
+
new _updateCatalogEnv.UpdateCatalogEnvCommand().load(program);
|
|
16
20
|
this.handleInvalidCommand(program);
|
|
17
21
|
}
|
|
18
22
|
static handleInvalidCommand(program) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RestoreFilesCommand = void 0;
|
|
7
|
+
var _actions = require("../../actions/index.cjs");
|
|
8
|
+
class RestoreFilesCommand {
|
|
9
|
+
load(program) {
|
|
10
|
+
program.command("restore-files").description("\u8FD8\u539F\u9884\u8BBE\u7684\u5DF2\u4FEE\u6539\u6587\u4EF6\u5217\u8868\u5230 HEAD \u7248\u672C").action(this.action.bind(this));
|
|
11
|
+
}
|
|
12
|
+
async action() {
|
|
13
|
+
await new _actions.RestoreFilesAction().run();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.RestoreFilesCommand = RestoreFilesCommand;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UpdateCatalogEnvCommand = void 0;
|
|
7
|
+
var _actions = require("../../actions/index.cjs");
|
|
8
|
+
class UpdateCatalogEnvCommand {
|
|
9
|
+
load(program) {
|
|
10
|
+
program.command("update-catalog-env").description("\u6839\u636E git \u5206\u652F\uFF0C\u66F4\u65B0\u9879\u76EE pnpm catalog \u914D\u7F6E\u4E3A\u5177\u4F53\u73AF\u5883").action(this.action.bind(this));
|
|
11
|
+
}
|
|
12
|
+
async action() {
|
|
13
|
+
await new _actions.UpdateCatalogEnvAction().run();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UpdateCatalogEnvCommand = UpdateCatalogEnvCommand;
|
|
@@ -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,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBranchName = getBranchName;
|
|
7
|
+
var _simpleGit = _interopRequireDefault(require("simple-git"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
async function getBranchName() {
|
|
10
|
+
let targetBranch = process.env.CI_COMMIT_BRANCH || process.env.CI_BUILD_REF_NAME;
|
|
11
|
+
if (!targetBranch) {
|
|
12
|
+
const cwdGit = (0, _simpleGit.default)(process.cwd());
|
|
13
|
+
try {
|
|
14
|
+
const raw = await cwdGit.revparse(["--abbrev-ref", "HEAD"]);
|
|
15
|
+
const resolved = raw.trim();
|
|
16
|
+
if (resolved && resolved !== "HEAD") {
|
|
17
|
+
targetBranch = resolved;
|
|
18
|
+
}
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
if (!targetBranch) {
|
|
22
|
+
throw new Error("\u65E0\u6CD5\u81EA\u52A8\u83B7\u53D6\u5F53\u524D git \u5206\u652F\uFF1A\u5F53\u524D\u53EF\u80FD\u5904\u4E8E\u6E38\u79BB HEAD\uFF08detached HEAD\uFF09\u72B6\u6001\uFF08CI \u73AF\u5883\u5E38\u89C1\uFF09\u3002\u8BF7\u901A\u8FC7 options.branch \u660E\u786E\u6307\u5B9A\u5206\u652F\u540D\uFF0C\u6216\u786E\u4FDD\u73AF\u5883\u53D8\u91CF CI_COMMIT_BRANCH / CI_BUILD_REF_NAME \u5DF2\u8BBE\u7F6E\u3002");
|
|
23
|
+
}
|
|
24
|
+
return targetBranch;
|
|
25
|
+
}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
localBinExists: true,
|
|
8
|
+
loadLocalBinCommandLoader: true
|
|
9
|
+
};
|
|
6
10
|
Object.defineProperty(exports, "loadLocalBinCommandLoader", {
|
|
7
11
|
enumerable: true,
|
|
8
12
|
get: function () {
|
|
@@ -15,4 +19,16 @@ Object.defineProperty(exports, "localBinExists", {
|
|
|
15
19
|
return _localBinaries.localBinExists;
|
|
16
20
|
}
|
|
17
21
|
});
|
|
22
|
+
var _gitUtil = require("./git-util/git-util.cjs");
|
|
23
|
+
Object.keys(_gitUtil).forEach(function (key) {
|
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
26
|
+
if (key in exports && exports[key] === _gitUtil[key]) return;
|
|
27
|
+
Object.defineProperty(exports, key, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _gitUtil[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
18
34
|
var _localBinaries = require("./local-binaries/local-binaries.cjs");
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
70
|
-
title: `${pkg}@${
|
|
63
|
+
lib_packages.map((pkg) => ({
|
|
64
|
+
title: `${pkg}@${tag}`,
|
|
71
65
|
task: async (_, task) => {
|
|
72
|
-
task.title = `${pkg}@${
|
|
73
|
-
const pkgInfo = await pacote.manifest(`${pkg}@${
|
|
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
|
});
|
package/es/actions/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { GenApiAction } from './gen-api/gen-api';
|
|
2
2
|
export { GenCdnLibAction } from './gen-cdn-lib/gen-cdn-lib';
|
|
3
3
|
export { InitGitAction } from './init-git/init-git';
|
|
4
|
+
export { RestoreFilesAction } from './restore-files/restore-files';
|
|
5
|
+
export { UpdateCatalogEnvAction } from './update-catalog-env/update-catalog-env';
|
package/es/actions/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { GenApiAction } from "./gen-api/gen-api.mjs";
|
|
2
2
|
export { GenCdnLibAction } from "./gen-cdn-lib/gen-cdn-lib.mjs";
|
|
3
3
|
export { InitGitAction } from "./init-git/init-git.mjs";
|
|
4
|
+
export { RestoreFilesAction } from "./restore-files/restore-files.mjs";
|
|
5
|
+
export { UpdateCatalogEnvAction } from "./update-catalog-env/update-catalog-env.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { consola } from "consola";
|
|
2
|
+
import simpleGit from "simple-git";
|
|
3
|
+
const FILES_TO_RESTORE = [
|
|
4
|
+
"pnpm-workspace.yaml"
|
|
5
|
+
];
|
|
6
|
+
export class RestoreFilesAction {
|
|
7
|
+
async run() {
|
|
8
|
+
const git = simpleGit(process.cwd());
|
|
9
|
+
consola.start(`\u8FD8\u539F\u6587\u4EF6: ${FILES_TO_RESTORE.join(", ")}`);
|
|
10
|
+
await git.checkout(FILES_TO_RESTORE);
|
|
11
|
+
consola.success("\u6587\u4EF6\u8FD8\u539F\u5B8C\u6210");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import pacote from "pacote";
|
|
2
|
+
import { consola } from "consola";
|
|
3
|
+
import { Listr } from "listr2";
|
|
4
|
+
import fse from "fs-extra";
|
|
5
|
+
import jsYaml from "js-yaml";
|
|
6
|
+
import { getBranchName } from "../../utils/index.mjs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { branch_2_tag, lib_packages } from "../../constants/index.mjs";
|
|
9
|
+
export class UpdateCatalogEnvAction {
|
|
10
|
+
async run() {
|
|
11
|
+
consola.start("\u4FEE\u6539 pnpm catalog \u914D\u7F6E...");
|
|
12
|
+
const branch = await getBranchName();
|
|
13
|
+
const tag = branch_2_tag[branch];
|
|
14
|
+
if (!tag) {
|
|
15
|
+
consola.info(`\u5F53\u524D\u5206\u652F ${branch} \u4E0D\u5339\u914D\u4EFB\u4F55\u73AF\u5883\u6807\u7B7E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const catalogPath = path.join(process.cwd(), "pnpm-workspace.yaml");
|
|
19
|
+
const pnpmConfig = jsYaml.load(await fse.readFile(catalogPath, "utf-8"));
|
|
20
|
+
const catalogCfg = pnpmConfig.catalog;
|
|
21
|
+
if (!catalogCfg) {
|
|
22
|
+
consola.warn("pnpm-workspace.yaml \u4E2D\u7F3A\u5C11 catalog \u914D\u7F6E\uFF0C\u8DF3\u8FC7 catalog \u8BBE\u7F6E");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const tasks = new Listr(
|
|
26
|
+
lib_packages.map((pkg) => ({
|
|
27
|
+
title: `\u8BBE\u7F6E ${pkg} \u7684 catalog \u6807\u7B7E\u4E3A ${tag}`,
|
|
28
|
+
task: async (_, task) => {
|
|
29
|
+
if (!catalogCfg[pkg]) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
task.title = `${pkg}@${tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
|
|
33
|
+
try {
|
|
34
|
+
const pkgInfo = await pacote.manifest(`${pkg}@${tag}`);
|
|
35
|
+
catalogCfg[pkg] = pkgInfo.version;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const err = error;
|
|
38
|
+
throw new Error(`\u65E0\u6CD5\u83B7\u53D6 ${pkg}@${tag} \u7684\u7248\u672C\u4FE1\u606F\uFF0C\u53EF\u80FD\u662F\u5305\u4E0D\u5B58\u5728\u6216\u7F51\u7EDC\u95EE\u9898: ${err.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})),
|
|
42
|
+
{ concurrent: true }
|
|
43
|
+
);
|
|
44
|
+
await tasks.run();
|
|
45
|
+
await fse.writeFile(catalogPath, jsYaml.dump(pnpmConfig, { indent: 2 }), "utf-8");
|
|
46
|
+
consola.success("pnpm catalog \u914D\u7F6E\u4FEE\u6539\u5B8C\u6210");
|
|
47
|
+
}
|
|
48
|
+
}
|
package/es/bin.mjs
CHANGED
|
File without changes
|
|
@@ -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"
|
|
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(
|
package/es/commands/index.mjs
CHANGED
|
@@ -2,11 +2,15 @@ import { consola } from "consola";
|
|
|
2
2
|
import { GenApiCommand } from "./gen-api/gen-api.mjs";
|
|
3
3
|
import { GenCdnLibCommand } from "./gen-cdn-lib/gen-cdn-lib.mjs";
|
|
4
4
|
import { InitGitCommand } from "./init-git/init-git.mjs";
|
|
5
|
+
import { RestoreFilesCommand } from "./restore-files/restore-files.mjs";
|
|
6
|
+
import { UpdateCatalogEnvCommand } from "./update-catalog-env/update-catalog-env.mjs";
|
|
5
7
|
export class CommandLoader {
|
|
6
8
|
static load(program) {
|
|
7
9
|
new GenApiCommand().load(program);
|
|
8
10
|
new GenCdnLibCommand().load(program);
|
|
9
11
|
new InitGitCommand().load(program);
|
|
12
|
+
new RestoreFilesCommand().load(program);
|
|
13
|
+
new UpdateCatalogEnvCommand().load(program);
|
|
10
14
|
this.handleInvalidCommand(program);
|
|
11
15
|
}
|
|
12
16
|
static handleInvalidCommand(program) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RestoreFilesAction } from "../../actions/index.mjs";
|
|
2
|
+
export class RestoreFilesCommand {
|
|
3
|
+
load(program) {
|
|
4
|
+
program.command("restore-files").description("\u8FD8\u539F\u9884\u8BBE\u7684\u5DF2\u4FEE\u6539\u6587\u4EF6\u5217\u8868\u5230 HEAD \u7248\u672C").action(this.action.bind(this));
|
|
5
|
+
}
|
|
6
|
+
async action() {
|
|
7
|
+
await new RestoreFilesAction().run();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UpdateCatalogEnvAction } from "../../actions/index.mjs";
|
|
2
|
+
export class UpdateCatalogEnvCommand {
|
|
3
|
+
load(program) {
|
|
4
|
+
program.command("update-catalog-env").description("\u6839\u636E git \u5206\u652F\uFF0C\u66F4\u65B0\u9879\u76EE pnpm catalog \u914D\u7F6E\u4E3A\u5177\u4F53\u73AF\u5883").action(this.action.bind(this));
|
|
5
|
+
}
|
|
6
|
+
async action() {
|
|
7
|
+
await new UpdateCatalogEnvAction().run();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import simpleGit from "simple-git";
|
|
2
|
+
export async function getBranchName() {
|
|
3
|
+
let targetBranch = process.env.CI_COMMIT_BRANCH || process.env.CI_BUILD_REF_NAME;
|
|
4
|
+
if (!targetBranch) {
|
|
5
|
+
const cwdGit = simpleGit(process.cwd());
|
|
6
|
+
try {
|
|
7
|
+
const raw = await cwdGit.revparse(["--abbrev-ref", "HEAD"]);
|
|
8
|
+
const resolved = raw.trim();
|
|
9
|
+
if (resolved && resolved !== "HEAD") {
|
|
10
|
+
targetBranch = resolved;
|
|
11
|
+
}
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (!targetBranch) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"\u65E0\u6CD5\u81EA\u52A8\u83B7\u53D6\u5F53\u524D git \u5206\u652F\uFF1A\u5F53\u524D\u53EF\u80FD\u5904\u4E8E\u6E38\u79BB HEAD\uFF08detached HEAD\uFF09\u72B6\u6001\uFF08CI \u73AF\u5883\u5E38\u89C1\uFF09\u3002\u8BF7\u901A\u8FC7 options.branch \u660E\u786E\u6307\u5B9A\u5206\u652F\u540D\uFF0C\u6216\u786E\u4FDD\u73AF\u5883\u53D8\u91CF CI_COMMIT_BRANCH / CI_BUILD_REF_NAME \u5DF2\u8BBE\u7F6E\u3002"
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return targetBranch;
|
|
21
|
+
}
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"bin": {
|
|
@@ -33,8 +33,18 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"author": "gct",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"run": "tsx src/bin.ts gen-cdn-lib --tag=dev --dir=/Users/zhr/workspace/gct/gct-paas-cdn/extras",
|
|
38
|
+
"build": "unbuild",
|
|
39
|
+
"publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
|
|
40
|
+
"publish:dev": "npm run build && npm publish --access public --tag=dev --registry=https://registry.npmjs.org/",
|
|
41
|
+
"publish:alpha": "npm run build && npm publish --access public --tag=alpha --registry=https://registry.npmjs.org/",
|
|
42
|
+
"publish:beta": "npm run build && npm publish --access public --tag=beta --registry=https://registry.npmjs.org/",
|
|
43
|
+
"publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
|
|
44
|
+
},
|
|
36
45
|
"dependencies": {
|
|
37
46
|
"@inquirer/prompts": "^8.2.0",
|
|
47
|
+
"@types/js-yaml": "^4.0.9",
|
|
38
48
|
"commander": "^14.0.2",
|
|
39
49
|
"consola": "^3.4.2",
|
|
40
50
|
"core-js": "^3.48.0",
|
|
@@ -43,6 +53,7 @@
|
|
|
43
53
|
"got": "^14.6.6",
|
|
44
54
|
"handlebars": "^4.7.8",
|
|
45
55
|
"handlebars-helpers": "^0.10.0",
|
|
56
|
+
"js-yaml": "^4.1.1",
|
|
46
57
|
"listr2": "^10.2.1",
|
|
47
58
|
"lodash-es": "^4.17.23",
|
|
48
59
|
"ora": "^9.1.0",
|
|
@@ -59,14 +70,5 @@
|
|
|
59
70
|
"tsx": "^4.21.0",
|
|
60
71
|
"typescript": "^5.9.3",
|
|
61
72
|
"unbuild": "^3.6.1"
|
|
62
|
-
},
|
|
63
|
-
"scripts": {
|
|
64
|
-
"run": "tsx src/bin.ts gen-cdn-lib --tag=dev --dir=/Users/zhr/workspace/gct/gct-paas-cdn/extras",
|
|
65
|
-
"build": "unbuild",
|
|
66
|
-
"publish:next": "npm run build && npm publish --access public --tag=next --registry=https://registry.npmjs.org/",
|
|
67
|
-
"publish:dev": "npm run build && npm publish --access public --tag=dev --registry=https://registry.npmjs.org/",
|
|
68
|
-
"publish:alpha": "npm run build && npm publish --access public --tag=alpha --registry=https://registry.npmjs.org/",
|
|
69
|
-
"publish:beta": "npm run build && npm publish --access public --tag=beta --registry=https://registry.npmjs.org/",
|
|
70
|
-
"publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
|
|
71
73
|
}
|
|
72
|
-
}
|
|
74
|
+
}
|