create-pubinfo 2.0.0-beta.9 → 2.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/index.js +352 -306
  2. package/package.json +13 -13
  3. package/templates/pubinfo-template/.browserslistrc +5 -0
  4. package/templates/pubinfo-template/.editorconfig +10 -0
  5. package/templates/pubinfo-template/.env +5 -0
  6. package/templates/pubinfo-template/.env.development +6 -0
  7. package/templates/pubinfo-template/.env.production +10 -0
  8. package/templates/pubinfo-template/_gitignore +37 -0
  9. package/templates/pubinfo-template/_npmrc +5 -0
  10. package/templates/pubinfo-template/eslint.config.ts +3 -0
  11. package/templates/pubinfo-template/index.html +47 -0
  12. package/templates/pubinfo-template/openapi.config.ts +33 -0
  13. package/templates/pubinfo-template/package.json +52 -0
  14. package/templates/pubinfo-template/pubinfo.config.ts +9 -0
  15. package/templates/pubinfo-template/public/browser_upgrade/chrome.png +0 -0
  16. package/templates/pubinfo-template/public/browser_upgrade/edge.png +0 -0
  17. package/templates/pubinfo-template/public/browser_upgrade/index.css +49 -0
  18. package/templates/pubinfo-template/public/loading.css +92 -0
  19. package/templates/pubinfo-template/src/App.vue +7 -0
  20. package/templates/pubinfo-template/src/api/modules/auth/index.ts +3 -0
  21. package/templates/pubinfo-template/src/api/modules/auth/renzhengfuwu.ts +145 -0
  22. package/templates/pubinfo-template/src/api/modules/auth/typings.d.ts +97 -0
  23. package/templates/pubinfo-template/src/api/request.ts +125 -0
  24. package/templates/pubinfo-template/src/assets/icons/logo.svg +1 -0
  25. package/templates/pubinfo-template/src/assets/icons/process-management.svg +1 -0
  26. package/templates/pubinfo-template/src/assets/icons/workbench.svg +1 -0
  27. package/templates/pubinfo-template/src/assets/images/login-bg.webp +0 -0
  28. package/templates/pubinfo-template/src/assets/images/login-bg_dark.webp +0 -0
  29. package/templates/pubinfo-template/src/assets/images/login-small.png +0 -0
  30. package/templates/pubinfo-template/src/assets/images/login-small_dark.webp +0 -0
  31. package/templates/pubinfo-template/src/components/UIProvider/index.vue +51 -0
  32. package/templates/pubinfo-template/src/layouts/index.vue +38 -0
  33. package/templates/pubinfo-template/src/main.ts +22 -0
  34. package/templates/pubinfo-template/src/modules/auth.ts +20 -0
  35. package/templates/pubinfo-template/src/modules/rbac.ts +10 -0
  36. package/templates/pubinfo-template/src/routes/index.ts +71 -0
  37. package/templates/pubinfo-template/src/routes/modules/demo/breadcrumb.example.ts +62 -0
  38. package/templates/pubinfo-template/src/routes/modules/demo/link.ts +15 -0
  39. package/templates/pubinfo-template/src/routes/modules/demo/multilevel.menu.example.ts +68 -0
  40. package/templates/pubinfo-template/src/routes/modules/demo/other.page.ts +37 -0
  41. package/templates/pubinfo-template/src/routes/modules/demo/single.ts +14 -0
  42. package/templates/pubinfo-template/src/settings.ts +8 -0
  43. package/templates/pubinfo-template/src/stores/index.ts +2 -0
  44. package/templates/pubinfo-template/src/stores/modules/conter.ts +16 -0
  45. package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail1.vue +11 -0
  46. package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail2.vue +11 -0
  47. package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list1.vue +11 -0
  48. package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list2.vue +11 -0
  49. package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +11 -0
  50. package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +11 -0
  51. package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/page.vue +11 -0
  52. package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/page.vue +11 -0
  53. package/templates/pubinfo-template/src/views/demo/other_page/des.vue +13 -0
  54. package/templates/pubinfo-template/src/views/demo/other_page/index.vue +25 -0
  55. package/templates/pubinfo-template/src/views/demo/preview-empty/index.vue +17 -0
  56. package/templates/pubinfo-template/src/views/demo/single/index.vue +13 -0
  57. package/templates/pubinfo-template/src/views/system/index.vue +5 -0
  58. package/templates/pubinfo-template/src/views/system/login/components/LoginForm.vue +29 -0
  59. package/templates/pubinfo-template/src/views/system/login/components/LoginWithPhone.vue +213 -0
  60. package/templates/pubinfo-template/src/views/system/login/components/PasswordLogin.vue +194 -0
  61. package/templates/pubinfo-template/src/views/system/login/components/Savephone.vue +17 -0
  62. package/templates/pubinfo-template/src/views/system/login/components/Useragreement.vue +26 -0
  63. package/templates/pubinfo-template/src/views/system/login/composables.ts +84 -0
  64. package/templates/pubinfo-template/src/views/system/login/index.vue +142 -0
  65. package/templates/pubinfo-template/stylelint.config.js +3 -0
  66. package/templates/pubinfo-template/tsconfig.json +3 -0
  67. package/templates/pubinfo-template/uno.config.ts +17 -0
  68. package/dist/index.cjs +0 -364
