@intlayer/cli 2.0.12 → 3.0.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 +32 -0
- package/dist/cjs/build.cjs.map +1 -0
- package/dist/cjs/cli.cjs +15 -4
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/pull.cjs +245 -0
- package/dist/cjs/pull.cjs.map +1 -0
- package/dist/cjs/push.cjs +242 -0
- package/dist/cjs/push.cjs.map +1 -0
- package/dist/esm/build.mjs +8 -0
- package/dist/esm/build.mjs.map +1 -0
- package/dist/esm/cli.mjs +15 -4
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/pull.mjs +211 -0
- package/dist/esm/pull.mjs.map +1 -0
- package/dist/esm/push.mjs +208 -0
- package/dist/esm/push.mjs.map +1 -0
- package/dist/types/build.d.ts +10 -0
- package/dist/types/build.d.ts.map +1 -0
- package/dist/types/cli.d.ts +11 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/pull.d.ts +12 -0
- package/dist/types/pull.d.ts.map +1 -0
- package/dist/types/push.d.ts +11 -0
- package/dist/types/push.d.ts.map +1 -0
- package/package.json +35 -11
- package/dist/cjs/cli.d.ts +0 -18
- package/dist/cjs/index.d.ts +0 -2
- package/dist/esm/cli.d.mts +0 -18
- package/dist/esm/index.d.mts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/build.ts"],"sourcesContent":["import { watch } from '@intlayer/chokidar';\n\ntype BuildOptions = { watch?: boolean };\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const build = (options?: BuildOptions) => {\n watch({ persistent: options?.watch ?? false });\n};\n"],"mappings":"AAAA,SAAS,aAAa;AAQf,MAAM,QAAQ,CAAC,YAA2B;AAC/C,QAAM,EAAE,YAAY,SAAS,SAAS,MAAM,CAAC;AAC/C;","names":[]}
|
package/dist/esm/cli.mjs
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
|
|
2
|
+
import { build } from './build.mjs';
|
|
3
|
+
import { pull } from './pull.mjs';
|
|
4
|
+
import { push } from './push.mjs';
|
|
5
|
+
const setAPI = () => {
|
|
3
6
|
const program = new Command();
|
|
4
7
|
program.version("1.0.0").description("Intlayer CLI");
|
|
5
|
-
program.command("build").description("Build the dictionaries").action(
|
|
6
|
-
program.command("
|
|
7
|
-
|
|
8
|
+
program.command("build").description("Build the dictionaries").option("-w, --watch", "Watch for changes").action((options) => build(options));
|
|
9
|
+
program.command("push").description(
|
|
10
|
+
"Push all dictionaries. Create or update the pushed dictionaries"
|
|
11
|
+
).option("-d, --dictionaries [ids...]", "List of dictionary IDs to push").option(
|
|
12
|
+
"-r, --deleteLocaleDir",
|
|
13
|
+
"Delete the local dictionaries directory after pushing"
|
|
14
|
+
).option(
|
|
15
|
+
"-k, --keepLocaleDir",
|
|
16
|
+
"Keep the local dictionaries directory after pushing"
|
|
17
|
+
).action((options) => push(options));
|
|
18
|
+
program.command("pull").option("-d, --dictionaries [ids...]", "List of dictionary IDs to pull").option("--newDictionariesPath [path]", "Path to save the new dictionaries").action((options) => pull(options));
|
|
8
19
|
program.parse(process.argv);
|
|
9
20
|
return program;
|
|
10
21
|
};
|
package/dist/esm/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import { Command } from 'commander';\
|
|
1
|
+
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { build } from './build';\nimport { pull } from './pull';\nimport { push } from './push';\n\n/**\n * Set the API for the CLI\n *\n * Example of commands:\n *\n * npm run intlayer build --watch\n * npm run intlayer push --dictionaries id1 id2 id3 --deleteLocaleDir\n */\nexport const setAPI = (): Command => {\n const program = new Command();\n\n program.version('1.0.0').description('Intlayer CLI');\n\n program\n .command('build')\n .description('Build the dictionaries')\n .option('-w, --watch', 'Watch for changes')\n .action((options) => build(options));\n\n program\n .command('push')\n .description(\n 'Push all dictionaries. Create or update the pushed dictionaries'\n )\n .option('-d, --dictionaries [ids...]', 'List of dictionary IDs to push')\n .option(\n '-r, --deleteLocaleDir',\n 'Delete the local dictionaries directory after pushing'\n )\n .option(\n '-k, --keepLocaleDir',\n 'Keep the local dictionaries directory after pushing'\n )\n .action((options) => push(options));\n\n program\n .command('pull')\n .option('-d, --dictionaries [ids...]', 'List of dictionary IDs to pull')\n .option('--newDictionariesPath [path]', 'Path to save the new dictionaries')\n .action((options) => pull(options));\n\n program.parse(process.argv);\n\n return program;\n};\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,YAAY;AAUd,MAAM,SAAS,MAAe;AACnC,QAAM,UAAU,IAAI,QAAQ;AAE5B,UAAQ,QAAQ,OAAO,EAAE,YAAY,cAAc;AAEnD,UACG,QAAQ,OAAO,EACf,YAAY,wBAAwB,EACpC,OAAO,eAAe,mBAAmB,EACzC,OAAO,CAAC,YAAY,MAAM,OAAO,CAAC;AAErC,UACG,QAAQ,MAAM,EACd;AAAA,IACC;AAAA,EACF,EACC,OAAO,+BAA+B,gCAAgC,EACtE;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC;AAEpC,UACG,QAAQ,MAAM,EACd,OAAO,+BAA+B,gCAAgC,EACtE,OAAO,gCAAgC,mCAAmC,EAC1E,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC;AAEpC,UAAQ,MAAM,QAAQ,IAAI;AAE1B,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './cli';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './cli';\nexport * from './build';\nexport * from './pull';\nexport * from './push';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import * as fsPromises from "fs/promises";
|
|
3
|
+
import { basename, dirname, extname } from "path";
|
|
4
|
+
import * as readline from "readline";
|
|
5
|
+
import { getConfiguration } from "@intlayer/config";
|
|
6
|
+
import { intlayerAPI } from "@intlayer/design-system/libs";
|
|
7
|
+
import dictionariesRecord from "@intlayer/dictionaries-entry";
|
|
8
|
+
import _ from "lodash";
|
|
9
|
+
import pLimit from "p-limit";
|
|
10
|
+
const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
11
|
+
const RESET = "\x1B[0m";
|
|
12
|
+
const GREEN = "\x1B[32m";
|
|
13
|
+
const RED = "\x1B[31m";
|
|
14
|
+
const BLUE = "\x1B[34m";
|
|
15
|
+
const GREY = "\x1B[90m";
|
|
16
|
+
const YELLOW = "\x1B[33m";
|
|
17
|
+
const GREY_DARK = "\x1B[90m";
|
|
18
|
+
const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
|
|
19
|
+
const pull = async (options) => {
|
|
20
|
+
try {
|
|
21
|
+
const {
|
|
22
|
+
editor: { clientId, clientSecret }
|
|
23
|
+
} = getConfiguration();
|
|
24
|
+
if (!clientId || !clientSecret) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
|
|
30
|
+
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
31
|
+
const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
|
|
32
|
+
headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
|
|
33
|
+
});
|
|
34
|
+
if (!getDictionariesKeysResult.data) {
|
|
35
|
+
throw new Error("No distant dictionaries found");
|
|
36
|
+
}
|
|
37
|
+
let distantDictionariesKeys = getDictionariesKeysResult.data;
|
|
38
|
+
if (options?.dictionaries) {
|
|
39
|
+
distantDictionariesKeys = distantDictionariesKeys.filter(
|
|
40
|
+
(dictionaryKey) => options.dictionaries.includes(dictionaryKey)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (distantDictionariesKeys.length === 0) {
|
|
44
|
+
console.error("No dictionaries to fetch");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
console.info("Fetching dictionaries:");
|
|
48
|
+
const dictionariesStatuses = distantDictionariesKeys.map((dictionaryKey, index) => ({
|
|
49
|
+
dictionaryKey,
|
|
50
|
+
icon: getStatusIcon("pending"),
|
|
51
|
+
status: "pending",
|
|
52
|
+
index,
|
|
53
|
+
spinnerFrameIndex: 0
|
|
54
|
+
}));
|
|
55
|
+
for (const statusObj of dictionariesStatuses) {
|
|
56
|
+
process.stdout.write(getStatusLine(statusObj) + "\n");
|
|
57
|
+
}
|
|
58
|
+
const spinnerTimer = setInterval(() => {
|
|
59
|
+
updateAllStatusLines(dictionariesStatuses);
|
|
60
|
+
}, 100);
|
|
61
|
+
const limit = pLimit(5);
|
|
62
|
+
const successfullyFetchedDictionaries = [];
|
|
63
|
+
const processDictionary = async (statusObj) => {
|
|
64
|
+
statusObj.status = "fetching";
|
|
65
|
+
try {
|
|
66
|
+
const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(
|
|
67
|
+
statusObj.dictionaryKey,
|
|
68
|
+
void 0,
|
|
69
|
+
{
|
|
70
|
+
headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const distantDictionary = getDictionaryResult.data;
|
|
74
|
+
if (!distantDictionary) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Dictionary ${statusObj.dictionaryKey} not found on remote`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const writeStatus = await writeDictionary(distantDictionary, options);
|
|
80
|
+
statusObj.status = writeStatus;
|
|
81
|
+
successfullyFetchedDictionaries.push(distantDictionary);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
statusObj.status = "error";
|
|
84
|
+
statusObj.error = error;
|
|
85
|
+
statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const fetchPromises = dictionariesStatuses.map(
|
|
89
|
+
(statusObj) => limit(() => processDictionary(statusObj))
|
|
90
|
+
);
|
|
91
|
+
await Promise.all(fetchPromises);
|
|
92
|
+
clearInterval(spinnerTimer);
|
|
93
|
+
updateAllStatusLines(dictionariesStatuses);
|
|
94
|
+
for (const statusObj of dictionariesStatuses) {
|
|
95
|
+
if (statusObj.errorMessage) {
|
|
96
|
+
console.error(statusObj.errorMessage);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(error);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const getStatusIcon = (status) => {
|
|
104
|
+
const statusIcons = {
|
|
105
|
+
pending: "\u23F2",
|
|
106
|
+
fetching: "",
|
|
107
|
+
// Spinner handled separately
|
|
108
|
+
"up-to-date": "\u2714",
|
|
109
|
+
updated: "\u2714",
|
|
110
|
+
fetched: "\u2714",
|
|
111
|
+
error: "\u2716"
|
|
112
|
+
};
|
|
113
|
+
return statusIcons[status] || "";
|
|
114
|
+
};
|
|
115
|
+
const getStatusLine = (statusObj) => {
|
|
116
|
+
let icon = getStatusIcon(statusObj.status);
|
|
117
|
+
let colorStart = "";
|
|
118
|
+
let colorEnd = "";
|
|
119
|
+
if (statusObj.status === "fetching") {
|
|
120
|
+
icon = spinnerFrames[statusObj.spinnerFrameIndex % spinnerFrames.length];
|
|
121
|
+
colorStart = BLUE;
|
|
122
|
+
colorEnd = RESET;
|
|
123
|
+
} else if (statusObj.status === "error") {
|
|
124
|
+
colorStart = RED;
|
|
125
|
+
colorEnd = RESET;
|
|
126
|
+
} else if (statusObj.status === "fetched" || statusObj.status === "imported" || statusObj.status === "updated" || statusObj.status === "up-to-date") {
|
|
127
|
+
colorStart = GREEN;
|
|
128
|
+
colorEnd = RESET;
|
|
129
|
+
} else if (statusObj.status === "reimported in JSON" || statusObj.status === "reimported in new location") {
|
|
130
|
+
colorStart = YELLOW;
|
|
131
|
+
colorEnd = RESET;
|
|
132
|
+
} else {
|
|
133
|
+
colorStart = GREY;
|
|
134
|
+
colorEnd = RESET;
|
|
135
|
+
}
|
|
136
|
+
return `- ${statusObj.dictionaryKey} ${GREY_DARK}[${colorStart}${icon} ${statusObj.status}${colorEnd}]`;
|
|
137
|
+
};
|
|
138
|
+
const updateAllStatusLines = (dictionariesStatuses) => {
|
|
139
|
+
readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);
|
|
140
|
+
for (const statusObj of dictionariesStatuses) {
|
|
141
|
+
readline.clearLine(process.stdout, 0);
|
|
142
|
+
if (statusObj.status === "fetching") {
|
|
143
|
+
statusObj.spinnerFrameIndex = (statusObj.spinnerFrameIndex + 1) % spinnerFrames.length;
|
|
144
|
+
}
|
|
145
|
+
process.stdout.write(getStatusLine(statusObj) + "\n");
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const writeDictionary = async (distantDictionary, options) => {
|
|
149
|
+
const {
|
|
150
|
+
content: { baseDir }
|
|
151
|
+
} = getConfiguration();
|
|
152
|
+
const newDictionaryRelativeLocationPath = options?.newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
153
|
+
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
154
|
+
const existingDictionary = dictionariesRecord[distantDictionary.key];
|
|
155
|
+
if (existingDictionary) {
|
|
156
|
+
const { filePath } = existingDictionary;
|
|
157
|
+
if (_.isEqual(existingDictionary, distantDictionary)) {
|
|
158
|
+
return "up-to-date";
|
|
159
|
+
} else {
|
|
160
|
+
if (filePath) {
|
|
161
|
+
const isDictionaryJSON = filePath.endsWith(".json");
|
|
162
|
+
if (isDictionaryJSON) {
|
|
163
|
+
await fsPromises.writeFile(
|
|
164
|
+
`${baseDir}/${filePath}`,
|
|
165
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
166
|
+
);
|
|
167
|
+
return "updated";
|
|
168
|
+
} else {
|
|
169
|
+
const dictionariesDirPath = dirname(filePath);
|
|
170
|
+
const dictionariesFileName = basename(filePath, extname(filePath));
|
|
171
|
+
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
172
|
+
await writeFileWithDirectories(
|
|
173
|
+
newFilePath,
|
|
174
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
175
|
+
);
|
|
176
|
+
return "reimported in JSON";
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
const dictionaryPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
180
|
+
await writeFileWithDirectories(
|
|
181
|
+
dictionaryPath,
|
|
182
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
183
|
+
);
|
|
184
|
+
return "reimported in new location";
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
const dictionaryPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;
|
|
189
|
+
await writeFileWithDirectories(
|
|
190
|
+
dictionaryPath,
|
|
191
|
+
JSON.stringify(distantDictionary, null, 2)
|
|
192
|
+
);
|
|
193
|
+
return "imported";
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const writeFileWithDirectories = async (filePath, data) => {
|
|
197
|
+
try {
|
|
198
|
+
const dir = dirname(filePath);
|
|
199
|
+
const directoryExists = existsSync(dir);
|
|
200
|
+
if (!directoryExists) {
|
|
201
|
+
await fsPromises.mkdir(dir, { recursive: true });
|
|
202
|
+
}
|
|
203
|
+
await fsPromises.writeFile(filePath, data);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
export {
|
|
209
|
+
pull
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=pull.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport * as readline from 'readline';\nimport { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { intlayerAPI } from '@intlayer/design-system/libs';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport _ from 'lodash';\nimport pLimit from 'p-limit';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n logPrefix?: string;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status:\n | 'pending'\n | 'fetching'\n | 'up-to-date'\n | 'updated'\n | 'fetched'\n | 'unknown'\n | 'error'\n | 'imported'\n | 'reimported in JSON'\n | 'reimported in new location';\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 YELLOW = '\\x1b[33m';\nconst GREY_DARK = '\\x1b[90m';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n try {\n const {\n editor: { clientId, clientSecret },\n } = getConfiguration();\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 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.dictionary.getDictionariesKeys({\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n if (options?.dictionaries) {\n // Filter the dictionaries from the provided list of IDs\n distantDictionariesKeys = distantDictionariesKeys.filter(\n (dictionaryKey) => options.dictionaries!.includes(dictionaryKey)\n );\n }\n\n // Check if dictionaries list is empty\n if (distantDictionariesKeys.length === 0) {\n console.error('No dictionaries to fetch');\n return;\n }\n\n console.info('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] =\n distantDictionariesKeys.map((dictionaryKey, index) => ({\n dictionaryKey,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n }));\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Adjust the limit as needed\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'fetching';\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n statusObj.dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const writeStatus = await writeDictionary(distantDictionary, options);\n\n statusObj.status = writeStatus;\n\n successfullyFetchedDictionaries.push(distantDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n }\n };\n\n const fetchPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n\n await Promise.all(fetchPromises);\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 console.error(statusObj.errorMessage);\n }\n }\n } catch (error) {\n console.error(error);\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n 'up-to-date': '✔',\n updated: '✔',\n fetched: '✔',\n error: '✖',\n };\n return statusIcons[status] || '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'fetching') {\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 (\n statusObj.status === 'fetched' ||\n statusObj.status === 'imported' ||\n statusObj.status === 'updated' ||\n statusObj.status === 'up-to-date'\n ) {\n colorStart = GREEN;\n colorEnd = RESET;\n } else if (\n statusObj.status === 'reimported in JSON' ||\n statusObj.status === 'reimported in new location'\n ) {\n colorStart = YELLOW;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionaryKey} ${GREY_DARK}[${colorStart}${icon} ${statusObj.status}${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 === 'fetching') {\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\nconst writeDictionary = async (\n distantDictionary: Dictionary,\n options?: PullOptions\n): Promise<DictionariesStatus['status']> => {\n const {\n content: { baseDir },\n } = getConfiguration();\n\n const newDictionaryRelativeLocationPath =\n options?.newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = dictionariesRecord[distantDictionary.key];\n\n if (existingDictionary) {\n const { filePath } = existingDictionary;\n\n // Compare existing dictionary with distant dictionary\n if (_.isEqual(existingDictionary, distantDictionary)) {\n // Up to date, nothing to do\n return 'up-to-date';\n } else {\n if (filePath) {\n const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n // Write the dictionary to the same location of the existing dictionary file\n await fsPromises.writeFile(\n `${baseDir}/${filePath}`,\n JSON.stringify(distantDictionary, null, 2)\n );\n return 'updated';\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return 'reimported in JSON';\n }\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionaryPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n await writeFileWithDirectories(\n dictionaryPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n return 'reimported in new location';\n }\n }\n } else {\n // No existing dictionary, write to new location\n const dictionaryPath = `${newDictionaryLocationPath}/${distantDictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n dictionaryPath,\n JSON.stringify(distantDictionary, null, 2)\n );\n\n return 'imported';\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await fsPromises.mkdir(dir, { recursive: true });\n }\n\n // Write the file\n await fsPromises.writeFile(filePath, data);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,YAAY,gBAAgB;AAC5B,SAAS,UAAU,SAAS,eAAe;AAC3C,YAAY,cAAc;AAC1B,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAC5B,OAAO,wBAAwB;AAC/B,OAAO,OAAO;AACd,OAAO,YAAY;AA4BnB,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,SAAS;AACf,MAAM,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G,OAAO,IAAI,QAAQ;AAAA,YACtB,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AACA,iBAAO;AAAA,QACT,OAAO;AAEL,gBAAM,sBAAsB,QAAQ,QAAQ;AAC5C,gBAAM,uBAAuB,SAAS,UAAU,QAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,UAC3C;AACA,iBAAO;AAAA,QACT;AAAA,MACF,OAAO;AAEL,cAAM,iBAAiB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AAC5E,cAAM;AAAA,UACJ;AAAA,UACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,QAC3C;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,iBAAiB,GAAG,yBAAyB,IAAI,kBAAkB,GAAG;AAE5E,UAAM;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,mBAAmB,MAAM,CAAC;AAAA,IAC3C;AAEA,WAAO;AAAA,EACT;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,MAAM,QAAQ,QAAQ;AAG5B,UAAM,kBAAkB,WAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAGA,UAAM,WAAW,UAAU,UAAU,IAAI;AAAA,EAC3C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":[]}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import * as fsPromises from "fs/promises";
|
|
2
|
+
import { relative } from "path";
|
|
3
|
+
import * as readline from "readline";
|
|
4
|
+
import { getConfiguration } from "@intlayer/config";
|
|
5
|
+
import { intlayerAPI } from "@intlayer/design-system/libs";
|
|
6
|
+
import dictionariesRecord from "@intlayer/dictionaries-entry";
|
|
7
|
+
import pLimit from "p-limit";
|
|
8
|
+
const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
9
|
+
const RESET = "\x1B[0m";
|
|
10
|
+
const GREEN = "\x1B[32m";
|
|
11
|
+
const RED = "\x1B[31m";
|
|
12
|
+
const BLUE = "\x1B[34m";
|
|
13
|
+
const GREY = "\x1B[90m";
|
|
14
|
+
const push = async (options) => {
|
|
15
|
+
try {
|
|
16
|
+
const { clientId, clientSecret } = getConfiguration().editor;
|
|
17
|
+
if (!clientId || !clientSecret) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
|
|
23
|
+
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
24
|
+
let dictionaries = Object.values(dictionariesRecord);
|
|
25
|
+
const existingDictionariesKeys = Object.keys(dictionariesRecord);
|
|
26
|
+
if (options?.dictionaries) {
|
|
27
|
+
const noneExistingDictionariesOption = options.dictionaries.filter(
|
|
28
|
+
(dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)
|
|
29
|
+
);
|
|
30
|
+
if (noneExistingDictionariesOption.length > 0) {
|
|
31
|
+
console.error(
|
|
32
|
+
`The following dictionaries do not exist: ${noneExistingDictionariesOption.join(
|
|
33
|
+
", "
|
|
34
|
+
)} and have been ignored.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
dictionaries = dictionaries.filter(
|
|
38
|
+
(dictionary) => options.dictionaries.includes(dictionary.key)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (dictionaries.length === 0) {
|
|
42
|
+
console.error("No local dictionaries found");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
console.info("Pushing dictionaries:");
|
|
46
|
+
const dictionariesStatuses = dictionaries.map(
|
|
47
|
+
(dictionary, index) => ({
|
|
48
|
+
dictionary,
|
|
49
|
+
icon: getStatusIcon("pending"),
|
|
50
|
+
status: "pending",
|
|
51
|
+
index,
|
|
52
|
+
spinnerFrameIndex: 0
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
for (const statusObj of dictionariesStatuses) {
|
|
56
|
+
process.stdout.write(getStatusLine(statusObj) + "\n");
|
|
57
|
+
}
|
|
58
|
+
const successfullyPushedDictionaries = [];
|
|
59
|
+
const spinnerTimer = setInterval(() => {
|
|
60
|
+
updateAllStatusLines(dictionariesStatuses);
|
|
61
|
+
}, 100);
|
|
62
|
+
const processDictionary = async (statusObj) => {
|
|
63
|
+
statusObj.status = "pushing";
|
|
64
|
+
try {
|
|
65
|
+
const pushResult = await intlayerAPI.dictionary.pushDictionaries(
|
|
66
|
+
[statusObj.dictionary],
|
|
67
|
+
{
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${oAuth2AccessToken}`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const updatedDictionaries = pushResult.data?.updatedDictionaries || [];
|
|
74
|
+
const newDictionaries = pushResult.data?.newDictionaries || [];
|
|
75
|
+
if (updatedDictionaries.includes(statusObj.dictionary.key)) {
|
|
76
|
+
statusObj.status = "modified";
|
|
77
|
+
successfullyPushedDictionaries.push(statusObj.dictionary);
|
|
78
|
+
} else if (newDictionaries.includes(statusObj.dictionary.key)) {
|
|
79
|
+
statusObj.status = "pushed";
|
|
80
|
+
successfullyPushedDictionaries.push(statusObj.dictionary);
|
|
81
|
+
} else {
|
|
82
|
+
statusObj.status = "unknown";
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
statusObj.status = "error";
|
|
86
|
+
statusObj.error = error;
|
|
87
|
+
statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const limit = pLimit(5);
|
|
91
|
+
const pushPromises = dictionariesStatuses.map(
|
|
92
|
+
(statusObj) => limit(() => processDictionary(statusObj))
|
|
93
|
+
);
|
|
94
|
+
await Promise.all(pushPromises);
|
|
95
|
+
clearInterval(spinnerTimer);
|
|
96
|
+
updateAllStatusLines(dictionariesStatuses);
|
|
97
|
+
for (const statusObj of dictionariesStatuses) {
|
|
98
|
+
if (statusObj.errorMessage) {
|
|
99
|
+
console.error(statusObj.errorMessage);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const deleteOption = options?.deleteLocaleDir;
|
|
103
|
+
const keepOption = options?.keepLocaleDir;
|
|
104
|
+
if (deleteOption && keepOption) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
"Cannot specify both --deleteLocaleDir and --keepLocaleDir options."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (deleteOption) {
|
|
110
|
+
await deleteLocalDictionaries(successfullyPushedDictionaries);
|
|
111
|
+
} else if (keepOption) {
|
|
112
|
+
} else {
|
|
113
|
+
const answer = await askUser(
|
|
114
|
+
"Do you want to delete the local dictionaries that were successfully pushed? (yes/no): "
|
|
115
|
+
);
|
|
116
|
+
if (answer.toLowerCase() === "yes" || answer.toLowerCase() === "y") {
|
|
117
|
+
await deleteLocalDictionaries(successfullyPushedDictionaries);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const askUser = (question) => {
|
|
125
|
+
const rl = readline.createInterface({
|
|
126
|
+
input: process.stdin,
|
|
127
|
+
output: process.stdout
|
|
128
|
+
});
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
rl.question(question, (answer) => {
|
|
131
|
+
rl.close();
|
|
132
|
+
resolve(answer);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const deleteLocalDictionaries = async (dictionariesToDelete) => {
|
|
137
|
+
const { baseDir } = getConfiguration().content;
|
|
138
|
+
const filePathsSet = /* @__PURE__ */ new Set();
|
|
139
|
+
for (const dictionary of dictionariesToDelete) {
|
|
140
|
+
const { filePath } = dictionary;
|
|
141
|
+
if (!filePath) {
|
|
142
|
+
console.error(`Dictionary ${dictionary.key} does not have a file path`);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
filePathsSet.add(filePath);
|
|
146
|
+
}
|
|
147
|
+
for (const filePath of filePathsSet) {
|
|
148
|
+
const relativePath = relative(baseDir, filePath);
|
|
149
|
+
try {
|
|
150
|
+
const stats = await fsPromises.lstat(filePath);
|
|
151
|
+
if (stats.isFile()) {
|
|
152
|
+
await fsPromises.unlink(filePath);
|
|
153
|
+
console.info(`Deleted file ${relativePath}`);
|
|
154
|
+
} else if (stats.isDirectory()) {
|
|
155
|
+
console.warn(`Path is a directory ${relativePath}, skipping.`);
|
|
156
|
+
} else {
|
|
157
|
+
console.warn(`Unknown file type for ${relativePath}, skipping.`);
|
|
158
|
+
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(`Error deleting ${relativePath}:`, err);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const getStatusIcon = (status) => {
|
|
165
|
+
const statusIcons = {
|
|
166
|
+
pending: "\u23F2",
|
|
167
|
+
pushing: "",
|
|
168
|
+
// Spinner handled separately
|
|
169
|
+
modified: "\u2714",
|
|
170
|
+
pushed: "\u2714",
|
|
171
|
+
error: "\u2716"
|
|
172
|
+
};
|
|
173
|
+
return statusIcons[status] || "";
|
|
174
|
+
};
|
|
175
|
+
const getStatusLine = (statusObj) => {
|
|
176
|
+
let icon = getStatusIcon(statusObj.status);
|
|
177
|
+
let colorStart = "";
|
|
178
|
+
let colorEnd = "";
|
|
179
|
+
if (statusObj.status === "pushing") {
|
|
180
|
+
icon = spinnerFrames[statusObj.spinnerFrameIndex % spinnerFrames.length];
|
|
181
|
+
colorStart = BLUE;
|
|
182
|
+
colorEnd = RESET;
|
|
183
|
+
} else if (statusObj.status === "error") {
|
|
184
|
+
colorStart = RED;
|
|
185
|
+
colorEnd = RESET;
|
|
186
|
+
} else if (statusObj.status === "pushed" || statusObj.status === "modified") {
|
|
187
|
+
colorStart = GREEN;
|
|
188
|
+
colorEnd = RESET;
|
|
189
|
+
} else {
|
|
190
|
+
colorStart = GREY;
|
|
191
|
+
colorEnd = RESET;
|
|
192
|
+
}
|
|
193
|
+
return `- ${statusObj.dictionary.key} [${colorStart}${icon} ${statusObj.status}${colorEnd}]`;
|
|
194
|
+
};
|
|
195
|
+
const updateAllStatusLines = (dictionariesStatuses) => {
|
|
196
|
+
readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);
|
|
197
|
+
for (const statusObj of dictionariesStatuses) {
|
|
198
|
+
readline.clearLine(process.stdout, 0);
|
|
199
|
+
if (statusObj.status === "pushing") {
|
|
200
|
+
statusObj.spinnerFrameIndex = (statusObj.spinnerFrameIndex + 1) % spinnerFrames.length;
|
|
201
|
+
}
|
|
202
|
+
process.stdout.write(getStatusLine(statusObj) + "\n");
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export {
|
|
206
|
+
push
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=push.mjs.map
|
|
@@ -0,0 +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 { getConfiguration } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { intlayerAPI } from '@intlayer/design-system/libs';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport pLimit from 'p-limit';\n\ntype PushOptions = {\n deleteLocaleDir?: boolean;\n keepLocaleDir?: boolean;\n dictionaries?: string[];\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';\n\n/**\n * Get all locale dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n try {\n const { clientId, clientSecret } = getConfiguration().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 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 console.error(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`\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 console.error('No local dictionaries found');\n return;\n }\n\n console.info('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); // Adjust the limit as needed\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 console.error(statusObj.errorMessage);\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDir;\n const keepOption = options?.keepLocaleDir;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDir and --keepLocaleDir options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries);\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);\n }\n }\n } catch (error) {\n console.error(error);\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): 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 console.error(`Dictionary ${dictionary.key} does not have a file path`);\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 console.info(`Deleted file ${relativePath}`);\n } else if (stats.isDirectory()) {\n console.warn(`Path is a directory ${relativePath}, skipping.`);\n } else {\n console.warn(`Unknown file type for ${relativePath}, skipping.`);\n }\n } catch (err) {\n console.error(`Error deleting ${relativePath}:`, err);\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 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} [${colorStart}${icon} ${statusObj.status}${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,wBAAwB;AAEjC,SAAS,mBAAmB;AAC5B,OAAO,wBAAwB;AAC/B,OAAO,YAAY;AAkBnB,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;AAKN,MAAM,OAAO,OAAO,YAAyC;AAClE,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,iBAAiB,EAAE;AAEtD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,QAAI,eAA6B,OAAO,OAAO,kBAAkB;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;AAEf,MAAI,UAAU,WAAW,WAAW;AAElC,WAAO,cAAc,UAAU,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,KAAK,UAAU,GAAG,IAAI,IAAI,UAAU,MAAM,GAAG,QAAQ;AAC3F;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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type BuildOptions = {
|
|
2
|
+
watch?: boolean;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.
|
|
6
|
+
* Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}
|
|
7
|
+
*/
|
|
8
|
+
export declare const build: (options?: BuildOptions) => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/build.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,KAAK,aAAc,YAAY,SAE3C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Set the API for the CLI
|
|
4
|
+
*
|
|
5
|
+
* Example of commands:
|
|
6
|
+
*
|
|
7
|
+
* npm run intlayer build --watch
|
|
8
|
+
* npm run intlayer push --dictionaries id1 id2 id3 --deleteLocaleDir
|
|
9
|
+
*/
|
|
10
|
+
export declare const setAPI: () => Command;
|
|
11
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OAoCzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type PullOptions = {
|
|
2
|
+
dictionaries?: string[];
|
|
3
|
+
newDictionariesPath?: string;
|
|
4
|
+
logPrefix?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Fetch distant dictionaries and write them locally,
|
|
8
|
+
* with progress indicators and concurrency control.
|
|
9
|
+
*/
|
|
10
|
+
export declare const pull: (options?: PullOptions) => Promise<void>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=pull.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/pull.ts"],"names":[],"mappings":"AAWA,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAkCF;;;GAGG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CA4H9D,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type PushOptions = {
|
|
2
|
+
deleteLocaleDir?: boolean;
|
|
3
|
+
keepLocaleDir?: boolean;
|
|
4
|
+
dictionaries?: string[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Get all locale dictionaries and push them simultaneously.
|
|
8
|
+
*/
|
|
9
|
+
export declare const push: (options?: PushOptions) => Promise<void>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/push.ts"],"names":[],"mappings":"AASA,KAAK,WAAW,GAAG;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAoBF;;GAEG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAqJ9D,CAAC"}
|