create-pubinfo 2.0.0-rc.3 → 2.0.0-rc.5

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 (139) hide show
  1. package/dist/index.js +201 -157
  2. package/package.json +5 -1
  3. package/templates/{pubinfo-template → pubinfo-app}/.env +0 -3
  4. package/templates/{pubinfo-template → pubinfo-app}/_gitignore +1 -0
  5. package/templates/{pubinfo-template/openapi.config.ts → pubinfo-app/openapi.config.ts.hbs} +1 -1
  6. package/templates/{pubinfo-template/package.json → pubinfo-app/package.json.hbs} +12 -7
  7. package/templates/pubinfo-app/src/settings.ts.hbs +8 -0
  8. package/templates/pubinfo-module/.editorconfig +10 -0
  9. package/templates/pubinfo-module/README.md.hbs +27 -0
  10. package/templates/pubinfo-module/_gitignore +38 -0
  11. package/templates/pubinfo-module/_npmrc +5 -0
  12. package/templates/pubinfo-module/eslint.config.ts +3 -0
  13. package/templates/pubinfo-module/package.json.hbs +67 -0
  14. package/templates/pubinfo-module/playground/.env +2 -0
  15. package/templates/pubinfo-module/playground/.env.development +6 -0
  16. package/templates/pubinfo-module/playground/.env.production +10 -0
  17. package/templates/pubinfo-module/playground/index.html +47 -0
  18. package/templates/pubinfo-module/playground/openapi.config.ts.hbs +33 -0
  19. package/templates/pubinfo-module/playground/package.json.hbs +22 -0
  20. package/templates/pubinfo-module/playground/pubinfo.config.ts +9 -0
  21. package/templates/pubinfo-module/playground/public/browser_upgrade/chrome.png +0 -0
  22. package/templates/pubinfo-module/playground/public/browser_upgrade/edge.png +0 -0
  23. package/templates/pubinfo-module/playground/public/browser_upgrade/index.css +49 -0
  24. package/templates/pubinfo-module/playground/public/loading.css +92 -0
  25. package/templates/pubinfo-module/playground/src/App.vue +7 -0
  26. package/templates/pubinfo-module/playground/src/api/modules/auth/index.ts +3 -0
  27. package/templates/pubinfo-module/playground/src/api/modules/auth/renzhengfuwu.ts +145 -0
  28. package/templates/pubinfo-module/playground/src/api/modules/auth/typings.d.ts +97 -0
  29. package/templates/pubinfo-module/playground/src/api/request.ts +125 -0
  30. package/templates/pubinfo-module/playground/src/assets/icons/logo.svg +1 -0
  31. package/templates/pubinfo-module/playground/src/assets/icons/process-management.svg +1 -0
  32. package/templates/pubinfo-module/playground/src/assets/icons/workbench.svg +1 -0
  33. package/templates/pubinfo-module/playground/src/assets/images/login-bg.webp +0 -0
  34. package/templates/pubinfo-module/playground/src/assets/images/login-bg_dark.webp +0 -0
  35. package/templates/pubinfo-module/playground/src/assets/images/login-small.png +0 -0
  36. package/templates/pubinfo-module/playground/src/assets/images/login-small_dark.webp +0 -0
  37. package/templates/pubinfo-module/playground/src/components/UIProvider/index.vue +51 -0
  38. package/templates/pubinfo-module/playground/src/layouts/index.vue +44 -0
  39. package/templates/pubinfo-module/playground/src/main.ts.hbs +24 -0
  40. package/templates/pubinfo-module/playground/src/modules/auth.ts +20 -0
  41. package/templates/pubinfo-module/playground/src/modules/rbac.ts +10 -0
  42. package/templates/pubinfo-module/playground/src/routes/index.ts +71 -0
  43. package/templates/pubinfo-module/playground/src/routes/modules/demo/breadcrumb.example.ts +62 -0
  44. package/templates/pubinfo-module/playground/src/routes/modules/demo/link.ts +15 -0
  45. package/templates/pubinfo-module/playground/src/routes/modules/demo/multilevel.menu.example.ts +68 -0
  46. package/templates/pubinfo-module/playground/src/routes/modules/demo/other.page.ts +37 -0
  47. package/templates/pubinfo-module/playground/src/routes/modules/demo/single.ts +14 -0
  48. package/templates/{pubinfo-template → pubinfo-module/playground}/src/settings.ts +1 -1
  49. package/templates/pubinfo-module/playground/src/stores/index.ts +2 -0
  50. package/templates/pubinfo-module/playground/src/stores/modules/conter.ts +16 -0
  51. package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/detail1.vue +11 -0
  52. package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/detail2.vue +11 -0
  53. package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/list1.vue +11 -0
  54. package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/list2.vue +11 -0
  55. package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +11 -0
  56. package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +11 -0
  57. package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/page.vue +11 -0
  58. package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/page.vue +11 -0
  59. package/templates/pubinfo-module/playground/src/views/demo/other_page/des.vue +13 -0
  60. package/templates/pubinfo-module/playground/src/views/demo/other_page/index.vue +25 -0
  61. package/templates/pubinfo-module/playground/src/views/demo/preview-empty/index.vue +17 -0
  62. package/templates/pubinfo-module/playground/src/views/demo/single/index.vue +13 -0
  63. package/templates/pubinfo-module/playground/src/views/system/index.vue +5 -0
  64. package/templates/pubinfo-module/playground/src/views/system/login/components/LoginForm.vue +29 -0
  65. package/templates/pubinfo-module/playground/src/views/system/login/components/LoginWithPhone.vue +213 -0
  66. package/templates/pubinfo-module/playground/src/views/system/login/components/PasswordLogin.vue +194 -0
  67. package/templates/pubinfo-module/playground/src/views/system/login/components/Savephone.vue +17 -0
  68. package/templates/pubinfo-module/playground/src/views/system/login/components/Useragreement.vue +26 -0
  69. package/templates/pubinfo-module/playground/src/views/system/login/composables.ts +84 -0
  70. package/templates/pubinfo-module/playground/src/views/system/login/index.vue +142 -0
  71. package/templates/pubinfo-module/playground/tsconfig.json +3 -0
  72. package/templates/pubinfo-module/playground/uno.config.ts +17 -0
  73. package/templates/pubinfo-module/pnpm-workspace.yaml +2 -0
  74. package/templates/pubinfo-module/pubinfo.config.ts.hbs +36 -0
  75. package/templates/pubinfo-module/src/index.ts.hbs +9 -0
  76. package/templates/pubinfo-module/src/pages/demo.vue +11 -0
  77. package/templates/pubinfo-module/stylelint.config.js +3 -0
  78. package/templates/pubinfo-module/tsconfig.json +16 -0
  79. package/templates/pubinfo-module/uno.config.ts +8 -0
  80. package/templates/{pubinfo-template → pubinfo-app}/.browserslistrc +0 -0
  81. package/templates/{pubinfo-template → pubinfo-app}/.editorconfig +0 -0
  82. package/templates/{pubinfo-template → pubinfo-app}/.env.development +0 -0
  83. package/templates/{pubinfo-template → pubinfo-app}/.env.production +0 -0
  84. package/templates/{pubinfo-template → pubinfo-app}/_npmrc +0 -0
  85. package/templates/{pubinfo-template → pubinfo-app}/eslint.config.ts +0 -0
  86. package/templates/{pubinfo-template → pubinfo-app}/index.html +0 -0
  87. package/templates/{pubinfo-template → pubinfo-app}/pubinfo.config.ts +0 -0
  88. package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/chrome.png +0 -0
  89. package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/edge.png +0 -0
  90. package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/index.css +0 -0
  91. package/templates/{pubinfo-template → pubinfo-app}/public/loading.css +0 -0
  92. package/templates/{pubinfo-template → pubinfo-app}/src/App.vue +0 -0
  93. package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/index.ts +0 -0
  94. package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/renzhengfuwu.ts +0 -0
  95. package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/typings.d.ts +0 -0
  96. package/templates/{pubinfo-template → pubinfo-app}/src/api/request.ts +0 -0
  97. package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/logo.svg +0 -0
  98. package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/process-management.svg +0 -0
  99. package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/workbench.svg +0 -0
  100. package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-bg.webp +0 -0
  101. package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-bg_dark.webp +0 -0
  102. package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-small.png +0 -0
  103. package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-small_dark.webp +0 -0
  104. package/templates/{pubinfo-template → pubinfo-app}/src/components/UIProvider/index.vue +0 -0
  105. package/templates/{pubinfo-template → pubinfo-app}/src/layouts/index.vue +0 -0
  106. package/templates/{pubinfo-template → pubinfo-app}/src/main.ts +0 -0
  107. package/templates/{pubinfo-template → pubinfo-app}/src/modules/auth.ts +0 -0
  108. package/templates/{pubinfo-template → pubinfo-app}/src/modules/rbac.ts +0 -0
  109. package/templates/{pubinfo-template → pubinfo-app}/src/routes/index.ts +0 -0
  110. package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/breadcrumb.example.ts +0 -0
  111. package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/link.ts +0 -0
  112. package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/multilevel.menu.example.ts +0 -0
  113. package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/other.page.ts +0 -0
  114. package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/single.ts +0 -0
  115. package/templates/{pubinfo-template → pubinfo-app}/src/stores/index.ts +0 -0
  116. package/templates/{pubinfo-template → pubinfo-app}/src/stores/modules/conter.ts +0 -0
  117. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/detail1.vue +0 -0
  118. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/detail2.vue +0 -0
  119. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/list1.vue +0 -0
  120. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/list2.vue +0 -0
  121. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +0 -0
  122. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +0 -0
  123. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/page.vue +0 -0
  124. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/page.vue +0 -0
  125. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/other_page/des.vue +0 -0
  126. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/other_page/index.vue +0 -0
  127. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/preview-empty/index.vue +0 -0
  128. package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/single/index.vue +0 -0
  129. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/index.vue +0 -0
  130. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/LoginForm.vue +0 -0
  131. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/LoginWithPhone.vue +0 -0
  132. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/PasswordLogin.vue +0 -0
  133. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/Savephone.vue +0 -0
  134. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/Useragreement.vue +0 -0
  135. package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/composables.ts +1 -1
  136. /package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/index.vue +0 -0
  137. /package/templates/{pubinfo-template → pubinfo-app}/stylelint.config.js +0 -0
  138. /package/templates/{pubinfo-template → pubinfo-app}/tsconfig.json +0 -0
  139. /package/templates/{pubinfo-template → pubinfo-app}/uno.config.ts +0 -0