package/dist/index.js CHANGED
@@ -1,342 +1,388 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/index.ts
4
2
  import { Command } from "commander";
5
- import consola6 from "consola";
3
+ import consola from "consola";
4
+ import fs, { existsSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
5
+ import { dirname, resolve } from "node:path";
6
+ import process, { cwd } from "node:process";
7
+ import { fileURLToPath } from "node:url";
8
+ import { readFile, writeFile } from "node:fs/promises";
9
+ import { parseJSON, parseJSONC, stringifyJSON } from "confbox";
10
+ import { checkbox, confirm, input, select } from "@inquirer/prompts";
11
+ import colors from "ansi-colors";
12
+ import { ofetch } from "ofetch";
13
+ import ora from "ora";
14
+ import { coerce, compare } from "semver";
15
+ import fonts from "cfonts";
16
+ import { downloadTemplate } from "giget";
17
+ import { rimrafSync } from "rimraf";
6
18
 
7
- // package.json
19
+ //#region package.json
20
+ var name = "create-pubinfo";
21
+ var type = "module";
22
+ var version = "2.0.0-rc.2";
23
+ var description = "初始化项目框架";
24
+ var author = "Werheng <werheng.zhang@gmail.com>";
25
+ var license = "MIT";
26
+ var bin = { "pubinfo": "./dist/index.js" };
27
+ var files = ["dist", "templates"];
28
+ var scripts = {
29
+ "dev": "tsdown --watch src",
30
+ "build": "tsdown",
31
+ "cli": "node dist/index.js",
32
+ "cli:clean": "rimraf ./my-app",
33
+ "lint": "eslint . --cache --fix"
34
+ };
35
+ var dependencies = {
36
+ "@inquirer/prompts": "catalog:node",
37
+ "ansi-colors": "catalog:node",
38
+ "cfonts": "catalog:node",
39
+ "commander": "catalog:node",
40
+ "confbox": "catalog:node",
41
+ "consola": "catalog:browser",
42
+ "giget": "catalog:node",
43
+ "ofetch": "catalog:http",
44
+ "ora": "catalog:node",
45
+ "rimraf": "catalog:node",
46
+ "semver": "catalog:node"
47
+ };
48
+ var devDependencies = { "@types/node": "catalog:ts" };
8
49
  var package_default = {
9
- name: "create-pubinfo",
10
- type: "module",
11
- version: "2.0.0-beta.9",
12
- description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
13
- author: "Werheng <werheng.zhang@gmail.com>",
14
- license: "MIT",
15
- bin: {
16
- pubinfo: "./dist/index.js"
17
- },
18
- files: [
19
- "dist"
20
- ],
21
- scripts: {
22
- dev: "tsup --watch src",
23
- build: "tsup",
24
- cli: "tsx src/index.ts",
25
- "cli:clean": "rimraf ./my-app",
26
- lint: "eslint . --cache --fix"
27
- },
28
- dependencies: {
29
- "@inquirer/prompts": "^5.5.0",
30
- "ansi-colors": "^4.1.3",
31
- cfonts: "^3.3.0",
32
- commander: "^12.1.0",
33
- confbox: "^0.1.8",
34
- consola: "^3.4.0",
35
- giget: "^1.2.5",
36
- ofetch: "^1.4.1",
37
- ora: "^8.2.0",
38
- rimraf: "^6.0.1",
39
- semver: "^7.7.1"
40
- },
41
- devDependencies: {
42
- "@types/node": "^22.13.9",
43
- tsup: "^8.4.0"
44
- }
50
+ name,
51
+ type,
52
+ version,
53
+ description,
54
+ author,
55
+ license,
56
+ bin,
57
+ files,
58
+ scripts,
59
+ dependencies,
60
+ devDependencies
45
61
  };
46
62
 
47
- // src/command/init.ts
48
- import { existsSync as existsSync2 } from "node:fs";
49
- import process2 from "node:process";
50
- import { checkbox, confirm, input } from "@inquirer/prompts";
51
- import colors from "ansi-colors";
52
- import consola3 from "consola";
53
-
54
- // src/constant.ts
55
- var REMOTE_URL = "http://43.143.107.174:80/templates";
56
- var PKG_NAME = "monorepo-project-template";
57
- var VERSION_FILE = "version.json";
58
- var SETTING_FILE_PATH = "src/settings.default.ts";
59
- var OPENAPI_FILE_PATH = "openapi.config.ts";
60
- var APPS_DIR = "apps";
61
- var APPS = [
62
- { name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
63
- // { name: '初始化项目模板(admin)', value: 'admin' },
64
- ];
65
- var METADATA_DIR = "configs/metadata";
66
- var META_FILENAME = "pubinfo.json";
67
-
68
- // src/fetch.ts
69
- import process from "node:process";
70
- import consola from "consola";
71
- import { ofetch } from "ofetch";
72
- import ora from "ora";
73
- import { compare } from "semver";
74
- async function fetchVersion() {
75
- const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
76
- versions.sort((v1, v2) => -compare(v1, v2));
77
- return {
78
- latest: versions[0],
79
- list: versions
80
- };
63
+ //#endregion
64
+ //#region src/utils.ts
65
+ /**
66
+ * 重写文件内容
67
+ */
68
+ function rewriteFile(path, fn) {
69
+ if (!existsSync(path)) {
70
+ consola.error(`RewriteFile fail: ${path} does not exist`);
71
+ return;
72
+ }
73
+ try {
74
+ const content = readFileSync(path, { encoding: "utf-8" });
75
+ writeFileSync(path, fn(content));
76
+ } catch (error) {
77
+ consola.error(`RewriteFile fail: ${error}`);
78
+ }
81
79
  }
82
- async function fetchData() {
83
- const spinner = ora({
84
- text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
85
- color: "blue"
86
- });
87
- spinner.start();
88
- try {
89
- const version = await fetchVersion();
90
- return {
91
- version
92
- };
93
- } catch (error) {
94
- if (error.message.includes(REMOTE_URL)) {
95
- error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
96
- }
97
- consola.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
98
- process.exit(1);
99
- } finally {
100
- spinner.stop();
101
- }
80
+ function copyDir(srcDir, destDir) {
81
+ fs.mkdirSync(destDir, { recursive: true });
82
+ for (const file of fs.readdirSync(srcDir)) {
83
+ const srcFile = resolve(srcDir, file);
84
+ const destFile = resolve(destDir, file);
85
+ copy(srcFile, destFile);
86
+ }
102
87
  }
103
-
104
- // src/utils.ts
105
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
106
- import { readFile, writeFile } from "node:fs/promises";
107
- import { parseJSON, parseJSONC, stringifyJSON } from "confbox";
108
- import consola2 from "consola";
109
- function rewriteFile(path, fn) {
110
- if (!existsSync(path)) {
111
- consola2.error(`RewriteFile fail: ${path} does not exist`);
112
- return;
113
- }
114
- try {
115
- const content = readFileSync(path, { encoding: "utf-8" });
116
- writeFileSync(path, fn(content));
117
- } catch (error) {
118
- consola2.error(`RewriteFile fail: ${error}`);
119
- }
88
+ function copy(src, dest) {
89
+ const stat = fs.statSync(src);
90
+ if (stat.isDirectory()) copyDir(src, dest);
91
+ else fs.copyFileSync(src, dest);
120
92
  }
121
93
  async function readJSON(path) {
122
- const blob = await readFile(path, "utf-8");
123
- let parsed;
124
- try {
125
- parsed = parseJSON(blob);
126
- } catch {
127
- parsed = parseJSONC(blob);
128
- }
129
- return parsed;
94
+ const blob = await readFile(path, "utf-8");
95
+ let parsed;
96
+ try {
97
+ parsed = parseJSON(blob);
98
+ } catch {
99
+ parsed = parseJSONC(blob);
100
+ }
101
+ return parsed;
130
102
  }
131
103
  async function writeJSON(path, json) {
132
- await writeFile(path, stringifyJSON(json));
104
+ await writeFile(path, stringifyJSON(json));
133
105
  }
134
106
  function assignValues(target, source) {
135
- for (const [key, value] of Object.entries(source)) {
136
- target[key] = value;
137
- }
107
+ for (const [key, value] of Object.entries(source)) target[key] = value;
108
+ }
109
+ function validateInput(input$1) {
110
+ const forbiddenChars = /[<>:"/\\|?*\s]/;
111
+ if (forbiddenChars.test(input$1)) return "错误提示: 该值不能包含空格或者非法字符 (例如, <>:\"/\\|?*).";
112
+ return true;
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/core/generate.ts
117
+ const __dirname = dirname(fileURLToPath(import.meta.url));
118
+ function generate(options, version$1) {
119
+ const root = cwd();
120
+ const templateDir = resolve(__dirname, "../templates", `pubinfo-template`);
121
+ const targetPath = resolve(root, options.dir);
122
+ copy(templateDir, targetPath);
123
+ rewriteFile(resolve(targetPath, "src/settings.ts"), (content) => {
124
+ return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${options.key}'`);
125
+ });
126
+ rewriteFile(resolve(targetPath, "openapi.config.ts"), (content) => {
127
+ return content.replace(/enabled:[^,]+,/g, `enabled: ${options.openapi},`);
128
+ });
129
+ rewriteFile(resolve(targetPath, "package.json"), (content) => {
130
+ const pattern = /"(@?pubinfo(?:\/module-(?:auth|rbac))?)":\s*"[^"]+"/g;
131
+ return content.replace(pattern, (_match, pkgName) => {
132
+ return `"${pkgName}": "${version$1}"`;
133
+ });
134
+ });
135
+ const renameFiles = {
136
+ _gitignore: ".gitignore",
137
+ _npmrc: ".npmrc"
138
+ };
139
+ for (const [oldName, newName] of Object.entries(renameFiles)) {
140
+ const oldPath = resolve(targetPath, oldName);
141
+ const newPath = resolve(targetPath, newName || oldName);
142
+ renameSync(oldPath, newPath);
143
+ }
138
144
  }
139
- function validateInput(input2) {
140
- const forbiddenChars = /[<>:"/\\|?*\s]/;
141
- if (forbiddenChars.test(input2)) {
142
- return '\u9519\u8BEF\u63D0\u793A: \u8BE5\u503C\u4E0D\u80FD\u5305\u542B\u7A7A\u683C\u6216\u8005\u975E\u6CD5\u5B57\u7B26 (\u4F8B\u5982, <>:"/\\|?*).';
143
- }
144
- return true;
145
+
146
+ //#endregion
147
+ //#region src/v1/constant.ts
148
+ const REMOTE_URL = "http://106.53.74.49:20000/templates";
149
+ const PKG_NAME = "monorepo-project-template";
150
+ const VERSION_FILE = "version.json";
151
+ const SETTING_FILE_PATH = "src/settings.default.ts";
152
+ const OPENAPI_FILE_PATH = "openapi.config.ts";
153
+ const APPS_DIR = "apps";
154
+ const APPS = [{
155
+ name: "用户权限系统(rbac)",
156
+ value: "rbac"
157
+ }];
158
+ const METADATA_DIR = "configs/metadata";
159
+ const META_FILENAME = "pubinfo.json";
160
+
161
+ //#endregion
162
+ //#region src/v1/fetch.ts
163
+ async function fetchVersion() {
164
+ const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
165
+ versions.sort((v1, v2) => -compare(v1, v2));
166
+ return {
167
+ latest: versions[0],
168
+ list: versions
169
+ };
170
+ }
171
+ async function fetchData() {
172
+ const spinner = ora({
173
+ text: "检测网络连接...",
174
+ color: "blue"
175
+ });
176
+ spinner.start();
177
+ try {
178
+ const version$1 = await fetchVersion();
179
+ return { version: version$1 };
180
+ } catch (error) {
181
+ if (error.message.includes(REMOTE_URL)) error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
182
+ consola.error(`网络连接异常: ${error.message}`);
183
+ process.exit(1);
184
+ } finally {
185
+ spinner.stop();
186
+ }
145
187
  }
146
188
 
147
- // src/command/init.ts
189
+ //#endregion
190
+ //#region src/core/init.ts
148
191
  async function init() {
149
- const { version } = await fetchData();
150
- const answer = {};
151
- try {
152
- answer.dir = await input({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
153
- answer.key = await input({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
154
- if (existsSync2(answer.dir)) {
155
- const overwrite = await confirm({ message: `\u76EE\u5F55 ${colors.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
156
- if (!overwrite) {
157
- throw Error;
158
- }
159
- }
160
- answer.version = await input({
161
- message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
162
- default: version.latest,
163
- validate: (input2) => {
164
- if (!version.list.includes(input2)) {
165
- return `\u7248\u672C\u53F7: ${colors.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${colors.bold(version.latest)}.`;
166
- }
167
- return true;
168
- }
169
- });
170
- answer.apps = await checkbox({
171
- message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
172
- choices: APPS,
173
- validate: (input2) => {
174
- if (input2.length === 0) {
175
- return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
176
- }
177
- return true;
178
- }
179
- });
180
- answer.openapi = await confirm({
181
- 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",
182
- default: false
183
- });
184
- return answer;
185
- } catch {
186
- consola3.fail("\u64CD\u4F5C\u7EC8\u6B62");
187
- process2.exit(1);
188
- }
192
+ try {
193
+ const answer = {};
194
+ answer.dir = await input({
195
+ message: "目录名称(dir)",
196
+ default: "my-app",
197
+ validate: validateInput
198
+ });
199
+ answer.key = await input({
200
+ message: "项目标识(key)",
201
+ default: answer.dir,
202
+ validate: validateInput
203
+ });
204
+ if (existsSync(answer.dir)) {
205
+ const overwrite = await confirm({ message: `目录 ${colors.cyan(answer.dir)} 已存在,是否覆盖?` });
206
+ if (!overwrite) throw Error;
207
+ }
208
+ answer.openapi = await confirm({
209
+ message: "运行时自动生成接口对接文件,若关闭可通过指令生成(openapi)",
210
+ default: false
211
+ });
212
+ const V1orV2 = await select({
213
+ message: "使用 v1 or v2 版本?",
214
+ default: "v2",
215
+ choices: ["v1", "v2"]
216
+ });
217
+ const isV1 = V1orV2 === "v1";
218
+ if (isV1) {
219
+ const { version: version$1 } = await fetchData();
220
+ answer.optionsV1 = JSON.parse(JSON.stringify(answer));
221
+ answer.optionsV1.version = await select({
222
+ message: "框架版本号(version)",
223
+ default: version$1.latest,
224
+ choices: version$1.list
225
+ });
226
+ answer.optionsV1.apps = await checkbox({
227
+ message: "选择应用模块(apps)",
228
+ choices: APPS,
229
+ validate: (input$1) => {
230
+ if (input$1.length === 0) return "请至少选择一个应用";
231
+ return true;
232
+ }
233
+ });
234
+ }
235
+ return answer;
236
+ } catch {
237
+ consola.fail("操作终止");
238
+ process.exit(1);
239
+ }
189
240
  }
190
241
 
191
- // src/download.ts
192
- import process3 from "node:process";
193
- import colors2 from "ansi-colors";
194
- import consola4 from "consola";
195
- import { downloadTemplate } from "giget";
196
- import ora2 from "ora";
197
- import { coerce } from "semver";
198
- var pubinfo = async (input2, { auth }) => {
199
- const semver = coerce(input2);
200
- return {
201
- name: "pubinfo",
202
- version: input2,
203
- headers: { Authorization: `token ${auth}` },
204
- tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
205
- };
242
+ //#endregion
243
+ //#region src/log.ts
244
+ function bootstrop() {
245
+ printLoGo("PUBINFO");
246
+ function printLoGo(logo) {
247
+ fonts.say(logo, {
248
+ font: "simple3d",
249
+ align: "left",
250
+ background: "transparent",
251
+ letterSpacing: 1,
252
+ lineHeight: 1,
253
+ space: true,
254
+ maxLength: 0,
255
+ spaceless: false,
256
+ gradient: ["blue", "magenta"],
257
+ independentGradient: false,
258
+ transitionGradient: false,
259
+ env: "node"
260
+ });
261
+ }
262
+ }
263
+
264
+ //#endregion
265
+ //#region src/v1/download.ts
266
+ const pubinfo = async (input$1, { auth }) => {
267
+ const semver = coerce(input$1);
268
+ return {
269
+ name: "pubinfo",
270
+ version: input$1,
271
+ headers: { Authorization: `token ${auth}` },
272
+ tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
273
+ };
206
274
  };
207
275
  async function download(options) {
208
- const finish = loading();
209
- try {
210
- await downloadTemplate(`pubinfo:${PKG_NAME}-${options.version}`, {
211
- providers: { pubinfo },
212
- force: true,
213
- forceClean: true,
214
- // auth: options.auth,
215
- dir: options.dir
216
- });
217
- } catch (error) {
218
- if (error.message.includes(REMOTE_URL)) {
219
- error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
220
- }
221
- consola4.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
222
- process3.exit(1);
223
- } finally {
224
- finish();
225
- }
276
+ const finish = loading();
277
+ try {
278
+ await downloadTemplate(`pubinfo:${PKG_NAME}-${options.version}`, {
279
+ providers: { pubinfo },
280
+ force: true,
281
+ forceClean: true,
282
+ dir: options.dir
283
+ });
284
+ } catch (error) {
285
+ if (error.message.includes(REMOTE_URL)) error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
286
+ consola.error(`下载失败: ${error.message}`);
287
+ process.exit(1);
288
+ } finally {
289
+ finish();
290
+ }
226
291
  }
227
292
  function loading() {
228
- const startTime = Date.now();
229
- const spinner = ora2({
230
- text: "\u4E0B\u8F7D\u4E2D...",
231
- color: "green"
232
- });
233
- spinner.start();
234
- return () => {
235
- const { green, yellow } = colors2;
236
- spinner.stop();
237
- consola4.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
238
- };
239
- }
240
-
241
- // src/log.ts
242
- import fonts from "cfonts";
243
- function bootstrop() {
244
- printLoGo("PUBINFO");
245
- function printLoGo(logo) {
246
- fonts.say(logo, {
247
- font: "simple3d",
248
- align: "left",
249
- background: "transparent",
250
- letterSpacing: 1,
251
- lineHeight: 1,
252
- space: true,
253
- maxLength: 0,
254
- spaceless: false,
255
- gradient: ["blue", "magenta"],
256
- independentGradient: false,
257
- transitionGradient: false,
258
- env: "node"
259
- });
260
- }
293
+ const startTime = Date.now();
294
+ const spinner = ora({
295
+ text: "下载中...",
296
+ color: "green"
297
+ });
298
+ spinner.start();
299
+ return () => {
300
+ const { green, yellow } = colors;
301
+ spinner.stop();
302
+ consola.success(`${green("下载完成, 用时")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
303
+ };
261
304
  }
262
305
 
263
- // src/rewrite.ts
264
- import { existsSync as existsSync3, readdirSync } from "node:fs";
265
- import { resolve } from "node:path";
266
- import process4 from "node:process";
267
- import consola5 from "consola";
268
- import { rimrafSync } from "rimraf";
306
+ //#endregion
307
+ //#region src/v1/rewrite.ts
269
308
  async function rewrite(options) {
270
- const { dir } = options;
271
- const root = process4.cwd();
272
- const projectDir = resolve(root, dir);
273
- writeMetaJSON(resolve(projectDir, METADATA_DIR), options);
274
- writeApps(resolve(projectDir, APPS_DIR), options);
309
+ const { dir } = options;
310
+ const root = process.cwd();
311
+ const projectDir = resolve(root, dir);
312
+ writeMetaJSON(resolve(projectDir, METADATA_DIR), options);
313
+ writeApps(resolve(projectDir, APPS_DIR), options);
275
314
  }
315
+ /**
316
+ * 写入项目整体配置
317
+ */
276
318
  async function writeMetaJSON(metaDir, options) {
277
- const { key, version, apps, openapi } = options;
278
- const path = resolve(metaDir, META_FILENAME);
279
- try {
280
- const json = await readJSON(path);
281
- assignValues(json, {
282
- key,
283
- version,
284
- apps,
285
- openapi
286
- });
287
- await writeJSON(path, json);
288
- } catch (error) {
289
- consola5.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
290
- }
319
+ const { key, version: version$1, apps, openapi } = options;
320
+ const path = resolve(metaDir, META_FILENAME);
321
+ try {
322
+ const json = await readJSON(path);
323
+ assignValues(json, {
324
+ key,
325
+ version: version$1,
326
+ apps,
327
+ openapi
328
+ });
329
+ await writeJSON(path, json);
330
+ } catch (error) {
331
+ consola.error(`初始化 metadata 失败: ${error}`);
332
+ }
291
333
  }
334
+ /**
335
+ * 处理目录 `/apps` 下的各个应用
336
+ */
292
337
  function writeApps(appsDir, options) {
293
- const { key, apps = [], openapi } = options;
294
- if (!existsSync3(appsDir)) {
295
- consola5.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
296
- return;
297
- }
298
- try {
299
- readdirSync(appsDir).forEach((app) => {
300
- const appPath = resolve(appsDir, app);
301
- const settingPath = resolve(appPath, SETTING_FILE_PATH);
302
- const openapiPath = resolve(appPath, OPENAPI_FILE_PATH);
303
- if (!apps.includes(app)) {
304
- rimrafSync(appPath);
305
- return;
306
- }
307
- rewriteFile(settingPath, (content) => {
308
- return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
309
- });
310
- rewriteFile(openapiPath, (content) => {
311
- return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
312
- });
313
- });
314
- } catch (error) {
315
- consola5.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
316
- }
338
+ const { key, apps = [], openapi } = options;
339
+ if (!existsSync(appsDir)) {
340
+ consola.error(`初始化 apps 失败: ${appsDir} 不存在`);
341
+ return;
342
+ }
343
+ try {
344
+ readdirSync(appsDir).forEach((app) => {
345
+ const appPath = resolve(appsDir, app);
346
+ const settingPath = resolve(appPath, SETTING_FILE_PATH);
347
+ const openapiPath = resolve(appPath, OPENAPI_FILE_PATH);
348
+ if (!apps.includes(app)) {
349
+ rimrafSync(appPath);
350
+ return;
351
+ }
352
+ rewriteFile(settingPath, (content) => {
353
+ return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
354
+ });
355
+ rewriteFile(openapiPath, (content) => {
356
+ return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
357
+ });
358
+ });
359
+ } catch (error) {
360
+ consola.error(`初始化 apps 失败: ${error}`);
361
+ }
317
362
  }
318
363
 
319
- // src/index.ts
364
+ //#endregion
365
+ //#region src/index.ts
320
366
  async function main() {
321
- const program = new Command();
322
- program.name(package_default.name).description(package_default.description).version(package_default.version);
323
- program.description("\u521D\u59CB\u5316\u6846\u67B6").action(async () => {
324
- bootstrop();
325
- try {
326
- const answer = await init();
327
- await download(answer);
328
- await rewrite(answer);
329
- } catch (error) {
330
- consola6.error(error);
331
- }
332
- });
333
- program.command("create").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684\u5E94\u7528").argument("<app-name>", "\u5E94\u7528\u540D\u79F0").action((name) => {
334
- consola6.info("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684\u5E94\u7528", name);
335
- });
336
- program.command("status").description("\u67E5\u770B\u6846\u67B6\u72B6\u6001").action(() => {
337
- });
338
- program.command("update").description("\u66F4\u65B0\u6846\u67B6\u7248\u672C").action(() => {
339
- });
340
- program.parse();
367
+ const program = new Command();
368
+ program.name(package_default.name).description(package_default.description).version(package_default.version);
369
+ program.description("初始化框架").action(async () => {
370
+ bootstrop();
371
+ try {
372
+ const answer = await init();
373
+ if (answer.optionsV1) {
374
+ await download(answer.optionsV1);
375
+ await rewrite(answer.optionsV1);
376
+ return;
377
+ }
378
+ generate(answer, package_default.version);
379
+ } catch (error) {
380
+ consola.error(error);
381
+ }
382
+ });
383
+ program.parse();
341
384
  }
342
385
  main();
386
+
387
+ //#endregion
388
+ export { };