@dune2/cli 0.1.25 → 0.1.26
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 +62 -282
- 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,50 +1,23 @@
|
|
|
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";
|
|
49
22
|
var log = createLogger("i18nData");
|
|
50
23
|
var I18nData = class {
|
|
@@ -55,7 +28,7 @@ var I18nData = class {
|
|
|
55
28
|
this.data = {};
|
|
56
29
|
this.unUsedKeys = /* @__PURE__ */ new Set();
|
|
57
30
|
this.isDefaultLocale = locale === config.defaultLocale;
|
|
58
|
-
this.filePath =
|
|
31
|
+
this.filePath = path.join(
|
|
59
32
|
config.cwd,
|
|
60
33
|
config.i18nDir,
|
|
61
34
|
config.i18nFileName.replace("{locale}", locale)
|
|
@@ -63,8 +36,8 @@ var I18nData = class {
|
|
|
63
36
|
}
|
|
64
37
|
async loadData() {
|
|
65
38
|
try {
|
|
66
|
-
if (await
|
|
67
|
-
this.data = await
|
|
39
|
+
if (await fs.pathExists(this.filePath)) {
|
|
40
|
+
this.data = await fs.readJSON(this.filePath);
|
|
68
41
|
} else {
|
|
69
42
|
log.info("File '%s' does not exist", pc.dim(this.filePath));
|
|
70
43
|
}
|
|
@@ -118,8 +91,8 @@ var I18nData = class {
|
|
|
118
91
|
pc.dim(this.filePath)
|
|
119
92
|
);
|
|
120
93
|
try {
|
|
121
|
-
await
|
|
122
|
-
await
|
|
94
|
+
await fs.ensureFile(this.filePath);
|
|
95
|
+
await fs.writeJson(this.filePath, this.data, { spaces: 2 });
|
|
123
96
|
log.info(
|
|
124
97
|
"Saved i18n data for locale '%s' to file '%s'",
|
|
125
98
|
pc.green(this.locale),
|
|
@@ -265,7 +238,7 @@ function promptApiConfigEnable(configArr) {
|
|
|
265
238
|
}
|
|
266
239
|
|
|
267
240
|
// src/commands/extract.ts
|
|
268
|
-
import
|
|
241
|
+
import path2 from "path";
|
|
269
242
|
var log2 = createLogger("extract");
|
|
270
243
|
async function extract(opts) {
|
|
271
244
|
const config = await getConfig();
|
|
@@ -288,7 +261,7 @@ async function extract(opts) {
|
|
|
288
261
|
await pMap2(
|
|
289
262
|
files,
|
|
290
263
|
async (file) => {
|
|
291
|
-
const content = await
|
|
264
|
+
const content = await fs2.readFile(file, "utf-8");
|
|
292
265
|
const res = await extract2(content, file);
|
|
293
266
|
if (res.data.size) {
|
|
294
267
|
log2.info(
|
|
@@ -330,9 +303,9 @@ async function extract(opts) {
|
|
|
330
303
|
}
|
|
331
304
|
}
|
|
332
305
|
async function saveDebugLog(dir, extractedI18nDataMap) {
|
|
333
|
-
await
|
|
334
|
-
await
|
|
335
|
-
|
|
306
|
+
await fs2.ensureDirSync(dir);
|
|
307
|
+
await fs2.writeJSON(
|
|
308
|
+
path2.join(dir, "extractedI18nDataMap.json"),
|
|
336
309
|
Array.from(extractedI18nDataMap.entries()).map(([key, value]) => value),
|
|
337
310
|
{
|
|
338
311
|
spaces: 2
|
|
@@ -343,201 +316,8 @@ async function saveDebugLog(dir, extractedI18nDataMap) {
|
|
|
343
316
|
// src/commands/download.ts
|
|
344
317
|
import pMap3 from "p-map";
|
|
345
318
|
|
|
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
319
|
// src/shared/resolveSheetData.ts
|
|
540
|
-
var
|
|
320
|
+
var log3 = createLogger("shared:resolveSheetData");
|
|
541
321
|
var SheetI18nItem = class {
|
|
542
322
|
constructor(spreadsheetId, range, key, colIndex, row, rowIndex) {
|
|
543
323
|
this.spreadsheetId = spreadsheetId;
|
|
@@ -564,13 +344,13 @@ var SheetI18nItem = class {
|
|
|
564
344
|
async function resolveSheetData(config) {
|
|
565
345
|
const { position } = config;
|
|
566
346
|
const parseStartIndex = config.parseStartIndex ?? 2;
|
|
567
|
-
|
|
347
|
+
log3.info(`\u8BFB\u53D6 ${config.sheetRange} sheet\u6570\u636E`);
|
|
568
348
|
const res = await googleSheet.get({
|
|
569
349
|
spreadsheetId: config.sheetId,
|
|
570
350
|
range: config.sheetRange
|
|
571
351
|
});
|
|
572
352
|
if (!res.data.values) {
|
|
573
|
-
|
|
353
|
+
log3.error(
|
|
574
354
|
`${config.sheetRange} sheet\u6570\u636E\u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5\uFF0C\u5E94\u8BE5\u6700\u5C11\u6709\u4E00\u884C\u5934\u90E8\u6570\u636E`
|
|
575
355
|
);
|
|
576
356
|
return new SheetData(config, 2);
|
|
@@ -585,7 +365,7 @@ async function resolveSheetData(config) {
|
|
|
585
365
|
const i18nKey = row[letterToNumber(position.key)];
|
|
586
366
|
if (i18nKey) {
|
|
587
367
|
if (sheetData.keySet.has(i18nKey)) {
|
|
588
|
-
|
|
368
|
+
log3.error(
|
|
589
369
|
`\u8868\u683C ${config.sheetRange} \u53D1\u73B0\u91CD\u590D\u7684i18nKey: ${i18nKey}, \u5C06\u8986\u76D6\u524D\u9762\u7684\u503C`
|
|
590
370
|
);
|
|
591
371
|
} else {
|
|
@@ -638,7 +418,7 @@ var SheetData = class {
|
|
|
638
418
|
};
|
|
639
419
|
|
|
640
420
|
// src/commands/download.ts
|
|
641
|
-
var
|
|
421
|
+
var log4 = createLogger("generate");
|
|
642
422
|
async function download() {
|
|
643
423
|
const config = await getConfig();
|
|
644
424
|
let i18nConfigs = await promptI18nConfigEnable(config.i18n);
|
|
@@ -646,7 +426,7 @@ async function download() {
|
|
|
646
426
|
for (const configItem of i18nConfigs) {
|
|
647
427
|
i++;
|
|
648
428
|
if (!configItem.sheetId || !configItem.sheetRange) {
|
|
649
|
-
|
|
429
|
+
log4.error(`config.${i} sheetId \u6216 sheetRange \u4E3A\u7A7A\uFF0C\u8BF7\u68C0\u67E5`);
|
|
650
430
|
continue;
|
|
651
431
|
}
|
|
652
432
|
const sheetData = await resolveSheetData(configItem);
|
|
@@ -667,26 +447,26 @@ async function download() {
|
|
|
667
447
|
import * as child_process from "child_process";
|
|
668
448
|
import _ from "lodash";
|
|
669
449
|
import pMap4 from "p-map";
|
|
670
|
-
import
|
|
450
|
+
import fs3 from "fs-extra";
|
|
671
451
|
import * as os2 from "os";
|
|
672
452
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
673
453
|
import { compile } from "json-schema-to-typescript";
|
|
674
|
-
import
|
|
675
|
-
var
|
|
454
|
+
import path3 from "path";
|
|
455
|
+
var log5 = createLogger("generateApi");
|
|
676
456
|
async function generateApi() {
|
|
677
457
|
const config = await getConfig();
|
|
678
458
|
const apiConfigs = await promptApiConfigEnable(config.api);
|
|
679
459
|
for (const apiConfig of apiConfigs) {
|
|
680
|
-
|
|
681
|
-
await
|
|
460
|
+
log5.info(`\u6E05\u9664\u65E7\u7684api\u6587\u4EF6: ${apiConfig.output}`);
|
|
461
|
+
await fs3.emptydir(apiConfig.output);
|
|
682
462
|
}
|
|
683
463
|
for (const apiConfig of apiConfigs) {
|
|
684
|
-
|
|
464
|
+
log5.info("\u5F00\u59CB\u89E3\u6790 %s", apiConfig.swaggerJSONPath);
|
|
685
465
|
const parsed = await SwaggerParser.dereference(
|
|
686
466
|
apiConfig.swaggerJSONPath
|
|
687
467
|
);
|
|
688
468
|
await pMap4(Object.entries(parsed.paths), async ([url, pathItemObject]) => {
|
|
689
|
-
|
|
469
|
+
log5.info("\u5F00\u59CB\u751F\u6210 %s", url);
|
|
690
470
|
if (pathItemObject) {
|
|
691
471
|
await pMap4(
|
|
692
472
|
["get", "put", "post", "delete", "patch"],
|
|
@@ -699,32 +479,32 @@ async function generateApi() {
|
|
|
699
479
|
operationObject,
|
|
700
480
|
apiConfig
|
|
701
481
|
});
|
|
702
|
-
const outputPath =
|
|
482
|
+
const outputPath = path3.join(
|
|
703
483
|
apiConfig.output,
|
|
704
484
|
url,
|
|
705
485
|
apiConfig.enableTs ? `${method}.ts` : `${method}.js`
|
|
706
486
|
).replace(/:/g, "_");
|
|
707
|
-
await
|
|
708
|
-
await
|
|
487
|
+
await fs3.ensureFile(outputPath);
|
|
488
|
+
await fs3.writeFile(outputPath, code);
|
|
709
489
|
}
|
|
710
490
|
}
|
|
711
491
|
);
|
|
712
492
|
}
|
|
713
493
|
});
|
|
714
494
|
if (apiConfig.format) {
|
|
715
|
-
|
|
495
|
+
log5.info(`\u5C1D\u8BD5\u683C\u5F0F\u5316\u4EE3\u7801: %s`, apiConfig.output);
|
|
716
496
|
child_process.exec(`prettier --write ${apiConfig.output}`, (error) => {
|
|
717
497
|
if (error) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
498
|
+
log5.error(`\u683C\u5F0F\u5316\u4EE3\u7801\u5931\u8D25: ${error}`);
|
|
499
|
+
log5.error(`\u8BF7\u624B\u52A8\u6267\u884C: prettier --write ${apiConfig.output}`);
|
|
500
|
+
log5.error(`\u6216\u8005\u5728\u914D\u7F6E\u6587\u4EF6\u4E2D\u5173\u95ED\u683C\u5F0F\u5316\u529F\u80FD`);
|
|
721
501
|
} else {
|
|
722
|
-
|
|
502
|
+
log5.info(`\u683C\u5F0F\u5316\u4EE3\u7801\u6210\u529F: %s`, apiConfig.output);
|
|
723
503
|
}
|
|
724
504
|
});
|
|
725
505
|
}
|
|
726
506
|
}
|
|
727
|
-
|
|
507
|
+
log5.info("generateApi Done");
|
|
728
508
|
}
|
|
729
509
|
async function generateApiRequestCode(options) {
|
|
730
510
|
var _a, _b;
|
|
@@ -831,7 +611,7 @@ async function compileRequestParams(operationObject) {
|
|
|
831
611
|
additionalProperties: false
|
|
832
612
|
});
|
|
833
613
|
} catch (e) {
|
|
834
|
-
|
|
614
|
+
log5.error("\u751F\u6210\u8BF7\u6C42\u53C2\u6570\u7C7B\u578B\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 %o", {
|
|
835
615
|
summary: operationObject.summary,
|
|
836
616
|
message: e.message
|
|
837
617
|
});
|
|
@@ -856,13 +636,13 @@ async function compileResponseParams(operationObject, apiConfig) {
|
|
|
856
636
|
additionalProperties: false
|
|
857
637
|
});
|
|
858
638
|
} catch (e) {
|
|
859
|
-
|
|
639
|
+
log5.error("\u8F6C\u6362\u54CD\u5E94\u53C2\u6570\u7C7B\u578B\u5931\u8D25, \u8BF7\u68C0\u67E5 %o", {
|
|
860
640
|
summary: operationObject.summary,
|
|
861
641
|
error: e.message
|
|
862
642
|
});
|
|
863
643
|
}
|
|
864
644
|
} else {
|
|
865
|
-
|
|
645
|
+
log5.error("responseSchemaTransformer \u8FD4\u56DE\u503C\u4E3A\u7A7A, \u8BF7\u68C0\u67E5");
|
|
866
646
|
}
|
|
867
647
|
}
|
|
868
648
|
return code ? code : "export type Res = any;";
|
|
@@ -885,9 +665,9 @@ function markCircularToRef(obj, parentMark = "#", map = /* @__PURE__ */ new Map(
|
|
|
885
665
|
}
|
|
886
666
|
|
|
887
667
|
// src/commands/initConfig.ts
|
|
888
|
-
import
|
|
889
|
-
import
|
|
890
|
-
var
|
|
668
|
+
import fs4 from "fs-extra";
|
|
669
|
+
import path4 from "path";
|
|
670
|
+
var log6 = createLogger("initConfig");
|
|
891
671
|
var tpl = `/**
|
|
892
672
|
* @template {import('@dune2/cli').Config} T
|
|
893
673
|
* @param {T} config - A generic parameter that flows through to the return type
|
|
@@ -900,19 +680,19 @@ module.exports = defineConfig({ i18n: [], api:[] });
|
|
|
900
680
|
`;
|
|
901
681
|
var initConfig = async () => {
|
|
902
682
|
const config = await getConfig();
|
|
903
|
-
const configPath =
|
|
904
|
-
|
|
905
|
-
if (await
|
|
906
|
-
|
|
683
|
+
const configPath = path4.join(config.cwd, configName);
|
|
684
|
+
log6.info(`config file path: ${configPath}`);
|
|
685
|
+
if (await fs4.pathExists(configPath)) {
|
|
686
|
+
log6.info(`config file already exists, skip`);
|
|
907
687
|
return;
|
|
908
688
|
}
|
|
909
|
-
await
|
|
910
|
-
|
|
689
|
+
await fs4.writeFile(configPath, tpl);
|
|
690
|
+
log6.info(`config file created`);
|
|
911
691
|
};
|
|
912
692
|
|
|
913
693
|
// src/commands/upload.ts
|
|
914
694
|
import pMap5 from "p-map";
|
|
915
|
-
var
|
|
695
|
+
var log7 = createLogger("upload");
|
|
916
696
|
async function batchUpdateKeys(config) {
|
|
917
697
|
let sheetData = await resolveSheetData(config);
|
|
918
698
|
const allKeys = [];
|
|
@@ -928,7 +708,7 @@ async function batchUpdateKeys(config) {
|
|
|
928
708
|
});
|
|
929
709
|
needSyncKeys = needSyncKeys.sort(config.keySorter);
|
|
930
710
|
if (needSyncKeys.length) {
|
|
931
|
-
|
|
711
|
+
log7.info(`\u5373\u5C06\u540C\u6B65\u672C\u5730\u65B0\u589E\u52A0 ${needSyncKeys.length} \u4E2A i18nKey \u5230\u4E91\u7AEF`);
|
|
932
712
|
await googleSheet.updateColumn(
|
|
933
713
|
config.sheetId,
|
|
934
714
|
config.sheetRange,
|
|
@@ -936,7 +716,7 @@ async function batchUpdateKeys(config) {
|
|
|
936
716
|
sheetData.nextAppendRowIndex,
|
|
937
717
|
needSyncKeys
|
|
938
718
|
);
|
|
939
|
-
|
|
719
|
+
log7.info("\u540C\u6B65\u65B0\u589E\u52A0i18nKey\u6210\u529F");
|
|
940
720
|
for (const lang of config.locales) {
|
|
941
721
|
const langFile = i18nDataMap.get(lang);
|
|
942
722
|
const needSyncValues = [];
|
|
@@ -945,7 +725,7 @@ async function batchUpdateKeys(config) {
|
|
|
945
725
|
needSyncValues.push(langFile.data[k]);
|
|
946
726
|
}
|
|
947
727
|
});
|
|
948
|
-
|
|
728
|
+
log7.info(
|
|
949
729
|
`\u5373\u5C06\u540C\u6B65\u672C\u5730 ${lang} \u65B0\u589E\u52A0 ${needSyncValues.length} \u4E2A\u503C\u5230\u4E91\u7AEF`
|
|
950
730
|
);
|
|
951
731
|
await googleSheet.updateColumn(
|
|
@@ -958,7 +738,7 @@ async function batchUpdateKeys(config) {
|
|
|
958
738
|
}
|
|
959
739
|
await sleep(1e3);
|
|
960
740
|
sheetData = await resolveSheetData(config);
|
|
961
|
-
|
|
741
|
+
log7.info(`\u5DF2\u91CD\u65B0\u83B7\u53D6 ${config.sheetRange} \u7684\u6570\u636E`);
|
|
962
742
|
}
|
|
963
743
|
return { sheetData, i18nDataMap };
|
|
964
744
|
}
|
|
@@ -977,16 +757,16 @@ async function upload() {
|
|
|
977
757
|
await i18nData.trySaveToGoogle(sheetData);
|
|
978
758
|
});
|
|
979
759
|
}
|
|
980
|
-
|
|
760
|
+
log7.info("\u4E0A\u4F20\u6210\u529F");
|
|
981
761
|
}
|
|
982
762
|
|
|
983
763
|
// package.json
|
|
984
|
-
var version = "0.1.
|
|
764
|
+
var version = "0.1.25";
|
|
985
765
|
|
|
986
766
|
// src/commands/interactive.ts
|
|
987
767
|
import enquirer2 from "enquirer";
|
|
988
768
|
var { prompt: prompt2 } = enquirer2;
|
|
989
|
-
var
|
|
769
|
+
var log8 = createLogger("interactive");
|
|
990
770
|
var interactive = async (args) => {
|
|
991
771
|
var _a;
|
|
992
772
|
const commands = cli.commands.filter((command2) => {
|
|
@@ -1012,7 +792,7 @@ var interactive = async (args) => {
|
|
|
1012
792
|
});
|
|
1013
793
|
const command = commandMap.get(res.command);
|
|
1014
794
|
if (!command) {
|
|
1015
|
-
|
|
795
|
+
log8.error("\u672A\u627E\u5230\u547D\u4EE4 %s", res.command);
|
|
1016
796
|
return;
|
|
1017
797
|
}
|
|
1018
798
|
(_a = command.commandAction) == null ? void 0 : _a.apply(cli, args);
|