@intlayer/cli 4.1.3 → 4.1.5

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.
Files changed (47) hide show
  1. package/dist/cjs/audit.cjs +21 -4
  2. package/dist/cjs/audit.cjs.map +1 -1
  3. package/dist/cjs/cli.cjs +7 -3
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/config.cjs +6 -2
  6. package/dist/cjs/config.cjs.map +1 -1
  7. package/dist/cjs/index.cjs +3 -1
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/listContentDeclaration.cjs +6 -2
  10. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  11. package/dist/cjs/pull.cjs +23 -4
  12. package/dist/cjs/pull.cjs.map +1 -1
  13. package/dist/cjs/push.cjs +55 -13
  14. package/dist/cjs/push.cjs.map +1 -1
  15. package/dist/cjs/pushConfig.cjs +65 -0
  16. package/dist/cjs/pushConfig.cjs.map +1 -0
  17. package/dist/esm/audit.mjs +21 -4
  18. package/dist/esm/audit.mjs.map +1 -1
  19. package/dist/esm/cli.mjs +7 -3
  20. package/dist/esm/cli.mjs.map +1 -1
  21. package/dist/esm/config.mjs +6 -2
  22. package/dist/esm/config.mjs.map +1 -1
  23. package/dist/esm/index.mjs +1 -0
  24. package/dist/esm/index.mjs.map +1 -1
  25. package/dist/esm/listContentDeclaration.mjs +6 -2
  26. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  27. package/dist/esm/pull.mjs +23 -4
  28. package/dist/esm/pull.mjs.map +1 -1
  29. package/dist/esm/push.mjs +55 -13
  30. package/dist/esm/push.mjs.map +1 -1
  31. package/dist/esm/pushConfig.mjs +41 -0
  32. package/dist/esm/pushConfig.mjs.map +1 -0
  33. package/dist/types/audit.d.ts +1 -0
  34. package/dist/types/audit.d.ts.map +1 -1
  35. package/dist/types/cli.d.ts.map +1 -1
  36. package/dist/types/config.d.ts +4 -2
  37. package/dist/types/config.d.ts.map +1 -1
  38. package/dist/types/index.d.ts +1 -0
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/listContentDeclaration.d.ts +4 -2
  41. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  42. package/dist/types/pull.d.ts.map +1 -1
  43. package/dist/types/push.d.ts +1 -0
  44. package/dist/types/push.d.ts.map +1 -1
  45. package/dist/types/pushConfig.d.ts +7 -0
  46. package/dist/types/pushConfig.d.ts.map +1 -0
  47. package/package.json +12 -12
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { intlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } 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};\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\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 intlayerAPI.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\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`);\n } catch (error) {\n logger(error, { level: 'error' });\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().editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult = await intlayerAPI.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(() => auditF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,YAAY,cAAc;AAC5B,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,cAAU,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,EAC3D,WAAW,CAAC,SAAS,cAAc;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,8BAA8B,SAAS,OAAO,IAAI,eAAe;AAErE,MAAI,CAAC,6BAA6B;AAEhC,UAAM,8BAA8B,sBAAsB;AAAA,MACxD,SAAS,SAAS;AAAA,IACpB,CAAC;AAED,kCAA8B;AAAA,EAChC;AAEA,QAAM,QAAQ,OAAO,SAAS,aAAa,OAAO,SAAS,UAAU,IAAI,CAAC;AAC1E,QAAM,eAAe,4BAA4B;AAAA,IAAI,CAAC,aACpD,MAAM,MAAM,UAAU,UAAU,EAAE,GAAG,SAAS,QAAQ,CAAC,CAAC;AAAA,EAC1D;AACA,QAAM,QAAQ,IAAI,YAAY;AAChC;","names":[]}
1
+ {"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { intlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } 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};\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 intlayerAPI.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().editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult = await intlayerAPI.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,SAAS,cAAc,qBAAqB;AAC5C,SAAS,MAAM,gBAAgB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB,cAAc;AACzC,OAAO,YAAY;AACnB,SAAS,6BAA6B;AAgBtC,MAAM,cAAc,QAAQ,IAAI;AAczB,MAAM,YAAY,OAAO,UAAkB,YAA2B;AAC3E,MAAI;AACF,UAAM,EAAE,eAAe,QAAQ,IAAI,iBAAiB,EAAE;AAEtD,UAAM,eAAe,SAAS,aAAa,QAAQ;AACnD,WAAO,kBAAkB,YAAY,IAAI;AAAA,MACvC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAGD,UAAM,cAAc,aAAa,UAAU,OAAO;AAGlD,UAAM,kBAAkB,MAAM,YAAY,GAAG;AAAA,MAC3C;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,g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4B;AAAA,IAAI,CAAC,aACpD,MAAM,MAAM,UAAU,UAAU,EAAE,GAAG,SAAS,QAAQ,CAAC,CAAC;AAAA,EAC1D;AACA,QAAM,QAAQ,IAAI,YAAY;AAChC;","names":[]}
package/dist/esm/cli.mjs CHANGED
@@ -5,11 +5,14 @@ import { getConfig } from "./config.mjs";
5
5
  import { listContentDeclaration } from "./listContentDeclaration.mjs";
6
6
  import { pull } from "./pull.mjs";
7
7
  import { push } from "./push.mjs";
8
+ import { pushConfig } from "./pushConfig.mjs";
8
9
  const setAPI = () => {
9
10
  const program = new Command();
10
11
  program.version("1.0.0").description("Intlayer CLI");
11
12
  program.command("build").description("Build the dictionaries").option("-w, --watch", "Watch for changes").action(build);
12
- program.command("push").description(
13
+ const dictionariesProgram = program.command("dictionaries").description("Dictionaries operations");
14
+ dictionariesProgram.command("pull").option("-d, --dictionaries [ids...]", "List of dictionary IDs to pull").option("--newDictionariesPath [path]", "Path to save the new dictionaries").action(pull);
15
+ dictionariesProgram.command("push").description(
13
16
  "Push all dictionaries. Create or update the pushed dictionaries"
14
17
  ).option("-d, --dictionaries [ids...]", "List of dictionary IDs to push").option(
15
18
  "-r, --deleteLocaleDictionary",
@@ -18,8 +21,9 @@ const setAPI = () => {
18
21
  "-k, --keepLocaleDictionary",
19
22
  "Keep the local dictionaries after pushing"
20
23
  ).action(push);
21
- program.command("pull").option("-d, --dictionaries [ids...]", "List of dictionary IDs to pull").option("--newDictionariesPath [path]", "Path to save the new dictionaries").action(pull);
22
- program.command("get config").description("Get the configuration").action(getConfig);
24
+ const configurationProgram = program.command("config").description("Configuration operations");
25
+ configurationProgram.command("get").description("Get the configuration").action(getConfig);
26
+ configurationProgram.command("push").description("Push the configuration").action(pushConfig);
23
27
  program.command("content list").description("List the content declaration files").action(listContentDeclaration);
24
28
  program.command("audit").description("Audit the dictionaries").option(
25
29
  "-f, --files [files...]",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { audit } from './audit';\nimport { build } from './build';\nimport { getConfig } from './config';\nimport { listContentDeclaration } from './listContentDeclaration';\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(build);\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, --deleteLocaleDictionary',\n 'Delete the local dictionaries after pushing'\n )\n .option(\n '-k, --keepLocaleDictionary',\n 'Keep the local dictionaries after pushing'\n )\n .action(push);\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(pull);\n\n program\n .command('get config')\n .description('Get the configuration')\n .action(getConfig);\n\n program\n .command('content list')\n .description('List the content declaration files')\n .action(listContentDeclaration);\n\n program\n .command('audit')\n .description('Audit the dictionaries')\n .option(\n '-f, --files [files...]',\n 'List of Content Declaration files to audit'\n )\n .option(\n '--exclude [excludedGlobs...]',\n 'Globs pattern to exclude from the audit'\n )\n .option('-m, --model [model]', 'Model')\n .option('-p, --custom-prompt [prompt]', 'Custom prompt')\n .option('-l, --async-limit [asyncLimit]', 'Async limit')\n .option('-k, --open-ai-api-key [openAiApiKey]', 'OpenAI API key')\n .action(audit);\n\n program.parse(process.argv);\n\n return program;\n};\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AACvC,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,KAAK;AAEf,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,IAAI;AAEd,UACG,QAAQ,MAAM,EACd,OAAO,+BAA+B,gCAAgC,EACtE,OAAO,gCAAgC,mCAAmC,EAC1E,OAAO,IAAI;AAEd,UACG,QAAQ,YAAY,EACpB,YAAY,uBAAuB,EACnC,OAAO,SAAS;AAEnB,UACG,QAAQ,cAAc,EACtB,YAAY,oCAAoC,EAChD,OAAO,sBAAsB;AAEhC,UACG,QAAQ,OAAO,EACf,YAAY,wBAAwB,EACpC;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC,OAAO,uBAAuB,OAAO,EACrC,OAAO,gCAAgC,eAAe,EACtD,OAAO,kCAAkC,aAAa,EACtD,OAAO,wCAAwC,gBAAgB,EAC/D,OAAO,KAAK;AAEf,UAAQ,MAAM,QAAQ,IAAI;AAE1B,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import { Command } from 'commander';\nimport { audit } from './audit';\nimport { build } from './build';\nimport { getConfig } from './config';\nimport { listContentDeclaration } from './listContentDeclaration';\nimport { pull } from './pull';\nimport { push } from './push';\nimport { pushConfig } from './pushConfig';\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(build);\n\n /**\n * DICTIONARIES\n */\n\n const dictionariesProgram = program\n .command('dictionaries')\n .description('Dictionaries operations');\n\n dictionariesProgram\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(pull);\n\n // Define the main `push` command\n dictionariesProgram\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, --deleteLocaleDictionary',\n 'Delete the local dictionaries after pushing'\n )\n .option(\n '-k, --keepLocaleDictionary',\n 'Keep the local dictionaries after pushing'\n )\n .action(push);\n\n /**\n * CONFIGURATION\n */\n\n const configurationProgram = program\n .command('config')\n .description('Configuration operations');\n\n configurationProgram\n .command('get')\n .description('Get the configuration')\n\n .action(getConfig);\n\n // Define the `push config` subcommand and add it to the `push` command\n configurationProgram\n .command('push')\n .description('Push the configuration')\n .action(pushConfig);\n\n /**\n * CONTENT DECLARATION\n */\n\n program\n .command('content list')\n .description('List the content declaration files')\n .action(listContentDeclaration);\n\n program\n .command('audit')\n .description('Audit the dictionaries')\n .option(\n '-f, --files [files...]',\n 'List of Content Declaration files to audit'\n )\n .option(\n '--exclude [excludedGlobs...]',\n 'Globs pattern to exclude from the audit'\n )\n .option('-m, --model [model]', 'Model')\n .option('-p, --custom-prompt [prompt]', 'Custom prompt')\n .option('-l, --async-limit [asyncLimit]', 'Async limit')\n .option('-k, --open-ai-api-key [openAiApiKey]', 'OpenAI API key')\n .action(audit);\n\n program.parse(process.argv);\n\n return program;\n};\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AACvC,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAUpB,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,KAAK;AAMf,QAAM,sBAAsB,QACzB,QAAQ,cAAc,EACtB,YAAY,yBAAyB;AAExC,sBACG,QAAQ,MAAM,EACd,OAAO,+BAA+B,gCAAgC,EACtE,OAAO,gCAAgC,mCAAmC,EAC1E,OAAO,IAAI;AAGd,sBACG,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,IAAI;AAMd,QAAM,uBAAuB,QAC1B,QAAQ,QAAQ,EAChB,YAAY,0BAA0B;AAEzC,uBACG,QAAQ,KAAK,EACb,YAAY,uBAAuB,EAEnC,OAAO,SAAS;AAGnB,uBACG,QAAQ,MAAM,EACd,YAAY,wBAAwB,EACpC,OAAO,UAAU;AAMpB,UACG,QAAQ,cAAc,EACtB,YAAY,oCAAoC,EAChD,OAAO,sBAAsB;AAEhC,UACG,QAAQ,OAAO,EACf,YAAY,wBAAwB,EACpC;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC;AAAA,IACC;AAAA,IACA;AAAA,EACF,EACC,OAAO,uBAAuB,OAAO,EACrC,OAAO,gCAAgC,eAAe,EACtD,OAAO,kCAAkC,aAAa,EACtD,OAAO,wCAAwC,gBAAgB,EAC/D,OAAO,KAAK;AAEf,UAAQ,MAAM,QAAQ,IAAI;AAE1B,SAAO;AACT;","names":[]}
@@ -1,7 +1,11 @@
1
1
  import { getConfiguration, logger } from "@intlayer/config";
2
- const getConfig = (_options) => {
2
+ const getConfig = (options) => {
3
3
  const config = getConfiguration();
4
- logger(config);
4
+ logger(JSON.stringify(config, null, 2), {
5
+ config: {
6
+ prefix: options?.logPrefix
7
+ }
8
+ });
5
9
  };
6
10
  export {
7
11
  getConfig
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import { getConfiguration, logger } from '@intlayer/config';\n\ntype ConfigOptions = {};\n\nexport const getConfig = (_options?: ConfigOptions) => {\n const config = getConfiguration();\n\n logger(config);\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,cAAc;AAIlC,MAAM,YAAY,CAAC,aAA6B;AACrD,QAAM,SAAS,iBAAiB;AAEhC,SAAO,MAAM;AACf;","names":[]}
1
+ {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import { getConfiguration, logger } from '@intlayer/config';\n\ntype ConfigOptions = {\n logPrefix?: string;\n};\n\nexport const getConfig = (options?: ConfigOptions) => {\n const config = getConfiguration();\n\n logger(JSON.stringify(config, null, 2), {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,cAAc;AAMlC,MAAM,YAAY,CAAC,YAA4B;AACpD,QAAM,SAAS,iBAAiB;AAEhC,SAAO,KAAK,UAAU,QAAQ,MAAM,CAAC,GAAG;AAAA,IACtC,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -4,4 +4,5 @@ export * from "./pull.mjs";
4
4
  export * from "./push.mjs";
5
5
  export * from "./listContentDeclaration.mjs";
6
6
  export * from "./audit.mjs";
7
+ export * from "./pushConfig.mjs";
7
8
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './cli';\nexport * from './build';\nexport * from './pull';\nexport * from './push';\nexport * from './listContentDeclaration';\nexport * from './audit';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './cli';\nexport * from './build';\nexport * from './pull';\nexport * from './push';\nexport * from './listContentDeclaration';\nexport * from './audit';\nexport * from './pushConfig';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -12,9 +12,13 @@ const getContentDeclaration = (options) => {
12
12
  );
13
13
  return contentDeclarationFilesPath;
14
14
  };
15
- const listContentDeclaration = (_options) => {
15
+ const listContentDeclaration = (options) => {
16
16
  const contentDeclarationFilesPath = getContentDeclaration();
17
- logger(`Content declaration files: ${contentDeclarationFilesPath}`);
17
+ logger(`Content declaration files: ${contentDeclarationFilesPath}`, {
18
+ config: {
19
+ prefix: options?.logPrefix
20
+ }
21
+ });
18
22
  };
19
23
  export {
20
24
  getContentDeclaration,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/listContentDeclaration.ts"],"sourcesContent":["import { getConfiguration, logger } from '@intlayer/config';\nimport fg from 'fast-glob';\n\ntype GetContentDeclarationOptions = {\n exclude?: string[];\n};\n\nexport const getContentDeclaration = (\n options?: GetContentDeclarationOptions\n): string[] => {\n const {\n content: { watchedFilesPatternWithPath },\n } = getConfiguration();\n\n const contentDeclarationFilesPath: string[] = fg.sync(\n watchedFilesPatternWithPath,\n {\n ignore: options?.exclude,\n }\n );\n\n return contentDeclarationFilesPath;\n};\n\ntype ListContentDeclarationOptions = {};\n\nexport const listContentDeclaration = (\n _options: ListContentDeclarationOptions\n) => {\n const contentDeclarationFilesPath = getContentDeclaration();\n\n logger(`Content declaration files: ${contentDeclarationFilesPath}`);\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,cAAc;AACzC,OAAO,QAAQ;AAMR,MAAM,wBAAwB,CACnC,YACa;AACb,QAAM;AAAA,IACJ,SAAS,EAAE,4BAA4B;AAAA,EACzC,IAAI,iBAAiB;AAErB,QAAM,8BAAwC,GAAG;AAAA,IAC/C;AAAA,IACA;AAAA,MACE,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAIO,MAAM,yBAAyB,CACpC,aACG;AACH,QAAM,8BAA8B,sBAAsB;AAE1D,SAAO,8BAA8B,2BAA2B,EAAE;AACpE;","names":[]}
1
+ {"version":3,"sources":["../../src/listContentDeclaration.ts"],"sourcesContent":["import { getConfiguration, logger } from '@intlayer/config';\nimport fg from 'fast-glob';\n\ntype GetContentDeclarationOptions = {\n exclude?: string[];\n};\n\nexport const getContentDeclaration = (\n options?: GetContentDeclarationOptions\n): string[] => {\n const {\n content: { watchedFilesPatternWithPath },\n } = getConfiguration();\n\n const contentDeclarationFilesPath: string[] = fg.sync(\n watchedFilesPatternWithPath,\n {\n ignore: options?.exclude,\n }\n );\n\n return contentDeclarationFilesPath;\n};\n\ntype ListContentDeclarationOptions = {\n logPrefix?: string;\n};\n\nexport const listContentDeclaration = (\n options: ListContentDeclarationOptions\n) => {\n const contentDeclarationFilesPath = getContentDeclaration();\n\n logger(`Content declaration files: ${contentDeclarationFilesPath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":"AAAA,SAAS,kBAAkB,cAAc;AACzC,OAAO,QAAQ;AAMR,MAAM,wBAAwB,CACnC,YACa;AACb,QAAM;AAAA,IACJ,SAAS,EAAE,4BAA4B;AAAA,EACzC,IAAI,iBAAiB;AAErB,QAAM,8BAAwC,GAAG;AAAA,IAC/C;AAAA,IACA;AAAA,MACE,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAMO,MAAM,yBAAyB,CACpC,YACG;AACH,QAAM,8BAA8B,sBAAsB;AAE1D,SAAO,8BAA8B,2BAA2B,IAAI;AAAA,IAClE,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
package/dist/esm/pull.mjs CHANGED
@@ -36,10 +36,19 @@ const pull = async (options) => {
36
36
  );
37
37
  }
