@gct-paas/cli 0.1.6-dev.6 → 0.1.6
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/actions/gen-api/model-manage.cjs +1 -1
- package/dist/actions/gen-cdn-lib/gen-cdn-lib.cjs +55 -38
- package/dist/actions/gen-cdn-lib/gen-cdn-lib.d.ts +4 -0
- package/dist/actions/index.cjs +8 -1
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/init-git/init-git.cjs +33 -0
- package/dist/actions/init-git/init-git.d.ts +3 -0
- package/dist/commands/gen-cdn-lib/gen-cdn-lib.cjs +1 -1
- package/dist/commands/index.cjs +2 -0
- package/dist/commands/init-git/init-git.cjs +16 -0
- package/dist/commands/init-git/init-git.d.ts +6 -0
- package/dist/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +16 -2
- package/es/actions/gen-api/model-manage.mjs +1 -1
- package/es/actions/gen-cdn-lib/gen-cdn-lib.d.ts +4 -0
- package/es/actions/gen-cdn-lib/gen-cdn-lib.mjs +55 -41
- package/es/actions/index.d.ts +1 -0
- package/es/actions/index.mjs +1 -0
- package/es/actions/init-git/init-git.d.ts +3 -0
- package/es/actions/init-git/init-git.mjs +23 -0
- package/es/bin.mjs +0 -0
- package/es/commands/gen-cdn-lib/gen-cdn-lib.mjs +1 -1
- package/es/commands/index.mjs +2 -0
- package/es/commands/init-git/init-git.d.ts +6 -0
- package/es/commands/init-git/init-git.mjs +9 -0
- package/es/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.d.ts +16 -2
- package/package.json +14 -13
|
@@ -8,9 +8,37 @@ var _pacote = _interopRequireDefault(require("pacote"));
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
10
10
|
var _consola = _interopRequireDefault(require("consola"));
|
|
11
|
+
var _listr = require("listr2");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
class GenCdnLibAction {
|
|
13
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
|
+
* 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
|
|
17
|
+
*/
|
|
18
|
+
async downloadPkg(pkg, pkgInfo, opts, extraDir, extractCacheDir, cacheDir) {
|
|
19
|
+
const _dlCacheDir = _path.default.join(extractCacheDir, pkgInfo.name, pkgInfo.version);
|
|
20
|
+
await _pacote.default.extract(pkgInfo.dist.tarball, _dlCacheDir, {
|
|
21
|
+
registry: opts.registry,
|
|
22
|
+
cache: cacheDir
|
|
23
|
+
});
|
|
24
|
+
const localPkgJson = _fsExtra.default.readJSONSync(_path.default.join(_dlCacheDir, "package.json"));
|
|
25
|
+
const loaderField = localPkgJson.loader;
|
|
26
|
+
if (!loaderField) return "";
|
|
27
|
+
if (!opts.noFiles) {
|
|
28
|
+
const sourceDistPath = _path.default.join(_dlCacheDir, "dist");
|
|
29
|
+
if (opts.clean) {
|
|
30
|
+
const extractPkgPath = _path.default.join(extraDir, pkgInfo.name);
|
|
31
|
+
if (_fsExtra.default.existsSync(extractPkgPath)) {
|
|
32
|
+
_fsExtra.default.removeSync(extractPkgPath);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const extractPath = _path.default.join(extraDir, pkgInfo.name);
|
|
36
|
+
_fsExtra.default.copySync(sourceDistPath, extractPath, {
|
|
37
|
+
overwrite: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return _path.default.basename(loaderField);
|
|
41
|
+
}
|
|
14
42
|
async run(opts) {
|
|
15
43
|
const cwd = process.cwd();
|
|
16
44
|
const extraDir = opts.dir ? _path.default.resolve(cwd, opts.dir) : cwd;
|
|
@@ -24,55 +52,44 @@ class GenCdnLibAction {
|
|
|
24
52
|
const extractCacheDir = _path.default.join(cacheDir, "tmp");
|
|
25
53
|
const importMapJsonPath = opts.jsonPath ? _path.default.resolve(cwd, opts.jsonPath) : _path.default.join(extraDir, "import-map.json");
|
|
26
54
|
if (!_fsExtra.default.existsSync(importMapJsonPath)) {
|
|
27
|
-
_consola.default.warn(
|
|
55
|
+
_consola.default.warn(`import-map.json \u6587\u4EF6\u4E0D\u5B58\u5728\u4E8E ${importMapJsonPath}\uFF0C\u8BF7\u786E\u4FDD\u8DEF\u5F84\u6B63\u786E\u6216\u4F7F\u7528 --jsonPath \u53C2\u6570\u6307\u5B9A\u6B63\u786E\u8DEF\u5F84`);
|
|
28
56
|
return;
|
|
29
57
|
}
|
|
30
|
-
_consola.default.info(
|
|
58
|
+
_consola.default.info("\u6B63\u5728\u8BFB\u53D6 import-map.json...");
|
|
31
59
|
const importMap = _fsExtra.default.readJSONSync(importMapJsonPath);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const sourceDistPath = _path.default.join(_dlCacheDir, "dist");
|
|
46
|
-
if (opts.clean) {
|
|
47
|
-
const extractPkgPath = _path.default.join(extraDir, pkgInfo.name);
|
|
48
|
-
if (_fsExtra.default.existsSync(extractPkgPath)) {
|
|
49
|
-
_consola.default.info(`\u6B63\u5728\u5220\u9664 ${pkg} \u5305\u7684\u65E7\u7248\u672C...`);
|
|
50
|
-
_fsExtra.default.removeSync(extractPkgPath);
|
|
60
|
+
const tasks = new _listr.Listr(this.packages.map(pkg => ({
|
|
61
|
+
title: `${pkg}@${opts.tag}`,
|
|
62
|
+
task: async (_, task) => {
|
|
63
|
+
task.title = `${pkg}@${opts.tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
|
|
64
|
+
const pkgInfo = await _pacote.default.manifest(`${pkg}@${opts.tag}`, {
|
|
65
|
+
registry: opts.registry,
|
|
66
|
+
cache: cacheDir
|
|
67
|
+
});
|
|
68
|
+
task.title = `${pkg}@${pkgInfo.version} \u4E0B\u8F7D\u4E2D...`;
|
|
69
|
+
const entryName = await this.downloadPkg(pkg, pkgInfo, opts, extraDir, extractCacheDir, cacheDir);
|
|
70
|
+
if (!entryName) {
|
|
71
|
+
task.skip("package.json \u4E2D\u6CA1\u6709 loader \u5B57\u6BB5\uFF0C\u5DF2\u8DF3\u8FC7");
|
|
72
|
+
return;
|
|
51
73
|
}
|
|
74
|
+
importMap.imports[pkg] = `/${extraDirName}/${pkgInfo.name}/${entryName}`;
|
|
75
|
+
task.title = `${pkg}@${pkgInfo.version}`;
|
|
52
76
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (_fsExtra.default.existsSync(loaderPath)) {
|
|
62
|
-
entryName = "loader.esm.min.js";
|
|
63
|
-
} else if (_fsExtra.default.existsSync(indexPath)) {
|
|
64
|
-
entryName = "index.esm.min.js";
|
|
77
|
+
})), {
|
|
78
|
+
concurrent: true
|
|
79
|
+
});
|
|
80
|
+
await tasks.run();
|
|
81
|
+
const timestamp = Date.now();
|
|
82
|
+
for (const key in importMap.imports) {
|
|
83
|
+
if (importMap.imports[key].includes("?t=")) {
|
|
84
|
+
importMap.imports[key] = importMap.imports[key].replace(/\?t=\d+/, `?t=${timestamp}`);
|
|
65
85
|
} else {
|
|
66
|
-
|
|
67
|
-
continue;
|
|
86
|
+
importMap.imports[key] = `${importMap.imports[key]}?t=${timestamp}`;
|
|
68
87
|
}
|
|
69
|
-
importMap.imports[pkg] = `./${extraDirName}/${pkgInfo.name}/${pkgInfo.version}/${entryName}`;
|
|
70
|
-
_consola.default.info(`\u6210\u529F\u4FEE\u6539 ${pkg} \u8DEF\u5F84`);
|
|
71
88
|
}
|
|
72
89
|
_fsExtra.default.writeJSONSync(importMapJsonPath, importMap, {
|
|
73
90
|
spaces: 2
|
|
74
91
|
});
|
|
75
|
-
if (_fsExtra.default.existsSync(cacheDir)) {
|
|
92
|
+
if (opts.cleanCache && _fsExtra.default.existsSync(cacheDir)) {
|
|
76
93
|
_consola.default.info(`\u6B63\u5728\u5220\u9664\u7F13\u5B58\u76EE\u5F55: ${cacheDir}`);
|
|
77
94
|
_fsExtra.default.removeSync(cacheDir);
|
|
78
95
|
}
|
package/dist/actions/index.cjs
CHANGED
|
@@ -15,5 +15,12 @@ Object.defineProperty(exports, "GenCdnLibAction", {
|
|
|
15
15
|
return _genCdnLib.GenCdnLibAction;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "InitGitAction", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _initGit.InitGitAction;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
var _genApi = require("./gen-api/gen-api.cjs");
|
|
19
|
-
var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
|
|
25
|
+
var _genCdnLib = require("./gen-cdn-lib/gen-cdn-lib.cjs");
|
|
26
|
+
var _initGit = require("./init-git/init-git.cjs");
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InitGitAction = void 0;
|
|
7
|
+
var _child_process = require("child_process");
|
|
8
|
+
var _consola = require("consola");
|
|
9
|
+
var _simpleGit = _interopRequireDefault(require("simple-git"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const GIT_CONFIGS = {
|
|
12
|
+
"merge.ours.driver": "true",
|
|
13
|
+
"pull.ff": "only",
|
|
14
|
+
"core.autocrlf": "false",
|
|
15
|
+
"core.safecrlf": "true",
|
|
16
|
+
"core.eol": "lf"
|
|
17
|
+
};
|
|
18
|
+
class InitGitAction {
|
|
19
|
+
async run() {
|
|
20
|
+
_consola.consola.start("\u521D\u59CB\u5316 Husky...");
|
|
21
|
+
(0, _child_process.execSync)("npx husky", {
|
|
22
|
+
stdio: "inherit"
|
|
23
|
+
});
|
|
24
|
+
const git = (0, _simpleGit.default)(process.cwd());
|
|
25
|
+
_consola.consola.start("\u914D\u7F6E Git \u672C\u5730\u8BBE\u7F6E...");
|
|
26
|
+
for (const [key, value] of Object.entries(GIT_CONFIGS)) {
|
|
27
|
+
await git.addConfig(key, value, false, "local");
|
|
28
|
+
_consola.consola.info(` git config --local ${key} "${value}"`);
|
|
29
|
+
}
|
|
30
|
+
_consola.consola.success("Git \u914D\u7F6E\u521D\u59CB\u5316\u5B8C\u6210");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.InitGitAction = InitGitAction;
|
|
@@ -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").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", "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
|
@@ -7,10 +7,12 @@ exports.CommandLoader = void 0;
|
|
|
7
7
|
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
|
+
var _initGit = require("./init-git/init-git.cjs");
|
|
10
11
|
class CommandLoader {
|
|
11
12
|
static load(program) {
|
|
12
13
|
new _genApi.GenApiCommand().load(program);
|
|
13
14
|
new _genCdnLib.GenCdnLibCommand().load(program);
|
|
15
|
+
new _initGit.InitGitCommand().load(program);
|
|
14
16
|
this.handleInvalidCommand(program);
|
|
15
17
|
}
|
|
16
18
|
static handleInvalidCommand(program) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InitGitCommand = void 0;
|
|
7
|
+
var _actions = require("../../actions/index.cjs");
|
|
8
|
+
class InitGitCommand {
|
|
9
|
+
load(program) {
|
|
10
|
+
program.command("init-git").description("\u521D\u59CB\u5316\u9879\u76EE\u901A\u7528 Git \u914D\u7F6E").action(this.action.bind(this));
|
|
11
|
+
}
|
|
12
|
+
async action() {
|
|
13
|
+
await new _actions.InitGitAction().run();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.InitGitCommand = InitGitCommand;
|
|
@@ -8,9 +8,10 @@ export interface IGenCdnLibOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* 制定下载的版本标签,默认为 latest
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @default 'latest'
|
|
12
|
+
* @type {string}
|
|
12
13
|
*/
|
|
13
|
-
tag:
|
|
14
|
+
tag: string;
|
|
14
15
|
/**
|
|
15
16
|
* 要输出的 extras 资源目录,未指定时默认为当前执行目录
|
|
16
17
|
*
|
|
@@ -23,6 +24,12 @@ export interface IGenCdnLibOptions {
|
|
|
23
24
|
* @type {string}
|
|
24
25
|
*/
|
|
25
26
|
jsonPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 是否只生成 import-map.json 文件而不下载包文件,默认为 false
|
|
29
|
+
*
|
|
30
|
+
* @type {boolean}
|
|
31
|
+
*/
|
|
32
|
+
noFiles?: boolean;
|
|
26
33
|
/**
|
|
27
34
|
* 是否清理输出目录后再生成
|
|
28
35
|
*
|
|
@@ -41,4 +48,11 @@ export interface IGenCdnLibOptions {
|
|
|
41
48
|
* @type {string}
|
|
42
49
|
*/
|
|
43
50
|
cache?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 清理缓存目录,默认为 false
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
* @type {boolean}
|
|
56
|
+
*/
|
|
57
|
+
cleanCache?: boolean;
|
|
44
58
|
}
|
|
@@ -56,7 +56,7 @@ export class ModelManage {
|
|
|
56
56
|
if (param.name === "requestBody") {
|
|
57
57
|
requestEntity = { title: "IObject" };
|
|
58
58
|
} else if (param.name === "file") {
|
|
59
|
-
requestEntity = { title: "
|
|
59
|
+
requestEntity = { title: "UploadFileData" };
|
|
60
60
|
} else {
|
|
61
61
|
const refKey = this.getOriginRef(param.schema);
|
|
62
62
|
requestEntity = cfg.definitions[refKey];
|
|
@@ -2,6 +2,7 @@ import pacote from "pacote";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fse from "fs-extra";
|
|
4
4
|
import log from "consola";
|
|
5
|
+
import { Listr } from "listr2";
|
|
5
6
|
export class GenCdnLibAction {
|
|
6
7
|
packages = [
|
|
7
8
|
"@gct-paas/api",
|
|
@@ -21,6 +22,31 @@ export class GenCdnLibAction {
|
|
|
21
22
|
"@gct-paas/schema",
|
|
22
23
|
"@gct-paas/v-ben"
|
|
23
24
|
];
|
|
25
|
+
/**
|
|
26
|
+
* 下载指定包并复制到外部依赖目录,返回入口文件名;若找不到入口文件则返回空字符串
|
|
27
|
+
*/
|
|
28
|
+
async downloadPkg(pkg, pkgInfo, opts, extraDir, extractCacheDir, cacheDir) {
|
|
29
|
+
const _dlCacheDir = path.join(extractCacheDir, pkgInfo.name, pkgInfo.version);
|
|
30
|
+
await pacote.extract(pkgInfo.dist.tarball, _dlCacheDir, {
|
|
31
|
+
registry: opts.registry,
|
|
32
|
+
cache: cacheDir
|
|
33
|
+
});
|
|
34
|
+
const localPkgJson = fse.readJSONSync(path.join(_dlCacheDir, "package.json"));
|
|
35
|
+
const loaderField = localPkgJson.loader;
|
|
36
|
+
if (!loaderField) return "";
|
|
37
|
+
if (!opts.noFiles) {
|
|
38
|
+
const sourceDistPath = path.join(_dlCacheDir, "dist");
|
|
39
|
+
if (opts.clean) {
|
|
40
|
+
const extractPkgPath = path.join(extraDir, pkgInfo.name);
|
|
41
|
+
if (fse.existsSync(extractPkgPath)) {
|
|
42
|
+
fse.removeSync(extractPkgPath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const extractPath = path.join(extraDir, pkgInfo.name);
|
|
46
|
+
fse.copySync(sourceDistPath, extractPath, { overwrite: true });
|
|
47
|
+
}
|
|
48
|
+
return path.basename(loaderField);
|
|
49
|
+
}
|
|
24
50
|
async run(opts) {
|
|
25
51
|
const cwd = process.cwd();
|
|
26
52
|
const extraDir = opts.dir ? path.resolve(cwd, opts.dir) : cwd;
|
|
@@ -33,56 +59,44 @@ export class GenCdnLibAction {
|
|
|
33
59
|
const importMapJsonPath = opts.jsonPath ? path.resolve(cwd, opts.jsonPath) : path.join(extraDir, "import-map.json");
|
|
34
60
|
if (!fse.existsSync(importMapJsonPath)) {
|
|
35
61
|
log.warn(
|
|
36
|
-
|
|
62
|
+
`import-map.json \u6587\u4EF6\u4E0D\u5B58\u5728\u4E8E ${importMapJsonPath}\uFF0C\u8BF7\u786E\u4FDD\u8DEF\u5F84\u6B63\u786E\u6216\u4F7F\u7528 --jsonPath \u53C2\u6570\u6307\u5B9A\u6B63\u786E\u8DEF\u5F84`
|
|
37
63
|
);
|
|
38
64
|
return;
|
|
39
65
|
}
|
|
40
|
-
log.info(
|
|
66
|
+
log.info("\u6B63\u5728\u8BFB\u53D6 import-map.json...");
|
|
41
67
|
const importMap = fse.readJSONSync(importMapJsonPath);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
const tasks = new Listr(
|
|
69
|
+
this.packages.map((pkg) => ({
|
|
70
|
+
title: `${pkg}@${opts.tag}`,
|
|
71
|
+
task: async (_, task) => {
|
|
72
|
+
task.title = `${pkg}@${opts.tag} \u83B7\u53D6\u5305\u4FE1\u606F...`;
|
|
73
|
+
const pkgInfo = await pacote.manifest(`${pkg}@${opts.tag}`, {
|
|
74
|
+
registry: opts.registry,
|
|
75
|
+
cache: cacheDir
|
|
76
|
+
});
|
|
77
|
+
task.title = `${pkg}@${pkgInfo.version} \u4E0B\u8F7D\u4E2D...`;
|
|
78
|
+
const entryName = await this.downloadPkg(pkg, pkgInfo, opts, extraDir, extractCacheDir, cacheDir);
|
|
79
|
+
if (!entryName) {
|
|
80
|
+
task.skip("package.json \u4E2D\u6CA1\u6709 loader \u5B57\u6BB5\uFF0C\u5DF2\u8DF3\u8FC7");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
importMap.imports[pkg] = `/${extraDirName}/${pkgInfo.name}/${entryName}`;
|
|
84
|
+
task.title = `${pkg}@${pkgInfo.version}`;
|
|
57
85
|
}
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const extractPath = path.join(extraDir, pkgInfo.name, pkgInfo.version);
|
|
68
|
-
log.info(`\u5C06 ${pkg}@${opts.tag} \u5305\u4ECE\u7F13\u5B58\u76EE\u5F55\u590D\u5236\u81F3\u5916\u90E8\u4F9D\u8D56\u76EE\u5F55...`);
|
|
69
|
-
fse.copySync(sourceDistPath, extractPath, { overwrite: true });
|
|
70
|
-
const loaderPath = path.join(extractPath, "loader.esm.min.js");
|
|
71
|
-
const indexPath = path.join(extractPath, "index.esm.min.js");
|
|
72
|
-
let entryName = "";
|
|
73
|
-
if (fse.existsSync(loaderPath)) {
|
|
74
|
-
entryName = "loader.esm.min.js";
|
|
75
|
-
} else if (fse.existsSync(indexPath)) {
|
|
76
|
-
entryName = "index.esm.min.js";
|
|
86
|
+
})),
|
|
87
|
+
{ concurrent: true }
|
|
88
|
+
);
|
|
89
|
+
await tasks.run();
|
|
90
|
+
const timestamp = Date.now();
|
|
91
|
+
for (const key in importMap.imports) {
|
|
92
|
+
if (importMap.imports[key].includes("?t=")) {
|
|
93
|
+
importMap.imports[key] = importMap.imports[key].replace(/\?t=\d+/, `?t=${timestamp}`);
|
|
77
94
|
} else {
|
|
78
|
-
|
|
79
|
-
continue;
|
|
95
|
+
importMap.imports[key] = `${importMap.imports[key]}?t=${timestamp}`;
|
|
80
96
|
}
|
|
81
|
-
importMap.imports[pkg] = `./${extraDirName}/${pkgInfo.name}/${pkgInfo.version}/${entryName}`;
|
|
82
|
-
log.info(`\u6210\u529F\u4FEE\u6539 ${pkg} \u8DEF\u5F84`);
|
|
83
97
|
}
|
|
84
98
|
fse.writeJSONSync(importMapJsonPath, importMap, { spaces: 2 });
|
|
85
|
-
if (fse.existsSync(cacheDir)) {
|
|
99
|
+
if (opts.cleanCache && fse.existsSync(cacheDir)) {
|
|
86
100
|
log.info(`\u6B63\u5728\u5220\u9664\u7F13\u5B58\u76EE\u5F55: ${cacheDir}`);
|
|
87
101
|
fse.removeSync(cacheDir);
|
|
88
102
|
}
|
package/es/actions/index.d.ts
CHANGED
package/es/actions/index.mjs
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { consola } from "consola";
|
|
3
|
+
import simpleGit from "simple-git";
|
|
4
|
+
const GIT_CONFIGS = {
|
|
5
|
+
"merge.ours.driver": "true",
|
|
6
|
+
"pull.ff": "only",
|
|
7
|
+
"core.autocrlf": "false",
|
|
8
|
+
"core.safecrlf": "true",
|
|
9
|
+
"core.eol": "lf"
|
|
10
|
+
};
|
|
11
|
+
export class InitGitAction {
|
|
12
|
+
async run() {
|
|
13
|
+
consola.start("\u521D\u59CB\u5316 Husky...");
|
|
14
|
+
execSync("npx husky", { stdio: "inherit" });
|
|
15
|
+
const git = simpleGit(process.cwd());
|
|
16
|
+
consola.start("\u914D\u7F6E Git \u672C\u5730\u8BBE\u7F6E...");
|
|
17
|
+
for (const [key, value] of Object.entries(GIT_CONFIGS)) {
|
|
18
|
+
await git.addConfig(key, value, false, "local");
|
|
19
|
+
consola.info(` git config --local ${key} "${value}"`);
|
|
20
|
+
}
|
|
21
|
+
consola.success("Git \u914D\u7F6E\u521D\u59CB\u5316\u5B8C\u6210");
|
|
22
|
+
}
|
|
23
|
+
}
|
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", "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").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", "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
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
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
|
+
import { InitGitCommand } from "./init-git/init-git.mjs";
|
|
4
5
|
export class CommandLoader {
|
|
5
6
|
static load(program) {
|
|
6
7
|
new GenApiCommand().load(program);
|
|
7
8
|
new GenCdnLibCommand().load(program);
|
|
9
|
+
new InitGitCommand().load(program);
|
|
8
10
|
this.handleInvalidCommand(program);
|
|
9
11
|
}
|
|
10
12
|
static handleInvalidCommand(program) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InitGitAction } from "../../actions/index.mjs";
|
|
2
|
+
export class InitGitCommand {
|
|
3
|
+
load(program) {
|
|
4
|
+
program.command("init-git").description("\u521D\u59CB\u5316\u9879\u76EE\u901A\u7528 Git \u914D\u7F6E").action(this.action.bind(this));
|
|
5
|
+
}
|
|
6
|
+
async action() {
|
|
7
|
+
await new InitGitAction().run();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -8,9 +8,10 @@ export interface IGenCdnLibOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* 制定下载的版本标签,默认为 latest
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* @default 'latest'
|
|
12
|
+
* @type {string}
|
|
12
13
|
*/
|
|
13
|
-
tag:
|
|
14
|
+
tag: string;
|
|
14
15
|
/**
|
|
15
16
|
* 要输出的 extras 资源目录,未指定时默认为当前执行目录
|
|
16
17
|
*
|
|
@@ -23,6 +24,12 @@ export interface IGenCdnLibOptions {
|
|
|
23
24
|
* @type {string}
|
|
24
25
|
*/
|
|
25
26
|
jsonPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 是否只生成 import-map.json 文件而不下载包文件,默认为 false
|
|
29
|
+
*
|
|
30
|
+
* @type {boolean}
|
|
31
|
+
*/
|
|
32
|
+
noFiles?: boolean;
|
|
26
33
|
/**
|
|
27
34
|
* 是否清理输出目录后再生成
|
|
28
35
|
*
|
|
@@ -41,4 +48,11 @@ export interface IGenCdnLibOptions {
|
|
|
41
48
|
* @type {string}
|
|
42
49
|
*/
|
|
43
50
|
cache?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 清理缓存目录,默认为 false
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
* @type {boolean}
|
|
56
|
+
*/
|
|
57
|
+
cleanCache?: boolean;
|
|
44
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/cli",
|
|
3
|
-
"version": "0.1.6
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"bin": {
|
|
@@ -33,15 +33,6 @@
|
|
|
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
|
-
},
|
|
45
36
|
"dependencies": {
|
|
46
37
|
"@inquirer/prompts": "^8.2.0",
|
|
47
38
|
"commander": "^14.0.2",
|
|
@@ -52,11 +43,13 @@
|
|
|
52
43
|
"got": "^14.6.6",
|
|
53
44
|
"handlebars": "^4.7.8",
|
|
54
45
|
"handlebars-helpers": "^0.10.0",
|
|
46
|
+
"listr2": "^10.2.1",
|
|
55
47
|
"lodash-es": "^4.17.23",
|
|
56
48
|
"ora": "^9.1.0",
|
|
57
49
|
"pacote": "^21.5.0",
|
|
58
50
|
"picocolors": "^1.1.1",
|
|
59
|
-
"rimraf": "^6.1.2"
|
|
51
|
+
"rimraf": "^6.1.2",
|
|
52
|
+
"simple-git": "^3.33.0"
|
|
60
53
|
},
|
|
61
54
|
"devDependencies": {
|
|
62
55
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -67,5 +60,13 @@
|
|
|
67
60
|
"typescript": "^5.9.3",
|
|
68
61
|
"unbuild": "^3.6.1"
|
|
69
62
|
},
|
|
70
|
-
"
|
|
71
|
-
|
|
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
|
+
}
|
|
72
|
+
}
|