@dune2/cli 0.3.15 → 0.4.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/cli.js CHANGED
@@ -1,203 +1,130 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- cli,
3
+ I18nData,
4
4
  configName,
5
- createLogger,
5
+ downloadFromPlatform,
6
6
  getConfig,
7
7
  googleSheet,
8
- letterToNumber
9
- } from "./chunk-DUIAXDMV.js";
10
- import "./chunk-U34QFMNX.js";
8
+ letterToNumber,
9
+ sleep
10
+ } from "./chunk-KCETBI3Y.js";
11
+ import "./chunk-4BXCANQI.js";
12
+ import {
13
+ cli,
14
+ createLogger
15
+ } from "./chunk-UGSBKD2I.js";
11
16
 
12
- // src/commands/extract.ts
13
- import fs2 from "fs-extra";
14
- import { globby } from "globby";
15
- import pMap2 from "p-map";
17
+ // package.json
18
+ var version = "0.4.1";
16
19
 
17
- // src/shared/i18nData.ts
18
- import Table from "cli-table3";
19
- import fs from "fs-extra";
20
+ // src/commands/download.ts
20
21
  import pMap from "p-map";
21
- import path from "path";
22
- import pc from "picocolors";
23
-
24
- // src/shared/sleep.ts
25
- function sleep(ms) {
26
- return new Promise((resolve) => {
27
- setTimeout(resolve, ms);
28
- });
29
- }
30
22
 
