create-pubinfo 2.0.0-rc.4 → 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.
- package/dist/index.js +199 -148
- package/package.json +5 -1
- package/templates/{pubinfo-template → pubinfo-app}/.env +0 -3
- package/templates/{pubinfo-template/openapi.config.ts → pubinfo-app/openapi.config.ts.hbs} +1 -1
- package/templates/{pubinfo-template/package.json → pubinfo-app/package.json.hbs} +8 -4
- package/templates/pubinfo-app/src/settings.ts.hbs +8 -0
- package/templates/pubinfo-module/.editorconfig +10 -0
- package/templates/pubinfo-module/README.md.hbs +27 -0
- package/templates/pubinfo-module/_gitignore +38 -0
- package/templates/pubinfo-module/_npmrc +5 -0
- package/templates/pubinfo-module/eslint.config.ts +3 -0
- package/templates/pubinfo-module/package.json.hbs +67 -0
- package/templates/pubinfo-module/playground/.env +2 -0
- package/templates/pubinfo-module/playground/.env.development +6 -0
- package/templates/pubinfo-module/playground/.env.production +10 -0
- package/templates/pubinfo-module/playground/index.html +47 -0
- package/templates/pubinfo-module/playground/openapi.config.ts.hbs +33 -0
- package/templates/pubinfo-module/playground/package.json.hbs +22 -0
- package/templates/pubinfo-module/playground/pubinfo.config.ts +9 -0
- package/templates/pubinfo-module/playground/public/browser_upgrade/chrome.png +0 -0
- package/templates/pubinfo-module/playground/public/browser_upgrade/edge.png +0 -0
- package/templates/pubinfo-module/playground/public/browser_upgrade/index.css +49 -0
- package/templates/pubinfo-module/playground/public/loading.css +92 -0
- package/templates/pubinfo-module/playground/src/App.vue +7 -0
- package/templates/pubinfo-module/playground/src/api/modules/auth/index.ts +3 -0
- package/templates/pubinfo-module/playground/src/api/modules/auth/renzhengfuwu.ts +145 -0
- package/templates/pubinfo-module/playground/src/api/modules/auth/typings.d.ts +97 -0
- package/templates/pubinfo-module/playground/src/api/request.ts +125 -0
- package/templates/pubinfo-module/playground/src/assets/icons/logo.svg +1 -0
- package/templates/pubinfo-module/playground/src/assets/icons/process-management.svg +1 -0
- package/templates/pubinfo-module/playground/src/assets/icons/workbench.svg +1 -0
- package/templates/pubinfo-module/playground/src/assets/images/login-bg.webp +0 -0
- package/templates/pubinfo-module/playground/src/assets/images/login-bg_dark.webp +0 -0
- package/templates/pubinfo-module/playground/src/assets/images/login-small.png +0 -0
- package/templates/pubinfo-module/playground/src/assets/images/login-small_dark.webp +0 -0
- package/templates/pubinfo-module/playground/src/components/UIProvider/index.vue +51 -0
- package/templates/pubinfo-module/playground/src/layouts/index.vue +44 -0
- package/templates/pubinfo-module/playground/src/main.ts.hbs +24 -0
- package/templates/pubinfo-module/playground/src/modules/auth.ts +20 -0
- package/templates/pubinfo-module/playground/src/modules/rbac.ts +10 -0
- package/templates/pubinfo-module/playground/src/routes/index.ts +71 -0
- package/templates/pubinfo-module/playground/src/routes/modules/demo/breadcrumb.example.ts +62 -0
- package/templates/pubinfo-module/playground/src/routes/modules/demo/link.ts +15 -0
- package/templates/pubinfo-module/playground/src/routes/modules/demo/multilevel.menu.example.ts +68 -0
- package/templates/pubinfo-module/playground/src/routes/modules/demo/other.page.ts +37 -0
- package/templates/pubinfo-module/playground/src/routes/modules/demo/single.ts +14 -0
- package/templates/{pubinfo-template → pubinfo-module/playground}/src/settings.ts +1 -1
- package/templates/pubinfo-module/playground/src/stores/index.ts +2 -0
- package/templates/pubinfo-module/playground/src/stores/modules/conter.ts +16 -0
- package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/detail1.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/detail2.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/list1.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/breadcrumb_example/list2.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/level2/page.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/multilevel_menu_example/page.vue +11 -0
- package/templates/pubinfo-module/playground/src/views/demo/other_page/des.vue +13 -0
- package/templates/pubinfo-module/playground/src/views/demo/other_page/index.vue +25 -0
- package/templates/pubinfo-module/playground/src/views/demo/preview-empty/index.vue +17 -0
- package/templates/pubinfo-module/playground/src/views/demo/single/index.vue +13 -0
- package/templates/pubinfo-module/playground/src/views/system/index.vue +5 -0
- package/templates/pubinfo-module/playground/src/views/system/login/components/LoginForm.vue +29 -0
- package/templates/pubinfo-module/playground/src/views/system/login/components/LoginWithPhone.vue +213 -0
- package/templates/pubinfo-module/playground/src/views/system/login/components/PasswordLogin.vue +194 -0
- package/templates/pubinfo-module/playground/src/views/system/login/components/Savephone.vue +17 -0
- package/templates/pubinfo-module/playground/src/views/system/login/components/Useragreement.vue +26 -0
- package/templates/pubinfo-module/playground/src/views/system/login/composables.ts +84 -0
- package/templates/pubinfo-module/playground/src/views/system/login/index.vue +142 -0
- package/templates/pubinfo-module/playground/tsconfig.json +3 -0
- package/templates/pubinfo-module/playground/uno.config.ts +17 -0
- package/templates/pubinfo-module/pnpm-workspace.yaml +2 -0
- package/templates/pubinfo-module/pubinfo.config.ts.hbs +36 -0
- package/templates/pubinfo-module/src/index.ts.hbs +9 -0
- package/templates/pubinfo-module/src/pages/demo.vue +11 -0
- package/templates/pubinfo-module/stylelint.config.js +3 -0
- package/templates/pubinfo-module/tsconfig.json +16 -0
- package/templates/pubinfo-module/uno.config.ts +8 -0
- package/templates/{pubinfo-template → pubinfo-app}/.browserslistrc +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/.editorconfig +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/.env.development +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/.env.production +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/_gitignore +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/_npmrc +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/eslint.config.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/index.html +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/pubinfo.config.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/chrome.png +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/edge.png +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/public/browser_upgrade/index.css +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/public/loading.css +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/App.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/index.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/renzhengfuwu.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/api/modules/auth/typings.d.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/api/request.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/logo.svg +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/process-management.svg +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/icons/workbench.svg +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-bg.webp +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-bg_dark.webp +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-small.png +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/assets/images/login-small_dark.webp +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/components/UIProvider/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/layouts/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/main.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/modules/auth.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/modules/rbac.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/index.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/breadcrumb.example.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/link.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/multilevel.menu.example.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/other.page.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/routes/modules/demo/single.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/stores/index.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/stores/modules/conter.ts +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/detail1.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/detail2.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/list1.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/breadcrumb_example/list2.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/level2/page.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/multilevel_menu_example/page.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/other_page/des.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/other_page/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/preview-empty/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/demo/single/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/index.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/LoginForm.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/LoginWithPhone.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/PasswordLogin.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/Savephone.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/components/Useragreement.vue +0 -0
- package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/composables.ts +1 -1
- /package/templates/{pubinfo-template → pubinfo-app}/src/views/system/login/index.vue +0 -0
- /package/templates/{pubinfo-template → pubinfo-app}/stylelint.config.js +0 -0
- /package/templates/{pubinfo-template → pubinfo-app}/tsconfig.json +0 -0
- /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
|
|
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.
|
|
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,126 +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
|
-
if (fs.statSync(src).isDirectory()) copyDir(src, dest);
|
|
90
|
-
else fs.copyFileSync(src, dest);
|
|
91
|
-
}
|
|
92
|
-
async function readJSON(path) {
|
|
93
|
-
const blob = await readFile(path, "utf-8");
|
|
94
|
-
let parsed;
|
|
95
|
-
try {
|
|
96
|
-
parsed = parseJSON(blob);
|
|
97
|
-
} catch {
|
|
98
|
-
parsed = parseJSONC(blob);
|
|
99
|
-
}
|
|
100
|
-
return parsed;
|
|
101
|
-
}
|
|
102
|
-
async function writeJSON(path, json) {
|
|
103
|
-
await writeFile(path, stringifyJSON(json));
|
|
104
|
-
}
|
|
105
|
-
function assignValues(target, source) {
|
|
106
|
-
for (const [key, value] of Object.entries(source)) target[key] = value;
|
|
107
|
-
}
|
|
108
69
|
function validateInput(input$1) {
|
|
109
70
|
if (/[<>:"/\\|?*\s]/.test(input$1)) return "错误提示: 该值不能包含空格或者非法字符 (例如, <>:\"/\\|?*).";
|
|
110
71
|
return true;
|
|
111
72
|
}
|
|
112
73
|
|
|
113
|
-
//#endregion
|
|
114
|
-
//#region src/core/generate.ts
|
|
115
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
116
|
-
function generate(options, version$1) {
|
|
117
|
-
const root = cwd();
|
|
118
|
-
const templateDir = resolve(__dirname, "../templates", `pubinfo-template`);
|
|
119
|
-
const targetPath = resolve(root, options.dir);
|
|
120
|
-
copy(templateDir, targetPath);
|
|
121
|
-
rewriteFile(resolve(targetPath, "src/settings.ts"), (content) => {
|
|
122
|
-
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${options.key}'`);
|
|
123
|
-
});
|
|
124
|
-
rewriteFile(resolve(targetPath, "openapi.config.ts"), (content) => {
|
|
125
|
-
return content.replace(/enabled:[^,]+,/g, `enabled: ${options.openapi},`);
|
|
126
|
-
});
|
|
127
|
-
rewriteFile(resolve(targetPath, "package.json"), (content) => {
|
|
128
|
-
return content.replace(/"(@?pubinfo(?:\/module-(?:auth|rbac))?)":\s*"[^"]+"/g, (_match, pkgName) => {
|
|
129
|
-
return `"${pkgName}": "${version$1}"`;
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
const renameFiles = {
|
|
133
|
-
_gitignore: ".gitignore",
|
|
134
|
-
_npmrc: ".npmrc"
|
|
135
|
-
};
|
|
136
|
-
for (const [oldName, newName] of Object.entries(renameFiles)) {
|
|
137
|
-
const oldPath = resolve(targetPath, oldName);
|
|
138
|
-
const newPath = resolve(targetPath, newName || oldName);
|
|
139
|
-
renameSync(oldPath, newPath);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region src/v1/constant.ts
|
|
145
|
-
const REMOTE_URL = "http://106.53.74.49:20000/templates";
|
|
146
|
-
const PKG_NAME = "monorepo-project-template";
|
|
147
|
-
const VERSION_FILE = "version.json";
|
|
148
|
-
const SETTING_FILE_PATH = "src/settings.default.ts";
|
|
149
|
-
const OPENAPI_FILE_PATH = "openapi.config.ts";
|
|
150
|
-
const APPS_DIR = "apps";
|
|
151
|
-
const APPS = [{
|
|
152
|
-
name: "用户权限系统(rbac)",
|
|
153
|
-
value: "rbac"
|
|
154
|
-
}];
|
|
155
|
-
const METADATA_DIR = "configs/metadata";
|
|
156
|
-
const META_FILENAME = "pubinfo.json";
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/v1/fetch.ts
|
|
160
|
-
async function fetchVersion() {
|
|
161
|
-
const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
|
|
162
|
-
versions.sort((v1, v2) => -compare(v1, v2));
|
|
163
|
-
return {
|
|
164
|
-
latest: versions[0],
|
|
165
|
-
list: versions
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
async function fetchData() {
|
|
169
|
-
const spinner = ora({
|
|
170
|
-
text: "检测网络连接...",
|
|
171
|
-
color: "blue"
|
|
172
|
-
});
|
|
173
|
-
spinner.start();
|
|
174
|
-
try {
|
|
175
|
-
return { version: await fetchVersion() };
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (error.message.includes(REMOTE_URL)) error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
178
|
-
consola.error(`网络连接异常: ${error.message}`);
|
|
179
|
-
process.exit(1);
|
|
180
|
-
} finally {
|
|
181
|
-
spinner.stop();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
74
|
//#endregion
|
|
186
75
|
//#region src/core/init.ts
|
|
187
76
|
async function init() {
|
|
@@ -200,31 +89,21 @@ async function init() {
|
|
|
200
89
|
if (existsSync(answer.dir)) {
|
|
201
90
|
if (!await confirm({ message: `目录 ${colors.cyan(answer.dir)} 已存在,是否覆盖?` })) throw Error;
|
|
202
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
|
+
});
|
|
203
103
|
answer.openapi = await confirm({
|
|
204
104
|
message: "运行时自动生成接口对接文件,若关闭可通过指令生成(openapi)",
|
|
205
105
|
default: false
|
|
206
106
|
});
|
|
207
|
-
if (await select({
|
|
208
|
-
message: "使用 v1 or v2 版本?",
|
|
209
|
-
default: "v2",
|
|
210
|
-
choices: ["v1", "v2"]
|
|
211
|
-
}) === "v1") {
|
|
212
|
-
const { version: version$1 } = await fetchData();
|
|
213
|
-
answer.optionsV1 = JSON.parse(JSON.stringify(answer));
|
|
214
|
-
answer.optionsV1.version = await select({
|
|
215
|
-
message: "框架版本号(version)",
|
|
216
|
-
default: version$1.latest,
|
|
217
|
-
choices: version$1.list
|
|
218
|
-
});
|
|
219
|
-
answer.optionsV1.apps = await checkbox({
|
|
220
|
-
message: "选择应用模块(apps)",
|
|
221
|
-
choices: APPS,
|
|
222
|
-
validate: (input$1) => {
|
|
223
|
-
if (input$1.length === 0) return "请至少选择一个应用";
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
107
|
return answer;
|
|
229
108
|
} catch {
|
|
230
109
|
consola.fail("操作终止");
|
|
@@ -232,6 +111,60 @@ async function init() {
|
|
|
232
111
|
}
|
|
233
112
|
}
|
|
234
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
|
+
|
|
235
168
|
//#endregion
|
|
236
169
|
//#region src/log.ts
|
|
237
170
|
function bootstrop() {
|
|
@@ -254,6 +187,21 @@ function bootstrop() {
|
|
|
254
187
|
}
|
|
255
188
|
}
|
|
256
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
|
+
|
|
257
205
|
//#endregion
|
|
258
206
|
//#region src/v1/download.ts
|
|
259
207
|
const pubinfo = async (input$1, { auth }) => {
|
|
@@ -296,6 +244,67 @@ function loading() {
|
|
|
296
244
|
};
|
|
297
245
|
}
|
|
298
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
|
+
|
|
299
308
|
//#endregion
|
|
300
309
|
//#region src/v1/rewrite.ts
|
|
301
310
|
async function rewrite(options) {
|
|
@@ -354,6 +363,46 @@ function writeApps(appsDir, options) {
|
|
|
354
363
|
}
|
|
355
364
|
}
|
|
356
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
|
+
|
|
357
406
|
//#endregion
|
|
358
407
|
//#region src/index.ts
|
|
359
408
|
async function main() {
|
|
@@ -362,13 +411,15 @@ async function main() {
|
|
|
362
411
|
program.description("初始化框架").action(async () => {
|
|
363
412
|
bootstrop();
|
|
364
413
|
try {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
414
|
+
if (await select({
|
|
415
|
+
message: "使用 v1/v2 版本?",
|
|
416
|
+
default: "v2",
|
|
417
|
+
choices: ["v1", "v2"]
|
|
418
|
+
}) === "v1") {
|
|
419
|
+
await generateV1();
|
|
369
420
|
return;
|
|
370
421
|
}
|
|
371
|
-
generate(
|
|
422
|
+
await generate(package_default.version);
|
|
372
423
|
} catch (error) {
|
|
373
424
|
consola.error(error);
|
|
374
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.
|
|
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,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
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",
|
|
14
|
+
"upgrade": "pubinfo upgrade",
|
|
11
15
|
"prepare": "pubinfo setup && pubinfo commit --init",
|
|
12
16
|
"lint": "pnpm run lint:eslint && pnpm run lint:stylelint",
|
|
13
17
|
"lint:eslint": "eslint . --cache --fix",
|
|
@@ -18,14 +22,14 @@
|
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
24
|
"@ant-design/icons-vue": "^7.0.1",
|
|
21
|
-
"@pubinfo/module-auth": "
|
|
22
|
-
"@pubinfo/module-rbac": "
|
|
25
|
+
"@pubinfo/module-auth": "{{version}}",
|
|
26
|
+
"@pubinfo/module-rbac": "{{version}}",
|
|
23
27
|
"@pubinfo/pro-components": "^1.7.1",
|
|
24
28
|
"@vueuse/core": "^13.7.0",
|
|
25
29
|
"alova": "^3.3.4",
|
|
26
30
|
"ant-design-vue": "^4.2.6",
|
|
27
31
|
"dayjs": "^1.11.13",
|
|
28
|
-
"pubinfo": "
|
|
32
|
+
"pubinfo": "{{version}}"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"@pubinfo/openapi": "^0.9.0",
|
|
@@ -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,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pubinfo-module-{{kebabCase dir}}",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"packageManager": "pnpm@10.12.4",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./style.css": "./dist/index.css"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"play": "pnpm run -C playground dev",
|
|
25
|
+
"play:build": "pnpm run -C playground build",
|
|
26
|
+
"play:preview": "pnpm run -C playground preview",
|
|
27
|
+
"dev": "pubinfo build -w",
|
|
28
|
+
"build": "pubinfo build",
|
|
29
|
+
"commit": "pubinfo commit",
|
|
30
|
+
"upgrade": "pubinfo upgrade",
|
|
31
|
+
"prepare": "pubinfo setup && pubinfo commit --init",
|
|
32
|
+
"lint": "pnpm run lint:eslint && pnpm run lint:stylelint",
|
|
33
|
+
"lint:eslint": "eslint . --cache --fix",
|
|
34
|
+
"lint:stylelint": "stylelint \"src/**/*.{css,scss,vue}\" --cache --fix",
|
|
35
|
+
"openapi": "pnpx @pubinfo/openapi generate",
|
|
36
|
+
"release": "bumpp",
|
|
37
|
+
"deps": "pnpx taze -r",
|
|
38
|
+
"deps:up": "pnpx taze -wr"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"pubinfo": ">=2.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@pubinfo/openapi": "^0.9.0",
|
|
45
|
+
"@pubinfo/preset-openapi": "^0.9.0",
|
|
46
|
+
"eslint": "^9.30.1",
|
|
47
|
+
"lint-staged": "^16.1.2",
|
|
48
|
+
"pubinfo": "{{version}}",
|
|
49
|
+
"simple-git-hooks": "^2.13.0",
|
|
50
|
+
"stylelint": "^16.21.0",
|
|
51
|
+
"typescript": "^5.8.3"
|
|
52
|
+
},
|
|
53
|
+
"simple-git-hooks": {
|
|
54
|
+
"pre-commit": "pnpm lint-staged",
|
|
55
|
+
"commit-msg": "pnpm exec pubinfo commit --edit $1"
|
|
56
|
+
},
|
|
57
|
+
"lint-staged": {
|
|
58
|
+
"*.{vue,js,ts,jsx,tsx,md,json}": "eslint --cache --fix",
|
|
59
|
+
"*.{css,less,scss,vue}": "stylelint --cache --fix"
|
|
60
|
+
},
|
|
61
|
+
"config": {
|
|
62
|
+
"commitizen": {
|
|
63
|
+
"path": "node_modules/cz-git",
|
|
64
|
+
"czConfig": ".pubinfo/cz.config.cjs"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|