create-pubinfo 0.6.8 → 2.0.0-beta.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.
Files changed (3) hide show
  1. package/dist/index.cjs +170 -172
  2. package/dist/index.js +169 -171
  3. package/package.json +13 -11
package/dist/index.cjs CHANGED
@@ -30,7 +30,7 @@ var import_consola6 = __toESM(require("consola"), 1);
30
30
  var package_default = {
31
31
  name: "create-pubinfo",
32
32
  type: "module",
33
- version: "0.6.8",
33
+ version: "2.0.0-beta.1",
34
34
  description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
35
35
  author: "Werheng <werheng.zhang@gmail.com>",
36
36
  license: "MIT",
@@ -45,32 +45,33 @@ var package_default = {
45
45
  build: "tsup",
46
46
  cli: "tsx src/index.ts",
47
47
  "cli:clean": "rimraf ./my-app",
48
- clean: "pnpm rimraf node_modules && pnpm rimraf dist && pnpm rimraf .turbo",
49
- stub: "unbuild --stub",
50
48
  lint: "eslint . --cache --fix"
51
49
  },
52
50
  dependencies: {
53
- "@inquirer/prompts": "^5.1.2",
51
+ "@inquirer/prompts": "^5.5.0",
54
52
  "ansi-colors": "^4.1.3",
55
53
  cfonts: "^3.3.0",
56
54
  commander: "^12.1.0",
57
- confbox: "^0.1.7",
58
- consola: "^3.2.3",
59
- giget: "^1.2.3",
60
- ofetch: "^1.3.4",
61
- ora: "^8.0.1",
62
- rimraf: "^6.0.0",
63
- semver: "^7.6.2"
55
+ confbox: "^0.1.8",
56
+ consola: "^3.4.0",
57
+ giget: "^1.2.5",
58
+ ofetch: "^1.4.1",
59
+ ora: "^8.2.0",
60
+ rimraf: "^6.0.1",
61
+ semver: "^7.7.1"
62
+ },
63
+ devDependencies: {
64
+ "@types/node": "^22.13.9",
65
+ tsup: "^8.4.0"
64
66
  }
65
67
  };
66
68
 
67
- // src/download.ts
68
- var import_node_process = __toESM(require("process"), 1);
69
- var import_giget = require("giget");
70
- var import_consola = __toESM(require("consola"), 1);
69
+ // src/command/init.ts
70
+ var import_node_fs2 = require("fs");
71
+ var import_node_process2 = __toESM(require("process"), 1);
72
+ var import_prompts = require("@inquirer/prompts");
71
73
  var import_ansi_colors = __toESM(require("ansi-colors"), 1);
72
- var import_ora = __toESM(require("ora"), 1);
73
- var import_semver = require("semver");
74
+ var import_consola3 = __toESM(require("consola"), 1);
74
75
 
75
76
  // src/constant.ts
76
77
  var REMOTE_URL = "http://124.223.184.245:20000/templates";