package/dist/index.js CHANGED
@@ -1,30 +1,32 @@
1
1
  #!/usr/bin/env node
2
+ import { checkbox, confirm, input, select } from "@inquirer/prompts";
2
3
  import { Command } from "commander";
3
4
  import consola from "consola";
4
5
  import fs, { existsSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
5
6
  import { dirname, resolve } from "node:path";
6
7
  import process, { cwd } from "node:process";
7
8
  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
9
  import colors from "ansi-colors";
12
- import { ofetch } from "ofetch";
13
- import ora from "ora";
14
- import { coerce, compare } from "semver";
10
+ import nodePlop from "node-plop";
15
11
  import fonts from "cfonts";
16
12
  import { downloadTemplate } from "giget";
13
+ import ora from "ora";
14
+ import { coerce, compare } from "semver";
15
+ import { ofetch } from "ofetch";
17
16
  import { rimrafSync } from "rimraf";
17
+ import { readFile, writeFile } from "node:fs/promises";
18
+ import { parseJSON, parseJSONC, stringifyJSON } from "confbox";
18
19
 
19
20
  //#region package.json
20
21
  var name = "create-pubinfo";
21
22
  var type = "module";
22
- var version = "2.0.0-rc.3";
23
+ var version = "2.0.0-rc.5";
23
24
  var description = "初始化项目框架";
24
25
  var author = "Werheng <werheng.zhang@gmail.com>";
25
26
  var license = "MIT";
26
27
  var bin = { "pubinfo": "./dist/index.js" };
27
28
  var files = ["dist", "templates"];
29
+ var engines = { "node": "^20.19.0 || >=22.12.0" };
28
30
  var scripts = {
29
31
  "dev": "tsdown --watch src",
30
32
  "build": "tsdown",
@@ -40,6 +42,7 @@ var dependencies = {
40
42
  "confbox": "catalog:node",
41
43
  "consola": "catalog:browser",
42
44
  "giget": "catalog:node",
45
+ "node-plop": "catalog:node",
43
46
  "ofetch": "catalog:http",
44
47
  "ora": "catalog:node",
45
48
  "rimraf": "catalog:node",
@@ -55,6 +58,7 @@ var package_default = {
55
58
  license,
56
59
  bin,
57
60
  files,
61
+ engines,
58
62
  scripts,
59
63
  dependencies,
60
64
  devDependencies
@@ -62,130 +66,11 @@ var package_default = {
62
66
 
63
67
  //#endregion
64
68
  //#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
- }
79
- }
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
- }
87
- }
88
- function copy(src, dest) {
89
- const stat = fs.statSync(src);
90
- if (stat.isDirectory()) copyDir(src, dest);
91
- else fs.copyFileSync(src, dest);
92
- }
93
- async function readJSON(path) {
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;
102
- }
103
- async function writeJSON(path, json) {
104
- await writeFile(path, stringifyJSON(json));
105
- }
106
- function assignValues(target, source) {
107
- for (const [key, value] of Object.entries(source)) target[key] = value;
108
- }
109
69
  function validateInput(input$1) {
110
- const forbiddenChars = /[<>:"/\\|?*\s]/;
111
- if (forbiddenChars.test(input$1)) return "错误提示: 该值不能包含空格或者非法字符 (例如, <>:\"/\\|?*).";
70
+ if (/[<>:"/\\|?*\s]/.test(input$1)) return "错误提示: 该值不能包含空格或者非法字符 (例如, <>:\"/\\|?*).";
112
71
  return true;
113
72
  }
114
73
 
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
- }
144
- }
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
- }
187
- }
188
-
189
74
  //#endregion
190
75
  //#region src/core/init.ts
191
76
  async function init() {
@@ -202,36 +87,23 @@ async function init() {
202
87
  validate: validateInput
203
88
  });
204
89
  if (existsSync(answer.dir)) {
205
- const overwrite = await confirm({ message: `目录 ${colors.cyan(answer.dir)} 已存在,是否覆盖?` });
206
- if (!overwrite) throw Error;
90
+ if (!await confirm({ message: `目录 ${colors.cyan(answer.dir)} 已存在,是否覆盖?` })) throw Error;
207
91
  }
92
+ answer.templateName = await select({
93
+ message: "选择模板类型",
94
+ default: "pubinfo-app",
95
+ choices: [{
96
+ name: "Web应用(app)",
97
+ value: "pubinfo-app"
98
+ }, {
99
+ name: "模块插件(module)",
100
+ value: "pubinfo-module"
101
+ }]
102
+ });
208
103
  answer.openapi = await confirm({
209
104
  message: "运行时自动生成接口对接文件,若关闭可通过指令生成(openapi)",
210
105
  default: false
211
106
  });
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
107
  return answer;
236
108
  } catch {
237
109
  consola.fail("操作终止");
@@ -239,6 +111,60 @@ async function init() {
239
111
  }
240
112
  }
