@intlayer/cli 5.2.3 → 5.2.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.
@@ -49,7 +49,7 @@ const auditFile = async (filePath, options) => {
49
49
  }
50
50
  });
51
51
  const fileContent = (0, import_fs.readFileSync)(filePath, "utf-8");
52
- const auditFileResult = await import_api.intlayerAPI.ai.auditContentDeclaration(
52
+ const auditFileResult = await (0, import_api.getIntlayerAPI)().ai.auditContentDeclaration(
53
53
  {
54
54
  fileContent,
55
55
  filePath,
@@ -97,7 +97,7 @@ const audit = async (options) => {
97
97
  const { clientId, clientSecret } = (0, import_config.getConfiguration)(options).editor;
98
98
  let headers = {};
99
99
  if (clientId && clientSecret) {
100
- const oAuth2TokenResult = await import_api.intlayerAPI.auth.getOAuth2AccessToken();
100
+ const oAuth2TokenResult = await (0, import_api.getIntlayerAPI)().auth.getOAuth2AccessToken();
101
101
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
102
102
  headers = { Authorization: `Bearer ${oAuth2AccessToken}` };
103
103
  } else if (!options?.openAiApiKey) {
@@ -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 {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await 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(options).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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4C;AAC5C,kBAA+B;AAC/B,iBAA4B;AAC5B,oBAIO;AACP,qBAAmB;AACnB,oCAAsC;AAgBtC,MAAM,cAAc,QAAQ,IAAI;AAczB,MAAM,YAAY,OAAO,UAAkB,YAA2B;AAC3E,MAAI;AACF,UAAM,EAAE,eAAe,QAAQ,QAAI,gCAAiB,EAAE;AAEtD,UAAM,mBAAe,sBAAS,aAAa,QAAQ;AACnD,8BAAO,kBAAkB,YAAY,IAAI;AAAA,MACvC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAGD,UAAM,kBAAc,wBAAa,UAAU,OAAO;AAGlD,UAAM,kBAAkB,MAAM,uBAAY,GAAG;AAAA,MAC3C;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,SAAS;AAAA,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AS,SAAS;AAAA,IACpB,CAAC;AAED,kCAA8B;AAAA,EAChC;AAEA,QAAM,YAAQ,eAAAA,SAAO,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":["pLimit"]}
1
+ {"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4C;AAC5C,kBAA+B;AAC/B,iBAA+B;AAC/B,oBAIO;AACP,qBAAmB;AACnB,oCAAsC;AAgBtC,MAAM,cAAc,QAAQ,IAAI;AAczB,MAAM,YAAY,OAAO,UAAkB,YAA2B;AAC3E,MAAI;AACF,UAAM,EAAE,eAAe,QAAQ,QAAI,gCAAiB,EAAE;AAEtD,UAAM,mBAAe,sBAAS,aAAa,QAAQ;AACnD,8BAAO,kBAAkB,YAAY,IAAI;AAAA,MACvC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAGD,UAAM,kBAAc,wBAAa,UAAU,OAAO;AAGlD,UAAM,kBAAkB,UAAM,2BAAe,EAAE,GAAG;AAAA,MAChD;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,SAAS;AAAA,QAChB,cAAc,SAAS;AAAA,QACvB,cAAc,SAAS;AAAA,MACzB;AAAA,MACA;AAAA,QACE,SAAS,SAAS;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,CAAC,gBAAgB,MAAM;AACzB,YAAM,IAAI,MAAM,cAAc;AAAA,IAChC;AAEA,iCAAc,UAAU,gBAAgB,KAAK,WAAW;AAExD,8BAAO,QAAQ,YAAY,YAAY;AAAA,MACrC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAED,8BAAO,GAAG,gBAAgB,KAAK,SAAS,+BAA+B;AAAA,MAC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{ intlayerAPI } from "@intlayer/api";
3
+ import { getIntlayerAPI } from "@intlayer/api";
4
4
  import {
5
5
  getConfiguration,
6
6
  logger
@@ -18,7 +18,7 @@ const auditFile = async (filePath, options) => {
18
18
  }
19
19
  });
20
20
  const fileContent = readFileSync(filePath, "utf-8");
21
- const auditFileResult = await intlayerAPI.ai.auditContentDeclaration(
21
+ const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(
22
22
  {
23
23
  fileContent,
24
24
  filePath,
@@ -66,7 +66,7 @@ const audit = async (options) => {
66
66
  const { clientId, clientSecret } = getConfiguration(options).editor;
67
67
  let headers = {};
68
68
  if (clientId && clientSecret) {
69
- const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();
69
+ const oAuth2TokenResult = await getIntlayerAPI().auth.getOAuth2AccessToken();
70
70
  const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
71
71
  headers = { Authorization: `Bearer ${oAuth2AccessToken}` };
72
72
  } else if (!options?.openAiApiKey) {
@@ -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 {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await 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(options).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;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,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,SA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AAa,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 { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":"AAAA,SAAS,cAAc,qBAAqB;AAC5C,SAAS,MAAM,gBAAgB;AAC/B,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,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,eAAe,EAAE,GAAG;AAAA,MAChD;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,SAAS;AAAA,QAChB,cAAc,SAAS;AAAA,QACvB,cAAc,SAAS;AAAA,MACzB;AAAA,MACA;AAAA,QACE,SAAS,SAAS;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,CAAC,gBAAgB,MAAM;AACzB,YAAM,IAAI,MAAM,cAAc;AAAA,IAChC;AAEA,kBAAc,UAAU,gBAAgB,KAAK,WAAW;AAExD,WAAO,QAAQ,YAAY,YAAY;AAAA,MACrC,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAED,WAAO,GAAG,gBAAgB,KAAK,SAAS,+BAA+B;AAAA,MACrE,QAAQ;AAAA,QACN,QAAQ,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,WAAO,OAAO;AAAA,M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jB,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,GAAG,uBAAuB,CAAC;AAI5B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,GAAU,UAAU,MAAM,EAAE,UAAU,YAAY,kBAuDvE,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAAU,SAAS,YAAY,kBAgChD,CAAC"}
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/audit.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,uBAAuB,EAExB,MAAM,kBAAkB,CAAC;AAO1B,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,GAAG,uBAAuB,CAAC;AAI5B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,GAAU,UAAU,MAAM,EAAE,UAAU,YAAY,kBAuDvE,CAAC;AAWF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAAU,SAAS,YAAY,kBAiChD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/cli",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
4
4
  "private": false,
5
5
  "description": "Provides uniform command-line interface scripts for Intlayer, used in packages like intlayer-cli and intlayer.",
6
6
  "keywords": [
@@ -51,11 +51,11 @@
51
51
  "commander": "^13.0.0",
52
52
  "fast-glob": "^3.3.3",
53
53
  "p-limit": "^3.1.0",
54
- "@intlayer/config": "5.2.3",
55
- "@intlayer/chokidar": "5.2.3",
56
- "@intlayer/dictionaries-entry": "5.2.3",
57
- "@intlayer/editor": "5.2.3",
58
- "@intlayer/api": "5.2.3"
54
+ "@intlayer/api": "5.2.5",
55
+ "@intlayer/chokidar": "5.2.5",
56
+ "@intlayer/config": "5.2.5",
57
+ "@intlayer/dictionaries-entry": "5.2.5",
58
+ "@intlayer/editor": "5.2.5"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/node": "^22.10.6",
@@ -67,18 +67,18 @@
67
67
  "tsc-alias": "^1.8.10",
68
68
  "tsup": "^8.3.5",
69
69
  "typescript": "^5.7.3",
70
- "@intlayer/core": "5.2.3",
71
- "@utils/ts-config": "1.0.4",
70
+ "@intlayer/core": "5.2.5",
72
71
  "@utils/eslint-config": "1.0.4",
73
- "@utils/tsup-config": "1.0.4",
74
- "@utils/ts-config-types": "1.0.4"
72
+ "@utils/ts-config": "1.0.4",
73
+ "@utils/ts-config-types": "1.0.4",
74
+ "@utils/tsup-config": "1.0.4"
75
75
  },
76
76
  "peerDependencies": {
77
- "@intlayer/api": "5.2.3",
78
- "@intlayer/chokidar": "5.2.3",
79
- "@intlayer/config": "5.2.3",
80
- "@intlayer/dictionaries-entry": "5.2.3",
81
- "@intlayer/editor": "5.2.3"
77
+ "@intlayer/api": "5.2.5",
78
+ "@intlayer/chokidar": "5.2.5",
79
+ "@intlayer/config": "5.2.5",
80
+ "@intlayer/dictionaries-entry": "5.2.5",
81
+ "@intlayer/editor": "5.2.5"
82
82
  },
83
83
  "bug": {
84
84
  "url": "https://github.com/aymericzip/intlayer/issues"