create-pubinfo 0.4.1 → 0.5.0
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.cjs +41 -23
- package/dist/index.js +41 -23
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var import_consola6 = __toESM(require("consola"), 1);
|
|
|
31
31
|
var package_default = {
|
|
32
32
|
name: "create-pubinfo",
|
|
33
33
|
type: "module",
|
|
34
|
-
version: "0.
|
|
34
|
+
version: "0.5.0",
|
|
35
35
|
description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
|
|
36
36
|
author: "Werheng <werheng.zhang@gmail.com>",
|
|
37
37
|
license: "MIT",
|
|
@@ -54,15 +54,15 @@ var package_default = {
|
|
|
54
54
|
dependencies: {
|
|
55
55
|
"@inquirer/prompts": "^4.3.3",
|
|
56
56
|
"ansi-colors": "^4.1.3",
|
|
57
|
-
cfonts: "^3.
|
|
58
|
-
commander: "^12.
|
|
57
|
+
cfonts: "^3.3.0",
|
|
58
|
+
commander: "^12.1.0",
|
|
59
59
|
confbox: "^0.1.7",
|
|
60
60
|
consola: "^3.2.3",
|
|
61
61
|
giget: "^1.2.3",
|
|
62
62
|
ofetch: "^1.3.4",
|
|
63
63
|
ora: "^8.0.1",
|
|
64
|
-
rimraf: "^5.0.
|
|
65
|
-
semver: "^7.6.
|
|
64
|
+
rimraf: "^5.0.7",
|
|
65
|
+
semver: "^7.6.2"
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -73,19 +73,35 @@ var import_consola = __toESM(require("consola"), 1);
|
|
|
73
73
|
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
74
74
|
var import_ora = __toESM(require("ora"), 1);
|
|
75
75
|
var import_semver = require("semver");
|
|
76
|
+
|
|
77
|
+
// src/constant.ts
|
|
78
|
+
var REMOTE_URL = "http://124.223.184.245:20000/templates";
|
|
79
|
+
var PKG_NAME = "monorepo-project-template";
|
|
80
|
+
var VERSION_FILE = "version.json";
|
|
81
|
+
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
82
|
+
var OPENAPI_FILE_PATH = "openapi.config.ts";
|
|
83
|
+
var APPS_DIR = "apps";
|
|
84
|
+
var APPS = [
|
|
85
|
+
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
86
|
+
// { name: '初始化项目模板(admin)', value: 'admin' },
|
|
87
|
+
];
|
|
88
|
+
var METADATA_DIR = "configs/metadata";
|
|
89
|
+
var META_FILENAME = "pubinfo.json";
|
|
90
|
+
|
|
91
|
+
// src/download.ts
|
|
76
92
|
var pubinfo = async (input2, { auth }) => {
|
|
77
93
|
const semver = (0, import_semver.coerce)(input2);
|
|
78
94
|
return {
|
|
79
95
|
name: "pubinfo",
|
|
80
96
|
version: input2,
|
|
81
97
|
headers: { Authorization: `token ${auth}` },
|
|
82
|
-
tar:
|
|
98
|
+
tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
|
|
83
99
|
};
|
|
84
100
|
};
|
|
85
101
|
async function download(options) {
|
|
86
102
|
const finish = loading();
|
|
87
103
|
try {
|
|
88
|
-
await (0, import_giget.downloadTemplate)(`pubinfo
|
|
104
|
+
await (0, import_giget.downloadTemplate)(`pubinfo:${PKG_NAME}-${options.version}`, {
|
|
89
105
|
providers: { pubinfo },
|
|
90
106
|
force: true,
|
|
91
107
|
forceClean: true,
|
|
@@ -93,7 +109,9 @@ async function download(options) {
|
|
|
93
109
|
dir: options.dir
|
|
94
110
|
});
|
|
95
111
|
} catch (error) {
|
|
96
|
-
|
|
112
|
+
if (error.message.includes(REMOTE_URL))
|
|
113
|
+
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
114
|
+
import_consola.default.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
|
|
97
115
|
import_node_process.default.exit(1);
|
|
98
116
|
} finally {
|
|
99
117
|
finish();
|
|
@@ -155,16 +173,6 @@ function assignValues(target, source) {
|
|
|
155
173
|
target[key] = value;
|
|
156
174
|
}
|
|
157
175
|
|
|
158
|
-
// src/constant.ts
|
|
159
|
-
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
160
|
-
var APPS_DIR = "apps";
|
|
161
|
-
var APPS = [
|
|
162
|
-
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
163
|
-
// { name: '初始化项目模板(admin)', value: 'admin' },
|
|
164
|
-
];
|
|
165
|
-
var METADATA_DIR = "configs/metadata";
|
|
166
|
-
var META_FILENAME = "pubinfo.json";
|
|
167
|
-
|
|
168
176
|
// src/rewrite.ts
|
|
169
177
|
async function rewrite(options) {
|
|
170
178
|
const { dir } = options;
|
|
@@ -174,14 +182,15 @@ async function rewrite(options) {
|
|
|
174
182
|
writeApps((0, import_node_path.resolve)(projectDir, APPS_DIR), options);
|
|
175
183
|
}
|
|
176
184
|
async function writeMetaJSON(metaDir, options) {
|
|
177
|
-
const { key, version, apps } = options;
|
|
185
|
+
const { key, version, apps, openapi } = options;
|
|
178
186
|
const path = (0, import_node_path.resolve)(metaDir, META_FILENAME);
|
|
179
187
|
try {
|
|
180
188
|
const json = await readJSON(path);
|
|
181
189
|
assignValues(json, {
|
|
182
190
|
key,
|
|
183
191
|
version,
|
|
184
|
-
apps
|
|
192
|
+
apps,
|
|
193
|
+
openapi
|
|
185
194
|
});
|
|
186
195
|
await writeJSON(path, json);
|
|
187
196
|
} catch (error) {
|
|
@@ -189,7 +198,7 @@ async function writeMetaJSON(metaDir, options) {
|
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
function writeApps(appsDir, options) {
|
|
192
|
-
const { key, apps = [] } = options;
|
|
201
|
+
const { key, apps = [], openapi } = options;
|
|
193
202
|
if (!(0, import_node_fs2.existsSync)(appsDir)) {
|
|
194
203
|
import_consola3.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
|
|
195
204
|
return;
|
|
@@ -198,6 +207,7 @@ function writeApps(appsDir, options) {
|
|
|
198
207
|
(0, import_node_fs2.readdirSync)(appsDir).forEach((app) => {
|
|
199
208
|
const appPath = (0, import_node_path.resolve)(appsDir, app);
|
|
200
209
|
const settingPath = (0, import_node_path.resolve)(appPath, SETTING_FILE_PATH);
|
|
210
|
+
const openapiPath = (0, import_node_path.resolve)(appPath, OPENAPI_FILE_PATH);
|
|
201
211
|
if (!apps.includes(app)) {
|
|
202
212
|
(0, import_rimraf.rimrafSync)(appPath);
|
|
203
213
|
return;
|
|
@@ -205,6 +215,9 @@ function writeApps(appsDir, options) {
|
|
|
205
215
|
rewriteFile(settingPath, (content) => {
|
|
206
216
|
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
|
|
207
217
|
});
|
|
218
|
+
rewriteFile(openapiPath, (content) => {
|
|
219
|
+
return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
|
|
220
|
+
});
|
|
208
221
|
});
|
|
209
222
|
} catch (error) {
|
|
210
223
|
import_consola3.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
|
|
@@ -247,7 +260,7 @@ var import_ofetch = require("ofetch");
|
|
|
247
260
|
var import_ora2 = __toESM(require("ora"), 1);
|
|
248
261
|
var import_semver2 = require("semver");
|
|
249
262
|
async function fetchVersion() {
|
|
250
|
-
const versions = await (0, import_ofetch.ofetch)(
|
|
263
|
+
const versions = await (0, import_ofetch.ofetch)(`${REMOTE_URL}/${VERSION_FILE}`);
|
|
251
264
|
versions.sort((v1, v2) => -(0, import_semver2.compare)(v1, v2));
|
|
252
265
|
return {
|
|
253
266
|
latest: versions[0],
|
|
@@ -266,7 +279,9 @@ async function fetchData() {
|
|
|
266
279
|
version
|
|
267
280
|
};
|
|
268
281
|
} catch (error) {
|
|
269
|
-
|
|
282
|
+
if (error.message.includes(REMOTE_URL))
|
|
283
|
+
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
284
|
+
import_consola4.default.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
|
|
270
285
|
import_node_process3.default.exit(1);
|
|
271
286
|
} finally {
|
|
272
287
|
spinner.stop();
|
|
@@ -303,6 +318,9 @@ async function init() {
|
|
|
303
318
|
return true;
|
|
304
319
|
}
|
|
305
320
|
});
|
|
321
|
+
answer.openapi = await (0, import_prompts.confirm)({
|
|
322
|
+
message: "\u8FD0\u884C\u65F6\u81EA\u52A8\u751F\u6210\u63A5\u53E3\u5BF9\u63A5\u6587\u4EF6\uFF0C\u82E5\u5173\u95ED\u53EF\u901A\u8FC7\u6307\u4EE4\u751F\u6210\uFF08openapi\uFF09"
|
|
323
|
+
});
|
|
306
324
|
return answer;
|
|
307
325
|
} catch (error) {
|
|
308
326
|
import_consola5.default.fail("\u64CD\u4F5C\u7EC8\u6B62");
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import consola6 from "consola";
|
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "create-pubinfo",
|
|
10
10
|
type: "module",
|
|
11
|
-
version: "0.
|
|
11
|
+
version: "0.5.0",
|
|
12
12
|
description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
|
|
13
13
|
author: "Werheng <werheng.zhang@gmail.com>",
|
|
14
14
|
license: "MIT",
|
|
@@ -31,15 +31,15 @@ var package_default = {
|
|
|
31
31
|
dependencies: {
|
|
32
32
|
"@inquirer/prompts": "^4.3.3",
|
|
33
33
|
"ansi-colors": "^4.1.3",
|
|
34
|
-
cfonts: "^3.
|
|
35
|
-
commander: "^12.
|
|
34
|
+
cfonts: "^3.3.0",
|
|
35
|
+
commander: "^12.1.0",
|
|
36
36
|
confbox: "^0.1.7",
|
|
37
37
|
consola: "^3.2.3",
|
|
38
38
|
giget: "^1.2.3",
|
|
39
39
|
ofetch: "^1.3.4",
|
|
40
40
|
ora: "^8.0.1",
|
|
41
|
-
rimraf: "^5.0.
|
|
42
|
-
semver: "^7.6.
|
|
41
|
+
rimraf: "^5.0.7",
|
|
42
|
+
semver: "^7.6.2"
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
|
|
@@ -50,19 +50,35 @@ import consola from "consola";
|
|
|
50
50
|
import colors from "ansi-colors";
|
|
51
51
|
import ora from "ora";
|
|
52
52
|
import { coerce } from "semver";
|
|
53
|
+
|
|
54
|
+
// src/constant.ts
|
|
55
|
+
var REMOTE_URL = "http://124.223.184.245:20000/templates";
|
|
56
|
+
var PKG_NAME = "monorepo-project-template";
|
|
57
|
+
var VERSION_FILE = "version.json";
|
|
58
|
+
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
59
|
+
var OPENAPI_FILE_PATH = "openapi.config.ts";
|
|
60
|
+
var APPS_DIR = "apps";
|
|
61
|
+
var APPS = [
|
|
62
|
+
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
63
|
+
// { name: '初始化项目模板(admin)', value: 'admin' },
|
|
64
|
+
];
|
|
65
|
+
var METADATA_DIR = "configs/metadata";
|
|
66
|
+
var META_FILENAME = "pubinfo.json";
|
|
67
|
+
|
|
68
|
+
// src/download.ts
|
|
53
69
|
var pubinfo = async (input2, { auth }) => {
|
|
54
70
|
const semver = coerce(input2);
|
|
55
71
|
return {
|
|
56
72
|
name: "pubinfo",
|
|
57
73
|
version: input2,
|
|
58
74
|
headers: { Authorization: `token ${auth}` },
|
|
59
|
-
tar:
|
|
75
|
+
tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
|
|
60
76
|
};
|
|
61
77
|
};
|
|
62
78
|
async function download(options) {
|
|
63
79
|
const finish = loading();
|
|
64
80
|
try {
|
|
65
|
-
await downloadTemplate(`pubinfo
|
|
81
|
+
await downloadTemplate(`pubinfo:${PKG_NAME}-${options.version}`, {
|
|
66
82
|
providers: { pubinfo },
|
|
67
83
|
force: true,
|
|
68
84
|
forceClean: true,
|
|
@@ -70,7 +86,9 @@ async function download(options) {
|
|
|
70
86
|
dir: options.dir
|
|
71
87
|
});
|
|
72
88
|
} catch (error) {
|
|
73
|
-
|
|
89
|
+
if (error.message.includes(REMOTE_URL))
|
|
90
|
+
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
91
|
+
consola.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
|
|
74
92
|
process.exit(1);
|
|
75
93
|
} finally {
|
|
76
94
|
finish();
|
|
@@ -132,16 +150,6 @@ function assignValues(target, source) {
|
|
|
132
150
|
target[key] = value;
|
|
133
151
|
}
|
|
134
152
|
|
|
135
|
-
// src/constant.ts
|
|
136
|
-
var SETTING_FILE_PATH = "src/settings.default.ts";
|
|
137
|
-
var APPS_DIR = "apps";
|
|
138
|
-
var APPS = [
|
|
139
|
-
{ name: "\u7528\u6237\u6743\u9650\u7CFB\u7EDF\uFF08rbac\uFF09", value: "rbac" }
|
|
140
|
-
// { name: '初始化项目模板(admin)', value: 'admin' },
|
|
141
|
-
];
|
|
142
|
-
var METADATA_DIR = "configs/metadata";
|
|
143
|
-
var META_FILENAME = "pubinfo.json";
|
|
144
|
-
|
|
145
153
|
// src/rewrite.ts
|
|
146
154
|
async function rewrite(options) {
|
|
147
155
|
const { dir } = options;
|
|
@@ -151,14 +159,15 @@ async function rewrite(options) {
|
|
|
151
159
|
writeApps(resolve(projectDir, APPS_DIR), options);
|
|
152
160
|
}
|
|
153
161
|
async function writeMetaJSON(metaDir, options) {
|
|
154
|
-
const { key, version, apps } = options;
|
|
162
|
+
const { key, version, apps, openapi } = options;
|
|
155
163
|
const path = resolve(metaDir, META_FILENAME);
|
|
156
164
|
try {
|
|
157
165
|
const json = await readJSON(path);
|
|
158
166
|
assignValues(json, {
|
|
159
167
|
key,
|
|
160
168
|
version,
|
|
161
|
-
apps
|
|
169
|
+
apps,
|
|
170
|
+
openapi
|
|
162
171
|
});
|
|
163
172
|
await writeJSON(path, json);
|
|
164
173
|
} catch (error) {
|
|
@@ -166,7 +175,7 @@ async function writeMetaJSON(metaDir, options) {
|
|
|
166
175
|
}
|
|
167
176
|
}
|
|
168
177
|
function writeApps(appsDir, options) {
|
|
169
|
-
const { key, apps = [] } = options;
|
|
178
|
+
const { key, apps = [], openapi } = options;
|
|
170
179
|
if (!existsSync2(appsDir)) {
|
|
171
180
|
consola3.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
|
|
172
181
|
return;
|
|
@@ -175,6 +184,7 @@ function writeApps(appsDir, options) {
|
|
|
175
184
|
readdirSync(appsDir).forEach((app) => {
|
|
176
185
|
const appPath = resolve(appsDir, app);
|
|
177
186
|
const settingPath = resolve(appPath, SETTING_FILE_PATH);
|
|
187
|
+
const openapiPath = resolve(appPath, OPENAPI_FILE_PATH);
|
|
178
188
|
if (!apps.includes(app)) {
|
|
179
189
|
rimrafSync(appPath);
|
|
180
190
|
return;
|
|
@@ -182,6 +192,9 @@ function writeApps(appsDir, options) {
|
|
|
182
192
|
rewriteFile(settingPath, (content) => {
|
|
183
193
|
return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
|
|
184
194
|
});
|
|
195
|
+
rewriteFile(openapiPath, (content) => {
|
|
196
|
+
return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
|
|
197
|
+
});
|
|
185
198
|
});
|
|
186
199
|
} catch (error) {
|
|
187
200
|
consola3.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
|
|
@@ -224,7 +237,7 @@ import { ofetch } from "ofetch";
|
|
|
224
237
|
import ora2 from "ora";
|
|
225
238
|
import { compare } from "semver";
|
|
226
239
|
async function fetchVersion() {
|
|
227
|
-
const versions = await ofetch(
|
|
240
|
+
const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
|
|
228
241
|
versions.sort((v1, v2) => -compare(v1, v2));
|
|
229
242
|
return {
|
|
230
243
|
latest: versions[0],
|
|
@@ -243,7 +256,9 @@ async function fetchData() {
|
|
|
243
256
|
version
|
|
244
257
|
};
|
|
245
258
|
} catch (error) {
|
|
246
|
-
|
|
259
|
+
if (error.message.includes(REMOTE_URL))
|
|
260
|
+
error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
|
|
261
|
+
consola4.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
|
|
247
262
|
process3.exit(1);
|
|
248
263
|
} finally {
|
|
249
264
|
spinner.stop();
|
|
@@ -280,6 +295,9 @@ async function init() {
|
|
|
280
295
|
return true;
|
|
281
296
|
}
|
|
282
297
|
});
|
|
298
|
+
answer.openapi = await confirm({
|
|
299
|
+
message: "\u8FD0\u884C\u65F6\u81EA\u52A8\u751F\u6210\u63A5\u53E3\u5BF9\u63A5\u6587\u4EF6\uFF0C\u82E5\u5173\u95ED\u53EF\u901A\u8FC7\u6307\u4EE4\u751F\u6210\uFF08openapi\uFF09"
|
|
300
|
+
});
|
|
283
301
|
return answer;
|
|
284
302
|
} catch (error) {
|
|
285
303
|
consola5.fail("\u64CD\u4F5C\u7EC8\u6B62");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pubinfo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "初始化项目框架",
|
|
6
6
|
"author": "Werheng <werheng.zhang@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@inquirer/prompts": "^4.3.3",
|
|
20
20
|
"ansi-colors": "^4.1.3",
|
|
21
|
-
"cfonts": "^3.
|
|
22
|
-
"commander": "^12.
|
|
21
|
+
"cfonts": "^3.3.0",
|
|
22
|
+
"commander": "^12.1.0",
|
|
23
23
|
"confbox": "^0.1.7",
|
|
24
24
|
"consola": "^3.2.3",
|
|
25
25
|
"giget": "^1.2.3",
|
|
26
26
|
"ofetch": "^1.3.4",
|
|
27
27
|
"ora": "^8.0.1",
|
|
28
|
-
"rimraf": "^5.0.
|
|
29
|
-
"semver": "^7.6.
|
|
28
|
+
"rimraf": "^5.0.7",
|
|
29
|
+
"semver": "^7.6.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "tsup --watch src",
|