241
113
 
114
+ //#endregion
115
+ //#region src/core/index.ts
116
+ const __dirname = dirname(fileURLToPath(import.meta.url));
117
+ async function generate(version$1) {
118
+ const options = await init();
119
+ const root = cwd();
120
+ const plop = await nodePlop();
121
+ const templateDir = resolve(__dirname, "../templates");
122
+ const destDir = resolve(root, options.dir);
123
+ plop.setGenerator("generate", { actions: () => {
124
+ return [{
125
+ type: "addMany",
126
+ destination: destDir,
127
+ base: resolve(templateDir, options.templateName),
128
+ templateFiles: resolve(templateDir, options.templateName, "**/*.hbs"),
129
+ globOptions: { dot: true }
130
+ }, async function copyRawFiles() {
131
+ const baseDir = resolve(templateDir, options.templateName);
132
+ async function walk(dir) {
133
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
134
+ for (const e of entries) {
135
+ const srcPath = resolve(dir, e.name);
136
+ const rel = srcPath.replace(`${baseDir}/`, "");
137
+ if (e.isDirectory()) {
138
+ await walk(srcPath);
139
+ continue;
140
+ }
141
+ if (e.name.endsWith(".hbs")) continue;
142
+ const targetPath$1 = resolve(destDir, rel);
143
+ await fs.promises.mkdir(resolve(targetPath$1, ".."), { recursive: true });
144
+ await fs.promises.copyFile(srcPath, targetPath$1);
145
+ }
146
+ }
147
+ await walk(baseDir);
148
+ return `Copied raw files from ${options.templateName}`;
149
+ }];
150
+ } });
151
+ await plop.getGenerator("generate").runActions({
152
+ ...options,
153
+ version: version$1
154
+ });
155
+ const renameFiles = {
156
+ _gitignore: ".gitignore",
157
+ _npmrc: ".npmrc"
158
+ };
159
+ const targetPath = resolve(root, options.dir);
160
+ for (const [oldName, newName] of Object.entries(renameFiles)) {
161
+ const oldPath = resolve(targetPath, oldName);
162
+ const newPath = resolve(targetPath, newName || oldName);
163
+ if (existsSync(oldPath)) renameSync(oldPath, newPath);
164
+ }
165
+ consola.success(`${colors.green("项目模板初始化完成.")}`);
166
+ }
167
+
242
168
  //#endregion
