create-pubinfo 2.0.0-beta.9 → 2.0.0-rc.1
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 +352 -306
- package/package.json +13 -13
- package/templates/pubinfo-template/.browserslistrc +5 -0
- package/templates/pubinfo-template/.editorconfig +10 -0
- package/templates/pubinfo-template/.env +5 -0
- package/templates/pubinfo-template/.env.development +6 -0
- package/templates/pubinfo-template/.env.production +10 -0
- package/templates/pubinfo-template/_gitignore +37 -0
- package/templates/pubinfo-template/_npmrc +5 -0
- package/templates/pubinfo-template/commitlint.config.js +66 -0
- package/templates/pubinfo-template/eslint.config.ts +3 -0
- package/templates/pubinfo-template/index.html +47 -0
- package/templates/pubinfo-template/openapi.config.ts +33 -0
- package/templates/pubinfo-template/package.json +53 -0
- package/templates/pubinfo-template/pubinfo.config.ts +9 -0
- package/templates/pubinfo-template/public/browser_upgrade/chrome.png +0 -0
- package/templates/pubinfo-template/public/browser_upgrade/edge.png +0 -0
- package/templates/pubinfo-template/public/browser_upgrade/index.css +49 -0
- package/templates/pubinfo-template/public/loading.css +92 -0
- package/templates/pubinfo-template/src/App.vue +7 -0
- package/templates/pubinfo-template/src/api/modules/auth/index.ts +3 -0
- package/templates/pubinfo-template/src/api/modules/auth/renzhengfuwu.ts +145 -0
- package/templates/pubinfo-template/src/api/modules/auth/typings.d.ts +97 -0
- package/templates/pubinfo-template/src/api/request.ts +125 -0
- package/templates/pubinfo-template/src/assets/icons/logo.svg +1 -0
- package/templates/pubinfo-template/src/assets/icons/process-management.svg +1 -0
- package/templates/pubinfo-template/src/assets/icons/workbench.svg +1 -0
- package/templates/pubinfo-template/src/assets/images/login-bg.webp +0 -0
- package/templates/pubinfo-template/src/assets/images/login-bg_dark.webp +0 -0
- package/templates/pubinfo-template/src/assets/images/login-small.png +0 -0
- package/templates/pubinfo-template/src/assets/images/login-small_dark.webp +0 -0
- package/templates/pubinfo-template/src/components/UIProvider/index.vue +51 -0
- package/templates/pubinfo-template/src/layouts/index.vue +38 -0
- package/templates/pubinfo-template/src/main.ts +22 -0
- package/templates/pubinfo-template/src/modules/auth.ts +20 -0
- package/templates/pubinfo-template/src/modules/rbac.ts +11 -0
- package/templates/pubinfo-template/src/routes/index.ts +71 -0
- package/templates/pubinfo-template/src/routes/modules/demo/breadcrumb.example.ts +62 -0
- package/templates/pubinfo-template/src/routes/modules/demo/link.ts +15 -0
- package/templates/pubinfo-template/src/routes/modules/demo/multilevel.menu.example.ts +68 -0
- package/templates/pubinfo-template/src/routes/modules/demo/other.page.ts +37 -0
- package/templates/pubinfo-template/src/routes/modules/demo/single.ts +14 -0
- package/templates/pubinfo-template/src/settings.ts +8 -0
- package/templates/pubinfo-template/src/stores/index.ts +2 -0
- package/templates/pubinfo-template/src/stores/modules/conter.ts +16 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/detail2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/breadcrumb_example/list2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page1.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/level3/page2.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/level2/page.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/multilevel_menu_example/page.vue +11 -0
- package/templates/pubinfo-template/src/views/demo/other_page/des.vue +13 -0
- package/templates/pubinfo-template/src/views/demo/other_page/index.vue +25 -0
- package/templates/pubinfo-template/src/views/demo/preview-empty/index.vue +17 -0
- package/templates/pubinfo-template/src/views/demo/single/index.vue +13 -0
- package/templates/pubinfo-template/src/views/system/index.vue +5 -0
- package/templates/pubinfo-template/src/views/system/login/components/LoginForm.vue +29 -0
- package/templates/pubinfo-template/src/views/system/login/components/LoginWithPhone.vue +213 -0
- package/templates/pubinfo-template/src/views/system/login/components/PasswordLogin.vue +194 -0
- package/templates/pubinfo-template/src/views/system/login/components/Savephone.vue +17 -0
- package/templates/pubinfo-template/src/views/system/login/components/Useragreement.vue +26 -0
- package/templates/pubinfo-template/src/views/system/login/composables.ts +84 -0
- package/templates/pubinfo-template/src/views/system/login/index.vue +147 -0
- package/templates/pubinfo-template/stylelint.config.js +3 -0
- package/templates/pubinfo-template/tsconfig.json +3 -0
- package/templates/pubinfo-template/uno.config.ts +17 -0
- 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
|
|
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
|
-
|
|
19
|
+
//#region package.json
|
|
20
|
+
var name = "create-pubinfo";
|
|
21
|
+
var type = "module";
|
|
22
|
+
var version = "2.0.0-rc.1";
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
104
|
+
await writeFile(path, stringifyJSON(json));
|
|
133
105
|
}
|
|
134
106
|
function assignValues(target, source) {
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
145
187
|
}
|
|
146
188
|
|
|
147
|
-
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/core/init.ts
|
|
148
191
|
async function init() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
264
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/index.ts
|
|
320
366
|
async function main() {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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 { };
|