@dune2/cli 0.4.0 → 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/{chunk-3E4MHEA4.js → chunk-4BXCANQI.js} +9 -1
- package/dist/chunk-4BXCANQI.js.map +1 -0
- package/dist/chunk-KCETBI3Y.js +483 -0
- package/dist/chunk-KCETBI3Y.js.map +1 -0
- package/dist/chunk-UGSBKD2I.js +37 -0
- package/dist/chunk-UGSBKD2I.js.map +1 -0
- package/dist/cli.js +276 -442
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +5 -2
- package/dist/normalizeConfig.d.ts +1 -1
- package/dist/normalizeConfig.js +1 -1
- package/dist/prettier.cjs.map +1 -1
- package/dist/prettier.d.cts +12 -0
- package/dist/prettier.js.map +1 -1
- package/dist/{types-acd58ece.d.ts → types-qEzXY222.d.ts} +16 -1
- package/dist/uploadToTranslatePlatform-GK4VUXIU.js +45 -0
- package/dist/uploadToTranslatePlatform-GK4VUXIU.js.map +1 -0
- package/package.json +5 -4
- package/dist/chunk-3E4MHEA4.js.map +0 -1
- package/dist/chunk-577AQ66N.js +0 -263
- package/dist/chunk-577AQ66N.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,203 +1,130 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
I18nData,
|
|
4
4
|
configName,
|
|
5
|
-
|
|
5
|
+
downloadFromPlatform,
|
|
6
6
|
getConfig,
|
|
7
7
|
googleSheet,
|
|
8
|
-
letterToNumber
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
//
|
|
13
|
-
|
|
14
|
-
import { globby } from "globby";
|
|
15
|
-
import pMap2 from "p-map";
|
|
17
|
+
// package.json
|
|
18
|
+
var version = "0.4.1";
|
|
16
19
|
|
|
17
|
-
// src/
|
|
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/
|
|
32
|
-
var log = createLogger("
|
|
33
|
-
var
|
|
34
|
-
constructor(
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
43
|
+
await googleSheet.updateCell(
|
|
44
|
+
this.spreadsheetId,
|
|
45
|
+
this.range,
|
|
46
|
+
this.colIndex,
|
|
47
|
+
this.rowIndex,
|
|
48
|
+
newValue
|
|
49
|
+
);
|
|
63
50
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
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/
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
|
248
|
+
const content = await fs.readFile(file, "utf-8");
|
|
290
249
|
const res = await extract2(content, file);
|
|
291
250
|
if (res.data.size) {
|
|
292
|
-
|
|
251
|
+
log3.info(
|
|
293
252
|
"\u4ECE %s \u4E2D\u63D0\u53D6\u5230 %s \u6761\u6587\u6848",
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
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(
|
|
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 =
|
|
337
|
-
await
|
|
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
|
|
306
|
+
await fs.writeJSON(
|
|
345
307
|
metaDataJsonPath,
|
|
346
308
|
data,
|
|
347
309
|
{
|
|
@@ -350,172 +312,42 @@ 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
|
|
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
|
|
490
|
-
import
|
|
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
|
|
326
|
+
var log4 = createLogger("formatFile");
|
|
495
327
|
function formatFile(filename) {
|
|
496
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
515
|
-
await
|
|
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
|
-
|
|
350
|
+
log5.info("\u5F00\u59CB\u89E3\u6790 %s", apiConfig.swaggerJSONPath);
|
|
519
351
|
const parsed = await SwaggerParser.dereference(apiConfig.swaggerJSONPath, {
|
|
520
352
|
resolve: {
|
|
521
353
|
http: {
|
|
@@ -523,10 +355,10 @@ async function generateApi() {
|
|
|
523
355
|
}
|
|
524
356
|
}
|
|
525
357
|
});
|
|
526
|
-
await
|
|
527
|
-
|
|
358
|
+
await pMap3(Object.entries(parsed.paths), async ([url, pathItemObject]) => {
|
|
359
|
+
log5.info("\u5F00\u59CB\u751F\u6210 %s", url);
|
|
528
360
|
if (pathItemObject) {
|
|
529
|
-
await
|
|
361
|
+
await pMap3(
|
|
530
362
|
["get", "put", "post", "delete", "patch"],
|
|
531
363
|
async (method) => {
|
|
532
364
|
const operationObject = pathItemObject[method];
|
|
@@ -537,13 +369,13 @@ async function generateApi() {
|
|
|
537
369
|
operationObject,
|
|
538
370
|
apiConfig
|
|
539
371
|
});
|
|
540
|
-
const outputPath =
|
|
372
|
+
const outputPath = path2.join(
|
|
541
373
|
apiConfig.output,
|
|
542
374
|
url,
|
|
543
375
|
apiConfig.enableTs ? `${method}.ts` : `${method}.js`
|
|
544
376
|
).replace(/:/g, "_");
|
|
545
|
-
await
|
|
546
|
-
await
|
|
377
|
+
await fs2.ensureFile(outputPath);
|
|
378
|
+
await fs2.writeFile(outputPath, code);
|
|
547
379
|
}
|
|
548
380
|
}
|
|
549
381
|
);
|
|
@@ -553,7 +385,7 @@ async function generateApi() {
|
|
|
553
385
|
await formatFile(apiConfig.output);
|
|
554
386
|
}
|
|
555
387
|
}
|
|
556
|
-
|
|
388
|
+
log5.info("generateApi Done");
|
|
557
389
|
}
|
|
558
390
|
async function generateApiRequestCode(options) {
|
|
559
391
|
var _a, _b;
|
|
@@ -656,6 +488,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
|
|
|
656
488
|
{
|
|
657
489
|
...schema2,
|
|
658
490
|
description: p.description
|
|
491
|
+
// enum: schema.enum ?? [],
|
|
659
492
|
}
|
|
660
493
|
];
|
|
661
494
|
})
|
|
@@ -674,6 +507,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
|
|
|
674
507
|
bannerComment: "",
|
|
675
508
|
ignoreMinAndMaxItems: true,
|
|
676
509
|
additionalProperties: false
|
|
510
|
+
// format: false,
|
|
677
511
|
});
|
|
678
512
|
const isPageSearchRequest = (data) => {
|
|
679
513
|
const keys = ["pageNum", "pageSize", "count"];
|
|
@@ -686,7 +520,7 @@ async function compileRequestParams(operationObject, generateFieldsMap = false)
|
|
|
686
520
|
});
|
|
687
521
|
}
|
|
688
522
|
} catch (e) {
|
|
689
|
-
|
|
523
|
+
log5.error("\u751F\u6210\u8BF7\u6C42\u53C2\u6570\u7C7B\u578B\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 %o", {
|
|
690
524
|
summary: operationObject.summary,
|
|
691
525
|
message: e.message
|
|
692
526
|
});
|
|
@@ -712,6 +546,7 @@ async function compileResponseParams(operationObject, apiConfig) {
|
|
|
712
546
|
bannerComment: "",
|
|
713
547
|
ignoreMinAndMaxItems: true,
|
|
714
548
|
additionalProperties: false
|
|
549
|
+
// format: false,
|
|
715
550
|
});
|
|
716
551
|
const isPageSearchResponse = (data2) => {
|
|
717
552
|
return _.get(data2, "type") === "object" && _.get(data2, "properties.result.type") === "array";
|
|
@@ -720,13 +555,13 @@ async function compileResponseParams(operationObject, apiConfig) {
|
|
|
720
555
|
code += `${os2.EOL}export type ResultItem = Res['result'][0]`;
|
|
721
556
|
}
|
|
722
557
|
} catch (e) {
|
|
723
|
-
|
|
558
|
+
log5.error("\u8F6C\u6362\u54CD\u5E94\u53C2\u6570\u7C7B\u578B\u5931\u8D25, \u8BF7\u68C0\u67E5 %o", {
|
|
724
559
|
summary: operationObject.summary,
|
|
725
560
|
error: e.message
|
|
726
561
|
});
|
|
727
562
|
}
|
|
728
563
|
} else {
|
|
729
|
-
|
|
564
|
+
log5.error("responseSchemaTransformer \u8FD4\u56DE\u503C\u4E3A\u7A7A, \u8BF7\u68C0\u67E5");
|
|
730
565
|
}
|
|
731
566
|
}
|
|
732
567
|
return code ? code : "export type Res = any;";
|
|
@@ -749,9 +584,9 @@ function markCircularToRef(obj, parentMark = "#", map = /* @__PURE__ */ new Map(
|
|
|
749
584
|
}
|
|
750
585
|
|
|
751
586
|
// src/commands/initConfig.ts
|
|
752
|
-
import
|
|
753
|
-
import
|
|
754
|
-
var
|
|
587
|
+
import fs3 from "fs-extra";
|
|
588
|
+
import path3 from "path";
|
|
589
|
+
var log6 = createLogger("initConfig");
|
|
755
590
|
var tpl = `/**
|
|
756
591
|
* @param {import('@dune2/cli').Config} config
|
|
757
592
|
*/
|
|
@@ -762,89 +597,20 @@ module.exports = defineConfig({ i18n: [], api:[] });
|
|
|
762
597
|
`;
|
|
763
598
|
var initConfig = async () => {
|
|
764
599
|
const config = await getConfig();
|
|
765
|
-
const configPath =
|
|
766
|
-
|
|
767
|
-
if (await
|
|
768
|
-
|
|
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`);
|
|
769
604
|
return;
|
|
770
605
|
}
|
|
771
|
-
await
|
|
772
|
-
|
|
606
|
+
await fs3.writeFile(configPath, tpl);
|
|
607
|
+
log6.info(`config file created`);
|
|
773
608
|
};
|
|
774
609
|
|
|
775
|
-
// src/commands/upload.ts
|
|
776
|
-
import _2 from "lodash";
|
|
777
|
-
import pMap5 from "p-map";
|
|
778
|
-
var log8 = createLogger("upload");
|
|
779
|
-
async function batchUpdateKeys(config) {
|
|
780
|
-
let sheetData = await resolveSheetData(config);
|
|
781
|
-
const allKeys = [];
|
|
782
|
-
const i18nDataMap = /* @__PURE__ */ new Map();
|
|
783
|
-
await pMap5(config.locales ?? [], async (locale) => {
|
|
784
|
-
const i18nData = new I18nData(locale, config);
|
|
785
|
-
i18nDataMap.set(locale, i18nData);
|
|
786
|
-
const data = await i18nData.loadData();
|
|
787
|
-
allKeys.push(...Object.keys(data));
|
|
788
|
-
});
|
|
789
|
-
let needSyncKeys = Array.from(new Set(allKeys)).filter((key) => {
|
|
790
|
-
return !sheetData.keySet.has(key);
|
|
791
|
-
});
|
|
792
|
-
needSyncKeys = _2.sortBy(needSyncKeys);
|
|
793
|
-
if (needSyncKeys.length) {
|
|
794
|
-
log8.info(`\u5373\u5C06\u540C\u6B65\u672C\u5730\u65B0\u589E\u52A0 ${needSyncKeys.length} \u4E2A i18nKey \u5230\u4E91\u7AEF`);
|
|
795
|
-
await googleSheet.updateColumn(
|
|
796
|
-
config.sheetId,
|
|
797
|
-
config.sheetRange,
|
|
798
|
-
letterToNumber(config.position.key),
|
|
799
|
-
sheetData.nextAppendRowIndex,
|
|
800
|
-
needSyncKeys
|
|
801
|
-
);
|
|
802
|
-
log8.info("\u540C\u6B65\u65B0\u589E\u52A0i18nKey\u6210\u529F");
|
|
803
|
-
for (const lang of config.locales) {
|
|
804
|
-
const langFile = i18nDataMap.get(lang);
|
|
805
|
-
const needSyncValues = [];
|
|
806
|
-
needSyncKeys.forEach((k) => {
|
|
807
|
-
if (langFile) {
|
|
808
|
-
needSyncValues.push(langFile.data[k]);
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
log8.info(
|
|
812
|
-
`\u5373\u5C06\u540C\u6B65\u672C\u5730 ${lang} \u65B0\u589E\u52A0 ${needSyncValues.length} \u4E2A\u503C\u5230\u4E91\u7AEF`
|
|
813
|
-
);
|
|
814
|
-
await googleSheet.updateColumn(
|
|
815
|
-
config.sheetId,
|
|
816
|
-
config.sheetRange,
|
|
817
|
-
letterToNumber(config.position[lang]),
|
|
818
|
-
sheetData.nextAppendRowIndex,
|
|
819
|
-
needSyncValues
|
|
820
|
-
);
|
|
821
|
-
}
|
|
822
|
-
await sleep(1e3);
|
|
823
|
-
sheetData = await resolveSheetData(config);
|
|
824
|
-
log8.info(`\u5DF2\u91CD\u65B0\u83B7\u53D6 ${config.sheetRange} \u7684\u6570\u636E`);
|
|
825
|
-
}
|
|
826
|
-
return { sheetData, i18nDataMap };
|
|
827
|
-
}
|
|
828
|
-
async function upload() {
|
|
829
|
-
const config = await getConfig();
|
|
830
|
-
let i18nConfigs = await promptI18nConfigEnable(config.i18n);
|
|
831
|
-
for (const configItem of i18nConfigs) {
|
|
832
|
-
const { sheetData, i18nDataMap } = await batchUpdateKeys(configItem);
|
|
833
|
-
await pMap5(configItem.locales ?? [], async (locale) => {
|
|
834
|
-
const i18nData = i18nDataMap.get(locale);
|
|
835
|
-
await i18nData.trySaveToGoogle(sheetData);
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
log8.info("\u4E0A\u4F20\u6210\u529F");
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// package.json
|
|
842
|
-
var version = "0.3.15";
|
|
843
|
-
|
|
844
610
|
// src/commands/interactive.ts
|
|
845
611
|
import enquirer2 from "enquirer";
|
|
846
612
|
var { prompt: prompt2 } = enquirer2;
|
|
847
|
-
var
|
|
613
|
+
var log7 = createLogger("interactive");
|
|
848
614
|
var interactive = async (args) => {
|
|
849
615
|
var _a;
|
|
850
616
|
const commands = cli.commands.filter((command2) => {
|
|
@@ -870,7 +636,7 @@ var interactive = async (args) => {
|
|
|
870
636
|
});
|
|
871
637
|
const command = commandMap.get(res.command);
|
|
872
638
|
if (!command) {
|
|
873
|
-
|
|
639
|
+
log7.error("\u672A\u627E\u5230\u547D\u4EE4 %s", res.command);
|
|
874
640
|
return;
|
|
875
641
|
}
|
|
876
642
|
(_a = command.commandAction) == null ? void 0 : _a.apply(cli, args);
|
|
@@ -878,11 +644,11 @@ var interactive = async (args) => {
|
|
|
878
644
|
|
|
879
645
|
// src/commands/namespace.ts
|
|
880
646
|
import enquirer3 from "enquirer";
|
|
881
|
-
import
|
|
647
|
+
import _2 from "lodash";
|
|
882
648
|
import { globby as globby2 } from "globby";
|
|
883
|
-
import
|
|
884
|
-
import
|
|
885
|
-
import
|
|
649
|
+
import fs4 from "fs-extra";
|
|
650
|
+
import pMap4 from "p-map";
|
|
651
|
+
import pc2 from "picocolors";
|
|
886
652
|
|
|
887
653
|
// src/shared/autoNamespaceByReg.ts
|
|
888
654
|
function autoNamespaceByReg(code, namespace2) {
|
|
@@ -909,14 +675,14 @@ function autoNamespaceByReg(code, namespace2) {
|
|
|
909
675
|
|
|
910
676
|
// src/commands/namespace.ts
|
|
911
677
|
var { prompt: prompt3 } = enquirer3;
|
|
912
|
-
var
|
|
678
|
+
var log8 = createLogger("namespace");
|
|
913
679
|
async function namespace(params) {
|
|
914
680
|
var _a, _b;
|
|
915
681
|
const { mode = "swc" } = params;
|
|
916
682
|
const config = await getConfig();
|
|
917
683
|
let i18nConfigs = (_a = config.i18n) == null ? void 0 : _a.filter((item) => !item.disableExtract);
|
|
918
684
|
if (!i18nConfigs) {
|
|
919
|
-
|
|
685
|
+
log8.info("\u6CA1\u6709\u914D\u7F6E i18n");
|
|
920
686
|
return;
|
|
921
687
|
}
|
|
922
688
|
const { i18nDir } = await prompt3({
|
|
@@ -932,7 +698,7 @@ async function namespace(params) {
|
|
|
932
698
|
});
|
|
933
699
|
let i18nConfig = i18nConfigs.find((item) => item.i18nDir === i18nDir);
|
|
934
700
|
if (!i18nConfig) {
|
|
935
|
-
|
|
701
|
+
log8.info("\u6CA1\u6709\u627E\u5230\u5BF9\u5E94\u7684\u914D\u7F6E");
|
|
936
702
|
return;
|
|
937
703
|
}
|
|
938
704
|
const { namespaces } = await prompt3({
|
|
@@ -943,7 +709,7 @@ async function namespace(params) {
|
|
|
943
709
|
validate(value) {
|
|
944
710
|
return value.length === 0 ? `\u81F3\u5C11\u9009\u62E9\u4E00\u9879` : true;
|
|
945
711
|
},
|
|
946
|
-
choices:
|
|
712
|
+
choices: _2.map(i18nConfig.namespace, (v, k) => {
|
|
947
713
|
return {
|
|
948
714
|
name: k
|
|
949
715
|
};
|
|
@@ -951,50 +717,117 @@ async function namespace(params) {
|
|
|
951
717
|
});
|
|
952
718
|
const autoNamespace = await (() => {
|
|
953
719
|
if (mode === "swc") {
|
|
954
|
-
|
|
720
|
+
log8.info("\u4F7F\u7528 swc \u6765\u5904\u7406");
|
|
955
721
|
return import("@dune2/wasm").then((m) => m.autoNamespace);
|
|
956
722
|
}
|
|
957
|
-
|
|
723
|
+
log8.info("\u4F7F\u7528 reg \u6765\u5904\u7406");
|
|
958
724
|
return autoNamespaceByReg;
|
|
959
725
|
})();
|
|
960
726
|
for (const namespace2 of namespaces) {
|
|
961
727
|
const namespaceConfig = (_b = i18nConfig.namespace) == null ? void 0 : _b[namespace2];
|
|
962
728
|
const suffix = `**/**.{js,jsx,ts,tsx}`;
|
|
963
|
-
const combined =
|
|
729
|
+
const combined = _2.map(_2.castArray(namespaceConfig), (v) => {
|
|
964
730
|
v = v.endsWith("/") ? v : v + "/";
|
|
965
731
|
return v + suffix;
|
|
966
732
|
});
|
|
967
|
-
|
|
968
|
-
|
|
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")));
|
|
969
735
|
const files = await globby2(
|
|
970
736
|
[
|
|
971
737
|
"!**/node_modules/**",
|
|
972
738
|
"!**.d.ts",
|
|
973
739
|
"!**/.next/**",
|
|
974
740
|
"!**/out/**"
|
|
741
|
+
//
|
|
975
742
|
].concat(combined),
|
|
976
743
|
{ cwd: i18nConfig.cwd }
|
|
977
744
|
);
|
|
978
|
-
|
|
745
|
+
log8.info("\u9884\u8BA1\u5171\u5904\u7406 %s \u4E2A\u6587\u4EF6", pc2.green(files.length));
|
|
979
746
|
let transformedFileSet = /* @__PURE__ */ new Set();
|
|
980
|
-
await
|
|
981
|
-
const content = await
|
|
747
|
+
await pMap4(files, async (file) => {
|
|
748
|
+
const content = await fs4.readFile(file, "utf-8");
|
|
982
749
|
const newContent = await autoNamespace(
|
|
983
750
|
content,
|
|
984
751
|
namespace2,
|
|
985
752
|
i18nConfig.namespaceSeparator
|
|
986
753
|
);
|
|
987
754
|
if (newContent) {
|
|
988
|
-
await
|
|
755
|
+
await fs4.writeFile(file, newContent);
|
|
989
756
|
await formatFile(file);
|
|
990
757
|
transformedFileSet.add(file);
|
|
991
758
|
}
|
|
992
759
|
});
|
|
993
|
-
|
|
760
|
+
log8.info(
|
|
994
761
|
"\u5DF2\u4E3A %s \u4E2A\u6587\u4EF6 \u81EA\u52A8\u6DFB\u52A0 namespace",
|
|
995
|
-
|
|
762
|
+
pc2.green(transformedFileSet.size)
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
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
|
|
996
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
|
+
});
|
|
997
829
|
}
|
|
830
|
+
log9.info("\u4E0A\u4F20\u6210\u529F");
|
|
998
831
|
}
|
|
999
832
|
|
|
1000
833
|
// src/cli.ts
|
|
@@ -1007,6 +840,7 @@ cli.command("namespaceReg", "\u6DFB\u52A0namespace\u524D\u7F00\uFF0C\u7531\u6B63
|
|
|
1007
840
|
return namespace({ mode: "reg" });
|
|
1008
841
|
});
|
|
1009
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);
|
|
1010
844
|
cli.command("generateApi", "\u751F\u6210api\u6587\u4EF6").example("dune generateApi").action(generateApi);
|
|
1011
845
|
cli.command("init", "\u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6").example("dune init").action(initConfig);
|
|
1012
846
|
cli.command("interactive", "\u4EA4\u4E92\u5F0F\u64CD\u4F5C").example("dune interactive").alias("i").action(interactive);
|