38
38
  if (distantDictionariesKeys.length === 0) {
39
- logger("No dictionaries to fetch", { level: "error" });
39
+ logger("No dictionaries to fetch", {
40
+ level: "error",
41
+ config: {
42
+ prefix: options?.logPrefix
43
+ }
44
+ });
40
45
  return;
41
46
  }
42
- logger("Fetching dictionaries:");
47
+ logger("Fetching dictionaries:", {
48
+ config: {
49
+ prefix: options?.logPrefix
50
+ }
51
+ });
43
52
  const dictionariesStatuses = distantDictionariesKeys.map((dictionaryKey, index) => ({
44
53
  dictionaryKey,
45
54
  icon: getStatusIcon("pending"),
@@ -92,11 +101,21 @@ const pull = async (options) => {
92
101
  updateAllStatusLines(dictionariesStatuses);
93
102
  for (const statusObj of dictionariesStatuses) {
94
103
  if (statusObj.errorMessage) {
95
- logger(statusObj.errorMessage, { level: "error" });
104
+ logger(statusObj.errorMessage, {
105
+ level: "error",
106
+ config: {
107
+ prefix: options?.logPrefix
108
+ }
109
+ });
96
110
  }
97
111
  }
98
112
  } catch (error) {
99
- logger(error, { level: "error" });
113
+ logger(error, {
114
+ level: "error",
115
+ config: {
116
+ prefix: options?.logPrefix
117
+ }
118
+ });
100
119
  }
101
120
  };
102
121
  const getStatusIcon = (status) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import * as readline from 'readline';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { writeContentDeclaration } from '@intlayer/editor/server';\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\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 config = getConfiguration();\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\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 logger('No dictionaries to fetch', { level: 'error' });\n return;\n }\n\n logger('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); // Limit the number of concurrent requests\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 { status } = await writeContentDeclaration(\n distantDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\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 logger(statusObj.errorMessage, { level: 'error' });\n }\n }\n } catch (error) {\n logger(error, { level: '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}${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 === '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"],"mappings":"AAAA,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,cAAc;AAEzC,SAAS,+BAA+B;AACxC,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,YAAY;AAMX,MAAM,OAAO,OAAO,YAAyC;AAClE,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,QAAI,CAAC,YAAY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WAAW,UAAU,WAAW,SAAS;AACvC,iBAAa;AACb,eAAW;AAAA,EACb,WACE,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB;AACA,iBAAa;AACb,eAAW;AAAA,EACb,WACE,UAAU,WAAW,wBACrB,UAAU,WAAW,8BACrB;AACA,iBAAa;AACb,eAAW;AAAA,EACb,OAAO;AACL,iBAAa;AACb,eAAW;AAAA,EACb;AAEA,SAAO,KAAK,UAAU,aAAa,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAG,UAAU,MAAM,GAAG,SAAS,IAAI,QAAQ;AAClH;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,YAAY;AAEnC,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/pull.ts"],"sourcesContent":["import * as readline from 'readline';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { writeContentDeclaration } from '@intlayer/editor/server';\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\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 config = getConfiguration();\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\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 logger('No dictionaries to fetch', {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n return;\n }\n\n logger('Fetching dictionaries:', {\n config: {\n prefix: options?.logPrefix,\n },\n });\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); // Limit the number of concurrent requests\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 { status } = await writeContentDeclaration(\n distantDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\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 logger(statusObj.errorMessage, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n }\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\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}${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 === '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"],"mappings":"AAAA,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,cAAc;AAEzC,SAAS,+BAA+B;AACxC,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,OA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H;AACF;AAEA,MAAM,gBAAgB,CAAC,WAA2B;AAChD,QAAM,cAAsC;AAAA,IAC1C,SAAS;AAAA,IACT,UAAU;AAAA;AAAA,IACV,cAAc;AAAA,IACd,SAAS;AAAA,IACT,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AACA,SAAO,YAAY,MAAM,KAAK;AAChC;AAEA,MAAM,gBAAgB,CAAC,cAA0C;AAC/D,MAAI,OAAO,cAAc,UAAU,MAAM;AACzC,MAAI,aAAa;AACjB,MAAI,WAAW;AAEf,MAAI,UAAU,WAAW,YAAY;AAEnC,WAAO,cAAc,UAAU,oBAAqB,cAAc,MAAM;AACxE,iBAAa;AACb,eAAW;AAAA,EACb,WAAW,UAAU,WAAW,SAAS;AACvC,iBAAa;AACb,eAAW;AAAA,EACb,WACE,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB;AACA,iBAAa;AACb,eAAW;AAAA,EACb,WACE,UAAU,WAAW,wBACrB,UAAU,WAAW,8BACrB;AACA,iBAAa;AACb,eAAW;AAAA,EACb,OAAO;AACL,iBAAa;AACb,eAAW;AAAA,EACb;AAEA,SAAO,KAAK,UAAU,aAAa,IAAI,SAAS,IAAI,UAAU,GAAG,IAAI,GAAG,UAAU,MAAM,GAAG,SAAS,IAAI,QAAQ;AAClH;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,YAAY;AAEnC,gBAAU,qBACP,UAAU,oBAAqB,KAAK,cAAc;AAAA,IACvD;AAGA,YAAQ,OAAO,MAAM,cAAc,SAAS,IAAI,IAAI;AAAA,EACtD;AACF;","names":[]}
package/dist/esm/push.mjs CHANGED
@@ -35,7 +35,12 @@ const push = async (options) => {
35
35
  `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(
36
36
  ", "
37
37
  )} and have been ignored.`,
38
- { level: "error" }
38
+ {
39
+ level: "error",
40
+ config: {
41
+ prefix: options?.logPrefix
42
+ }
43
+ }
39
44
  );
40
45
  }
41
46
  dictionaries = dictionaries.filter(
@@ -43,10 +48,19 @@ const push = async (options) => {
43
48
  );
44
49
  }
45
50
  if (dictionaries.length === 0) {
46
- logger("No local dictionaries found", { level: "error" });
51
+ logger("No local dictionaries found", {
52
+ level: "error",
53
+ config: {
54
+ prefix: options?.logPrefix
55
+ }
56
+ });
47
57
  return;
48
58
  }
49
- logger("Pushing dictionaries:");
59
+ logger("Pushing dictionaries:", {
60
+ config: {
61
+ prefix: options?.logPrefix
62
+ }
63
+ });
50
64
  const dictionariesStatuses = dictionaries.map(
51
65
  (dictionary, index) => ({
52
66
  dictionary,
@@ -100,7 +114,12 @@ const push = async (options) => {
100
114
  updateAllStatusLines(dictionariesStatuses);
101
115
  for (const statusObj of dictionariesStatuses) {
102
116
  if (statusObj.errorMessage) {
103
- logger(statusObj.errorMessage, { level: "error" });
117
+ logger(statusObj.errorMessage, {
118
+ level: "error",
119
+ config: {
120
+ prefix: options?.logPrefix
121
+ }
122
+ });
104
123
  }
105
124
  }
106
125
  const deleteOption = options?.deleteLocaleDictionary;
@@ -111,18 +130,23 @@ const push = async (options) => {
111
130
  );
112
131
  }
113
132
  if (deleteOption) {
114
- await deleteLocalDictionaries(successfullyPushedDictionaries);
133
+ await deleteLocalDictionaries(successfullyPushedDictionaries, options);
115
134
  } else if (keepOption) {
116
135
  } else {
117
136
  const answer = await askUser(
118
137
  "Do you want to delete the local dictionaries that were successfully pushed? (yes/no): "
119
138
  );
120
139
  if (answer.toLowerCase() === "yes" || answer.toLowerCase() === "y") {
121
- await deleteLocalDictionaries(successfullyPushedDictionaries);
140
+ await deleteLocalDictionaries(successfullyPushedDictionaries, options);
122
141
  }
123
142
  }
124
143
  } catch (error) {
125
- logger(error, { level: "error" });
144
+ logger(error, {
145
+ level: "error",
146
+ config: {
147
+ prefix: options?.logPrefix
148
+ }
149
+ });
126
150
  }
127
151
  };
128
152
  const askUser = (question) => {
@@ -137,14 +161,17 @@ const askUser = (question) => {
137
161
  });
138
162
  });