31
- // src/shared/i18nData.ts
32
- var log = createLogger("i18nData");
33
- var I18nData = class {
34
- constructor(locale, config, shouldDeleteUnused = false) {
35
- this.locale = locale;
36
- this.config = config;
37
- this.shouldDeleteUnused = shouldDeleteUnused;
38
- this.data = {};
39
- this.unUsedKeys = /* @__PURE__ */ new Set();
40
- this.isDefaultLocale = locale === config.defaultLocale;
41
- this.filePath = path.join(
42
- config.cwd,
43
- config.i18nDir,
44
- config.i18nFileName.replace("{locale}", locale)
45
- );
23
+ // src/shared/resolveSheetData.ts
24
+ var log = createLogger("shared:resolveSheetData");
25
+ var SheetI18nItem = class {
26
+ constructor(spreadsheetId, range, key, colIndex, row, rowIndex) {
27
+ this.spreadsheetId = spreadsheetId;
28
+ this.range = range;
29
+ this.key = key;
30
+ this.row = row;
31
+ this.rowIndex = rowIndex;
32
+ this.colIndex = letterToNumber(colIndex);
33
+ this.value = this.row[this.colIndex] || "";
46
34
  }
47
- async loadData() {
48
- try {
49
- if (await fs.pathExists(this.filePath)) {
50
- this.data = await fs.readJSON(this.filePath);
51
- } else {
52
- log.info("File '%s' does not exist", pc.dim(this.filePath));
53
- }
54
- } catch (e) {
55
- log.error(
56
- "Error loading i18n data for locale '%s' from file '%s'",
57
- pc.yellow(this.locale),
58
- pc.yellow(this.filePath)
59
- );
60
- log.error("Error: %s", e.message);
35
+ /**
36
+ * 尝试更新 单元格的值
37
+ * 如果一样则不更新
38
+ */
39
+ async tryUpdate(newValue) {
40
+ if (newValue === this.value) {
41
+ return;
61
42
  }
62
- return this.data;
43
+ await googleSheet.updateCell(
44
+ this.spreadsheetId,
45
+ this.range,
46
+ this.colIndex,
47
+ this.rowIndex,
48
+ newValue
49
+ );
63
50
  }
64
- async updateByExtractedData(extractedData) {
65
- const oldData = await this.loadData();
66
- let newData = {};
67
- extractedData.forEach((value, key) => {
68
- let newValue = oldData[key] || "";
69
- if (this.isDefaultLocale) {
70
- newValue = newValue || value.messages || key;
71
- newValue = this.normalizeNamespacedDefaultLocaleData(newValue);
72
- }
73
- newData[key] = newValue;
74
- });
75
- if (!this.shouldDeleteUnused) {
76
- newData = { ...oldData, ...newData };
77
- }
78
- this.data = newData;
79
- Object.keys(oldData).forEach((key) => {
80
- if (!extractedData.has(key)) {
81
- this.unUsedKeys.add(key);
82
- }
83
- });
51
+ };
52
+ async function resolveSheetData(config) {
53
+ const { position } = config;
54
+ const parseStartIndex = config.parseStartIndex ?? 2;
55
+ log.info(`\u8BFB\u53D6 ${config.sheetRange} sheet\u6570\u636E`);
56
+ const res = await googleSheet.get({
57
+ spreadsheetId: config.sheetId,
58
+ range: config.sheetRange
59
+ });
60
+ if (!res.data.values) {
61
+ log.error(
62
+ `${config.sheetRange} sheet\u6570\u636E\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\uFF0C\u5E94\u8BE5\u6700\u5C11\u6709\u4E00\u884C\u5934\u90E8\u6570\u636E`
63
+ );
64
+ return new SheetData(config, 2);
84
65
  }
85
- normalizeNamespacedDefaultLocaleData(v) {
86
- if (!this.namespaceReg && this.config.namespace) {
87
- const names = Object.keys(this.config.namespace).join("|");
88
- const separator = this.config.namespaceSeparator;
89
- this.namespaceReg = new RegExp(`^(${names})\\${separator}`);
66
+ const sheetData = new SheetData(config, res.data.values.length + 1);
67
+ res.data.values.forEach((row, rowIndex) => {
68
+ var _a;
69
+ const trulyRowIndex = rowIndex + 1;
70
+ if (parseStartIndex > trulyRowIndex) {
71
+ return;
90
72
  }
91
- if (this.namespaceReg) {
92
- return v.replace(this.namespaceReg, "");
73
+ const i18nKey = row[letterToNumber(position.key)];
74
+ if (i18nKey) {
75
+ if (sheetData.keySet.has(i18nKey)) {
76
+ log.error(
77
+ `\u8868\u683C ${config.sheetRange} \u53D1\u73B0\u91CD\u590D\u7684i18nKey: ${i18nKey}, \u5C06\u8986\u76D6\u524D\u9762\u7684\u503C`
78
+ );
79
+ } else {
80
+ sheetData.keySet.add(i18nKey);
81
+ }
82
+ (_a = config.locales) == null ? void 0 : _a.forEach((lang) => {
83
+ sheetData.setI18nItem(
84
+ lang,
85
+ new SheetI18nItem(
86
+ config.sheetId,
87
+ config.sheetRange,
88
+ i18nKey,
89
+ position[lang],
90
+ row,
91
+ trulyRowIndex
92
+ )
93
+ );
94
+ });
93
95
  }
94
- return v;
95
- }
96
- async updateFromSheetData(sheetData) {
97
- await this.loadData();
98
- this.data = { ...this.data, ...sheetData };
99
- }
100
- sortData() {
101
- this.data = this.config.jsonSorter(this.data);
102
- }
103
- async saveToDisk() {
104
- this.sortData();
105
- log.info(
106
- "Saving i18n data for locale '%s' to file '%s'",
107
- pc.green(this.locale),
108
- pc.dim(this.filePath)
96
+ });
97
+ return sheetData;
98
+ }
99
+ var SheetData = class {
100
+ constructor(config, nextAppendRowIndex) {
101
+ this.config = config;
102
+ this.nextAppendRowIndex = nextAppendRowIndex;
103
+ this.keySet = /* @__PURE__ */ new Set();
104
+ this.value = new Map(
105
+ this.config.locales.map((lang) => {
106
+ return [lang, /* @__PURE__ */ new Map()];
107
+ })
109
108
  );
110
- try {
111
- await fs.ensureFile(this.filePath);
112
- await fs.writeJson(this.filePath, this.data, { spaces: 2 });
113
- log.info(
114
- "Saved i18n data for locale '%s' to file '%s'",
115
- pc.green(this.locale),
116
- pc.dim(this.filePath)
117
- );
118
- } catch (e) {
119
- log.error(
120
- "Error saving i18n data for locale '%s' to file '%s'",
121
- pc.green(this.locale),
122
- pc.dim(this.filePath)
123
- );
124
- log.error("Error: %s", pc.red(e.message));
125
- }
126
109
  }
127
- async trySaveToGoogle(sheetData) {
128
- await pMap(
129
- Object.entries(this.data),
130
- async ([key, value]) => {
131
- var _a;
132
- if (sheetData.hasI18nItem(this.locale, key)) {
133
- await ((_a = sheetData.getI18nItem(this.locale, key)) == null ? void 0 : _a.tryUpdate(value));
134
- await sleep(1e3);
135
- } else {
136
- log.error(
137
- "%s range %s not found key %s",
138
- pc.bold(this.config.sheetRange),
139
- pc.bold(this.locale),
140
- pc.bold(key)
141
- );
142
- }
143
- },
144
- { concurrency: 50 }
145
- );
110
+ getI18nItem(lang, i18nKey) {
111
+ return this.value.get(lang).get(i18nKey);
146
112
  }
147
- statistic() {
148
- const total = Object.keys(this.data).length;
149
- const missing = Object.values(this.data).filter((v) => !v).length;
150
- return {
151
- locale: this.locale,
152
- total,
153
- missing
154
- };
113
+ setI18nItem(lang, i18nItem) {
114
+ this.value.get(lang).set(i18nItem.key, i18nItem);
155
115
  }
156
- static printStatistic(label, i18nDataArr) {
157
- const unUsedKeys = i18nDataArr.reduce((keys, item) => {
158
- return new Set(item.unUsedKeys);
159
- }, /* @__PURE__ */ new Set());
160
- if (unUsedKeys.size) {
161
- console.log(
162
- pc.bold(
163
- `\u5171\u6709 ${pc.green(
164
- unUsedKeys.size
165
- )} \u4E2A key \u672A\u5728\u4EE3\u7801\u4E2D\u4F7F\u7528\uFF0C\u4EE5\u4E0B\u662F\u5177\u4F53\u7684 key`
166
- )
167
- );
168
- console.log(
169
- pc.red(
170
- "\u6CE8\u610F\uFF1A\u8FD9\u4E9Bkey\u53EF\u80FD\u662F\u5DF2\u7ECF\u5220\u9664\u7684\u4EE3\u7801\uFF0C\u4E5F\u53EF\u80FD\u662F\u901A\u8FC7 `t.ignoreExtract` \u8C03\u7528\u5FFD\u7565\u4E86\u63D0\u53D6 \u5E76\u4E0D\u4E00\u5B9A\u662F\u5197\u4F59\u7684 key"
171
- )
172
- );
173
- console.table(unUsedKeys);
174
- }
175
- const table = new Table({
176
- head: ["Language", "Total count", "Missing"],
177
- colAligns: ["left", "center", "center"],
178
- style: {
179
- head: ["green"],
180
- border: [],
181
- compact: true
182
- }
183
- });
184
- i18nDataArr.forEach((i18nData) => {
185
- const statistic = i18nData.statistic();
186
- table.push([
187
- statistic.locale,
188
- statistic.total,
189
- statistic.missing > 0 ? pc.red(statistic.missing) : statistic.missing
190
- ]);
116
+ hasI18nItem(lang, i18nKey) {
117
+ return this.value.get(lang).has(i18nKey);
118
+ }
119
+ getLangDataJSON(lang) {
120
+ const res = {};
121
+ this.value.get(lang).forEach((i18nItem) => {
122
+ res[i18nItem.key] = i18nItem.value;
191
123
  });
192
- console.log(pc.bold(label));
193
- console.log(table.toString());
124
+ return res;
194
125
  }
195
126
  };
196
127
 
197
- // src/commands/extract.ts
198
- import pc2 from "picocolors";
199
- import os from "os";
200
-
201
128
  // src/shared/promptConfigEnable.ts
202
129
  import enquirer from "enquirer";
203
130
  var { prompt } = enquirer;
@@ -218,6 +145,7 @@ async function promptConfigEnable(opt) {
218
145
  const res = await prompt({
219
146
  type: "multiselect",
220
147
  message: "\u9009\u62E9\u8981\u751F\u6548\u7684\u914D\u7F6E\u9879",
148
+ // @ts-ignore
221
149
  hint: "(\u7A7A\u683C\u9009\u4E2D\uFF0C\u56DE\u8F66\u786E\u8BA4)",
222
150
  name: "enabled",
223
151
  validate(value) {
@@ -259,9 +187,40 @@ function promptApiConfigEnable(configArr) {
259
187
  });
260
188
  }
261
189
 
262
- // src/commands/extract.ts
263
- import path2 from "path";
264
- var log2 = createLogger("extract");
190
+ // src/commands/download.ts
191
+ var log2 = createLogger("generate");
192
+ async function download() {
193
+ const config = await getConfig();
194
+ let i18nConfigs = await promptI18nConfigEnable(config.i18n);
195
+ let i = 0;
196
+ for (const configItem of i18nConfigs) {
197
+ i++;
198
+ if (!configItem.sheetId || !configItem.sheetRange) {
199
+ log2.error(`config.${i} sheetId \u6216 sheetRange \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5`);
200
+ continue;
201
+ }
202
+ const sheetData = await resolveSheetData(configItem);
203
+ const statistics = await pMap(
204
+ configItem.locales ?? [],
205
+ async (locale, index) => {
206
+ const i18nData = new I18nData(locale, configItem);
207
+ await i18nData.updateFromSheetData(sheetData.getLangDataJSON(locale));
208
+ await i18nData.saveToDisk();
209
+ return i18nData;
210
+ }
211
+ );
212
+ I18nData.printStatistic(`${configItem.sheetRange} \u751F\u6210\u7ED3\u679C: `, statistics);
213
+ }
214
+ }
215
+
216
+ // src/commands/extract/index.ts
217
+ import fs from "fs-extra";
218
+ import { globby } from "globby";
219
+ import os from "os";
220
+ import pMap2 from "p-map";
221
+ import path from "path";
222
+ import pc from "picocolors";
223
+ var log3 = createLogger("extract");
265
224
  async function extract(opts) {
266
225
  var _a;
267
226
  const config = await getConfig();
@@ -280,19 +239,19 @@ async function extract(opts) {
280
239
  ].concat(configItem.include ?? []),
281
240
  { cwd: configItem.cwd }
282
241
  );
283
- log2.info("\u9884\u8BA1\u5171\u89E3\u6790 %s \u4E2A\u6587\u4EF6", pc2.green(files.length));
242
+ log3.info("\u9884\u8BA1\u5171\u89E3\u6790 %s \u4E2A\u6587\u4EF6", pc.green(files.length));
284
243
  let errMsgs = [];
285
244
  const extractedI18nDataMap = /* @__PURE__ */ new Map();
286
245
  await pMap2(
287
246
  files,
288
247
  async (file) => {
289
- const content = await fs2.readFile(file, "utf-8");
248
+ const content = await fs.readFile(file, "utf-8");
290
249
  const res = await extract2(content, file);
291
250
  if (res.data.size) {
292
- log2.info(
251
+ log3.info(
293
252
  "\u4ECE %s \u4E2D\u63D0\u53D6\u5230 %s \u6761\u6587\u6848",
294
- pc2.dim(file),
295
- pc2.green(res.data.size)
253
+ pc.dim(file),
254
+ pc.green(res.data.size)
296
255
  );
297
256
  res.data.forEach((value, key) => {
298
257
  let cur = extractedI18nDataMap.get(key);
@@ -301,7 +260,7 @@ async function extract(opts) {
301
260
  cur = { ...value, files: [] };
302
261
  }
303
262
  cur.files.push(
304
- path2.resolve(file) + ":" + value.line + ":" + value.column
263
+ path.resolve(file) + ":" + value.line + ":" + value.column
305
264
  );
306
265
  cur.messages = value.messages || cur.messages;
307
266
  if (!hasCache) {
@@ -323,25 +282,28 @@ async function extract(opts) {
323
282
  return i18nData;
324
283
  });
325
284
  if (errMsgs.length) {
326
- console.log(pc2.bold("\u4EE5\u4E0B\u672A\u80FD\u6210\u529F\u63D0\u53D6\u7684\u6587\u6848\uFF0C\u8BF7\u624B\u52A8\u5904\u7406\uFF1A"));
285
+ console.log(pc.bold("\u4EE5\u4E0B\u672A\u80FD\u6210\u529F\u63D0\u53D6\u7684\u6587\u6848\uFF0C\u8BF7\u624B\u52A8\u5904\u7406\uFF1A"));
327
286
  console.log(errMsgs.join(os.EOL));
328
287
  }
329
288
  I18nData.printStatistic("\u63D0\u53D6\u7ED3\u679C: ", i18nDataArr);
289
+ await import("./uploadToTranslatePlatform-GK4VUXIU.js").then(
290
+ (mod) => mod.uploadToTranslatePlatform(configItem, i18nDataArr)
291
+ );
330
292
  }
331
293
  }
332
294
  async function saveExtractedMetaData(config, extractedI18nDataMap) {
333
295
  const { i18nDir } = config;
334
296
  const prefix = i18nDir.replace("./", "").replace(/\//g, "_");
335
297
  const filename = `${prefix}.extractedLog.json`;
336
- const metaDataJsonPath = path2.join(i18nDir, filename);
337
- await fs2.ensureFile(metaDataJsonPath);
298
+ const metaDataJsonPath = path.join(i18nDir, filename);
299
+ await fs.ensureFile(metaDataJsonPath);
338
300
  let data = Array.from(extractedI18nDataMap.entries()).map(
339
301
  ([key, value]) => value
340
302
  );
341
303
  data = data.sort((a, b) => {
342
304
  return a.id.localeCompare(b.id);
343
305
  });
344
- await fs2.writeJSON(
306
+ await fs.writeJSON(
345
307
  metaDataJsonPath,
346
308
  data,
347
309
  {
@@ -350,179 +312,53 @@ async function saveExtractedMetaData(config, extractedI18nDataMap) {
350
312
  );
351
313
  }
352
314
 
353
- // src/commands/download.ts
354
- import pMap3 from "p-map";
355
-
356
- // src/shared/resolveSheetData.ts
357
- var log3 = createLogger("shared:resolveSheetData");
358
- var SheetI18nItem = class {
359
- constructor(spreadsheetId, range, key, colIndex, row, rowIndex) {
360
- this.spreadsheetId = spreadsheetId;
361
- this.range = range;
362
- this.key = key;
363
- this.row = row;
364
- this.rowIndex = rowIndex;
365
- this.colIndex = letterToNumber(colIndex);
366
- this.value = this.row[this.colIndex] || "";
367
- }
368
- async tryUpdate(newValue) {
369
- if (newValue === this.value) {
370
- return;
371
- }
372
- await googleSheet.updateCell(
373
- this.spreadsheetId,
374
- this.range,
375
- this.colIndex,
376
- this.rowIndex,
377
- newValue
378
- );
379
- }
380
- };
381
- async function resolveSheetData(config) {
382
- const { position } = config;
383
- const parseStartIndex = config.parseStartIndex ?? 2;
384
- log3.info(`\u8BFB\u53D6 ${config.sheetRange} sheet\u6570\u636E`);
385
- const res = await googleSheet.get({
386
- spreadsheetId: config.sheetId,
387
- range: config.sheetRange
388
- });
389
- if (!res.data.values) {
390
- log3.error(
391
- `${config.sheetRange} sheet\u6570\u636E\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\uFF0C\u5E94\u8BE5\u6700\u5C11\u6709\u4E00\u884C\u5934\u90E8\u6570\u636E`
392
- );
393
- return new SheetData(config, 2);
394
- }
395
- const sheetData = new SheetData(config, res.data.values.length + 1);
396
- res.data.values.forEach((row, rowIndex) => {
397
- var _a;
398
- const trulyRowIndex = rowIndex + 1;
399
- if (parseStartIndex > trulyRowIndex) {
400
- return;
401
- }
402
- const i18nKey = row[letterToNumber(position.key)];
403
- if (i18nKey) {
404
- if (sheetData.keySet.has(i18nKey)) {
405
- log3.error(
406
- `\u8868\u683C ${config.sheetRange} \u53D1\u73B0\u91CD\u590D\u7684i18nKey: ${i18nKey}, \u5C06\u8986\u76D6\u524D\u9762\u7684\u503C`
407
- );
408
- } else {
409
- sheetData.keySet.add(i18nKey);
410
- }
411
- (_a = config.locales) == null ? void 0 : _a.forEach((lang) => {
412
- sheetData.setI18nItem(
413
- lang,
414
- new SheetI18nItem(
415
- config.sheetId,
416
- config.sheetRange,
417
- i18nKey,
418
- position[lang],
419
- row,
420
- trulyRowIndex
421
- )
422
- );
423
- });
424
- }
425
- });
426
- return sheetData;
427
- }
428
- var SheetData = class {
429
- constructor(config, nextAppendRowIndex) {
430
- this.config = config;
431
- this.nextAppendRowIndex = nextAppendRowIndex;
432
- this.keySet = /* @__PURE__ */ new Set();
433
- this.value = new Map(
434
- this.config.locales.map((lang) => {
435
- return [lang, /* @__PURE__ */ new Map()];
436
- })
437
- );
438
- }
439
- getI18nItem(lang, i18nKey) {
440
- return this.value.get(lang).get(i18nKey);
441
- }
442
- setI18nItem(lang, i18nItem) {
443
- this.value.get(lang).set(i18nItem.key, i18nItem);
444
- }
445
- hasI18nItem(lang, i18nKey) {
446
- return this.value.get(lang).has(i18nKey);
447
- }
448
- getLangDataJSON(lang) {
449
- const res = {};
450
- this.value.get(lang).forEach((i18nItem) => {
451
- res[i18nItem.key] = i18nItem.value;
452
- });
453
- return res;
454
- }
455
- };
456
-
457
- // src/commands/download.ts
458
- var log4 = createLogger("generate");
459
- async function download() {
460
- const config = await getConfig();
461
- let i18nConfigs = await promptI18nConfigEnable(config.i18n);
462
- let i = 0;
463
- for (const configItem of i18nConfigs) {
464
- i++;
465
- if (!configItem.sheetId || !configItem.sheetRange) {
466
- log4.error(`config.${i} sheetId \u6216 sheetRange \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5`);
467
- continue;
468
- }
469
- const sheetData = await resolveSheetData(configItem);
470
- const statistics = await pMap3(
471
- configItem.locales ?? [],
472
- async (locale, index) => {
473
- const i18nData = new I18nData(locale, configItem);
474
- await i18nData.updateFromSheetData(sheetData.getLangDataJSON(locale));
475
- await i18nData.saveToDisk();
476
- return i18nData;
477
- }
478
- );
479
- I18nData.printStatistic(`${configItem.sheetRange} \u751F\u6210\u7ED3\u679C: `, statistics);
480
- }
481
- }
482
-
483
315
  // src/commands/generateApi/index.ts
484
316
  import SwaggerParser from "@apidevtools/swagger-parser";
485
- import fs3 from "fs-extra";
317
+ import fs2 from "fs-extra";
486
318
  import { compile } from "json-schema-to-typescript";
487
319
  import _ from "lodash";
488
320
  import * as os2 from "os";
489
- import pMap4 from "p-map";
490
- import path3 from "path";
321
+ import pMap3 from "p-map";
322
+ import path2 from "path";
491
323
 
492
324
  // src/shared/formatFile.ts
493
325
  import * as child_process from "child_process";
494
- var log5 = createLogger("formatFile");
326
+ var log4 = createLogger("formatFile");
495
327
  function formatFile(filename) {
496
- log5.info(`\u5C1D\u8BD5\u683C\u5F0F\u5316\u4EE3\u7801: %s`, filename);
328
+ log4.info(`\u5C1D\u8BD5\u683C\u5F0F\u5316\u4EE3\u7801: %s`, filename);
497
329
  child_process.exec(`prettier --write '${filename}'`, (error) => {
498
330
  if (error) {
499
- log5.error(`\u683C\u5F0F\u5316\u4EE3\u7801\u5931\u8D25: ${error}`);
500
- log5.error(`\u8BF7\u624B\u52A8\u6267\u884C: prettier --write ${filename}`);
501
- log5.error(`\u6216\u8005\u5728\u914D\u7F6E\u6587\u4EF6\u4E2D\u5173\u95ED\u683C\u5F0F\u5316\u529F\u80FD`);
331
+ log4.error(`\u683C\u5F0F\u5316\u4EE3\u7801\u5931\u8D25: ${error}`);
332
+ log4.error(`\u8BF7\u624B\u52A8\u6267\u884C: prettier --write ${filename}`);
333
+ log4.error(`\u6216\u8005\u5728\u914D\u7F6E\u6587\u4EF6\u4E2D\u5173\u95ED\u683C\u5F0F\u5316\u529F\u80FD`);
502
334
  } else {
503
- log5.info(`\u683C\u5F0F\u5316\u4EE3\u7801\u6210\u529F: %s`, filename);
335
+ log4.info(`\u683C\u5F0F\u5316\u4EE3\u7801\u6210\u529F: %s`, filename);
504
336
  }
505
337
  });
506
338
  }
507
339
 
508
340
  // src/commands/generateApi/index.ts
509
- var log6 = createLogger("generateApi");
341
+ var log5 = createLogger("generateApi");
510
342
  async function generateApi() {
511
343
  const config = await getConfig();
512
344
  const apiConfigs = await promptApiConfigEnable(config.api);
513
345
  for (const apiConfig of apiConfigs) {
514
- log6.info(`\u6E05\u9664\u65E7\u7684api\u6587\u4EF6: ${apiConfig.output}`);
515
- await fs3.emptydir(apiConfig.output);
346
+ log5.info(`\u6E05\u9664\u65E7\u7684api\u6587\u4EF6: ${apiConfig.output}`);
347
+ await fs2.emptydir(apiConfig.output);
516
348
  }
517
349
  for (const apiConfig of apiConfigs) {
518
- log6.info("\u5F00\u59CB\u89E3\u6790 %s", apiConfig.swaggerJSONPath);
519
- const parsed = await SwaggerParser.dereference(
520
- apiConfig.swaggerJSONPath
521
- );
522
- await pMap4(Object.entries(parsed.paths), async ([url, pathItemObject]) => {
523
- log6.info("\u5F00\u59CB\u751F\u6210 %s", url);
350
+ log5.info("\u5F00\u59CB\u89E3\u6790 %s", apiConfig.swaggerJSONPath);
351
+ const parsed = await SwaggerParser.dereference(apiConfig.swaggerJSONPath, {
352
+ resolve: {
353
+ http: {
354
+ timeout: 30 * 1e3
355
+ }
356
+ }
357
+ });
358
+ await pMap3(Object.entries(parsed.paths), async ([url, pathItemObject]) => {
359
+ log5.info("\u5F00\u59CB\u751F\u6210 %s", url);
524
360
  if (pathItemObject) {
525
- await pMap4(
361
+ await pMap3(
526
362
  ["get", "put", "post", "delete", "patch"],
527
363
  async (method) => {
528
364
  const operationObject = pathItemObject[method];
@@ -533,13 +369,13 @@ async function generateApi() {
533
369
  operationObject,
534
370
  apiConfig
535
371
  });
536
- const outputPath = path3.join(
372
+ const outputPath = path2.join(
537
373
  apiConfig.output,
538
374
  url,
539
375
  apiConfig.enableTs ? `${method}.ts` : `${method}.js`
540
376
  ).replace(/:/g, "_");
541
- await fs3.ensureFile(outputPath);
542
- await fs3.writeFile(outputPath, code);
377
+ await fs2.ensureFile(outputPath);
378
+ await fs2.writeFile(outputPath, code);
543
379
  }
544
380
  }
545
381
  );
@@ -549,7 +385,7 @@ async function generateApi() {
549
385
  await formatFile(apiConfig.output);
550
386
  }
551
387
  }
552
- log6.info("generateApi Done");
388
+ log5.info("generateApi Done");
553
389
  }
554
390
  async function generateApiRequestCode(options) {
555
391
  var _a, _b;
@@ -652,6 +488,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
652
488
  {
653
489
  ...schema2,
654
490
  description: p.description
491
+ // enum: schema.enum ?? [],
655
492
  }
656
493
  ];
657
494
  })
@@ -670,6 +507,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
670
507
  bannerComment: "",
671
508
  ignoreMinAndMaxItems: true,
672
509
  additionalProperties: false
510
+ // format: false,
673
511
  });
674
512
  const isPageSearchRequest = (data) => {
675
513
  const keys = ["pageNum", "pageSize", "count"];
@@ -682,7 +520,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
682
520
  });
683
521
  }
684
522
  } catch (e) {
685
- log6.error("\u751F\u6210\u8BF7\u6C42\u53C2\u6570\u7C7B\u578B\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 %o", {
523
+ log5.error("\u751F\u6210\u8BF7\u6C42\u53C2\u6570\u7C7B\u578B\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 %o", {
686
524
  summary: operationObject.summary,
687
525
  message: e.message
688
526
  });
@@ -708,6 +546,7 @@ async function compileResponseParams(operationObject, apiConfig) {
708
546
  bannerComment: "",
709
547
  ignoreMinAndMaxItems: true,
710
548
  additionalProperties: false
549
+ // format: false,
711
550
  });
712
551
  const isPageSearchResponse = (data2) => {
713
552
  return _.get(data2, "type") === "object" && _.get(data2, "properties.result.type") === "array";
@@ -716,13 +555,13 @@ async function compileResponseParams(operationObject, apiConfig) {
716
555
  code += `${os2.EOL}export type ResultItem = Res['result'][0]`;
717
556
  }
718
557
  } catch (e) {
719
- log6.error("\u8F6C\u6362\u54CD\u5E94\u53C2\u6570\u7C7B\u578B\u5931\u8D25, \u8BF7\u68C0\u67E5 %o", {
558
+ log5.error("\u8F6C\u6362\u54CD\u5E94\u53C2\u6570\u7C7B\u578B\u5931\u8D25, \u8BF7\u68C0\u67E5 %o", {
720
559
  summary: operationObject.summary,
721
560
  error: e.message
722
561
  });
723
562
  }
724
563
  } else {
725
- log6.error("responseSchemaTransformer \u8FD4\u56DE\u503C\u4E3A\u7A7A, \u8BF7\u68C0\u67E5");
564
+ log5.error("responseSchemaTransformer \u8FD4\u56DE\u503C\u4E3A\u7A7A, \u8BF7\u68C0\u67E5");
726
565
  }
727
566
  }
728
567
  return code ? code : "export type Res = any;";
@@ -745,9 +584,9 @@ function markCircularToRef(obj, parentMark = "#", map = /* @__PURE__ */ new Map(
745
584
  }
746
585
 
747
586
  // src/commands/initConfig.ts
748
- import fs4 from "fs-extra";
749
- import path4 from "path";
750
- var log7 = createLogger("initConfig");
587
+ import fs3 from "fs-extra";
588
+ import path3 from "path";
589
+ var log6 = createLogger("initConfig");
751
590
  var tpl = `/**
752
591
  * @param {import('@dune2/cli').Config} config
753
592
  */
@@ -758,89 +597,20 @@ module.exports = defineConfig({ i18n: [], api:[] });
758
597
  `;
759
598
  var initConfig = async () => {
760
599
  const config = await getConfig();
761
- const configPath = path4.join(config.cwd, configName);
762
- log7.info(`config file path: ${configPath}`);
763
- if (await fs4.pathExists(configPath)) {
764
- log7.info(`config file already exists, skip`);
600
+ const configPath = path3.join(config.cwd, configName);
601
+ log6.info(`config file path: ${configPath}`);
602
+ if (await fs3.pathExists(configPath)) {
603
+ log6.info(`config file already exists, skip`);
765
604
  return;
766
605
  }
767
- await fs4.writeFile(configPath, tpl);
768
- log7.info(`config file created`);
606
+ await fs3.writeFile(configPath, tpl);
607
+ log6.info(`config file created`);
769
608
  };
770
609
 
771
- // src/commands/upload.ts
772
- import _2 from "lodash";
773
- import pMap5 from "p-map";
774
- var log8 = createLogger("upload");
775
- async function batchUpdateKeys(config) {
776
- let sheetData = await resolveSheetData(config);
777
- const allKeys = [];
778
- const i18nDataMap = /* @__PURE__ */ new Map();
779
- await pMap5(config.locales ?? [], async (locale) => {
780
- const i18nData = new I18nData(locale, config);
781
- i18nDataMap.set(locale, i18nData);
782
- const data = await i18nData.loadData();
783
- allKeys.push(...Object.keys(data));
784
- });
785
- let needSyncKeys = Array.from(new Set(allKeys)).filter((key) => {
786
- return !sheetData.keySet.has(key);
787
- });
788
- needSyncKeys = _2.sortBy(needSyncKeys);
789
- if (needSyncKeys.length) {
790
- log8.info(`\u5373\u5C06\u540C\u6B65\u672C\u5730\u65B0\u589E\u52A0 ${needSyncKeys.length} \u4E2A i18nKey \u5230\u4E91\u7AEF`);
791
- await googleSheet.updateColumn(
792
- config.sheetId,
793
- config.sheetRange,
794
- letterToNumber(config.position.key),
795
- sheetData.nextAppendRowIndex,
796
- needSyncKeys
797
- );
798
- log8.info("\u540C\u6B65\u65B0\u589E\u52A0i18nKey\u6210\u529F");
799
- for (const lang of config.locales) {
800
- const langFile = i18nDataMap.get(lang);
801
- const needSyncValues = [];
802
- needSyncKeys.forEach((k) => {
803
- if (langFile) {
804
- needSyncValues.push(langFile.data[k]);
805
- }
806
- });
807
- log8.info(
808
- `\u5373\u5C06\u540C\u6B65\u672C\u5730 ${lang} \u65B0\u589E\u52A0 ${needSyncValues.length} \u4E2A\u503C\u5230\u4E91\u7AEF`
809
- );
810
- await googleSheet.updateColumn(
811
- config.sheetId,
812
- config.sheetRange,
813
- letterToNumber(config.position[lang]),
814
- sheetData.nextAppendRowIndex,
815
- needSyncValues
816
- );
817
- }
818
- await sleep(1e3);
819
- sheetData = await resolveSheetData(config);
820
- log8.info(`\u5DF2\u91CD\u65B0\u83B7\u53D6 ${config.sheetRange} \u7684\u6570\u636E`);
821
- }
822
- return { sheetData, i18nDataMap };
823
- }
824
- async function upload() {
825
- const config = await getConfig();
826
- let i18nConfigs = await promptI18nConfigEnable(config.i18n);
827
- for (const configItem of i18nConfigs) {
828
- const { sheetData, i18nDataMap } = await batchUpdateKeys(configItem);
829
- await pMap5(configItem.locales ?? [], async (locale) => {
830
- const i18nData = i18nDataMap.get(locale);
831
- await i18nData.trySaveToGoogle(sheetData);
832
- });
833
- }
834
- log8.info("\u4E0A\u4F20\u6210\u529F");
835
- }
836
-
837
- // package.json
838
- var version = "0.3.14";
839
-
840
610
  // src/commands/interactive.ts
841
611
  import enquirer2 from "enquirer";
842
612
  var { prompt: prompt2 } = enquirer2;
843
- var log9 = createLogger("interactive");
613
+ var log7 = createLogger("interactive");
844
614
  var interactive = async (args) => {
845
615
  var _a;
846
616
  const commands = cli.commands.filter((command2) => {
@@ -866,7 +636,7 @@ var interactive = async (args) => {
866
636
  });
867
637
  const command = commandMap.get(res.command);
868
638
  if (!command) {
869
- log9.error("\u672A\u627E\u5230\u547D\u4EE4 %s", res.command);
639
+ log7.error("\u672A\u627E\u5230\u547D\u4EE4 %s", res.command);
870
640
  return;
871
641
  }
872
642
  (_a = command.commandAction) == null ? void 0 : _a.apply(cli, args);
@@ -874,11 +644,11 @@ var interactive = async (args) => {
874
644
 
875
645
  // src/commands/namespace.ts
876
646
  import enquirer3 from "enquirer";
877
- import _3 from "lodash";
647
+ import _2 from "lodash";
878
648
  import { globby as globby2 } from "globby";
879
- import fs5 from "fs-extra";
880
- import pMap6 from "p-map";
881
- import pc3 from "picocolors";
649
+ import fs4 from "fs-extra";
650
+ import pMap4 from "p-map";
651
+ import pc2 from "picocolors";
882
652
 
883
653
  // src/shared/autoNamespaceByReg.ts
884
654
  function autoNamespaceByReg(code, namespace2) {
@@ -905,14 +675,14 @@ function autoNamespaceByReg(code, namespace2) {
905
675
 
906
676
  // src/commands/namespace.ts
907
677
  var { prompt: prompt3 } = enquirer3;
908
- var log10 = createLogger("namespace");
678
+ var log8 = createLogger("namespace");
909
679
  async function namespace(params) {
910
680
  var _a, _b;
911
681
  const { mode = "swc" } = params;
912
682
  const config = await getConfig();
913
683
  let i18nConfigs = (_a = config.i18n) == null ? void 0 : _a.filter((item) => !item.disableExtract);
914
684
  if (!i18nConfigs) {
915
- log10.info("\u6CA1\u6709\u914D\u7F6E i18n");
685
+ log8.info("\u6CA1\u6709\u914D\u7F6E i18n");
916
686
  return;
917
687
  }
918
688
  const { i18nDir } = await prompt3({
@@ -928,7 +698,7 @@ async function namespace(params) {
928
698
  });
929
699
  let i18nConfig = i18nConfigs.find((item) => item.i18nDir === i18nDir);
930
700
  if (!i18nConfig) {
931
- log10.info("\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u914D\u7F6E");
701
+ log8.info("\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u914D\u7F6E");
932
702
  return;
933
703
  }
934
704
  const { namespaces } = await prompt3({
@@ -939,7 +709,7 @@ async function namespace(params) {
939
709
  validate(value) {
940
710
  return value.length === 0 ? `\u81F3\u5C11\u9009\u62E9\u4E00\u9879` : true;
941
711
  },
942
- choices: _3.map(i18nConfig.namespace, (v, k) => {
712
+ choices: _2.map(i18nConfig.namespace, (v, k) => {
943
713
  return {
944
714
  name: k
945
715
  };
@@ -947,52 +717,119 @@ async function namespace(params) {
947
717
  });
948
718
  const autoNamespace = await (() => {
949
719
  if (mode === "swc") {
950
- log10.info("\u4F7F\u7528 swc \u6765\u5904\u7406");
720
+ log8.info("\u4F7F\u7528 swc \u6765\u5904\u7406");
951
721
  return import("@dune2/wasm").then((m) => m.autoNamespace);
952
722
  }
953
- log10.info("\u4F7F\u7528 reg \u6765\u5904\u7406");
723
+ log8.info("\u4F7F\u7528 reg \u6765\u5904\u7406");
954
724
  return autoNamespaceByReg;
955
725
  })();
956
726
  for (const namespace2 of namespaces) {
957
727
  const namespaceConfig = (_b = i18nConfig.namespace) == null ? void 0 : _b[namespace2];
958
728
  const suffix = `**/**.{js,jsx,ts,tsx}`;
959
- const combined = _3.map(_3.castArray(namespaceConfig), (v) => {
729
+ const combined = _2.map(_2.castArray(namespaceConfig), (v) => {
960
730
  v = v.endsWith("/") ? v : v + "/";
961
731
  return v + suffix;
962
732
  });
963
- log10.info("\u6B63\u5728\u5904\u7406 namespace: %s", pc3.green(namespace2));
964
- log10.info("\u9884\u8BA1\u5904\u7406\u7684\u6587\u4EF6\u8DEF\u5F84: %s", pc3.green(combined.join("\n")));
733
+ log8.info("\u6B63\u5728\u5904\u7406 namespace: %s", pc2.green(namespace2));
734
+ log8.info("\u9884\u8BA1\u5904\u7406\u7684\u6587\u4EF6\u8DEF\u5F84: %s", pc2.green(combined.join("\n")));
965
735
  const files = await globby2(
966
736
  [
967
737
  "!**/node_modules/**",
968
738
  "!**.d.ts",
969
739
  "!**/.next/**",
970
740
  "!**/out/**"
741
+ //
971
742
  ].concat(combined),
972
743
  { cwd: i18nConfig.cwd }
973
744
  );
974
- log10.info("\u9884\u8BA1\u5171\u5904\u7406 %s \u4E2A\u6587\u4EF6", pc3.green(files.length));
745
+ log8.info("\u9884\u8BA1\u5171\u5904\u7406 %s \u4E2A\u6587\u4EF6", pc2.green(files.length));
975
746
  let transformedFileSet = /* @__PURE__ */ new Set();
976
- await pMap6(files, async (file) => {
977
- const content = await fs5.readFile(file, "utf-8");
747
+ await pMap4(files, async (file) => {
748
+ const content = await fs4.readFile(file, "utf-8");
978
749
  const newContent = await autoNamespace(
979
750
  content,
980
751
  namespace2,
981
752
  i18nConfig.namespaceSeparator
982
753
  );
983
754
  if (newContent) {
984
- await fs5.writeFile(file, newContent);
755
+ await fs4.writeFile(file, newContent);
985
756
  await formatFile(file);
986
757
  transformedFileSet.add(file);
987
758
  }
988
759
  });
989
- log10.info(
760
+ log8.info(
990
761
  "\u5DF2\u4E3A %s \u4E2A\u6587\u4EF6 \u81EA\u52A8\u6DFB\u52A0 namespace",
991
- pc3.green(transformedFileSet.size)
762
+ pc2.green(transformedFileSet.size)
992
763
  );
993
764
  }
994
765
  }
995
766
 
767
+ // src/commands/upload.ts
768
+ import _3 from "lodash";
769
+ import pMap5 from "p-map";
770
+ var log9 = createLogger("upload");
771
+ async function batchUpdateKeys(config) {
772
+ let sheetData = await resolveSheetData(config);
773
+ const allKeys = [];
774
+ const i18nDataMap = /* @__PURE__ */ new Map();
775
+ await pMap5(config.locales ?? [], async (locale) => {
776
+ const i18nData = new I18nData(locale, config);
777
+ i18nDataMap.set(locale, i18nData);
778
+ const data = await i18nData.loadData();
779
+ allKeys.push(...Object.keys(data));
780
+ });
781
+ let needSyncKeys = Array.from(new Set(allKeys)).filter((key) => {
782
+ return !sheetData.keySet.has(key);
783
+ });
784
+ needSyncKeys = _3.sortBy(needSyncKeys);
785
+ if (needSyncKeys.length) {
786
+ log9.info(`\u5373\u5C06\u540C\u6B65\u672C\u5730\u65B0\u589E\u52A0 ${needSyncKeys.length} \u4E2A i18nKey \u5230\u4E91\u7AEF`);
787
+ await googleSheet.updateColumn(
788
+ config.sheetId,
789
+ config.sheetRange,
790
+ letterToNumber(config.position.key),
791
+ sheetData.nextAppendRowIndex,
792
+ needSyncKeys
793
+ );
794
+ log9.info("\u540C\u6B65\u65B0\u589E\u52A0i18nKey\u6210\u529F");
795
+ for (const lang of config.locales) {
796
+ const langFile = i18nDataMap.get(lang);
797
+ const needSyncValues = [];
798
+ needSyncKeys.forEach((k) => {
799
+ if (langFile) {
800
+ needSyncValues.push(langFile.data[k]);
801
+ }
802
+ });
803
+ log9.info(
804
+ `\u5373\u5C06\u540C\u6B65\u672C\u5730 ${lang} \u65B0\u589E\u52A0 ${needSyncValues.length} \u4E2A\u503C\u5230\u4E91\u7AEF`
805
+ );
806
+ await googleSheet.updateColumn(
807
+ config.sheetId,
808
+ config.sheetRange,
809
+ letterToNumber(config.position[lang]),
810
+ sheetData.nextAppendRowIndex,
811
+ needSyncValues
812
+ );
813
+ }
814
+ await sleep(1e3);
815
+ sheetData = await resolveSheetData(config);
816
+ log9.info(`\u5DF2\u91CD\u65B0\u83B7\u53D6 ${config.sheetRange} \u7684\u6570\u636E`);
817
+ }
818
+ return { sheetData, i18nDataMap };
819
+ }
820
+ async function upload() {
821
+ const config = await getConfig();
822
+ let i18nConfigs = await promptI18nConfigEnable(config.i18n);
823
+ for (const configItem of i18nConfigs) {
824
+ const { sheetData, i18nDataMap } = await batchUpdateKeys(configItem);
825
+ await pMap5(configItem.locales ?? [], async (locale) => {
826
+ const i18nData = i18nDataMap.get(locale);
827
+ await i18nData.trySaveToGoogle(sheetData);
828
+ });
829
+ }
830
+ log9.info("\u4E0A\u4F20\u6210\u529F");
831
+ }
832
+
996
833
  // src/cli.ts
997
834
  cli.command("download", "\u751F\u6210\u7FFB\u8BD1\u6587\u4EF6").example("dune download").action(download);
998
835
  cli.command("extract", "\u63D0\u53D6\u4EE3\u7801\u4E2D\u7684\u6587\u6848").option("--deleteUnused", "\u5220\u9664\u672A\u4F7F\u7528\u7684\u6587\u6848").example("dune extract").action(extract);
@@ -1003,6 +840,7 @@ cli.command("namespaceReg", "\u6DFB\u52A0namespace\u524D\u7F00\uFF0C\u7531\u6B63
1003
840
  return namespace({ mode: "reg" });
1004
841
  });
1005
842
  cli.command("upload", "\u4E0A\u4F20\u7FFB\u8BD1\u6587\u4EF6").example("dune upload").action(upload);
843
+ cli.command("downloadFromPlatform", "\u4ECE\u7FFB\u8BD1\u5E73\u53F0\u4E0B\u8F7D\u6587\u4EF6").example("dune downloadFromPlatform").action(downloadFromPlatform);
1006
844
  cli.command("generateApi", "\u751F\u6210api\u6587\u4EF6").example("dune generateApi").action(generateApi);
1007
845
  cli.command("init", "\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6").example("dune init").action(initConfig);
1008
846
  cli.command("interactive", "\u4EA4\u4E92\u5F0F\u64CD\u4F5C").example("dune interactive").alias("i").action(interactive);