243
169
  //#region src/log.ts
244
170
  function bootstrop() {
@@ -261,6 +187,21 @@ function bootstrop() {
261
187
  }
262
188
  }
263
189
 
190
+ //#endregion
191
+ //#region src/v1/constant.ts
192
+ const REMOTE_URL = "http://106.53.74.49:20000/templates";
193
+ const PKG_NAME = "monorepo-project-template";
194
+ const VERSION_FILE = "version.json";
195
+ const SETTING_FILE_PATH = "src/settings.default.ts";
196
+ const OPENAPI_FILE_PATH = "openapi.config.ts";
197
+ const APPS_DIR = "apps";
198
+ const APPS = [{
199
+ name: "用户权限系统(rbac)",
200
+ value: "rbac"
201
+ }];
202
+ const METADATA_DIR = "configs/metadata";
203
+ const META_FILENAME = "pubinfo.json";
204
+
264
205
  //#endregion
265
206
  //#region src/v1/download.ts
266
207
  const pubinfo = async (input$1, { auth }) => {
@@ -303,6 +244,67 @@ function loading() {
303
244
  };
304
245
  }
305
246
 
247
+ //#endregion
248
+ //#region src/v1/fetch.ts
249
+ async function fetchVersion() {
250
+ const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
251
+ versions.sort((v1, v2) => -compare(v1, v2));
252
+ return {
253
+ latest: versions[0],
254
+ list: versions
255
+ };
256
+ }
257
+ async function fetchData() {
258
+ const spinner = ora({
259
+ text: "检测网络连接...",
260
+ color: "blue"
261
+ });
262
+ spinner.start();
263
+ try {
264
+ return { version: await fetchVersion() };
265
+ } catch (error) {
266
+ if (error.message.includes(REMOTE_URL)) error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
267
+ consola.error(`网络连接异常: ${error.message}`);
268
+ process.exit(1);
269
+ } finally {
270
+ spinner.stop();
271
+ }
272
+ }
273
+
274
+ //#endregion
275
+ //#region src/v1/utils.ts
276
+ function assignValues(target, source) {
277
+ for (const [key, value] of Object.entries(source)) target[key] = value;
278
+ }
279
+ async function readJSON(path) {
280
+ const blob = await readFile(path, "utf-8");
281
+ let parsed;
282
+ try {
283
+ parsed = parseJSON(blob);
284
+ } catch {
285
+ parsed = parseJSONC(blob);
286
+ }
287
+ return parsed;
288
+ }
289
+ async function writeJSON(path, json) {
290
+ await writeFile(path, stringifyJSON(json));
291
+ }
292
+ /**
293
+ * 重写文件内容
294
+ */
295
+ function rewriteFile(path, fn) {
296
+ if (!existsSync(path)) {
297
+ consola.error(`RewriteFile fail: ${path} does not exist`);
298
+ return;
299
+ }
300
+ try {
301
+ const content = readFileSync(path, { encoding: "utf-8" });
302
+ writeFileSync(path, fn(content));
303
+ } catch (error) {
304
+ consola.error(`RewriteFile fail: ${error}`);
305
+ }
306
+ }
307
+
306
308
  //#endregion