@@ -86,62 +87,47 @@ var APPS = [
86
87
  var METADATA_DIR = "configs/metadata";
87
88
  var META_FILENAME = "pubinfo.json";
88
89
 
89
- // src/download.ts
90
- var pubinfo = async (input2, { auth }) => {
91
- const semver = (0, import_semver.coerce)(input2);
90
+ // src/fetch.ts
91
+ var import_node_process = __toESM(require("process"), 1);
92
+ var import_consola = __toESM(require("consola"), 1);
93
+ var import_ofetch = require("ofetch");
94
+ var import_ora = __toESM(require("ora"), 1);
95
+ var import_semver = require("semver");
96
+ async function fetchVersion() {
97
+ const versions = await (0, import_ofetch.ofetch)(`${REMOTE_URL}/${VERSION_FILE}`);
98
+ versions.sort((v1, v2) => -(0, import_semver.compare)(v1, v2));
92
99
  return {
93
- name: "pubinfo",
94
- version: input2,
95
- headers: { Authorization: `token ${auth}` },
96
- tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
100
+ latest: versions[0],
101
+ list: versions
97
102
  };
98
- };
99
- async function download(options) {
100
- const finish = loading();
103
+ }
104
+ async function fetchData() {
105
+ const spinner = (0, import_ora.default)({
106
+ text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
107
+ color: "blue"
108
+ });
109
+ spinner.start();
101
110
  try {
102
- await (0, import_giget.downloadTemplate)(`pubinfo:${PKG_NAME}-${options.version}`, {
103
- providers: { pubinfo },
104
- force: true,
105
- forceClean: true,
106
- // auth: options.auth,
107
- dir: options.dir
108
- });
111
+ const version = await fetchVersion();
112
+ return {
113
+ version
114
+ };
109
115
  } catch (error) {
110
116
  if (error.message.includes(REMOTE_URL)) {
111
117
  error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
112
118
  }
113
- import_consola.default.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
119
+ import_consola.default.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
114
120
  import_node_process.default.exit(1);
115
121
  } finally {
116
- finish();
117
- }
118
- }
119
- function loading() {
120
- const startTime = Date.now();
121
- const spinner = (0, import_ora.default)({
122
- text: "\u4E0B\u8F7D\u4E2D...",
123
- color: "green"
124
- });
125
- spinner.start();
126
- return () => {
127
- const { green, yellow } = import_ansi_colors.default;
128
122
  spinner.stop();
129
- import_consola.default.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
130
- };
123
+ }
131
124
  }
132
125
 
133
- // src/rewrite.ts
134
- var import_node_process2 = __toESM(require("process"), 1);
135
- var import_node_path = require("path");
136
- var import_node_fs2 = require("fs");
137
- var import_rimraf = require("rimraf");
138
- var import_consola3 = __toESM(require("consola"), 1);
139
-
140
126
  // src/utils.ts
141
127
  var import_node_fs = require("fs");
142
128
  var import_promises = require("fs/promises");
143
- var import_consola2 = __toESM(require("consola"), 1);
144
129
  var import_confbox = require("confbox");
130
+ var import_consola2 = __toESM(require("consola"), 1);
145
131
  function rewriteFile(path, fn) {
146
132
  if (!(0, import_node_fs.existsSync)(path)) {
147
133
  import_consola2.default.error(`RewriteFile fail: ${path} does not exist`);
@@ -180,56 +166,99 @@ function validateInput(input2) {
180
166
  return true;
181
167
  }
182
168
 
183
- // src/rewrite.ts
184
- async function rewrite(options) {
185
- const { dir } = options;
186
- const root = import_node_process2.default.cwd();
187
- const projectDir = (0, import_node_path.resolve)(root, dir);
188
- writeMetaJSON((0, import_node_path.resolve)(projectDir, METADATA_DIR), options);
189
- writeApps((0, import_node_path.resolve)(projectDir, APPS_DIR), options);
190
- }
191
- async function writeMetaJSON(metaDir, options) {
192
- const { key, version, apps, openapi } = options;
193
- const path = (0, import_node_path.resolve)(metaDir, META_FILENAME);
169
+ // src/command/init.ts
170
+ async function init() {
171
+ const { version } = await fetchData();
172
+ const answer = {};
194
173
  try {
195
- const json = await readJSON(path);
196
- assignValues(json, {
197
- key,
198
- version,
199
- apps,
200
- openapi
174
+ answer.dir = await (0, import_prompts.input)({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
175
+ answer.key = await (0, import_prompts.input)({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
176
+ if ((0, import_node_fs2.existsSync)(answer.dir)) {
177
+ const overwrite = await (0, import_prompts.confirm)({ message: `\u76EE\u5F55 ${import_ansi_colors.default.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
178
+ if (!overwrite) {
179
+ throw Error;
180
+ }
181
+ }
182
+ answer.version = await (0, import_prompts.input)({
183
+ message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
184
+ default: version.latest,
185
+ validate: (input2) => {
186
+ if (!version.list.includes(input2)) {
187
+ return `\u7248\u672C\u53F7: ${import_ansi_colors.default.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${import_ansi_colors.default.bold(version.latest)}.`;
188
+ }
189
+ return true;
190
+ }
201
191
  });
202
- await writeJSON(path, json);
203
- } catch (error) {
204
- import_consola3.default.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
192
+ answer.apps = await (0, import_prompts.checkbox)({
193
+ message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
194
+ choices: APPS,
195
+ validate: (input2) => {
196
+ if (input2.length === 0) {
197
+ return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
198
+ }
199
+ return true;
200
+ }
201
+ });
202
+ answer.openapi = await (0, import_prompts.confirm)({
203
+ 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",
204
+ default: false
205
+ });
206
+ return answer;
207
+ } catch {
208
+ import_consola3.default.fail("\u64CD\u4F5C\u7EC8\u6B62");
209
+ import_node_process2.default.exit(1);
205
210
  }
206
211
  }
207
- function writeApps(appsDir, options) {
208
- const { key, apps = [], openapi } = options;
209
- if (!(0, import_node_fs2.existsSync)(appsDir)) {
210
- import_consola3.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
211
- return;
212
- }
212
+
213
+ // src/download.ts
214
+ var import_node_process3 = __toESM(require("process"), 1);
215
+ var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
216
+ var import_consola4 = __toESM(require("consola"), 1);
217
+ var import_giget = require("giget");
218
+ var import_ora2 = __toESM(require("ora"), 1);
219
+ var import_semver2 = require("semver");
220
+ var pubinfo = async (input2, { auth }) => {
221
+ const semver = (0, import_semver2.coerce)(input2);
222
+ return {
223
+ name: "pubinfo",
224
+ version: input2,
225
+ headers: { Authorization: `token ${auth}` },
226
+ tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
227
+ };
228
+ };
229
+ async function download(options) {
230
+ const finish = loading();
213
231
  try {
214
- (0, import_node_fs2.readdirSync)(appsDir).forEach((app) => {
215
- const appPath = (0, import_node_path.resolve)(appsDir, app);
216
- const settingPath = (0, import_node_path.resolve)(appPath, SETTING_FILE_PATH);
217
- const openapiPath = (0, import_node_path.resolve)(appPath, OPENAPI_FILE_PATH);
218
- if (!apps.includes(app)) {
219
- (0, import_rimraf.rimrafSync)(appPath);
220
- return;
221
- }
222
- rewriteFile(settingPath, (content) => {
223
- return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
224
- });
225
- rewriteFile(openapiPath, (content) => {
226
- return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
227
- });
232
+ await (0, import_giget.downloadTemplate)(`pubinfo:${PKG_NAME}-${options.version}`, {
233
+ providers: { pubinfo },
234
+ force: true,
235
+ forceClean: true,
236
+ // auth: options.auth,
237
+ dir: options.dir
228
238
  });
229
239
  } catch (error) {
230
- import_consola3.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
240
+ if (error.message.includes(REMOTE_URL)) {
241
+ error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
242
+ }
243
+ import_consola4.default.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
244
+ import_node_process3.default.exit(1);
245
+ } finally {
246
+ finish();
231
247
  }
232
248
  }
249
+ function loading() {
250
+ const startTime = Date.now();
251
+ const spinner = (0, import_ora2.default)({
252
+ text: "\u4E0B\u8F7D\u4E2D...",
253
+ color: "green"
254
+ });
255
+ spinner.start();
256
+ return () => {
257
+ const { green, yellow } = import_ansi_colors2.default;
258
+ spinner.stop();
259
+ import_consola4.default.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
260
+ };
261
+ }
233
262
 
234
263
  // src/log.ts
235
264
  var import_cfonts = __toESM(require("cfonts"), 1);
@@ -253,90 +282,59 @@ function bootstrop() {
253
282
  }
254
283
  }
255
284
 
256
- // src/command/init.ts
257
- var import_node_process4 = __toESM(require("process"), 1);
285
+ // src/rewrite.ts
258
286
  var import_node_fs3 = require("fs");
259
- var import_prompts = require("@inquirer/prompts");
287
+ var import_node_path = require("path");
288
+ var import_node_process4 = __toESM(require("process"), 1);
260
289
  var import_consola5 = __toESM(require("consola"), 1);
261
- var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
262
-
263
- // src/fetch.ts
264
- var import_node_process3 = __toESM(require("process"), 1);
265
- var import_consola4 = __toESM(require("consola"), 1);
266
- var import_ofetch = require("ofetch");
267
- var import_ora2 = __toESM(require("ora"), 1);
268
- var import_semver2 = require("semver");
269
- async function fetchVersion() {
270
- const versions = await (0, import_ofetch.ofetch)(`${REMOTE_URL}/${VERSION_FILE}`);
271
- versions.sort((v1, v2) => -(0, import_semver2.compare)(v1, v2));
272
- return {
273
- latest: versions[0],
274
- list: versions
275
- };
290
+ var import_rimraf = require("rimraf");
291
+ async function rewrite(options) {
292
+ const { dir } = options;
293
+ const root = import_node_process4.default.cwd();
294
+ const projectDir = (0, import_node_path.resolve)(root, dir);
295
+ writeMetaJSON((0, import_node_path.resolve)(projectDir, METADATA_DIR), options);
296
+ writeApps((0, import_node_path.resolve)(projectDir, APPS_DIR), options);
276
297
  }
277
- async function fetchData() {
278
- const spinner = (0, import_ora2.default)({
279
- text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
280
- color: "blue"
281
- });
282
- spinner.start();
298
+ async function writeMetaJSON(metaDir, options) {
299
+ const { key, version, apps, openapi } = options;
300
+ const path = (0, import_node_path.resolve)(metaDir, META_FILENAME);
283
301
  try {
284
- const version = await fetchVersion();
285
- return {
286
- version
287
- };
302
+ const json = await readJSON(path);
303
+ assignValues(json, {
304
+ key,
305
+ version,
306
+ apps,
307
+ openapi
308
+ });
309
+ await writeJSON(path, json);
288
310
  } catch (error) {
289
- if (error.message.includes(REMOTE_URL)) {
290
- error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
291
- }
292
- import_consola4.default.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
293
- import_node_process3.default.exit(1);
294
- } finally {
295
- spinner.stop();
311
+ import_consola5.default.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
296
312
  }
297
313
  }
298
-
299
- // src/command/init.ts
300
- async function init() {
301
- const { version } = await fetchData();
302
- const answer = {};
314
+ function writeApps(appsDir, options) {
315
+ const { key, apps = [], openapi } = options;
316
+ if (!(0, import_node_fs3.existsSync)(appsDir)) {
317
+ import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
318
+ return;
319
+ }
303
320
  try {
304
- answer.dir = await (0, import_prompts.input)({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
305
- answer.key = await (0, import_prompts.input)({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
306
- if ((0, import_node_fs3.existsSync)(answer.dir)) {
307
- const overwrite = await (0, import_prompts.confirm)({ message: `\u76EE\u5F55 ${import_ansi_colors2.default.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
308
- if (!overwrite) {
309
- throw Error;
310
- }
311
- }
312
- answer.version = await (0, import_prompts.input)({
313
- message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
314
- default: version.latest,
315
- validate: (input2) => {
316
- if (!version.list.includes(input2)) {
317
- return `\u7248\u672C\u53F7: ${import_ansi_colors2.default.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${import_ansi_colors2.default.bold(version.latest)}.`;
318
- }
319
- return true;
320
- }
321
- });
322
- answer.apps = await (0, import_prompts.checkbox)({
323
- message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
324
- choices: APPS,
325
- validate: (input2) => {
326
- if (input2.length === 0) {
327
- return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
328
- }
329
- return true;
321
+ (0, import_node_fs3.readdirSync)(appsDir).forEach((app) => {
322
+ const appPath = (0, import_node_path.resolve)(appsDir, app);
323
+ const settingPath = (0, import_node_path.resolve)(appPath, SETTING_FILE_PATH);
324
+ const openapiPath = (0, import_node_path.resolve)(appPath, OPENAPI_FILE_PATH);
325
+ if (!apps.includes(app)) {
326
+ (0, import_rimraf.rimrafSync)(appPath);
327
+ return;
330
328
  }
329
+ rewriteFile(settingPath, (content) => {
330
+ return content.replace(/storagePrefix:\s*'([^']*)'/g, `storagePrefix: '${key}'`);
331
+ });
332
+ rewriteFile(openapiPath, (content) => {
333
+ return content.replace(/enabled:[^,]+,/g, `enabled: ${openapi},`);
334
+ });
331
335
  });
332
- answer.openapi = await (0, import_prompts.confirm)({
333
- 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",
334
- default: false
335
- });
336
- return answer;
337
- } catch {
338
- import_consola5.default.fail("\u64CD\u4F5C\u7EC8\u6B62");
339
- import_node_process4.default.exit(1);
336
+ } catch (error) {
337
+ import_consola5.default.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
340
338
  }
341
339
  }
342
340
 
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.6.8",
11
+ version: "2.0.0-beta.1",
12
12
  description: "\u521D\u59CB\u5316\u9879\u76EE\u6846\u67B6",
13
13
  author: "Werheng <werheng.zhang@gmail.com>",
14
14
  license: "MIT",
@@ -23,32 +23,33 @@ var package_default = {
23
23
  build: "tsup",
24
24
  cli: "tsx src/index.ts",
25
25
  "cli:clean": "rimraf ./my-app",
26
- clean: "pnpm rimraf node_modules && pnpm rimraf dist && pnpm rimraf .turbo",
27
- stub: "unbuild --stub",
28
26
  lint: "eslint . --cache --fix"
29
27
  },
30
28
  dependencies: {
31
- "@inquirer/prompts": "^5.1.2",
29
+ "@inquirer/prompts": "^5.5.0",
32
30
  "ansi-colors": "^4.1.3",
33
31
  cfonts: "^3.3.0",
34
32
  commander: "^12.1.0",
35
- confbox: "^0.1.7",
36
- consola: "^3.2.3",
37
- giget: "^1.2.3",
38
- ofetch: "^1.3.4",
39
- ora: "^8.0.1",
40
- rimraf: "^6.0.0",
41
- semver: "^7.6.2"
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"
42
44
  }
43
45
  };
44
46
 
45
- // src/download.ts
46
- import process from "node:process";
47
- import { downloadTemplate } from "giget";
48
- import consola from "consola";
47
+ // src/command/init.ts
48
+ import { existsSync as existsSync2 } from "node:fs";
49
+ import process2 from "node:process";
50
+ import { checkbox, confirm, input } from "@inquirer/prompts";
49
51
  import colors from "ansi-colors";
50
- import ora from "ora";
51
- import { coerce } from "semver";
52
+ import consola3 from "consola";
52
53
 
53
54
  // src/constant.ts
54
55
  var REMOTE_URL = "http://124.223.184.245:20000/templates";
@@ -64,62 +65,47 @@ var APPS = [
64
65
  var METADATA_DIR = "configs/metadata";
65
66
  var META_FILENAME = "pubinfo.json";
66
67
 
67
- // src/download.ts
68
- var pubinfo = async (input2, { auth }) => {
69
- const semver = coerce(input2);
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));
70
77
  return {
71
- name: "pubinfo",
72
- version: input2,
73
- headers: { Authorization: `token ${auth}` },
74
- tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
78
+ latest: versions[0],
79
+ list: versions
75
80
  };
76
- };
77
- async function download(options) {
78
- const finish = loading();
81
+ }
82
+ async function fetchData() {
83
+ const spinner = ora({
84
+ text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
85
+ color: "blue"
86
+ });
87
+ spinner.start();
79
88
  try {
80
- await downloadTemplate(`pubinfo:${PKG_NAME}-${options.version}`, {
81
- providers: { pubinfo },
82
- force: true,
83
- forceClean: true,
84
- // auth: options.auth,
85
- dir: options.dir
86
- });
89
+ const version = await fetchVersion();
90
+ return {
91
+ version
92
+ };
87
93
  } catch (error) {
88
94
  if (error.message.includes(REMOTE_URL)) {
89
95
  error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
90
96
  }
91
- consola.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
97
+ consola.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
92
98
  process.exit(1);
93
99
  } finally {
94
- finish();
95
- }
96
- }
97
- function loading() {
98
- const startTime = Date.now();
99
- const spinner = ora({
100
- text: "\u4E0B\u8F7D\u4E2D...",
101
- color: "green"
102
- });
103
- spinner.start();
104
- return () => {
105
- const { green, yellow } = colors;
106
100
  spinner.stop();
107
- consola.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
108
- };
101
+ }
109
102
  }
110
103
 
111
- // src/rewrite.ts
112
- import process2 from "node:process";
113
- import { resolve } from "node:path";
114
- import { existsSync as existsSync2, readdirSync } from "node:fs";
115
- import { rimrafSync } from "rimraf";
116
- import consola3 from "consola";
117
-
118
104
  // src/utils.ts
119
105
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
120
106
  import { readFile, writeFile } from "node:fs/promises";
121
- import consola2 from "consola";
122
107
  import { parseJSON, parseJSONC, stringifyJSON } from "confbox";
108
+ import consola2 from "consola";
123
109
  function rewriteFile(path, fn) {
124
110
  if (!existsSync(path)) {
125
111
  consola2.error(`RewriteFile fail: ${path} does not exist`);
@@ -158,10 +144,131 @@ function validateInput(input2) {
158
144
  return true;
159
145
  }
160
146
 
147
+ // src/command/init.ts
148
+ async function init() {
149
+ const { version } = await fetchData();
150
+ const answer = {};
151
+ try {
152
+ answer.dir = await input({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
153
+ answer.key = await input({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
154
+ if (existsSync2(answer.dir)) {
155
+ const overwrite = await confirm({ message: `\u76EE\u5F55 ${colors.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
156
+ if (!overwrite) {
157
+ throw Error;
158
+ }
159
+ }
160
+ answer.version = await input({
161
+ message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
162
+ default: version.latest,
163
+ validate: (input2) => {
164
+ if (!version.list.includes(input2)) {
165
+ return `\u7248\u672C\u53F7: ${colors.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${colors.bold(version.latest)}.`;
166
+ }
167
+ return true;
168
+ }
169
+ });
170
+ answer.apps = await checkbox({
171
+ message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
172
+ choices: APPS,
173
+ validate: (input2) => {
174
+ if (input2.length === 0) {
175
+ return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
176
+ }
177
+ return true;
178
+ }
179
+ });
180
+ answer.openapi = await confirm({
181
+ message: "\u8FD0\u884C\u65F6\u81EA\u52A8\u751F\u6210\u63A5\u53E3\u5BF9\u63A5\u6587\u4EF6\uFF0C\u82E5\u5173\u95ED\u53EF\u901A\u8FC7\u6307\u4EE4\u751F\u6210\uFF08openapi\uFF09",
182
+ default: false
183
+ });
184
+ return answer;
185
+ } catch {
186
+ consola3.fail("\u64CD\u4F5C\u7EC8\u6B62");
187
+ process2.exit(1);
188
+ }
189
+ }
190
+
191
+ // src/download.ts
192
+ import process3 from "node:process";
193
+ import colors2 from "ansi-colors";
194
+ import consola4 from "consola";
195
+ import { downloadTemplate } from "giget";
196
+ import ora2 from "ora";
197
+ import { coerce } from "semver";
198
+ var pubinfo = async (input2, { auth }) => {
199
+ const semver = coerce(input2);
200
+ return {
201
+ name: "pubinfo",
202
+ version: input2,
203
+ headers: { Authorization: `token ${auth}` },
204
+ tar: `${REMOTE_URL}/${PKG_NAME}-${semver?.version}.tar.gz`
205
+ };
206
+ };
207
+ async function download(options) {
208
+ const finish = loading();
209
+ try {
210
+ await downloadTemplate(`pubinfo:${PKG_NAME}-${options.version}`, {
211
+ providers: { pubinfo },
212
+ force: true,
213
+ forceClean: true,
214
+ // auth: options.auth,
215
+ dir: options.dir
216
+ });
217
+ } catch (error) {
218
+ if (error.message.includes(REMOTE_URL)) {
219
+ error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
220
+ }
221
+ consola4.error(`\u4E0B\u8F7D\u5931\u8D25: ${error.message}`);
222
+ process3.exit(1);
223
+ } finally {
224
+ finish();
225
+ }
226
+ }
227
+ function loading() {
228
+ const startTime = Date.now();
229
+ const spinner = ora2({
230
+ text: "\u4E0B\u8F7D\u4E2D...",
231
+ color: "green"
232
+ });
233
+ spinner.start();
234
+ return () => {
235
+ const { green, yellow } = colors2;
236
+ spinner.stop();
237
+ consola4.success(`${green("\u4E0B\u8F7D\u5B8C\u6210, \u7528\u65F6")} ${yellow(`${Date.now() - startTime}`)} ${green("ms.")}`);
238
+ };
239
+ }
240
+
241
+ // src/log.ts
242
+ import fonts from "cfonts";
243
+ function bootstrop() {
244
+ printLoGo("PUBINFO");
245
+ function printLoGo(logo) {
246
+ fonts.say(logo, {
247
+ font: "simple3d",
248
+ align: "left",
249
+ background: "transparent",
250
+ letterSpacing: 1,
251
+ lineHeight: 1,
252
+ space: true,
253
+ maxLength: 0,
254
+ spaceless: false,
255
+ gradient: ["blue", "magenta"],
256
+ independentGradient: false,
257
+ transitionGradient: false,
258
+ env: "node"
259
+ });
260
+ }
261
+ }
262
+
161
263
  // src/rewrite.ts
264
+ import { existsSync as existsSync3, readdirSync } from "node:fs";
265
+ import { resolve } from "node:path";
266
+ import process4 from "node:process";
267
+ import consola5 from "consola";
268
+ import { rimrafSync } from "rimraf";
162
269
  async function rewrite(options) {
163
270
  const { dir } = options;
164
- const root = process2.cwd();
271
+ const root = process4.cwd();
165
272
  const projectDir = resolve(root, dir);
166
273
  writeMetaJSON(resolve(projectDir, METADATA_DIR), options);
167
274
  writeApps(resolve(projectDir, APPS_DIR), options);
@@ -179,13 +286,13 @@ async function writeMetaJSON(metaDir, options) {
179
286
  });
180
287
  await writeJSON(path, json);
181
288
  } catch (error) {
182
- consola3.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
289
+ consola5.error(`\u521D\u59CB\u5316 metadata \u5931\u8D25: ${error}`);
183
290
  }
184
291
  }
185
292
  function writeApps(appsDir, options) {
186
293
  const { key, apps = [], openapi } = options;
187
- if (!existsSync2(appsDir)) {
188
- consola3.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
294
+ if (!existsSync3(appsDir)) {
295
+ consola5.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${appsDir} \u4E0D\u5B58\u5728`);
189
296
  return;
190
297
  }
191
298
  try {
@@ -205,116 +312,7 @@ function writeApps(appsDir, options) {
205
312
  });
206
313
  });
207
314
  } catch (error) {
208
- consola3.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
209
- }
210
- }
211
-
212
- // src/log.ts
213
- import fonts from "cfonts";
214
- function bootstrop() {
215
- printLoGo("PUBINFO");
216
- function printLoGo(logo) {
217
- fonts.say(logo, {
218
- font: "simple3d",
219
- align: "left",
220
- background: "transparent",
221
- letterSpacing: 1,
222
- lineHeight: 1,
223
- space: true,
224
- maxLength: 0,
225
- spaceless: false,
226
- gradient: ["blue", "magenta"],
227
- independentGradient: false,
228
- transitionGradient: false,
229
- env: "node"
230
- });
231
- }
232
- }
233
-
234
- // src/command/init.ts
235
- import process4 from "node:process";
236
- import { existsSync as existsSync3 } from "node:fs";
237
- import { checkbox, confirm, input } from "@inquirer/prompts";
238
- import consola5 from "consola";
239
- import colors2 from "ansi-colors";
240
-
241
- // src/fetch.ts
242
- import process3 from "node:process";
243
- import consola4 from "consola";
244
- import { ofetch } from "ofetch";
245
- import ora2 from "ora";
246
- import { compare } from "semver";
247
- async function fetchVersion() {
248
- const versions = await ofetch(`${REMOTE_URL}/${VERSION_FILE}`);
249
- versions.sort((v1, v2) => -compare(v1, v2));
250
- return {
251
- latest: versions[0],
252
- list: versions
253
- };
254
- }
255
- async function fetchData() {
256
- const spinner = ora2({
257
- text: "\u68C0\u6D4B\u7F51\u7EDC\u8FDE\u63A5...",
258
- color: "blue"
259
- });
260
- spinner.start();
261
- try {
262
- const version = await fetchVersion();
263
- return {
264
- version
265
- };
266
- } catch (error) {
267
- if (error.message.includes(REMOTE_URL)) {
268
- error.message = error.message.replace(REMOTE_URL, "[REMOTE_URL]");
269
- }
270
- consola4.error(`\u7F51\u7EDC\u8FDE\u63A5\u5F02\u5E38: ${error.message}`);
271
- process3.exit(1);
272
- } finally {
273
- spinner.stop();
274
- }
275
- }
276
-
277
- // src/command/init.ts
278
- async function init() {
279
- const { version } = await fetchData();
280
- const answer = {};
281
- try {
282
- answer.dir = await input({ message: "\u76EE\u5F55\u540D\u79F0\uFF08dir\uFF09", default: "my-app", validate: validateInput });
283
- answer.key = await input({ message: "\u9879\u76EE\u6807\u8BC6\uFF08key\uFF09", default: answer.dir, validate: validateInput });
284
- if (existsSync3(answer.dir)) {
285
- const overwrite = await confirm({ message: `\u76EE\u5F55 ${colors2.cyan(answer.dir)} \u5DF2\u5B58\u5728\uFF0C\u662F\u5426\u8986\u76D6\uFF1F` });
286
- if (!overwrite) {
287
- throw Error;
288
- }
289
- }
290
- answer.version = await input({
291
- message: "\u6846\u67B6\u7248\u672C\u53F7\uFF08version\uFF09",
292
- default: version.latest,
293
- validate: (input2) => {
294
- if (!version.list.includes(input2)) {
295
- return `\u7248\u672C\u53F7: ${colors2.bold(input2)} \u4E0D\u5B58\u5728, \u5F53\u524D\u6700\u65B0\u7248\u672C\u53F7: ${colors2.bold(version.latest)}.`;
296
- }
297
- return true;
298
- }
299
- });
300
- answer.apps = await checkbox({
301
- message: "\u9009\u62E9\u5E94\u7528\u6A21\u5757\uFF08apps\uFF09",
302
- choices: APPS,
303
- validate: (input2) => {
304
- if (input2.length === 0) {
305
- return "\u8BF7\u81F3\u5C11\u9009\u62E9\u4E00\u4E2A\u5E94\u7528";
306
- }
307
- return true;
308
- }
309
- });
310
- answer.openapi = await confirm({
311
- 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",
312
- default: false
313
- });
314
- return answer;
315
- } catch {
316
- consola5.fail("\u64CD\u4F5C\u7EC8\u6B62");
317
- process4.exit(1);
315
+ consola5.error(`\u521D\u59CB\u5316 apps \u5931\u8D25: ${error}`);
318
316
  }
319
317
  }
320
318
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-pubinfo",
3
3
  "type": "module",
4
- "version": "0.6.8",
4
+ "version": "2.0.0-beta.1",
5
5
  "description": "初始化项目框架",
6
6
  "author": "Werheng <werheng.zhang@gmail.com>",
7
7
  "license": "MIT",
@@ -12,25 +12,27 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@inquirer/prompts": "^5.1.2",
15
+ "@inquirer/prompts": "^5.5.0",
16
16
  "ansi-colors": "^4.1.3",
17
17
  "cfonts": "^3.3.0",
18
18
  "commander": "^12.1.0",
19
- "confbox": "^0.1.7",
20
- "consola": "^3.2.3",
21
- "giget": "^1.2.3",
22
- "ofetch": "^1.3.4",
23
- "ora": "^8.0.1",
24
- "rimraf": "^6.0.0",
25
- "semver": "^7.6.2"
19
+ "confbox": "^0.1.8",
20
+ "consola": "^3.4.0",
21
+ "giget": "^1.2.5",
22
+ "ofetch": "^1.4.1",
23
+ "ora": "^8.2.0",
24
+ "rimraf": "^6.0.1",
25
+ "semver": "^7.7.1"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^22.13.9",
29
+ "tsup": "^8.4.0"
26
30
  },
27
31
  "scripts": {
28
32
  "dev": "tsup --watch src",
29
33
  "build": "tsup",
30
34
  "cli": "tsx src/index.ts",
31
35
  "cli:clean": "rimraf ./my-app",
32
- "clean": "pnpm rimraf node_modules && pnpm rimraf dist && pnpm rimraf .turbo",
33
- "stub": "unbuild --stub",
34
36
  "lint": "eslint . --cache --fix"
35
37
  }
36
38
  }