create-pubinfo 2.0.0-beta.23 → 2.0.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +2 -2
- package/dist/index.cjs +0 -413
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import consola6 from "consola";
|
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "create-pubinfo",
|
|
10
10
|
type: "module",
|
|
11
|
-
version: "2.0.0-beta.
|
|
11
|
+
version: "2.0.0-beta.24",
|
|
12
12
|
description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
|
|
13
13
|
author: "Werheng <werheng.zhang@gmail.com>",
|
|
14
14
|
license: "MIT",
|
|
@@ -22,7 +22,7 @@ var package_default = {
|
|
|
22
22
|
scripts: {
|
|
23
23
|
dev: "tsup --watch src",
|
|
24
24
|
build: "tsup",
|
|
25
|
-
cli: "
|
|
25
|
+
cli: "node dist/index.js",
|
|
26
26
|
"cli:clean": "rimraf ./my-app",
|
|
27
27
|
lint: "eslint . --cache --fix"
|
|
28
28
|
},
|
|
@@ -117,7 +117,7 @@ function generate(options, version) {
|
|
|
117
117
|
const root = cwd();
|
|
118
118
|
const templateDir = resolve2(
|
|
119
119
|
__dirname,
|
|
120
|
-
"
|
|
120
|
+
"../templates",
|
|
121
121
|
`pubinfo-template`
|
|
122
122
|
);
|
|
123
123
|
const targetPath = resolve2(root, options.dir);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pubinfo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.24",
|
|
5
5
|
"description": "初始化项目框架",
|
|
6
6
|
"author": "Werheng <werheng.zhang@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"dev": "tsup --watch src",
|
|
34
34
|
"build": "tsup",
|
|
35
|
-
"cli": "
|
|
35
|
+
"cli": "node dist/index.js",
|
|
36
36
|
"cli:clean": "rimraf ./my-app",
|
|
37
37
|
"lint": "eslint . --cache --fix"
|
|
38
38
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
|
|
25
|
-
// src/index.ts
|
|
26
|
-
var import_commander = require("commander");
|
|
27
|
-
var import_consola6 = __toESM(require("consola"), 1);
|
|
28
|
-
|
|
29
|
-
// package.json
|
|
30
|
-
var package_default = {
|
|
31
|
-
name: "create-pubinfo",
|
|
32
|
-
type: "module",
|
|
33
|
-
version: "2.0.0-beta.23",
|
|
34
|
-
description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
|
|
35
|
-
author: "Werheng <werheng.zhang@gmail.com>",
|
|
36
|
-
license: "MIT",
|
|
37
|
-
bin: {
|
|
38
|
-
pubinfo: "./dist/index.js"
|
|
39
|
-
},
|
|
40
|
-
files: [
|
|
41
|
-
"dist",
|
|
42
|
-
"templates"
|
|
43
|
-
],
|
|
44
|
-
scripts: {
|
|
45
|
-
dev: "tsup --watch src",
|
|
46
|
-
build: "tsup",
|
|
47
|
-
cli: "tsx src/index.ts",
|
|
48
|
-
"cli:clean": "rimraf ./my-app",
|
|
49
|
-
lint: "eslint . --cache --fix"
|
|
50
|
-
},
|
|
51
|
-
dependencies: {
|
|
52
|
-
"@inquirer/prompts": "^5.5.0",
|
|
53
|
-
"ansi-colors": "^4.1.3",
|
|
54
|
-
cfonts: "^3.3.0",
|
|
55
|
-
commander: "^12.1.0",
|
|
56
|
-
confbox: "^0.1.8",
|
|
57
|
-
consola: "^3.4.0",
|
|
58
|
-
giget: "^1.2.5",
|
|
59
|
-
ofetch: "^1.4.1",
|
|
60
|
-
ora: "^8.2.0",
|
|
61
|
-
rimraf: "^6.0.1",
|
|
62
|
-
semver: "^7.7.1"
|
|
63
|
-
},
|
|
64
|
-
devDependencies: {
|
|
65
|
-
"@types/node": "^22.13.9",
|
|
66
|
-
tsup: "catalog:"
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/core/generate.ts
|
|
71
|
-
var import_node_path2 = require("path");
|
|
72
|
-
var import_node_process = require("process");
|
|
73
|
-
var import_node_url = require("url");
|
|
74
|
-
|
|
75
|
-
// src/utils.ts
|
|
76
|
-
var import_node_fs = require("fs");
|
|
77
|
-
var fs = __toESM(require("fs"), 1);
|
|
78
|
-
var import_promises = require("fs/promises");
|
|
79
|
-
var import_node_path = require("path");
|
|
80
|
-
var import_confbox = require("confbox");
|
|
81
|
-
var import_consola = __toESM(require("consola"), 1);
|
|
82
|
-
function rewriteFile(path, fn) {
|
|
83
|
-
if (!(0, import_node_fs.existsSync)(path)) {
|
|
84
|
-
import_consola.default.error(`RewriteFile fail: ${path} does not exist`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
const content = (0, import_node_fs.readFileSync)(path, { encoding: "utf-8" });
|
|
89
|
-
(0, import_node_fs.writeFileSync)(path, fn(content));
|
|
90
|
-
} catch (error) {
|
|
91
|
-
import_consola.default.error(`RewriteFile fail: ${error}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function copyDir(srcDir, destDir) {
|
|
95
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
96
|
-
for (const file of fs.readdirSync(srcDir)) {
|
|
97
|
-
const srcFile = (0, import_node_path.resolve)(srcDir, file);
|
|
98
|
-
const destFile = (0, import_node_path.resolve)(destDir, file);
|
|
99
|
-
copy(srcFile, destFile);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function copy(src, dest) {
|
|
103
|
-
const stat = fs.statSync(src);
|
|
104
|
-
if (stat.isDirectory()) {
|
|
105
|
-
copyDir(src, dest);
|
|
106
|
-
} else {
|
|
107
|
-
fs.copyFileSync(src, dest);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async function readJSON(path) {
|
|
111
|
-
const blob = await (0, import_promises.readFile)(path, "utf-8");
|
|
112
|
-
let parsed;
|
|
113
|
-
try {
|
|
114
|
-
parsed = (0, import_confbox.parseJSON)(blob);
|
|
115
|
-
} catch {
|
|
116
|
-
parsed = (0, import_confbox.parseJSONC)(blob);
|
|
117
|
-
}
|
|
118
|
-
return parsed;
|
|
119
|
-
}
|
|
120
|
-
async function writeJSON(path, json) {
|
|
121
|
-
await (0, import_promises.writeFile)(path, (0, import_confbox.stringifyJSON)(json));
|
|
122
|
-
}
|
|
123
|
-
function assignValues(target, source) {
|
|
124
|
-
for (const [key, value] of Object.entries(source)) {
|
|
125
|
-
target[key] = value;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function validateInput(input2) {
|
|
129
|
-
const forbiddenChars = /[<>:"/\\|?*\s]/;
|
|
130
|
-
if (forbiddenChars.test(input2)) {
|
|
131
|
-
return '\u9519\u8BEF\u63D0\u793A: \u8BE5\u503C\u4E0D\u80FD\u5305\u542B\u7A7A\u683C\u6216\u8005\u975E\u6CD5\u5B57\u7B26 (\u4F8B\u5982, <>:"/\\|?*).';
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// src/core/generate.ts
|
|
137
|
-
var import_meta = {};
|
|
138
|
-
var __dirname = (0, import_node_path2.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
139
|
-
function generate(options, version) {
|
|
140
|
-
const root = (0, import_node_process.cwd)();
|
|
141
|
-
const templateDir = (0, import_node_path2.resolve)(
|
|
142
|
-
__dirname,
|
|
143
|
-
"../../templates",
|
|
144
|
-
`pubinfo-template`
|
|
145
|
-
);
|
|
146
|
-
const targetPath = (0, import_node_path2.resolve)(root, options.dir);
|
|
147
|
-
copy(templateDir, targetPath);
|
|
148
|
-
rewriteFile((0, import_node_path2.resolve)(targetPath, "src/settings.ts"), (content) => {
|
|
149
|
-
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${options.key}'`);
|
|
150
|
-
});
|
|
151
|
-
rewriteFile((0, import_node_path2.resolve)(targetPath, "openapi.config.ts"), (content) => {
|
|
152
|
-
return content.replace(/enabled:[^,]+,/g, `enabled: ${options.openapi},`);
|
|
153
|
-
});
|
|
154
|
-
rewriteFile((0, import_node_path2.resolve)(targetPath, "package.json"), (content) => {
|
|
155
|
-
const pattern = /"(@?pubinfo(?:\/module-(?:auth|rbac))?)":\s*"[^"]+"/g;
|
|
156
|
-
return content.replace(pattern, (_match, pkgName) => {
|
|
157
|
-
return `"${pkgName}": "${version}"`;
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// src/core/init.ts
|
|
163
|
-
var import_node_fs2 = require("fs");
|
|
164
|
-
var import_node_process3 = __toESM(require("process"), 1);
|
|
165
|
-
var import_prompts = require("@inquirer/prompts");
|
|
166
|
-
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
167
|
-
var import_consola3 = __toESM(require("consola"), 1);
|
|
168
|
-
|
|
169
|
-
// src/v1/constant.ts
|
|
170
|
-
var REMOTE_URL = "http://43.143.107.174:80/templates";
|
|
171
|
-
var PKG_NAME = "monorepo-project-template";
|
|
172
|
-
var VERSION_FILE = "version.json";
|
|
173
|
-
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
174
|
-
var OPENAPI_FILE_PATH = "openapi.config.ts";
|
|
175
|
-
var APPS_DIR = "apps";
|
|
176
|
-
var APPS = [
|
|
177
|
-
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
178
|
-
];
|
|
179
|
-
var METADATA_DIR = "configs/metadata";
|
|
180
|
-
var META_FILENAME = "pubinfo.json";
|
|
181
|
-
|
|
182
|
-
// src/v1/fetch.ts
|
|
183
|
-
var import_node_process2 = __toESM(require("process"), 1);
|
|
184
|
-
var import_consola2 = __toESM(require("consola"), 1);
|
|
185
|
-
var import_ofetch = require("ofetch");
|
|
186
|
-
var import_ora = __toESM(require("ora"), 1);
|
|
187
|
-
var import_semver = require("semver");
|
|
188
|
-
async function fetchVersion() {
|
|
189
|
-
const versions = await (0, import_ofetch.ofetch)(`${REMOTE_URL}/${VERSION_FILE}`);
|
|
190
|
-
versions.sort((v1, v2) => -(0, import_semver.compare)(v1, v2));
|
|
191
|
-
return {
|
|
192
|
-
latest: versions[0],
|
|
193
|
-
list: versions
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
async function fetchData() {
|
|
197
|
-
const spinner = (0, import_ora.default)({
|
|
198
|
-
text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
|
|
199
|
-
color: "blue"
|
|
200
|
-
});
|
|
201
|
-
spinner.start();
|
|
202
|
-
try {
|
|
203
|
-
const version = await fetchVersion();
|
|
204
|
-
return {
|
|
205
|
-
version
|
|
206
|
-
};
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (error.message.includes(REMOTE_URL)) {
|
|
209
|
-
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
210
|
-
}
|
|
211
|
-
import_consola2.default.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
|
|
212
|
-
import_node_process2.default.exit(1);
|
|
213
|
-
} finally {
|
|
214
|
-
spinner.stop();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/core/init.ts
|
|
219
|
-
async function init() {
|
|
220
|
-
const { version } = await fetchData();
|
|
221
|
-
try {
|
|
222
|
-
const answer = {};
|
|
223
|
-
answer.dir = await (0, import_prompts.input)({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
|
|
224
|
-
answer.key = await (0, import_prompts.input)({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
|
|
225
|
-
if ((0, import_node_fs2.existsSync)(answer.dir)) {
|
|
226
|
-
const overwrite = await (0, import_prompts.confirm)({ message: `\u76EE\u5F55 ${import_ansi_colors.default.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
|
|
227
|
-
if (!overwrite) {
|
|
228
|
-
throw Error;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
answer.openapi = await (0, import_prompts.confirm)({
|
|
232
|
-
message: "\u8FD0\u884C\u65F6\u81EA\u52A8\u751F\u6210\u63A5\u53E3\u5BF9\u63A5\u6587\u4EF6\uFF0C\u82E5\u5173\u95ED\u53EF\u901A\u8FC7\u6307\u4EE4\u751F\u6210\uFF08openapi\uFF09",
|
|
233
|
-
default: false
|
|
234
|
-
});
|
|
235
|
-
const V1orV2 = await (0, import_prompts.select)({
|
|
236
|
-
message: "\u4F7F\u7528 v1 or v2 \u7248\u672C\uFF1F",
|
|
237
|
-
default: "v2",
|
|
238
|
-
choices: ["v1", "v2"]
|
|
239
|
-
});
|
|
240
|
-
const isV1 = V1orV2 === "v1";
|
|
241
|
-
if (isV1) {
|
|
242
|
-
answer.optionsV1 = JSON.parse(JSON.stringify(answer));
|
|
243
|
-
answer.optionsV1.version = await (0, import_prompts.select)({
|
|
244
|
-
message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
|
|
245
|
-
default: version.latest,
|
|
246
|
-
choices: version.list
|
|
247
|
-
});
|
|
248
|
-
answer.optionsV1.apps = await (0, import_prompts.checkbox)({
|
|
249
|
-
message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
|
|
250
|
-
choices: APPS,
|
|
251
|
-
validate: (input2) => {
|
|
252
|
-
if (input2.length === 0) {
|
|
253
|
-
return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
|
|
254
|
-
}
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
return answer;
|
|
260
|
-
} catch {
|
|
261
|
-
import_consola3.default.fail("\u64CD\u4F5C\u7EC8\u6B62");
|
|
262
|
-
import_node_process3.default.exit(1);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// src/log.ts
|
|
267
|
-
var import_cfonts = __toESM(require("cfonts"), 1);
|
|
268
|
-
function bootstrop() {
|
|
269
|
-
printLoGo("PUBINFO");
|
|
270
|
-
function printLoGo(logo) {
|
|
271
|
-
import_cfonts.default.say(logo, {
|
|
272
|
-
font: "simple3d",
|
|
273
|
-
align: "left",
|
|
274
|
-
background: "transparent",
|
|
275
|
-
letterSpacing: 1,
|
|
276
|
-
lineHeight: 1,
|
|
277
|
-
space: true,
|
|
278
|
-
maxLength: 0,
|
|
279
|
-
spaceless: false,
|
|
280
|
-
gradient: ["blue", "magenta"],
|
|
281
|
-
independentGradient: false,
|
|
282
|
-
transitionGradient: false,
|
|
283
|
-
env: "node"
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// src/v1/download.ts
|
|
289
|
-
var import_node_process4 = __toESM(require("process"), 1);
|
|
290
|
-
var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
291
|
-
var import_consola4 = __toESM(require("consola"), 1);
|
|
292
|
-
var import_giget = require("giget");
|
|
293
|
-
var import_ora2 = __toESM(require("ora"), 1);
|
|
294
|
-
var import_semver2 = require("semver");
|
|
295
|
-
var pubinfo = async (input2, { auth }) => {
|
|
296
|
-
const semver = (0, import_semver2.coerce)(input2);
|
|
297
|
-
return {
|
|
298
|
-
name: "pubinfo",
|
|
299
|
-
version: input2,
|
|
300
|
-
headers: { Authorization: `token ${auth}` },
|
|
301
|
-
tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
async function download(options) {
|
|
305
|
-
const finish = loading();
|
|
306
|
-
try {
|
|
307
|
-
await (0, import_giget.downloadTemplate)(`pubinfo:${PKG_NAME}-${options.version}`, {
|
|
308
|
-
providers: { pubinfo },
|
|
309
|
-
force: true,
|
|
310
|
-
forceClean: true,
|
|
311
|
-
dir: options.dir
|
|
312
|
-
});
|
|
313
|
-
} catch (error) {
|
|
314
|
-
if (error.message.includes(REMOTE_URL)) {
|
|
315
|
-
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
316
|
-
}
|
|
317
|
-
import_consola4.default.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
|
|
318
|
-
import_node_process4.default.exit(1);
|
|
319
|
-
} finally {
|
|
320
|
-
finish();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function loading() {
|
|
324
|
-
const startTime = Date.now();
|
|
325
|
-
const spinner = (0, import_ora2.default)({
|
|
326
|
-
text: "\u4E0B\u8F7D\u4E2D...",
|
|
327
|
-
color: "green"
|
|
328
|
-
});
|
|
329
|
-
spinner.start();
|
|
330
|
-
return () => {
|
|
331
|
-
const { green, yellow } = import_ansi_colors2.default;
|
|
332
|
-
spinner.stop();
|
|
333
|
-
import_consola4.default.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// src/v1/rewrite.ts
|
|
338
|
-
var import_node_fs3 = require("fs");
|
|
339
|
-
var import_node_path3 = require("path");
|
|
340
|
-
var import_node_process5 = __toESM(require("process"), 1);
|
|
341
|
-
var import_consola5 = __toESM(require("consola"), 1);
|
|
342
|
-
var import_rimraf = require("rimraf");
|
|
343
|
-
async function rewrite(options) {
|
|
344
|
-
const { dir } = options;
|
|
345
|
-
const root = import_node_process5.default.cwd();
|
|
346
|
-
const projectDir = (0, import_node_path3.resolve)(root, dir);
|
|
347
|
-
writeMetaJSON((0, import_node_path3.resolve)(projectDir, METADATA_DIR), options);
|
|
348
|
-
writeApps((0, import_node_path3.resolve)(projectDir, APPS_DIR), options);
|
|
349
|
-
}
|
|
350
|
-
async function writeMetaJSON(metaDir, options) {
|
|
351
|
-
const { key, version, apps, openapi } = options;
|
|
352
|
-
const path = (0, import_node_path3.resolve)(metaDir, META_FILENAME);
|
|
353
|
-
try {
|
|
354
|
-
const json = await readJSON(path);
|
|
355
|
-
assignValues(json, {
|
|
356
|
-
key,
|
|
357
|
-
version,
|
|
358
|
-
apps,
|
|
359
|
-
openapi
|
|
360
|
-
});
|
|
361
|
-
await writeJSON(path, json);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
function writeApps(appsDir, options) {
|
|
367
|
-
const { key, apps = [], openapi } = options;
|
|
368
|
-
if (!(0, import_node_fs3.existsSync)(appsDir)) {
|
|
369
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
try {
|
|
373
|
-
(0, import_node_fs3.readdirSync)(appsDir).forEach((app) => {
|
|
374
|
-
const appPath = (0, import_node_path3.resolve)(appsDir, app);
|
|
375
|
-
const settingPath = (0, import_node_path3.resolve)(appPath, SETTING_FILE_PATH);
|
|
376
|
-
const openapiPath = (0, import_node_path3.resolve)(appPath, OPENAPI_FILE_PATH);
|
|
377
|
-
if (!apps.includes(app)) {
|
|
378
|
-
(0, import_rimraf.rimrafSync)(appPath);
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
rewriteFile(settingPath, (content) => {
|
|
382
|
-
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
|
|
383
|
-
});
|
|
384
|
-
rewriteFile(openapiPath, (content) => {
|
|
385
|
-
return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
} catch (error) {
|
|
389
|
-
import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// src/index.ts
|
|
394
|
-
async function main() {
|
|
395
|
-
const program = new import_commander.Command();
|
|
396
|
-
program.name(package_default.name).description(package_default.description).version(package_default.version);
|
|
397
|
-
program.description("\u521D\u59CB\u5316\u6846\u67B6").action(async () => {
|
|
398
|
-
bootstrop();
|
|
399
|
-
try {
|
|
400
|
-
const answer = await init();
|
|
401
|
-
if (answer.optionsV1) {
|
|
402
|
-
await download(answer.optionsV1);
|
|
403
|
-
await rewrite(answer.optionsV1);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
generate(answer, package_default.version);
|
|
407
|
-
} catch (error) {
|
|
408
|
-
import_consola6.default.error(error);
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
program.parse();
|
|
412
|
-
}
|
|
413
|
-
main();
|