307
309
  //#region src/v1/rewrite.ts
308
310
  async function rewrite(options) {
@@ -361,6 +363,46 @@ function writeApps(appsDir, options) {
361
363
  }
362
364
  }
363
365
 
366
+ //#endregion
367
+ //#region src/v1/index.ts
368
+ async function generateV1() {
369
+ const { version: version$1 } = await fetchData();
370
+ const answer = {};
371
+ answer.dir = await input({
372
+ message: "目录名称(dir)",
373
+ default: "my-app",
374
+ validate: validateInput
375
+ });
376
+ answer.key = await input({
377
+ message: "项目标识(key)",
378
+ default: answer.dir,
379
+ validate: validateInput
380
+ });
381
+ if (existsSync(answer.dir)) {
382
+ if (!await confirm({ message: `目录 ${colors.cyan(answer.dir)} 已存在,是否覆盖?` })) throw Error;
383
+ }
384
+ answer.openapi = await confirm({
385
+ message: "运行时自动生成接口对接文件,若关闭可通过指令生成(openapi)",
386
+ default: false
387
+ });
388
+ const optionsV1 = JSON.parse(JSON.stringify(answer));
389
+ optionsV1.version = await select({
390
+ message: "框架版本号(version)",
391
+ default: version$1.latest,
392
+ choices: version$1.list
393
+ });
394
+ optionsV1.apps = await checkbox({
395
+ message: "选择应用模块(apps)",
396
+ choices: APPS,
397
+ validate: (input$1) => {
398
+ if (input$1.length === 0) return "请至少选择一个应用";
399
+ return true;
400
+ }
401
+ });
402
+ await download(optionsV1);
403
+ await rewrite(optionsV1);
404
+ }
405
+
364
406
  //#endregion
