@dune2/cli 0.1.25 → 0.1.27
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-IPRK5TYY.js +302 -0
- package/dist/chunk-IPRK5TYY.js.map +1 -0
- package/dist/cli.js +89 -300
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +11 -3
- package/package.json +1 -1
- package/dist/chunk-RADJ36VS.js +0 -74
- package/dist/chunk-RADJ36VS.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,51 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
cli,
|
|
3
4
|
configName,
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
createLogger,
|
|
6
|
+
getConfig,
|
|
7
|
+
googleSheet,
|
|
8
|
+
letterToNumber
|
|
9
|
+
} from "./chunk-IPRK5TYY.js";
|
|
6
10
|
|
|
7
11
|
// src/commands/extract.ts
|
|
8
|
-
import
|
|
12
|
+
import fs2 from "fs-extra";
|
|
9
13
|
import { globby } from "globby";
|
|
10
14
|
import pMap2 from "p-map";
|
|
11
15
|
|
|
12
|
-
// src/shared/index.ts
|
|
13
|
-
import cac from "cac";
|
|
14
|
-
import debug from "debug";
|
|
15
|
-
import path from "path";
|
|
16
|
-
import fs from "fs-extra";
|
|
17
|
-
var cli = cac("dune");
|
|
18
|
-
var createLogger = (name) => {
|
|
19
|
-
const info = debug(`${cli.name}:${name}`);
|
|
20
|
-
return {
|
|
21
|
-
...info,
|
|
22
|
-
info,
|
|
23
|
-
error: info.extend("error")
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
debug.enable(`${cli.name}:*`);
|
|
27
|
-
var homeConfigDir = (() => {
|
|
28
|
-
const isWin = process.platform === "win32";
|
|
29
|
-
const USER_HOME_DIR = isWin ? process.env.USERPROFILE : process.env.HOME;
|
|
30
|
-
const configDir = path.join(USER_HOME_DIR, ".config", cli.name);
|
|
31
|
-
if (!fs.existsSync(configDir)) {
|
|
32
|
-
fs.mkdirSync(configDir);
|
|
33
|
-
}
|
|
34
|
-
return homeConfigDir2;
|
|
35
|
-
function homeConfigDir2(p) {
|
|
36
|
-
if (!p) {
|
|
37
|
-
return configDir;
|
|
38
|
-
}
|
|
39
|
-
return path.join(configDir, p);
|
|
40
|
-
}
|
|
41
|
-
})();
|
|
42
|
-
|
|
43
16
|
// src/shared/i18nData.ts
|
|
44
17
|
import pMap from "p-map";
|
|
45
|
-
import
|
|
18
|
+
import fs from "fs-extra";
|
|
46
19
|
import pc from "picocolors";
|
|
47
|
-
import
|
|
20
|
+
import path from "path";
|
|
48
21
|
import Table from "cli-table3";
|
|
22
|
+
|
|
23
|
+
// src/shared/sleep.ts
|
|
24
|
+
function sleep(ms) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
setTimeout(resolve, ms);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/shared/i18nData.ts
|
|
49
31
|
var log = createLogger("i18nData");
|
|
50
32
|
var I18nData = class {
|
|
51
33
|
constructor(locale, config, shouldDeleteUnused = false) {
|
|
@@ -55,7 +37,7 @@ var I18nData = class {
|
|
|
55
37
|
this.data = {};
|
|
56
38
|
this.unUsedKeys = /* @__PURE__ */ new Set();
|
|
57
39
|
this.isDefaultLocale = locale === config.defaultLocale;
|
|
58
|
-
this.filePath =
|
|
40
|
+
this.filePath = path.join(
|
|
59
41
|
config.cwd,
|
|
60
42
|
config.i18nDir,
|
|
61
43
|
config.i18nFileName.replace("{locale}", locale)
|
|
@@ -63,8 +45,8 @@ var I18nData = class {
|
|
|
63
45
|
}
|
|
64
46
|
async loadData() {
|
|
65
47
|
try {
|
|
66
|
-
if (await
|
|
67
|
-
this.data = await
|
|
48
|
+
if (await fs.pathExists(this.filePath)) {
|
|
49
|
+
this.data = await fs.readJSON(this.filePath);
|
|
68
50
|
} else {
|
|
69
51
|
log.info("File '%s' does not exist", pc.dim(this.filePath));
|
|
70
52
|
}
|
|
@@ -118,8 +100,8 @@ var I18nData = class {
|
|
|
118
100
|
pc.dim(this.filePath)
|
|
119
101
|
);
|
|
120
102
|
try {
|
|
121
|
-
await
|
|
122
|
-
await
|
|
103
|
+
await fs.ensureFile(this.filePath);
|
|
104
|
+
await fs.writeJson(this.filePath, this.data, { spaces: 2 });
|
|
123
105
|
log.info(
|
|
124
106
|
"Saved i18n data for locale '%s' to file '%s'",
|
|
125
107
|
pc.green(this.locale),
|
|
@@ -135,19 +117,24 @@ var I18nData = class {
|
|
|
135
117
|
}
|
|
136
118
|
}
|
|
137
119
|
async trySaveToGoogle(sheetData) {
|
|
138
|
-
await pMap(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
120
|
+
await pMap(
|
|
121
|
+
Object.entries(this.data),
|
|
122
|
+
async ([key, value]) => {
|
|
123
|
+
var _a;
|
|
124
|
+
if (sheetData.hasI18nItem(this.locale, key)) {
|
|
125
|
+
await ((_a = sheetData.getI18nItem(this.locale, key)) == null ? void 0 : _a.tryUpdate(value));
|
|
126
|
+
await sleep(500);
|
|
127
|
+
} else {
|
|
128
|
+
log.error(
|
|
129
|
+
"%s range %s not found key %s",
|
|
130
|
+
pc.bold(this.config.sheetRange),
|
|
131
|
+
pc.bold(this.locale),
|
|
132
|
+
pc.bold(key)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{ concurrency: 50 }
|
|
137
|
+
);
|
|
151
138
|
}
|
|
152
139
|
statistic() {
|
|
153
140
|
const total = Object.keys(this.data).length;
|
|
@@ -265,7 +252,7 @@ function promptApiConfigEnable(configArr) {
|
|
|
265
252
|
}
|
|
266
253
|
|
|
267
254
|
// src/commands/extract.ts
|
|
268
|
-
import
|
|
255
|
+
import path2 from "path";
|
|
269
256
|
var log2 = createLogger("extract");
|
|
270
257
|
async function extract(opts) {
|
|
271
258
|
const config = await getConfig();
|
|
@@ -288,7 +275,7 @@ async function extract(opts) {
|
|
|
288
275
|
await pMap2(
|
|
289
276
|
files,
|
|
290
277
|
async (file) => {
|
|
291
|
-
const content = await
|
|
278
|
+
const content = await fs2.readFile(file, "utf-8");
|
|
292
279
|
const res = await extract2(content, file);
|
|
293
280
|
if (res.data.size) {
|
|
294
281
|
log2.info(
|
|
@@ -330,9 +317,9 @@ async function extract(opts) {
|
|
|
330
317
|
}
|
|
331
318
|
}
|
|
332
319
|
async function saveDebugLog(dir, extractedI18nDataMap) {
|
|
333
|
-
await
|
|
334
|
-
await
|
|
335
|
-
|
|
320
|
+
await fs2.ensureDirSync(dir);
|
|
321
|
+
await fs2.writeJSON(
|
|
322
|
+
path2.join(dir, "extractedI18nDataMap.json"),
|
|
336
323
|
Array.from(extractedI18nDataMap.entries()).map(([key, value]) => value),
|
|
337
324
|
{
|
|
338
325
|
spaces: 2
|
|
@@ -343,201 +330,8 @@ async function saveDebugLog(dir, extractedI18nDataMap) {
|
|
|
343
330
|
// src/commands/download.ts
|
|
344
331
|
import pMap3 from "p-map";
|
|
345
332
|
|
|
346
|
-
// src/shared/google/sheet.ts
|
|
347
|
-
import { google as google2 } from "googleapis";
|
|
348
|
-
|
|
349
|
-
// src/shared/letters.ts
|
|
350
|
-
function letterToNumber(letters) {
|
|
351
|
-
if (typeof letters === "number" || !Number.isNaN(+letters)) {
|
|
352
|
-
return +letters;
|
|
353
|
-
}
|
|
354
|
-
let n = 0;
|
|
355
|
-
letters = letters.toUpperCase();
|
|
356
|
-
for (let p = 0; p < letters.length; p++) {
|
|
357
|
-
n = letters[p].charCodeAt(0) - 64 + n * 26;
|
|
358
|
-
}
|
|
359
|
-
return Math.max(0, n - 1);
|
|
360
|
-
}
|
|
361
|
-
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
362
|
-
var base = alphabet.length;
|
|
363
|
-
function numberToLetter(n) {
|
|
364
|
-
const digits = [];
|
|
365
|
-
do {
|
|
366
|
-
const v = n % base;
|
|
367
|
-
digits.push(v);
|
|
368
|
-
n = Math.floor(n / base);
|
|
369
|
-
} while (n-- > 0);
|
|
370
|
-
const chars = [];
|
|
371
|
-
while (digits.length) {
|
|
372
|
-
chars.push(alphabet[digits.pop()]);
|
|
373
|
-
}
|
|
374
|
-
return chars.join("");
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// src/shared/google/auth.ts
|
|
378
|
-
import fs4 from "fs-extra";
|
|
379
|
-
import { google } from "googleapis";
|
|
380
|
-
|
|
381
|
-
// src/shared/google/shared.ts
|
|
382
|
-
import connect from "connect";
|
|
383
|
-
import open from "open";
|
|
384
|
-
import { URL } from "url";
|
|
385
|
-
var log3 = createLogger("google:shared");
|
|
386
|
-
function openBrowser(url) {
|
|
387
|
-
log3.info(`\u5982\u672A\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668\uFF0C\u53EF\u8BBF\u95EE\u4EE5\u4E0B\u5730\u5740\uFF1A${url}`);
|
|
388
|
-
open(url, { app: { name: open.apps.chrome } });
|
|
389
|
-
}
|
|
390
|
-
function openAndWaitReturnQuery(toOpenUrl, port, queryKey) {
|
|
391
|
-
return new Promise((resolve) => {
|
|
392
|
-
openBrowser(toOpenUrl);
|
|
393
|
-
const app = connect();
|
|
394
|
-
app.use((req, res, next) => {
|
|
395
|
-
const parsedUrl = new URL(req.url, `http://localhost:${port}`);
|
|
396
|
-
const target = parsedUrl.searchParams.get(queryKey);
|
|
397
|
-
if (target) {
|
|
398
|
-
res.writeHead(200, {
|
|
399
|
-
"content-type": "text/html;charset=utf8"
|
|
400
|
-
});
|
|
401
|
-
res.end(
|
|
402
|
-
`<div>\u5F53\u524D\u7A97\u53E3\u53EF\u76F4\u63A5\u5173\u95ED</div>
|
|
403
|
-
<script>
|
|
404
|
-
window.open("", "_self", "");
|
|
405
|
-
window.close();
|
|
406
|
-
<\/script>`
|
|
407
|
-
);
|
|
408
|
-
server.close();
|
|
409
|
-
server.unref();
|
|
410
|
-
resolve(target);
|
|
411
|
-
}
|
|
412
|
-
next();
|
|
413
|
-
});
|
|
414
|
-
const server = app.listen(port);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// src/shared/google/auth.ts
|
|
419
|
-
var log4 = createLogger("google:auth");
|
|
420
|
-
var GoogleAuth = class {
|
|
421
|
-
constructor(options) {
|
|
422
|
-
this.options = options;
|
|
423
|
-
this.tokens = null;
|
|
424
|
-
this.tokensCachePath = homeConfigDir("chromeAuthToken.json");
|
|
425
|
-
this.oauth2Client = new google.auth.OAuth2(
|
|
426
|
-
this.options.client_id,
|
|
427
|
-
this.options.client_secret,
|
|
428
|
-
"http://localhost:12345"
|
|
429
|
-
);
|
|
430
|
-
this.initCredentialsPromise = null;
|
|
431
|
-
this.options.scope = this.options.scope ?? ["spreadsheets"];
|
|
432
|
-
const scopePrefix = `https://www.googleapis.com/auth/`;
|
|
433
|
-
this.scope = this.options.scope.map((item) => {
|
|
434
|
-
if (item.startsWith(scopePrefix)) {
|
|
435
|
-
return item;
|
|
436
|
-
}
|
|
437
|
-
return `${scopePrefix}${item}`;
|
|
438
|
-
});
|
|
439
|
-
try {
|
|
440
|
-
this.tokens = fs4.readJsonSync(this.tokensCachePath);
|
|
441
|
-
} catch (e) {
|
|
442
|
-
log4.info("\u672A\u83B7\u53D6\u5230\u7F13\u5B58\u7684token");
|
|
443
|
-
this.tokens = null;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
async saveTokens(tokens) {
|
|
447
|
-
this.tokens = tokens;
|
|
448
|
-
await fs4.writeJSON(this.tokensCachePath, tokens);
|
|
449
|
-
log4.info("\u4FDD\u5B58token\u6210\u529F");
|
|
450
|
-
}
|
|
451
|
-
async getCode() {
|
|
452
|
-
log4.info("\u5C06\u6253\u5F00chrome\u6D4F\u89C8\u5668\u8FDB\u884C\u6388\u6743");
|
|
453
|
-
const authUrl = this.oauth2Client.generateAuthUrl({
|
|
454
|
-
access_type: "offline",
|
|
455
|
-
scope: this.scope
|
|
456
|
-
});
|
|
457
|
-
return await openAndWaitReturnQuery(authUrl, 12345, "code");
|
|
458
|
-
}
|
|
459
|
-
async initCredentialsImpl() {
|
|
460
|
-
if (!this.tokens) {
|
|
461
|
-
const code = await this.getCode();
|
|
462
|
-
const { tokens } = await this.oauth2Client.getToken(code);
|
|
463
|
-
await this.saveTokens(tokens);
|
|
464
|
-
}
|
|
465
|
-
this.oauth2Client.setCredentials(this.tokens);
|
|
466
|
-
}
|
|
467
|
-
async initCredentials() {
|
|
468
|
-
if (!this.initCredentialsPromise) {
|
|
469
|
-
this.initCredentialsPromise = this.initCredentialsImpl();
|
|
470
|
-
}
|
|
471
|
-
return await this.initCredentialsPromise;
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
var clientSecret = {
|
|
475
|
-
client_id: "467670582023-3sr5gnfsuebgtde1mk3vp78om43no4kv.apps.googleusercontent.com",
|
|
476
|
-
project_id: "dune-cli-376503",
|
|
477
|
-
auth_uri: "https://accounts.google.com/o/oauth2/auth",
|
|
478
|
-
token_uri: "https://oauth2.googleapis.com/token",
|
|
479
|
-
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
|
|
480
|
-
client_secret: "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",
|
|
481
|
-
redirect_uris: ["http://localhost"],
|
|
482
|
-
javascript_origins: ["http://localhost"]
|
|
483
|
-
};
|
|
484
|
-
var googleAuth = new GoogleAuth(clientSecret);
|
|
485
|
-
|
|
486
|
-
// src/shared/google/sheet.ts
|
|
487
|
-
var log5 = createLogger("google:sheets");
|
|
488
|
-
var GoogleSheet = class {
|
|
489
|
-
constructor() {
|
|
490
|
-
this.initPromise = null;
|
|
491
|
-
this.get = async (options) => {
|
|
492
|
-
await this.init();
|
|
493
|
-
return this.sheets.spreadsheets.values.get(options);
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
async initImpl() {
|
|
497
|
-
if (!this.sheets) {
|
|
498
|
-
await googleAuth.initCredentials();
|
|
499
|
-
this.sheets = google2.sheets({
|
|
500
|
-
version: "v4",
|
|
501
|
-
auth: googleAuth.oauth2Client
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
async init() {
|
|
506
|
-
if (!this.initPromise) {
|
|
507
|
-
this.initPromise = this.initImpl();
|
|
508
|
-
}
|
|
509
|
-
await this.initPromise;
|
|
510
|
-
}
|
|
511
|
-
async update(spreadsheetId, range, colIndex, rowIndex, values) {
|
|
512
|
-
await this.init();
|
|
513
|
-
const colLetter = numberToLetter(colIndex);
|
|
514
|
-
const sheetNeedRange = `${range}!${colLetter}${rowIndex}`;
|
|
515
|
-
const res = await this.sheets.spreadsheets.values.update({
|
|
516
|
-
spreadsheetId,
|
|
517
|
-
range: sheetNeedRange,
|
|
518
|
-
valueInputOption: "USER_ENTERED",
|
|
519
|
-
requestBody: { values }
|
|
520
|
-
});
|
|
521
|
-
if (res.status === 200) {
|
|
522
|
-
log5.info(`\u66F4\u65B0 ${sheetNeedRange} \u7684\u503C\u6210\u529F`);
|
|
523
|
-
} else {
|
|
524
|
-
log5.error("some thing wrong", res);
|
|
525
|
-
}
|
|
526
|
-
return res;
|
|
527
|
-
}
|
|
528
|
-
async updateCell(spreadsheetId, range, colIndex, rowIndex, values) {
|
|
529
|
-
return this.update(spreadsheetId, range, colIndex, rowIndex, [[values]]);
|
|
530
|
-
}
|
|
531
|
-
async updateColumn(spreadsheetId, range, colIndex, rowIndex, values) {
|
|
532
|
-
return this.update(spreadsheetId, range, colIndex, rowIndex, [
|
|
533
|
-
...values.map((v) => [v])
|
|
534
|
-
]);
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
var googleSheet = new GoogleSheet();
|
|
538
|
-
|
|
539
333
|
// src/shared/resolveSheetData.ts
|
|
540
|
-
var
|
|
334
|
+
var log3 = createLogger("shared:resolveSheetData");
|
|
541
335
|
var SheetI18nItem = class {
|
|
542
336
|
constructor(spreadsheetId, range, key, colIndex, row, rowIndex) {
|
|
543
337
|
this.spreadsheetId = spreadsheetId;
|
|
@@ -564,13 +358,13 @@ var SheetI18nItem = class {
|
|
|
564
358
|
async function resolveSheetData(config) {
|
|
565
359
|
const { position } = config;
|
|
566
360
|
const parseStartIndex = config.parseStartIndex ?? 2;
|
|
567
|
-
|
|
361
|
+
log3.info(`\u8BFB\u53D6 ${config.sheetRange} sheet\u6570\u636E`);
|
|
568
362
|
const res = await googleSheet.get({
|
|
569
363
|
spreadsheetId: config.sheetId,
|
|
570
364
|
range: config.sheetRange
|
|
571
365
|
});
|
|
572
366
|
if (!res.data.values) {
|
|
573
|
-
|
|
367
|
+
log3.error(
|
|
574
368
|
`${config.sheetRange} sheet\u6570\u636E\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\uFF0C\u5E94\u8BE5\u6700\u5C11\u6709\u4E00\u884C\u5934\u90E8\u6570\u636E`
|
|
575
369
|
);
|
|
576
370
|
return new SheetData(config, 2);
|
|
@@ -585,7 +379,7 @@ async function resolveSheetData(config) {
|
|
|
585
379
|
const i18nKey = row[letterToNumber(position.key)];
|
|
586
380
|
if (i18nKey) {
|
|
587
381
|
if (sheetData.keySet.has(i18nKey)) {
|
|
588
|
-
|
|
382
|
+
log3.error(
|
|
589
383
|
`\u8868\u683C ${config.sheetRange} \u53D1\u73B0\u91CD\u590D\u7684i18nKey: ${i18nKey}, \u5C06\u8986\u76D6\u524D\u9762\u7684\u503C`
|
|
590
384
|
);
|
|
591
385
|
} else {
|
|
@@ -638,7 +432,7 @@ var SheetData = class {
|
|
|
638
432
|
};
|
|
639
433
|
|
|
640
434
|
// src/commands/download.ts
|
|
641
|
-
var
|
|
435
|
+
var log4 = createLogger("generate");
|
|
642
436
|
async function download() {
|
|
643
437
|
const config = await getConfig();
|
|
644
438
|
let i18nConfigs = await promptI18nConfigEnable(config.i18n);
|
|
@@ -646,7 +440,7 @@ async function download() {
|
|
|
646
440
|
for (const configItem of i18nConfigs) {
|
|
647
441
|
i++;
|
|
648
442
|
if (!configItem.sheetId || !configItem.sheetRange) {
|
|
649
|
-
|
|
443
|
+
log4.error(`config.${i} sheetId \u6216 sheetRange \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5`);
|
|
650
444
|
continue;
|
|
651
445
|
}
|
|
652
446
|
const sheetData = await resolveSheetData(configItem);
|
|
@@ -667,26 +461,26 @@ async function download() {
|
|
|
667
461
|
import * as child_process from "child_process";
|
|
668
462
|
import _ from "lodash";
|
|
669
463
|
import pMap4 from "p-map";
|
|
670
|
-
import
|
|
464
|
+
import fs3 from "fs-extra";
|
|
671
465
|
import * as os2 from "os";
|
|
672
466
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
673
467
|
import { compile } from "json-schema-to-typescript";
|
|
674
|
-
import
|
|
675
|
-
var
|
|
468
|
+
import path3 from "path";
|
|
469
|
+
var log5 = createLogger("generateApi");
|
|
676
470
|
async function generateApi() {
|
|
677
471
|
const config = await getConfig();
|
|
678
472
|
const apiConfigs = await promptApiConfigEnable(config.api);
|
|
679
473
|
for (const apiConfig of apiConfigs) {
|
|
680
|
-
|
|
681
|
-
await
|
|
474
|
+
log5.info(`\u6E05\u9664\u65E7\u7684api\u6587\u4EF6: ${apiConfig.output}`);
|
|
475
|
+
await fs3.emptydir(apiConfig.output);
|
|
682
476
|
}
|
|
683
477
|
for (const apiConfig of apiConfigs) {
|
|
684
|
-
|
|
478
|
+
log5.info("\u5F00\u59CB\u89E3\u6790 %s", apiConfig.swaggerJSONPath);
|
|
685
479
|
const parsed = await SwaggerParser.dereference(
|
|
686
480
|
apiConfig.swaggerJSONPath
|
|
687
481
|
);
|
|
688
482
|
await pMap4(Object.entries(parsed.paths), async ([url, pathItemObject]) => {
|
|
689
|
-
|
|
483
|
+
log5.info("\u5F00\u59CB\u751F\u6210 %s", url);
|
|
690
484
|
if (pathItemObject) {
|
|
691
485
|
await pMap4(
|
|
692
486
|
["get", "put", "post", "delete", "patch"],
|
|
@@ -699,32 +493,32 @@ async function generateApi() {
|
|
|
699
493
|
operationObject,
|
|
700
494
|
apiConfig
|
|
701
495
|
});
|
|
702
|
-
const outputPath =
|
|
496
|
+
const outputPath = path3.join(
|
|
703
497
|
apiConfig.output,
|
|
704
498
|
url,
|
|
705
499
|
apiConfig.enableTs ? `${method}.ts` : `${method}.js`
|
|
706
500
|
).replace(/:/g, "_");
|
|
707
|
-
await
|
|
708
|
-
await
|
|
501
|
+
await fs3.ensureFile(outputPath);
|
|
502
|
+
await fs3.writeFile(outputPath, code);
|
|
709
503
|
}
|
|
710
504
|
}
|
|
711
505
|
);
|
|
712
506
|
}
|
|
713
507
|
});
|
|
714
508
|
if (apiConfig.format) {
|
|
715
|
-
|
|
509
|
+
log5.info(`\u5C1D\u8BD5\u683C\u5F0F\u5316\u4EE3\u7801: %s`, apiConfig.output);
|
|
716
510
|
child_process.exec(`prettier --write ${apiConfig.output}`, (error) => {
|
|
717
511
|
if (error) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
512
|
+
log5.error(`\u683C\u5F0F\u5316\u4EE3\u7801\u5931\u8D25: ${error}`);
|
|
513
|
+
log5.error(`\u8BF7\u624B\u52A8\u6267\u884C: prettier --write ${apiConfig.output}`);
|
|
514
|
+
log5.error(`\u6216\u8005\u5728\u914D\u7F6E\u6587\u4EF6\u4E2D\u5173\u95ED\u683C\u5F0F\u5316\u529F\u80FD`);
|
|
721
515
|
} else {
|
|
722
|
-
|
|
516
|
+
log5.info(`\u683C\u5F0F\u5316\u4EE3\u7801\u6210\u529F: %s`, apiConfig.output);
|
|
723
517
|
}
|
|
724
518
|
});
|
|
725
519
|
}
|
|
726
520
|
}
|
|
727
|
-
|
|
521
|
+
log5.info("generateApi Done");
|
|
728
522
|
}
|
|
729
523
|
async function generateApiRequestCode(options) {
|
|
730
524
|
var _a, _b;
|
|
@@ -831,7 +625,7 @@ async function compileRequestParams(operationObject) {
|
|
|
831
625
|
additionalProperties: false
|
|
832
626
|
});
|
|
833
627
|
} catch (e) {
|
|
834
|
-
|
|
628
|
+
log5.error("\u751F\u6210\u8BF7\u6C42\u53C2\u6570\u7C7B\u578B\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 %o", {
|
|
835
629
|
summary: operationObject.summary,
|
|
836
630
|
message: e.message
|
|
837
631
|
});
|
|
@@ -856,13 +650,13 @@ async function compileResponseParams(operationObject, apiConfig) {
|
|
|
856
650
|
additionalProperties: false
|
|
857
651
|
});
|
|
858
652
|
} catch (e) {
|
|
859
|
-
|
|
653
|
+
log5.error("\u8F6C\u6362\u54CD\u5E94\u53C2\u6570\u7C7B\u578B\u5931\u8D25, \u8BF7\u68C0\u67E5 %o", {
|
|
860
654
|
summary: operationObject.summary,
|
|
861
655
|
error: e.message
|
|
862
656
|
});
|
|
863
657
|
}
|
|
864
658
|
} else {
|
|
865
|
-
|
|
659
|
+
log5.error("responseSchemaTransformer \u8FD4\u56DE\u503C\u4E3A\u7A7A, \u8BF7\u68C0\u67E5");
|
|
866
660
|
}
|
|
867
661
|
}
|
|
868
662
|
return code ? code : "export type Res = any;";
|
|
@@ -885,9 +679,9 @@ function markCircularToRef(obj, parentMark = "#", map = /* @__PURE__ */ new Map(
|
|
|
885
679
|
}
|
|
886
680
|
|
|
887
681
|
// src/commands/initConfig.ts
|
|
888
|
-
import
|
|
889
|
-
import
|
|
890
|
-
var
|
|
682
|
+
import fs4 from "fs-extra";
|
|
683
|
+
import path4 from "path";
|
|
684
|
+
var log6 = createLogger("initConfig");
|
|
891
685
|
var tpl = `/**
|
|
892
686
|
* @template {import('@dune2/cli').Config} T
|
|
893
687
|
* @param {T} config - A generic parameter that flows through to the return type
|
|
@@ -900,19 +694,19 @@ module.exports = defineConfig({ i18n: [], api:[] });
|
|
|
900
694
|
`;
|
|
901
695
|
var initConfig = async () => {
|
|
902
696
|
const config = await getConfig();
|
|
903
|
-
const configPath =
|
|
904
|
-
|
|
905
|
-
if (await
|
|
906
|
-
|
|
697
|
+
const configPath = path4.join(config.cwd, configName);
|
|
698
|
+
log6.info(`config file path: ${configPath}`);
|
|
699
|
+
if (await fs4.pathExists(configPath)) {
|
|
700
|
+
log6.info(`config file already exists, skip`);
|
|
907
701
|
return;
|
|
908
702
|
}
|
|
909
|
-
await
|
|
910
|
-
|
|
703
|
+
await fs4.writeFile(configPath, tpl);
|
|
704
|
+
log6.info(`config file created`);
|
|
911
705
|
};
|
|
912
706
|
|
|
913
707
|
// src/commands/upload.ts
|
|
914
708
|
import pMap5 from "p-map";
|
|
915
|
-
var
|
|
709
|
+
var log7 = createLogger("upload");
|
|
916
710
|
async function batchUpdateKeys(config) {
|
|
917
711
|
let sheetData = await resolveSheetData(config);
|
|
918
712
|
const allKeys = [];
|
|
@@ -928,7 +722,7 @@ async function batchUpdateKeys(config) {
|
|
|
928
722
|
});
|
|
929
723
|
needSyncKeys = needSyncKeys.sort(config.keySorter);
|
|
930
724
|
if (needSyncKeys.length) {
|
|
931
|
-
|
|
725
|
+
log7.info(`\u5373\u5C06\u540C\u6B65\u672C\u5730\u65B0\u589E\u52A0 ${needSyncKeys.length} \u4E2A i18nKey \u5230\u4E91\u7AEF`);
|
|
932
726
|
await googleSheet.updateColumn(
|
|
933
727
|
config.sheetId,
|
|
934
728
|
config.sheetRange,
|
|
@@ -936,7 +730,7 @@ async function batchUpdateKeys(config) {
|
|
|
936
730
|
sheetData.nextAppendRowIndex,
|
|
937
731
|
needSyncKeys
|
|
938
732
|
);
|
|
939
|
-
|
|
733
|
+
log7.info("\u540C\u6B65\u65B0\u589E\u52A0i18nKey\u6210\u529F");
|
|
940
734
|
for (const lang of config.locales) {
|
|
941
735
|
const langFile = i18nDataMap.get(lang);
|
|
942
736
|
const needSyncValues = [];
|
|
@@ -945,7 +739,7 @@ async function batchUpdateKeys(config) {
|
|
|
945
739
|
needSyncValues.push(langFile.data[k]);
|
|
946
740
|
}
|
|
947
741
|
});
|
|
948
|
-
|
|
742
|
+
log7.info(
|
|
949
743
|
`\u5373\u5C06\u540C\u6B65\u672C\u5730 ${lang} \u65B0\u589E\u52A0 ${needSyncValues.length} \u4E2A\u503C\u5230\u4E91\u7AEF`
|
|
950
744
|
);
|
|
951
745
|
await googleSheet.updateColumn(
|
|
@@ -958,15 +752,10 @@ async function batchUpdateKeys(config) {
|
|
|
958
752
|
}
|
|
959
753
|
await sleep(1e3);
|
|
960
754
|
sheetData = await resolveSheetData(config);
|
|
961
|
-
|
|
755
|
+
log7.info(`\u5DF2\u91CD\u65B0\u83B7\u53D6 ${config.sheetRange} \u7684\u6570\u636E`);
|
|
962
756
|
}
|
|
963
757
|
return { sheetData, i18nDataMap };
|
|
964
758
|
}
|
|
965
|
-
function sleep(ms) {
|
|
966
|
-
return new Promise((resolve) => {
|
|
967
|
-
setTimeout(resolve, ms);
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
759
|
async function upload() {
|
|
971
760
|
const config = await getConfig();
|
|
972
761
|
let i18nConfigs = await promptI18nConfigEnable(config.i18n);
|
|
@@ -977,16 +766,16 @@ async function upload() {
|
|
|
977
766
|
await i18nData.trySaveToGoogle(sheetData);
|
|
978
767
|
});
|
|
979
768
|
}
|
|
980
|
-
|
|
769
|
+
log7.info("\u4E0A\u4F20\u6210\u529F");
|
|
981
770
|
}
|
|
982
771
|
|
|
983
772
|
// package.json
|
|
984
|
-
var version = "0.1.
|
|
773
|
+
var version = "0.1.26";
|
|
985
774
|
|
|
986
775
|
// src/commands/interactive.ts
|
|
987
776
|
import enquirer2 from "enquirer";
|
|
988
777
|
var { prompt: prompt2 } = enquirer2;
|
|
989
|
-
var
|
|
778
|
+
var log8 = createLogger("interactive");
|
|
990
779
|
var interactive = async (args) => {
|
|
991
780
|
var _a;
|
|
992
781
|
const commands = cli.commands.filter((command2) => {
|
|
@@ -1012,7 +801,7 @@ var interactive = async (args) => {
|
|
|
1012
801
|
});
|
|
1013
802
|
const command = commandMap.get(res.command);
|
|
1014
803
|
if (!command) {
|
|
1015
|
-
|
|
804
|
+
log8.error("\u672A\u627E\u5230\u547D\u4EE4 %s", res.command);
|
|
1016
805
|
return;
|
|
1017
806
|
}
|
|
1018
807
|
(_a = command.commandAction) == null ? void 0 : _a.apply(cli, args);
|