@intlayer/cli 5.4.1 → 5.5.0-canary.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/dist/cjs/build.cjs +1 -1
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +222 -19
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +3 -6
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/fill.cjs +360 -0
- package/dist/cjs/fill.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listContentDeclaration.cjs +3 -7
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/pull.cjs +3 -3
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push.cjs +24 -54
- package/dist/cjs/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +1 -1
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/esm/build.mjs +1 -1
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +211 -18
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +4 -8
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/fill.mjs +338 -0
- package/dist/esm/fill.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listContentDeclaration.mjs +5 -9
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/pull.mjs +5 -5
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push.mjs +26 -56
- package/dist/esm/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +1 -1
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/types/build.d.ts +2 -1
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/fill.d.ts +27 -0
- package/dist/types/fill.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listContentDeclaration.d.ts +4 -3
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/pull.d.ts +2 -1
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push.d.ts +4 -2
- package/dist/types/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +2 -1
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/package.json +12 -11
- package/dist/cjs/audit.cjs +0 -126
- package/dist/cjs/audit.cjs.map +0 -1
- package/dist/esm/audit.mjs +0 -94
- package/dist/esm/audit.mjs.map +0 -1
- package/dist/types/audit.d.ts +0 -38
- package/dist/types/audit.d.ts.map +0 -1
package/dist/esm/push.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import * as fsPromises from "fs/promises";
|
|
2
|
-
import { relative } from "path";
|
|
3
|
-
import * as readline from "readline";
|
|
4
1
|
import { getIntlayerAPI } from "@intlayer/api";
|
|
2
|
+
import { listGitFiles } from "@intlayer/chokidar";
|
|
5
3
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
appLogger,
|
|
5
|
+
getConfiguration
|
|
8
6
|
} from "@intlayer/config";
|
|
9
7
|
import dictionariesRecord from "@intlayer/dictionaries-entry";
|
|
8
|
+
import * as fsPromises from "fs/promises";
|
|
10
9
|
import pLimit from "p-limit";
|
|
10
|
+
import { relative } from "path";
|
|
11
|
+
import * as readline from "readline";
|
|
11
12
|
const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
12
13
|
const RESET = "\x1B[0m";
|
|
13
14
|
const GREEN = "\x1B[32m";
|
|
@@ -17,7 +18,7 @@ const GREY = "\x1B[90m";
|
|
|
17
18
|
const GREY_DARK = "\x1B[90m";
|
|
18
19
|
const push = async (options) => {
|
|
19
20
|
try {
|
|
20
|
-
const config = getConfiguration(options);
|
|
21
|
+
const config = getConfiguration(options?.configOptions);
|
|
21
22
|
const { clientId, clientSecret } = config.editor;
|
|
22
23
|
if (!clientId || !clientSecret) {
|
|
23
24
|
throw new Error(
|
|
@@ -34,15 +35,12 @@ const push = async (options) => {
|
|
|
34
35
|
(dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)
|
|
35
36
|
);
|
|
36
37
|
if (noneExistingDictionariesOption.length > 0) {
|
|
37
|
-
|
|
38
|
+
appLogger(
|
|
38
39
|
`The following dictionaries do not exist: ${noneExistingDictionariesOption.join(
|
|
39
40
|
", "
|
|
40
41
|
)} and have been ignored.`,
|
|
41
42
|
{
|
|
42
|
-
level: "error"
|
|
43
|
-
config: {
|
|
44
|
-
prefix: options?.logPrefix
|
|
45
|
-
}
|
|
43
|
+
level: "error"
|
|
46
44
|
}
|
|
47
45
|
);
|
|
48
46
|
}
|
|
@@ -50,20 +48,16 @@ const push = async (options) => {
|
|
|
50
48
|
(dictionary) => options.dictionaries.includes(dictionary.key)
|
|
51
49
|
);
|
|
52
50
|
}
|
|
51
|
+
if (options?.gitOptions) {
|
|
52
|
+
const gitFiles = await listGitFiles(options.gitOptions);
|
|
53
|
+
}
|
|
53
54
|
if (dictionaries.length === 0) {
|
|
54
|
-
|
|
55
|
-
level: "error"
|
|
56
|
-
config: {
|
|
57
|
-
prefix: options?.logPrefix
|
|
58
|
-
}
|
|
55
|
+
appLogger("No local dictionaries found", {
|
|
56
|
+
level: "error"
|
|
59
57
|
});
|
|
60
58
|
return;
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
config: {
|
|
64
|
-
prefix: options?.logPrefix
|
|
65
|
-
}
|
|
66
|
-
});
|
|
60
|
+
appLogger("Pushing dictionaries:", {});
|
|
67
61
|
const dictionariesStatuses = dictionaries.map(
|
|
68
62
|
(dictionary, index) => ({
|
|
69
63
|
dictionary,
|
|
@@ -117,11 +111,8 @@ const push = async (options) => {
|
|
|
117
111
|
updateAllStatusLines(dictionariesStatuses);
|
|
118
112
|
for (const statusObj of dictionariesStatuses) {
|
|
119
113
|
if (statusObj.errorMessage) {
|
|
120
|
-
|
|
121
|
-
level: "error"
|
|
122
|
-
config: {
|
|
123
|
-
prefix: options?.logPrefix
|
|
124
|
-
}
|
|
114
|
+
appLogger(statusObj.errorMessage, {
|
|
115
|
+
level: "error"
|
|
125
116
|
});
|
|
126
117
|
}
|
|
127
118
|
}
|
|
@@ -144,11 +135,8 @@ const push = async (options) => {
|
|
|
144
135
|
}
|
|
145
136
|
}
|
|
146
137
|
} catch (error) {
|
|
147
|
-
|
|
148
|
-
level: "error"
|
|
149
|
-
config: {
|
|
150
|
-
prefix: options?.logPrefix
|
|
151
|
-
}
|
|
138
|
+
appLogger(error, {
|
|
139
|
+
level: "error"
|
|
152
140
|
});
|
|
153
141
|
}
|
|
154
142
|
};
|
|
@@ -170,11 +158,8 @@ const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
|
|
|
170
158
|
for (const dictionary of dictionariesToDelete) {
|
|
171
159
|
const { filePath } = dictionary;
|
|
172
160
|
if (!filePath) {
|
|
173
|
-
|
|
174
|
-
level: "error"
|
|
175
|
-
config: {
|
|
176
|
-
prefix: options?.logPrefix
|
|
177
|
-
}
|
|
161
|
+
appLogger(`Dictionary ${dictionary.key} does not have a file path`, {
|
|
162
|
+
level: "error"
|
|
178
163
|
});
|
|
179
164
|
continue;
|
|
180
165
|
}
|
|
@@ -186,30 +171,15 @@ const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
|
|
|
186
171
|
const stats = await fsPromises.lstat(filePath);
|
|
187
172
|
if (stats.isFile()) {
|
|
188
173
|
await fsPromises.unlink(filePath);
|
|
189
|
-
|
|
190
|
-
config: {
|
|
191
|
-
prefix: options?.logPrefix
|
|
192
|
-
}
|
|
193
|
-
});
|
|
174
|
+
appLogger(`Deleted file ${relativePath}`, {});
|
|
194
175
|
} else if (stats.isDirectory()) {
|
|
195
|
-
|
|
196
|
-
config: {
|
|
197
|
-
prefix: options?.logPrefix
|
|
198
|
-
}
|
|
199
|
-
});
|
|
176
|
+
appLogger(`Path is a directory ${relativePath}, skipping.`, {});
|
|
200
177
|
} else {
|
|
201
|
-
|
|
202
|
-
config: {
|
|
203
|
-
prefix: options?.logPrefix
|
|
204
|
-
}
|
|
205
|
-
});
|
|
178
|
+
appLogger(`Unknown file type for ${relativePath}, skipping.`, {});
|
|
206
179
|
}
|
|
207
180
|
} catch (err) {
|
|
208
|
-
|
|
209
|
-
level: "error"
|
|
210
|
-
config: {
|
|
211
|
-
prefix: options?.logPrefix
|
|
212
|
-
}
|
|
181
|
+
appLogger(`Error deleting ${relativePath}: ${err}`, {
|
|
182
|
+
level: "error"
|
|
213
183
|
});
|
|
214
184
|
}
|
|
215
185
|
}
|
package/dist/esm/push.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/push.ts"],"sourcesContent":["import * as fsPromises from 'fs/promises';\nimport { relative } from 'path';\nimport * as readline from 'readline';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport pLimit from 'p-limit';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n logPrefix?: string;\n} & GetConfigurationOptions;\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nconst spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst GREY_DARK = '\\x1b[90m';\n\n/**\n * Get all locale dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n try {\n const config = getConfiguration(options);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n logger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n logger('No local dictionaries found', {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n return;\n }\n\n logger('Pushing dictionaries:', {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary, index) => ({\n dictionary,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n })\n );\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries(\n [statusObj.dictionary],\n {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }\n );\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n const pushPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n await Promise.all(pushPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n logger(statusObj.errorMessage, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const { baseDir } = getConfiguration().content;\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n logger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n const relativePath = relative(baseDir, filePath);\n\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n logger(`Deleted file ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } else if (stats.isDirectory()) {\n logger(`Path is a directory ${relativePath}, skipping.`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } else {\n logger(`Unknown file type for ${relativePath}, skipping.`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n } catch (err) {\n logger(`Error deleting ${relativePath}: ${err}`, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n pushing: '', // Spinner handled separately\n modified: '✔',\n pushed: '✔',\n error: '✖',\n };\n return statusIcons[status] || '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n const {\n log: { prefix },\n } = getConfiguration();\n\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'pushing') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (statusObj.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (statusObj.status === 'pushed' || statusObj.status === 'modified') {\n colorStart = GREEN;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionary.key} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'pushing') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":"AAAA,YAAY,gBAAgB;AAC5B,SAAS,gBAAgB;AACzB,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAEP,OAAO,wBAAwB;AAC/B,OAAO,YAAY;AAmBnB,MAAM,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAEvE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,YAAY;AAKX,MAAM,OAA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oBAAqB,cAAc,MAAM;AACxE,iBAAa;AACb,eAAW;AAAA,EACb,WAAW,UAAU,WAAW,SAAS;AACvC,iBAAa;AACb,eAAW;AAAA,EACb,WAAW,UAAU,WAAW,YAAY,UAAU,WAAW,YAAY;AAC3E,iBAAa;AACb,eAAW;AAAA,EACb,OAAO;AACL,iBAAa;AACb,eAAW;AAAA,EACb;AAEA,SAAO,KAAK,UAAU,WAAW,GAAG,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAG,UAAU,MAAM,GAAG,SAAS,IAAI,QAAQ;AACnH;AAEA,MAAM,uBAAuB,CAAC,yBAA+C;AAE3E,WAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC,qBAAqB,MAAM;AACnE,aAAW,aAAa,sBAAsB;AAE5C,aAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,QAAI,UAAU,WAAW,WAAW;AAElC,gBAAU,qBACP,UAAU,oBAAqB,KAAK,cAAc;AAAA,IACvD;AAGA,YAAQ,OAAO,MAAM,cAAc,SAAS,IAAI,IAAI;AAAA,EACtD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/push.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport { listGitFiles } from '@intlayer/chokidar';\nimport {\n appLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport * as fsPromises from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { relative } from 'path';\nimport * as readline from 'readline';\nimport { ListGitFilesOptions } from '../../chokidar/dist/types/listGitFiles';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nconst spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst GREY_DARK = '\\x1b[90m';\n\n/**\n * Get all locale dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n try {\n const config = getConfiguration(options?.configOptions);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:', {});\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary, index) => ({\n dictionary,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n })\n );\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries(\n [statusObj.dictionary],\n {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }\n );\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n const pushPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n await Promise.all(pushPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const { baseDir } = getConfiguration().content;\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n const relativePath = relative(baseDir, filePath);\n\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${relativePath}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${relativePath}, skipping.`, {});\n } else {\n appLogger(`Unknown file type for ${relativePath}, skipping.`, {});\n }\n } catch (err) {\n appLogger(`Error deleting ${relativePath}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n pushing: '', // Spinner handled separately\n modified: '✔',\n pushed: '✔',\n error: '✖',\n };\n return statusIcons[status] || '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n const {\n log: { prefix },\n } = getConfiguration();\n\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'pushing') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (statusObj.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (statusObj.status === 'pushed' || statusObj.status === 'modified') {\n colorStart = GREEN;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionary.key} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'pushing') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,OAAO,wBAAwB;AAC/B,YAAY,gBAAgB;AAC5B,OAAO,YAAY;AACnB,SAAS,gBAAgB;AACzB,YAAY,cAAc;AAqB1B,MAAM,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAEvE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,YAAY;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AAW,aAAa,sBAAsB;AAE5C,aAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,QAAI,UAAU,WAAW,WAAW;AAElC,gBAAU,qBACP,UAAU,oBAAqB,KAAK,cAAc;AAAA,IACvD;AAGA,YAAQ,OAAO,MAAM,cAAc,SAAS,IAAI,IAAI;AAAA,EACtD;AACF;","names":[]}
|
package/dist/esm/pushConfig.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
logger
|
|
5
5
|
} from "@intlayer/config";
|
|
6
6
|
const pushConfig = async (options) => {
|
|
7
|
-
const config = getConfiguration(options);
|
|
7
|
+
const config = getConfiguration(options?.configOptions);
|
|
8
8
|
const { clientId, clientSecret } = config.editor;
|
|
9
9
|
if (!clientId || !clientSecret) {
|
|
10
10
|
logger(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n logger,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n
|
|
1
|
+
{"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n logger,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n logger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config, {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n logger('Project configuration pushed successfully', {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAOA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,SAAS,iBAAiB,SAAS,aAAa;AAEtD,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,QAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,QAAQ;AAAA,IACzD,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC1D,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,SAAO,6CAA6C;AAAA,IAClD,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AAED,SAAO,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,GAAG;AAAA,IAC9D,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/types/build.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type GetConfigurationOptions } from '@intlayer/config';
|
|
2
2
|
type BuildOptions = {
|
|
3
3
|
watch?: boolean;
|
|
4
|
-
|
|
4
|
+
configOptions?: GetConfigurationOptions;
|
|
5
|
+
};
|
|
5
6
|
/**
|
|
6
7
|
* Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.
|
|
7
8
|
* Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,KAAK,YAAY,GAAG;
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAU,UAAU,YAAY,kBAOjD,CAAC"}
|
package/dist/types/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmIpC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OAiOzB,CAAC"}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type GetConfigurationOptions } from '@intlayer/config';
|
|
2
2
|
type ConfigOptions = {
|
|
3
|
-
|
|
4
|
-
}
|
|
3
|
+
configOptions?: GetConfigurationOptions;
|
|
4
|
+
};
|
|
5
5
|
export declare const getConfig: (options?: ConfigOptions) => void;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAG1B,KAAK,aAAa,GAAG;IACnB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,UAAU,aAAa,SAIhD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AIOptions } from '@intlayer/api';
|
|
2
|
+
import { ListGitFilesOptions } from '@intlayer/chokidar';
|
|
3
|
+
import { GetConfigurationOptions, Locales } from '@intlayer/config';
|
|
4
|
+
import { type Dictionary } from '@intlayer/core';
|
|
5
|
+
export type FillOptions = {
|
|
6
|
+
sourceLocale: Locales;
|
|
7
|
+
outputLocales?: Locales | Locales[];
|
|
8
|
+
file?: string | string[];
|
|
9
|
+
mode?: 'complete' | 'review';
|
|
10
|
+
keys?: string | string[];
|
|
11
|
+
excludedKeys?: string | string[];
|
|
12
|
+
filter?: (entry: Dictionary) => boolean;
|
|
13
|
+
pathFilter?: string | string[];
|
|
14
|
+
gitOptions?: ListGitFilesOptions;
|
|
15
|
+
configOptions?: GetConfigurationOptions;
|
|
16
|
+
aiOptions?: AIOptions;
|
|
17
|
+
verbose?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type AutoFillData = {
|
|
20
|
+
localeList: Locales[];
|
|
21
|
+
filePath: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Fill translations based on the provided options.
|
|
25
|
+
*/
|
|
26
|
+
export declare const fill: (options: FillOptions) => Promise<void>;
|
|
27
|
+
//# sourceMappingURL=fill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fill.d.ts","sourceRoot":"","sources":["../../src/fill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,eAAe,CAAC;AACpD,OAAO,EAGL,mBAAmB,EAKpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAGL,uBAAuB,EAEvB,OAAO,EACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGL,KAAK,UAAU,EAEhB,MAAM,gBAAgB,CAAC;AAMxB,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAiFF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAoKF;;GAEG;AACH,eAAO,MAAM,IAAI,GAAU,SAAS,WAAW,KAAG,OAAO,CAAC,IAAI,CAkL7D,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './cli';
|
|
2
1
|
export * from './build';
|
|
2
|
+
export * from './cli';
|
|
3
|
+
export * from './fill';
|
|
4
|
+
export * from './listContentDeclaration';
|
|
3
5
|
export * from './pull';
|
|
4
6
|
export * from './push';
|
|
5
|
-
export * from './listContentDeclaration';
|
|
6
|
-
export * from './audit';
|
|
7
7
|
export * from './pushConfig';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,0BAA0B,CAAC;AACzC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type GetConfigurationOptions } from '@intlayer/config';
|
|
2
2
|
type GetContentDeclarationOptions = {
|
|
3
3
|
exclude?: string[];
|
|
4
|
-
|
|
4
|
+
configOptions?: GetConfigurationOptions;
|
|
5
|
+
};
|
|
5
6
|
export declare const getContentDeclaration: (options?: GetContentDeclarationOptions) => string[];
|
|
6
7
|
type ListContentDeclarationOptions = {
|
|
7
|
-
|
|
8
|
+
configOptions?: GetConfigurationOptions;
|
|
8
9
|
};
|
|
9
|
-
export declare const listContentDeclaration: (options
|
|
10
|
+
export declare const listContentDeclaration: (options?: ListContentDeclarationOptions) => void;
|
|
10
11
|
export {};
|
|
11
12
|
//# sourceMappingURL=listContentDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listContentDeclaration.d.ts","sourceRoot":"","sources":["../../src/listContentDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"listContentDeclaration.d.ts","sourceRoot":"","sources":["../../src/listContentDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAG1B,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,UAAU,4BAA4B,KACrC,MAAM,EAaR,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,UAAU,6BAA6B,SAKxC,CAAC"}
|
package/dist/types/pull.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ type PullOptions = {
|
|
|
3
3
|
dictionaries?: string[];
|
|
4
4
|
newDictionariesPath?: string;
|
|
5
5
|
logPrefix?: string;
|
|
6
|
-
|
|
6
|
+
configOptions?: GetConfigurationOptions;
|
|
7
|
+
};
|
|
7
8
|
/**
|
|
8
9
|
* Fetch distant dictionaries and write them locally,
|
|
9
10
|
* with progress indicators and concurrency control.
|
package/dist/types/pull.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/pull.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/pull.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAK1B,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAsBF;;;GAGG;AACH,eAAO,MAAM,IAAI,GAAU,UAAU,WAAW,KAAG,OAAO,CAAC,IAAI,CAoJ9D,CAAC"}
|
package/dist/types/push.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { GetConfigurationOptions } from '@intlayer/config';
|
|
2
|
+
import { ListGitFilesOptions } from '../../chokidar/dist/types/listGitFiles';
|
|
2
3
|
type PushOptions = {
|
|
3
4
|
deleteLocaleDictionary?: boolean;
|
|
4
5
|
keepLocaleDictionary?: boolean;
|
|
5
6
|
dictionaries?: string[];
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
gitOptions?: ListGitFilesOptions;
|
|
8
|
+
configOptions?: GetConfigurationOptions;
|
|
9
|
+
};
|
|
8
10
|
/**
|
|
9
11
|
* Get all locale dictionaries and push them simultaneously.
|
|
10
12
|
*/
|
package/dist/types/push.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/push.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/push.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,uBAAuB,EACxB,MAAM,kBAAkB,CAAC;AAO1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAE7E,KAAK,WAAW,GAAG;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAqBF;;GAEG;AACH,eAAO,MAAM,IAAI,GAAU,UAAU,WAAW,KAAG,OAAO,CAAC,IAAI,CAoK9D,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type GetConfigurationOptions } from '@intlayer/config';
|
|
2
2
|
type PushOptions = {
|
|
3
3
|
logPrefix?: string;
|
|
4
|
-
|
|
4
|
+
configOptions?: GetConfigurationOptions;
|
|
5
|
+
};
|
|
5
6
|
export declare const pushConfig: (options?: PushOptions) => Promise<void>;
|
|
6
7
|
export {};
|
|
7
8
|
//# sourceMappingURL=pushConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushConfig.d.ts","sourceRoot":"","sources":["../../src/pushConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,KAAK,WAAW,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"pushConfig.d.ts","sourceRoot":"","sources":["../../src/pushConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,KAAK,WAAW,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,UAAU,WAAW,kBA6CrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0-canary.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides uniform command-line interface scripts for Intlayer, used in packages like intlayer-cli and intlayer.",
|
|
6
6
|
"keywords": [
|
|
@@ -52,10 +52,11 @@
|
|
|
52
52
|
"commander": "^13.0.0",
|
|
53
53
|
"fast-glob": "^3.3.3",
|
|
54
54
|
"p-limit": "^3.1.0",
|
|
55
|
-
"@intlayer/
|
|
56
|
-
"@intlayer/
|
|
57
|
-
"@intlayer/
|
|
58
|
-
"@intlayer/
|
|
55
|
+
"@intlayer/chokidar": "5.5.0-canary.0",
|
|
56
|
+
"@intlayer/config": "5.5.0-canary.0",
|
|
57
|
+
"@intlayer/dictionaries-entry": "5.5.0-canary.0",
|
|
58
|
+
"@intlayer/api": "5.5.0-canary.0",
|
|
59
|
+
"@intlayer/unmerged-dictionaries-entry": "5.5.0-canary.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@types/node": "^22.13.10",
|
|
@@ -67,17 +68,17 @@
|
|
|
67
68
|
"tsc-alias": "^1.8.11",
|
|
68
69
|
"tsup": "^8.4.0",
|
|
69
70
|
"typescript": "^5.8.2",
|
|
70
|
-
"@intlayer/core": "5.4.1",
|
|
71
|
-
"@utils/ts-config": "1.0.4",
|
|
72
71
|
"@utils/eslint-config": "1.0.4",
|
|
72
|
+
"@intlayer/core": "5.5.0-canary.0",
|
|
73
|
+
"@utils/ts-config": "1.0.4",
|
|
73
74
|
"@utils/ts-config-types": "1.0.4",
|
|
74
75
|
"@utils/tsup-config": "1.0.4"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
77
|
-
"@intlayer/api": "5.
|
|
78
|
-
"@intlayer/
|
|
79
|
-
"@intlayer/
|
|
80
|
-
"@intlayer/dictionaries-entry": "5.
|
|
78
|
+
"@intlayer/api": "5.5.0-canary.0",
|
|
79
|
+
"@intlayer/config": "5.5.0-canary.0",
|
|
80
|
+
"@intlayer/chokidar": "5.5.0-canary.0",
|
|
81
|
+
"@intlayer/dictionaries-entry": "5.5.0-canary.0"
|
|
81
82
|
},
|
|
82
83
|
"bug": {
|
|
83
84
|
"url": "https://github.com/aymericzip/intlayer/issues"
|
package/dist/cjs/audit.cjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var audit_exports = {};
|
|
30
|
-
__export(audit_exports, {
|
|
31
|
-
audit: () => audit,
|
|
32
|
-
auditFile: () => auditFile
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(audit_exports);
|
|
35
|
-
var import_fs = require("fs");
|
|
36
|
-
var import_path = require("path");
|
|
37
|
-
var import_api = require("@intlayer/api");
|
|
38
|
-
var import_config = require("@intlayer/config");
|
|
39
|
-
var import_p_limit = __toESM(require("p-limit"));
|
|
40
|
-
var import_listContentDeclaration = require('./listContentDeclaration.cjs');
|
|
41
|
-
const projectPath = process.cwd();
|
|
42
|
-
const auditFile = async (filePath, options) => {
|
|
43
|
-
try {
|
|
44
|
-
const { defaultLocale, locales } = (0, import_config.getConfiguration)().internationalization;
|
|
45
|
-
const relativePath = (0, import_path.relative)(projectPath, filePath);
|
|
46
|
-
(0, import_config.logger)(`Auditing file: ${relativePath}`, {
|
|
47
|
-
config: {
|
|
48
|
-
prefix: options?.logPrefix
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const fileContent = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
52
|
-
const auditFileResult = await (0, import_api.getIntlayerAPI)().ai.auditContentDeclaration(
|
|
53
|
-
{
|
|
54
|
-
fileContent,
|
|
55
|
-
filePath,
|
|
56
|
-
locales,
|
|
57
|
-
defaultLocale,
|
|
58
|
-
model: options?.model,
|
|
59
|
-
openAiApiKey: options?.openAiApiKey,
|
|
60
|
-
customPrompt: options?.customPrompt
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
headers: options?.headers
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
if (!auditFileResult.data) {
|
|
67
|
-
throw new Error("Audit failed");
|
|
68
|
-
}
|
|
69
|
-
(0, import_fs.writeFileSync)(filePath, auditFileResult.data.fileContent);
|
|
70
|
-
(0, import_config.logger)(`File ${relativePath} updated`, {
|
|
71
|
-
config: {
|
|
72
|
-
prefix: options?.logPrefix
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
(0, import_config.logger)(`${auditFileResult.data.tokenUsed} tokens used in the request`, {
|
|
76
|
-
config: {
|
|
77
|
-
prefix: options?.logPrefix
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
} catch (error) {
|
|
81
|
-
(0, import_config.logger)(error, {
|
|
82
|
-
level: "error",
|
|
83
|
-
config: {
|
|
84
|
-
prefix: options?.logPrefix
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const getAbsolutePath = (filePath) => {
|
|
90
|
-
if (filePath.startsWith(".")) {
|
|
91
|
-
const absolutePath = (0, import_path.join)(process.cwd(), filePath);
|
|
92
|
-
return absolutePath;
|
|
93
|
-
}
|
|
94
|
-
return filePath;
|
|
95
|
-
};
|
|
96
|
-
const audit = async (options) => {
|
|
97
|
-
const { clientId, clientSecret } = (0, import_config.getConfiguration)(options).editor;
|
|
98
|
-
let headers = {};
|
|
99
|
-
if (clientId && clientSecret) {
|
|
100
|
-
const oAuth2TokenResult = await (0, import_api.getIntlayerAPI)().auth.getOAuth2AccessToken();
|
|
101
|
-
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
102
|
-
headers = { Authorization: `Bearer ${oAuth2AccessToken}` };
|
|
103
|
-
} else if (!options?.openAiApiKey) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option."
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);
|
|
109
|
-
if (!contentDeclarationFilesList) {
|
|
110
|
-
const contentDeclarationFilesPath = (0, import_listContentDeclaration.getContentDeclaration)({
|
|
111
|
-
exclude: options?.excludedGlobs
|
|
112
|
-
});
|
|
113
|
-
contentDeclarationFilesList = contentDeclarationFilesPath;
|
|
114
|
-
}
|
|
115
|
-
const limit = (0, import_p_limit.default)(options?.asyncLimit ? Number(options?.asyncLimit) : 5);
|
|
116
|
-
const pushPromises = contentDeclarationFilesList.map(
|
|
117
|
-
(filePath) => limit(() => auditFile(filePath, { ...options, headers }))
|
|
118
|
-
);
|
|
119
|
-
await Promise.all(pushPromises);
|
|
120
|
-
};
|
|
121
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
-
0 && (module.exports = {
|
|
123
|
-
audit,
|
|
124
|
-
auditFile
|
|
125
|
-
});
|
|
126
|
-
//# sourceMappingURL=audit.cjs.map
|
package/dist/cjs/audit.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4C;AAC5C,kBAA+B;AAC/B,iBAA+B;AAC/B,oBAIO;AACP,qBAAmB;AACnB,oCAAsC;AAgBtC,MAAM,cAAc,QAAQ,IAAI;AAczB,MAAM,YAAY,OAAO,UAAkB,YAA2B;AAC3E,MAAI;AACF,UAAM,EAAE,eAAe,QAAQ,QAAI,gCAAiB,EAAE;AAEtD,UAAM,mBAAe,sBAAS,aAAa,QAAQ;AACnD,8BAAO,kBAAkB,YAAY,IAAI;AAAA,MACvC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAGD,UAAM,kBAAc,wBAAa,UAAU,OAAO;AAGlD,UAAM,kBAAkB,UAAM,2BAAe,EAAE,GAAG;AAAA,MAChD;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,SAAS;AAAA,QAChB,cAAc,SAAS;AAAA,QACvB,cAAc,SAAS;AAAA,MACzB;AAAA,MACA;AAAA,QACE,SAAS,SAAS;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,CAAC,gBAAgB,MAAM;AACzB,YAAM,IAAI,MAAM,cAAc;AAAA,IAChC;AAEA,iCAAc,UAAU,gBAAgB,KAAK,WAAW;AAExD,8BAAO,QAAQ,YAAY,YAAY;AAAA,MACrC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAED,8BAAO,GAAG,gBAAgB,KAAK,SAAS,+BAA+B;AAAA,MACrE,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,8BAAO,OAAO;AAAA,MACZ,OAAO;AAAA,MACP,QAAQ;AAAA,QAC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