139
163
  };
140
- const deleteLocalDictionaries = async (dictionariesToDelete) => {
164
+ const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
141
165
  const { baseDir } = getConfiguration().content;
142
166
  const filePathsSet = /* @__PURE__ */ new Set();
143
167
  for (const dictionary of dictionariesToDelete) {
144
168
  const { filePath } = dictionary;
145
169
  if (!filePath) {
146
170
  logger(`Dictionary ${dictionary.key} does not have a file path`, {
147
- level: "error"
171
+ level: "error",
172
+ config: {
173
+ prefix: options?.logPrefix
174
+ }
148
175
  });
149
176
  continue;
150
177
  }
@@ -156,15 +183,30 @@ const deleteLocalDictionaries = async (dictionariesToDelete) => {
156
183
  const stats = await fsPromises.lstat(filePath);
157
184
  if (stats.isFile()) {
158
185
  await fsPromises.unlink(filePath);
159
- logger(`Deleted file ${relativePath}`);
186
+ logger(`Deleted file ${relativePath}`, {
187
+ config: {
188
+ prefix: options?.logPrefix
189
+ }
190
+ });
160
191
  } else if (stats.isDirectory()) {
161
- logger(`Path is a directory ${relativePath}, skipping.`);
192
+ logger(`Path is a directory ${relativePath}, skipping.`, {
193
+ config: {
194
+ prefix: options?.logPrefix
195
+ }
196
+ });
162
197
  } else {
163
- logger(`Unknown file type for ${relativePath}, skipping.`);
198
+ logger(`Unknown file type for ${relativePath}, skipping.`, {
199
+ config: {
200
+ prefix: options?.logPrefix
201
+ }
202
+ });
164
203
  }
165
204
  } catch (err) {
166
205
  logger(`Error deleting ${relativePath}: ${err}`, {
167
- level: "error"
206
+ level: "error",
207
+ config: {
208
+ prefix: options?.logPrefix
209
+ }
168
210
  });
169
211
  }
170
212
  }
@@ -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 { getConfiguration, logger } from '@intlayer/config';\nimport { 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};\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();\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 { level: 'error' }\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', { level: 'error' });\n return;\n }\n\n logger('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 logger(statusObj.errorMessage, { level: 'error' });\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);\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 logger(error, { level: '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 logger(`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 logger(`Deleted file ${relativePath}`);\n } else if (stats.isDirectory()) {\n logger(`Path is a directory ${relativePath}, skipping.`);\n } else {\n logger(`Unknown file type for ${relativePath}, skipping.`);\n }\n } catch (err) {\n logger(`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,YAAY,gBAAgB;AAC5B,SAAS,gBAAgB;AACzB,YAAY,cAAc;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB,cAAc;AAEzC,OAAO,wBAAwB;AAC/B,OAAO,YAAY;AAkBnB,MAAM,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAA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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 * as fsPromises from 'fs/promises';\nimport { relative } from 'path';\nimport * as readline from 'readline';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } from '@intlayer/config';\nimport { 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};\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();\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,SAAS,kBAAkB,cAAc;AAEzC,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,OAAO,OAAO,YAAyC;AAClE,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cAAc,eAAe,QAAW,MAAM;AACpD,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAElD,QAAI,eAA6B,OAAO,OAAO,kBAAkB;AACjE,UAAM,2BAAqC,OAAO,KAAK,kBAAkB;AAEzE,QAAI,SAAS,cAAc;AAEzB,YAAM,iCAAiC,QAAQ,aAAa;AAAA,QAC1D,CAAC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BAAsB;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,41 @@
1
+ import { getIntlayerAPI } from "@intlayer/api";
2
+ import { getConfiguration, logger } from "@intlayer/config";
3
+ const pushConfig = async (options) => {
4
+ const config = getConfiguration();
5
+ const { clientId, clientSecret } = config.editor;
6
+ if (!clientId || !clientSecret) {
7
+ logger(
8
+ "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.",
9
+ {
10
+ level: "error",
11
+ config: {
12
+ prefix: options?.logPrefix
13
+ }
14
+ }
15
+ );
16
+ return;
17
+ }
18
+ const intlayerAPI = getIntlayerAPI(void 0, config);
19
+ const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
20
+ const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
21
+ const getDictionariesKeysResult = await intlayerAPI.project.pushProjectConfiguration(config, {
22
+ headers: { Authorization: `Bearer ${oAuth2AccessToken}` }
23
+ });
24
+ if (!getDictionariesKeysResult.data) {
25
+ throw new Error("Error pushing project configuration");
26
+ }
27
+ logger("Project configuration pushed successfully", {
28
+ config: {
29
+ prefix: options?.logPrefix
30
+ }
31
+ });
32
+ logger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {
33
+ config: {
34
+ prefix: options?.logPrefix
35
+ }
36
+ });
37
+ };
38
+ export {
39
+ pushConfig
40
+ };
41
+ //# sourceMappingURL=pushConfig.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport { getConfiguration, logger } from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n environment?: string;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration();\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,SAAS,kBAAkB,cAAc;AAOlC,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,SAAS,iBAAiB;AAEhC,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":[]}
@@ -6,6 +6,7 @@ type AuditOptions = {
6
6
  openAiApiKey?: string;
7
7
  excludedGlobs?: string[];
8
8
  headers?: Record<string, string>;
9
+ logPrefix?: string;
9
10
  };
10
11
  /**
11
12
  * Audits a content declaration file by constructing a prompt for ChatGPT.
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/audit.ts"],"names":[],"mappings":"AAUA,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAIF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,aAAoB,MAAM,YAAY,YAAY,kBAsCvE,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,YAAmB,YAAY,kBAgChD,CAAC"}
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/audit.ts"],"names":[],"mappings":"AAUA,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAIF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,aAAoB,MAAM,YAAY,YAAY,kBAuDvE,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,YAAmB,YAAY,kBAgChD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OA+DzB,CAAC"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OA2FzB,CAAC"}
@@ -1,4 +1,6 @@
1
- type ConfigOptions = {};
2
- export declare const getConfig: (_options?: ConfigOptions) => void;
1
+ type ConfigOptions = {
2
+ logPrefix?: string;
3
+ };
4
+ export declare const getConfig: (options?: ConfigOptions) => void;
3
5
  export {};
4
6
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG,EAAE,CAAC;AAExB,eAAO,MAAM,SAAS,cAAe,aAAa,SAIjD,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,KAAK,aAAa,GAAG;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,SAAS,aAAc,aAAa,SAQhD,CAAC"}
@@ -4,4 +4,5 @@ export * from './pull';
4
4
  export * from './push';
5
5
  export * from './listContentDeclaration';
6
6
  export * from './audit';
7
+ export * from './pushConfig';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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;AACvB,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC"}
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;AACvB,cAAc,0BAA0B,CAAC;AACzC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -2,7 +2,9 @@ type GetContentDeclarationOptions = {
2
2
  exclude?: string[];
3
3
  };
4
4
  export declare const getContentDeclaration: (options?: GetContentDeclarationOptions) => string[];
5
- type ListContentDeclarationOptions = {};
6
- export declare const listContentDeclaration: (_options: ListContentDeclarationOptions) => void;
5
+ type ListContentDeclarationOptions = {
6
+ logPrefix?: string;
7
+ };
8
+ export declare const listContentDeclaration: (options: ListContentDeclarationOptions) => void;
7
9
  export {};
8
10
  //# sourceMappingURL=listContentDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listContentDeclaration.d.ts","sourceRoot":"","sources":["../../src/listContentDeclaration.ts"],"names":[],"mappings":"AAGA,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,qBAAqB,aACtB,4BAA4B,KACrC,MAAM,EAaR,CAAC;AAEF,KAAK,6BAA6B,GAAG,EAAE,CAAC;AAExC,eAAO,MAAM,sBAAsB,aACvB,6BAA6B,SAKxC,CAAC"}
1
+ {"version":3,"file":"listContentDeclaration.d.ts","sourceRoot":"","sources":["../../src/listContentDeclaration.ts"],"names":[],"mappings":"AAGA,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,qBAAqB,aACtB,4BAA4B,KACrC,MAAM,EAaR,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,sBAAsB,YACxB,6BAA6B,SASvC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/pull.ts"],"names":[],"mappings":"AAOA,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAgCF;;;GAGG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAiI9D,CAAC"}
1
+ {"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/pull.ts"],"names":[],"mappings":"AAOA,KAAK,WAAW,GAAG;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAgCF;;;GAGG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAoJ9D,CAAC"}
@@ -2,6 +2,7 @@ type PushOptions = {
2
2
  deleteLocaleDictionary?: boolean;
3
3
  keepLocaleDictionary?: boolean;
4
4
  dictionaries?: string[];
5
+ logPrefix?: string;
5
6
  };
6
7
  /**
7
8
  * Get all locale dictionaries and push them simultaneously.
@@ -1 +1 @@
1
- {"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/push.ts"],"names":[],"mappings":"AASA,KAAK,WAAW,GAAG;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAqBF;;GAEG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAwJ9D,CAAC"}
1
+ {"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/push.ts"],"names":[],"mappings":"AASA,KAAK,WAAW,GAAG;IACjB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAqBF;;GAEG;AACH,eAAO,MAAM,IAAI,aAAoB,WAAW,KAAG,OAAO,CAAC,IAAI,CAgL9D,CAAC"}
@@ -0,0 +1,7 @@
1
+ type PushOptions = {
2
+ logPrefix?: string;
3
+ environment?: string;
4
+ };
5
+ export declare const pushConfig: (options?: PushOptions) => Promise<void>;
6
+ export {};
7
+ //# sourceMappingURL=pushConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pushConfig.d.ts","sourceRoot":"","sources":["../../src/pushConfig.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,UAAU,aAAoB,WAAW,kBA6CrD,CAAC"}