@logto/cli 1.19.0 → 1.21.0
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/lib/commands/database/alteration/utils.js +12 -2
- package/lib/commands/database/seed/tables.js +2 -1
- package/lib/index.js +0 -4
- package/lib/package-json.d.ts +1 -8
- package/lib/package-json.js +6 -13
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js +1 -19
- package/package.json +6 -13
- package/lib/commands/proxy/index.d.ts +0 -4
- package/lib/commands/proxy/index.js +0 -80
- package/lib/commands/proxy/types.d.ts +0 -16
- package/lib/commands/proxy/types.js +0 -1
- package/lib/commands/proxy/utils.d.ts +0 -27
- package/lib/commands/proxy/utils.js +0 -123
- package/lib/commands/translate/create.d.ts +0 -8
- package/lib/commands/translate/create.js +0 -37
- package/lib/commands/translate/index.d.ts +0 -3
- package/lib/commands/translate/index.js +0 -27
- package/lib/commands/translate/list-tags.d.ts +0 -3
- package/lib/commands/translate/list-tags.js +0 -19
- package/lib/commands/translate/openai.d.ts +0 -11
- package/lib/commands/translate/openai.js +0 -73
- package/lib/commands/translate/prompts.d.ts +0 -18
- package/lib/commands/translate/prompts.js +0 -48
- package/lib/commands/translate/sync-keys/index.d.ts +0 -13
- package/lib/commands/translate/sync-keys/index.js +0 -73
- package/lib/commands/translate/sync-keys/utils.d.ts +0 -57
- package/lib/commands/translate/sync-keys/utils.js +0 -295
- package/lib/commands/translate/sync.d.ts +0 -10
- package/lib/commands/translate/sync.js +0 -44
- package/lib/commands/translate/utils.d.ts +0 -14
- package/lib/commands/translate/utils.js +0 -130
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { conditionalString } from '@silverhand/essentials';
|
|
5
|
-
import PQueue from 'p-queue';
|
|
6
|
-
import { consoleLog } from '../../utils.js';
|
|
7
|
-
import { createOpenaiApi, translate } from './openai.js';
|
|
8
|
-
import { untranslatedMark } from './prompts.js';
|
|
9
|
-
export const baseLanguage = 'en';
|
|
10
|
-
export const readLocaleFiles = async (directory) => {
|
|
11
|
-
const entities = await fs.readdir(directory, { withFileTypes: true });
|
|
12
|
-
const result = await Promise.all(entities.map(async (entity) => {
|
|
13
|
-
if (entity.isDirectory()) {
|
|
14
|
-
return readLocaleFiles(path.join(directory, entity.name));
|
|
15
|
-
}
|
|
16
|
-
return entity.name.endsWith('.ts') ? path.join(directory, entity.name) : [];
|
|
17
|
-
}));
|
|
18
|
-
return result.flat();
|
|
19
|
-
};
|
|
20
|
-
export const readBaseLocaleFiles = async (directory) => {
|
|
21
|
-
const enDirectory = path.join(directory, baseLanguage.toLowerCase());
|
|
22
|
-
const stat = await fs.stat(enDirectory);
|
|
23
|
-
if (!stat.isDirectory()) {
|
|
24
|
-
consoleLog.fatal(directory, 'has no `' + baseLanguage.toLowerCase() + '` directory');
|
|
25
|
-
}
|
|
26
|
-
return readLocaleFiles(enDirectory);
|
|
27
|
-
};
|
|
28
|
-
export const createFullTranslation = async ({ instancePath, packageName, languageTag, verbose = true, queue = new PQueue({ concurrency: 10 }), }) => {
|
|
29
|
-
const localeFiles = await getBaseAndTargetLocaleFiles(instancePath, packageName, languageTag);
|
|
30
|
-
if (verbose) {
|
|
31
|
-
consoleLog.info('Found ' +
|
|
32
|
-
String(localeFiles.length) +
|
|
33
|
-
' file' +
|
|
34
|
-
conditionalString(localeFiles.length !== 1 && 's') +
|
|
35
|
-
' in ' +
|
|
36
|
-
packageName +
|
|
37
|
-
' to create');
|
|
38
|
-
}
|
|
39
|
-
const openai = createOpenaiApi();
|
|
40
|
-
for (const { baseLocaleFile, targetLocaleFile } of localeFiles) {
|
|
41
|
-
if (existsSync(targetLocaleFile)) {
|
|
42
|
-
if (verbose) {
|
|
43
|
-
consoleLog.info(`Target locale file ${targetLocaleFile} exists, skipping`);
|
|
44
|
-
}
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
void createLocaleFile({
|
|
48
|
-
api: openai,
|
|
49
|
-
baseLocaleFile,
|
|
50
|
-
targetPath: targetLocaleFile,
|
|
51
|
-
targetLanguage: languageTag,
|
|
52
|
-
queue,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return queue.onIdle();
|
|
56
|
-
};
|
|
57
|
-
export const syncTranslation = async ({ instancePath, packageName, languageTag, verbose = true, queue = new PQueue({ concurrency: 10 }), }) => {
|
|
58
|
-
const localeFiles = await getBaseAndTargetLocaleFiles(instancePath, packageName, languageTag);
|
|
59
|
-
if (verbose) {
|
|
60
|
-
consoleLog.info('Found ' +
|
|
61
|
-
String(localeFiles.length) +
|
|
62
|
-
' file' +
|
|
63
|
-
conditionalString(localeFiles.length !== 1 && 's') +
|
|
64
|
-
' in ' +
|
|
65
|
-
packageName +
|
|
66
|
-
' to translate');
|
|
67
|
-
}
|
|
68
|
-
const openai = createOpenaiApi();
|
|
69
|
-
/* eslint-disable no-await-in-loop */
|
|
70
|
-
for (const { baseLocaleFile, targetLocaleFile } of localeFiles) {
|
|
71
|
-
if (!existsSync(targetLocaleFile)) {
|
|
72
|
-
void createLocaleFile({
|
|
73
|
-
api: openai,
|
|
74
|
-
baseLocaleFile,
|
|
75
|
-
targetPath: targetLocaleFile,
|
|
76
|
-
targetLanguage: languageTag,
|
|
77
|
-
queue,
|
|
78
|
-
});
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const currentContent = await fs.readFile(targetLocaleFile, 'utf8');
|
|
82
|
-
if (!currentContent.includes(untranslatedMark)) {
|
|
83
|
-
if (verbose) {
|
|
84
|
-
consoleLog.info(`Target path ${targetLocaleFile} exists and has no untranslated mark, skipping`);
|
|
85
|
-
}
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
void queue.add(async () => {
|
|
89
|
-
consoleLog.info(`Translating ${targetLocaleFile}`);
|
|
90
|
-
const result = await translate({
|
|
91
|
-
api: openai,
|
|
92
|
-
sourceFilePath: targetLocaleFile,
|
|
93
|
-
targetLanguage: languageTag,
|
|
94
|
-
});
|
|
95
|
-
if (!result) {
|
|
96
|
-
consoleLog.fatal(`Unable to translate ${targetLocaleFile}`);
|
|
97
|
-
}
|
|
98
|
-
await fs.unlink(targetLocaleFile);
|
|
99
|
-
await fs.writeFile(targetLocaleFile, result);
|
|
100
|
-
consoleLog.succeed(`Translated ${targetLocaleFile}`);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/* eslint-enable no-await-in-loop */
|
|
104
|
-
return queue.onIdle();
|
|
105
|
-
};
|
|
106
|
-
const getBaseAndTargetLocaleFiles = async (instancePath, packageName, languageTag) => {
|
|
107
|
-
const directory = path.join(instancePath, 'packages', packageName, 'src/locales');
|
|
108
|
-
const baseLocaleFiles = await readBaseLocaleFiles(directory);
|
|
109
|
-
return baseLocaleFiles.map((baseLocaleFile) => {
|
|
110
|
-
const basePath = path.relative(path.join(directory, baseLanguage.toLowerCase()), baseLocaleFile);
|
|
111
|
-
return {
|
|
112
|
-
baseLocaleFile,
|
|
113
|
-
targetLocaleFile: path.join(directory, languageTag.toLowerCase(), basePath),
|
|
114
|
-
};
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
const createLocaleFile = async ({ api, baseLocaleFile, targetPath, targetLanguage, queue, }) => queue.add(async () => {
|
|
118
|
-
consoleLog.info(`Creating the translation for ${targetPath}`);
|
|
119
|
-
const result = await translate({
|
|
120
|
-
api,
|
|
121
|
-
sourceFilePath: baseLocaleFile,
|
|
122
|
-
targetLanguage,
|
|
123
|
-
});
|
|
124
|
-
if (!result) {
|
|
125
|
-
consoleLog.fatal(`Unable to create the translation for ${targetPath}`);
|
|
126
|
-
}
|
|
127
|
-
await fs.mkdir(path.parse(targetPath).dir, { recursive: true });
|
|
128
|
-
await fs.writeFile(targetPath, result);
|
|
129
|
-
consoleLog.succeed(`The translation for ${targetPath} created`);
|
|
130
|
-
});
|