365
407
  //#region src/index.ts
366
408
  async function main() {
@@ -369,13 +411,15 @@ async function main() {
369
411
  program.description("初始化框架").action(async () => {
370
412
  bootstrop();
371
413
  try {
372
- const answer = await init();
373
- if (answer.optionsV1) {
374
- await download(answer.optionsV1);
375
- await rewrite(answer.optionsV1);
414
+ if (await select({
415
+ message: "使用 v1/v2 版本?",
416
+ default: "v2",
417
+ choices: ["v1", "v2"]
418
+ }) === "v1") {
419
+ await generateV1();
376
420
  return;
377
421
  }
378
- generate(answer, package_default.version);
422
+ await generate(package_default.version);
379
423
  } catch (error) {
380
424
  consola.error(error);
381
425
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-pubinfo",
3
3
  "type": "module",
4
- "version": "2.0.0-rc.3",
4
+ "version": "2.0.0-rc.5",
5
5
  "description": "初始化项目框架",
6
6
  "author": "Werheng <werheng.zhang@gmail.com>",
7
7
  "license": "MIT",
@@ -12,6 +12,9 @@
12
12
  "dist",
13
13
  "templates"
14
14
  ],
15
+ "engines": {
16
+ "node": "^20.19.0 || >=22.12.0"
17
+ },
15
18
  "dependencies": {
16
19
  "@inquirer/prompts": "^7.6.0",
17
20
  "ansi-colors": "^4.1.3",
@@ -20,6 +23,7 @@
20
23
  "confbox": "^0.2.2",
21
24
  "consola": "^3.4.2",
22
25
  "giget": "^2.0.0",
26
+ "node-plop": "0.32.1",
23
27
  "ofetch": "^1.4.1",
24
28
  "ora": "^8.2.0",
25
29
  "rimraf": "^6.0.1",
@@ -1,5 +1,2 @@
1
1
  # 页面标题
2
2
  VITE_APP_TITLE = 产数开发底座
3
-
4
- # 开启多租户
5
- VITE_TENANT_ENABLED = false
@@ -1,6 +1,7 @@
1
1
  .pubinfo
2
2
  .eslintcache
3
3
  .stylelintcache
4
+ .gitmessage
4
5
 
5
6
  # auto generated
6
7
  auto-imports.d.ts
@@ -2,7 +2,7 @@ import { defineConfig } from '@pubinfo/openapi';
2
2
  import { presetName } from '@pubinfo/preset-openapi';
3
3
 
4
4
  export default defineConfig({
5
- enabled: false,
5
+ enabled: {{openapi}},
6
6
 
7
7
  presets: [
8
8
  // 小驼峰式命名
@@ -1,14 +1,19 @@
1
1
  {
2
- "name": "pubinfo-template",
2
+ "name": "{{dir}}",
3
3
  "type": "module",
4
4
  "private": true,
5
5
  "packageManager": "pnpm@10.12.4",
6
+ "engines": {
7
+ "node": "^20.19.0 || >=22.12.0"
8
+ },
6
9
  "scripts": {
7
10
  "dev": "pubinfo dev",
8
11
  "build": "pubinfo build",
9
12
  "preview": "pubinfo preview",
10
13
  "commit": "pubinfo commit",
11
- "prepare": "pubinfo commit --init && simple-git-hooks",
14
+ "upgrade": "pubinfo upgrade",
15
+ "prepare": "pubinfo setup && pubinfo commit --init",
16
+ "lint": "pnpm run lint:eslint && pnpm run lint:stylelint",
12
17
  "lint:eslint": "eslint . --cache --fix",
13
18
  "lint:stylelint": "stylelint \"src/**/*.{css,scss,vue}\" --cache --fix",
14
19
  "viewer:eslint-rule": "pnpx @eslint/config-inspector",
@@ -17,14 +22,14 @@
17
22
  },
18
23
  "dependencies": {
19
24
  "@ant-design/icons-vue": "^7.0.1",
20
- "@pubinfo/module-auth": "^2.0.0-rc.1",
21
- "@pubinfo/module-rbac": "^2.0.0-rc.1",
25
+ "@pubinfo/module-auth": "{{version}}",
26
+ "@pubinfo/module-rbac": "{{version}}",
22
27
  "@pubinfo/pro-components": "^1.7.1",
23
28
  "@vueuse/core": "^13.7.0",
24
29
  "alova": "^3.3.4",
25
30
  "ant-design-vue": "^4.2.6",
26
31
  "dayjs": "^1.11.13",
27
- "pubinfo": "^2.0.0-rc.1"
32
+ "pubinfo": "{{version}}"
28
33
  },
29
34
  "devDependencies": {
30
35
  "@pubinfo/openapi": "^0.9.0",
@@ -36,12 +41,12 @@
36
41
  "typescript": "^5.8.3"
37
42
  },
38
43
  "simple-git-hooks": {
39
- "pre-commit": "pnpm lint-staged && pnpm run lint",
44
+ "pre-commit": "pnpm lint-staged",
40
45
  "commit-msg": "pnpm exec pubinfo commit --edit $1"
41
46
  },
42
47
  "lint-staged": {
43
48
  "*.{vue,js,ts,jsx,tsx,md,json}": "eslint --cache --fix",
44
- "*.{css,scss,vue}": "stylelint --cache --fix"
49
+ "*.{css,less,scss,vue}": "stylelint --cache --fix"
45
50
  },
46
51
  "config": {
47
52
  "commitizen": {
@@ -0,0 +1,8 @@
1
+ import { defineSettings } from 'pubinfo';
2
+
3
+ export default defineSettings({
4
+ // 请在此处编写或粘贴配置代码
5
+ app: {
6
+ storagePrefix: '{{key}}',
7
+ },
8
+ });
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+ quote_type = single
@@ -0,0 +1,27 @@
1
+ # pubinfo-module-{{kebabCase dir}}
2
+
3
+ ## 安装依赖
4
+
5
+ ```bash
6
+ pnpm install
7
+ ```
8
+
9
+ ## 运行
10
+
11
+ 监听模块插件:
12
+
13
+ ```bash
14
+ pnpm dev
15
+ ```
16
+
17
+ 运行演练场调试:
18
+
19
+ ```bash
20
+ pnpm play
21
+ ```
22
+
23
+ ## 构建
24
+
25
+ ```bash
26
+ pnpm build
27
+ ```
@@ -0,0 +1,38 @@
1
+ .pubinfo
2
+ .eslintcache
3
+ .stylelintcache
4
+ .gitmessage
5
+
6
+ # auto generated
7
+ auto-imports.d.ts
8
+ components.d.ts
9
+
10
+ .DS_Store
11
+ node_modules
12
+ dist
13
+ cache
14
+ coverage
15
+ .turbo
16
+ .eslintcache
17
+ .stylelintcache
18
+
19
+ # local env files
20
+ .env.local
21
+ .env.*.local
22
+
23
+ # Log files
24
+ npm-debug.log*
25
+ yarn-debug.log*
26
+ yarn-error.log*
27
+ pnpm-debug.log*
28
+ lerna-debug.log*
29
+
30
+ # Editor directories and files
31
+ .idea
32
+ # .vscode
33
+ *.suo
34
+ *.ntvs*
35
+ *.njsproj
36
+ *.sln
37
+ *.sw?
38
+
@@ -0,0 +1,5 @@
1
+ ignore-workspace-root-check=true
2
+ shamefully-hoist=true
3
+ strict-peer-dependencies=false
4
+ shell-emulator=true
5
+ max-old-space-size=4096
@@ -0,0 +1,3 @@
1
+ import pubinfo from 'pubinfo/eslint';
2
+
3
+ export default pubinfo();