@intlayer/cli 5.4.2 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/build.cjs +1 -1
  2. package/dist/cjs/build.cjs.map +1 -1
  3. package/dist/cjs/cli.cjs +242 -20
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/config.cjs +3 -6
  6. package/dist/cjs/config.cjs.map +1 -1
  7. package/dist/cjs/fill.cjs +362 -0
  8. package/dist/cjs/fill.cjs.map +1 -0
  9. package/dist/cjs/index.cjs +6 -6
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/cjs/listContentDeclaration.cjs +5 -7
  12. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  13. package/dist/cjs/pull.cjs +11 -23
  14. package/dist/cjs/pull.cjs.map +1 -1
  15. package/dist/cjs/push.cjs +29 -59
  16. package/dist/cjs/push.cjs.map +1 -1
  17. package/dist/cjs/pushConfig.cjs +5 -4
  18. package/dist/cjs/pushConfig.cjs.map +1 -1
  19. package/dist/esm/build.mjs +1 -1
  20. package/dist/esm/build.mjs.map +1 -1
  21. package/dist/esm/cli.mjs +230 -19
  22. package/dist/esm/cli.mjs.map +1 -1
  23. package/dist/esm/config.mjs +5 -8
  24. package/dist/esm/config.mjs.map +1 -1
  25. package/dist/esm/fill.mjs +340 -0
  26. package/dist/esm/fill.mjs.map +1 -0
  27. package/dist/esm/index.mjs +3 -3
  28. package/dist/esm/index.mjs.map +1 -1
  29. package/dist/esm/listContentDeclaration.mjs +7 -9
  30. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  31. package/dist/esm/pull.mjs +14 -26
  32. package/dist/esm/pull.mjs.map +1 -1
  33. package/dist/esm/push.mjs +31 -61
  34. package/dist/esm/push.mjs.map +1 -1
  35. package/dist/esm/pushConfig.mjs +7 -6
  36. package/dist/esm/pushConfig.mjs.map +1 -1
  37. package/dist/types/build.d.ts +2 -1
  38. package/dist/types/build.d.ts.map +1 -1
  39. package/dist/types/cli.d.ts +10 -0
  40. package/dist/types/cli.d.ts.map +1 -1
  41. package/dist/types/config.d.ts +2 -2
  42. package/dist/types/config.d.ts.map +1 -1
  43. package/dist/types/fill.d.ts +27 -0
  44. package/dist/types/fill.d.ts.map +1 -0
  45. package/dist/types/index.d.ts +3 -3
  46. package/dist/types/index.d.ts.map +1 -1
  47. package/dist/types/listContentDeclaration.d.ts +4 -3
  48. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  49. package/dist/types/pull.d.ts +2 -2
  50. package/dist/types/pull.d.ts.map +1 -1
  51. package/dist/types/push.d.ts +4 -2
  52. package/dist/types/push.d.ts.map +1 -1
  53. package/dist/types/pushConfig.d.ts +2 -1
  54. package/dist/types/pushConfig.d.ts.map +1 -1
  55. package/package.json +13 -12
  56. package/dist/cjs/audit.cjs +0 -126
  57. package/dist/cjs/audit.cjs.map +0 -1
  58. package/dist/esm/audit.mjs +0 -94
  59. package/dist/esm/audit.mjs.map +0 -1
  60. package/dist/types/audit.d.ts +0 -38
  61. package/dist/types/audit.d.ts.map +0 -1
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var audit_exports = {};
30
- __export(audit_exports, {
31
- audit: () => audit,
32
- auditFile: () => auditFile
33
- });
34
- module.exports = __toCommonJS(audit_exports);
35
- var import_fs = require("fs");
36
- var import_path = require("path");
37
- var import_api = require("@intlayer/api");
38
- var import_config = require("@intlayer/config");
39
- var import_p_limit = __toESM(require("p-limit"));
40
- var import_listContentDeclaration = require('./listContentDeclaration.cjs');
41
- const projectPath = process.cwd();
42
- const auditFile = async (filePath, options) => {
43
- try {
44
- const { defaultLocale, locales } = (0, import_config.getConfiguration)().internationalization;
45
- const relativePath = (0, import_path.relative)(projectPath, filePath);
46
- (0, import_config.logger)(`Auditing file: ${relativePath}`, {
47
- config: {
48
- prefix: options?.logPrefix
49
- }
50
- });
51
- const fileContent = (0, import_fs.readFileSync)(filePath, "utf-8");
52
- const auditFileResult = await (0, import_api.getIntlayerAPI)().ai.auditContentDeclaration(
53
- {
54
- fileContent,
55
- filePath,
56
- locales,
57
- defaultLocale,
58
- model: options?.model,
59
- openAiApiKey: options?.openAiApiKey,
60
- customPrompt: options?.customPrompt
61
- },
62
- {
63
- headers: options?.headers
64
- }
65
- );
66
- if (!auditFileResult.data) {
67
- throw new Error("Audit failed");
68
- }
69
- (0, import_fs.writeFileSync)(filePath, auditFileResult.data.fileContent);
70
- (0, import_config.logger)(`File ${relativePath} updated`, {
71
- config: {
72
- prefix: options?.logPrefix
73
- }
74
- });
75
- (0, import_config.logger)(`${auditFileResult.data.tokenUsed} tokens used in the request`, {
76
- config: {
77
- prefix: options?.logPrefix
78
- }
79
- });
80
- } catch (error) {
81
- (0, import_config.logger)(error, {
82
- level: "error",
83
- config: {
84
- prefix: options?.logPrefix
85
- }
86
- });
87
- }
88
- };
89
- const getAbsolutePath = (filePath) => {
90
- if (filePath.startsWith(".")) {
91
- const absolutePath = (0, import_path.join)(process.cwd(), filePath);
92
- return absolutePath;
93
- }
94
- return filePath;
95
- };
96
- const audit = async (options) => {
97
- const { clientId, clientSecret } = (0, import_config.getConfiguration)(options).editor;
98
- let headers = {};
99
- if (clientId && clientSecret) {
100
- const oAuth2TokenResult = await (0, import_api.getIntlayerAPI)().auth.getOAuth2AccessToken();
101
- const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
102
- headers = { Authorization: `Bearer ${oAuth2AccessToken}` };
103
- } else if (!options?.openAiApiKey) {
104
- throw new Error(
105
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option."
106
- );
107
- }
108
- let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);
109
- if (!contentDeclarationFilesList) {
110
- const contentDeclarationFilesPath = (0, import_listContentDeclaration.getContentDeclaration)({
111
- exclude: options?.excludedGlobs
112
- });
113
- contentDeclarationFilesList = contentDeclarationFilesPath;
114
- }
115
- const limit = (0, import_p_limit.default)(options?.asyncLimit ? Number(options?.asyncLimit) : 5);
116
- const pushPromises = contentDeclarationFilesList.map(
117
- (filePath) => limit(() => auditFile(filePath, { ...options, headers }))
118
- );
119
- await Promise.all(pushPromises);
120
- };
121
- // Annotate the CommonJS export names for ESM import in node:
122
- 0 && (module.exports = {
123
- audit,
124
- auditFile
125
- });
126
- //# sourceMappingURL=audit.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA4C;AAC5C,kBAA+B;AAC/B,iBAA+B;AAC/B,oBAIO;AACP,qBAAmB;AACnB,oCAAsC;AAgBtC,MAAM,cAAc,QAAQ,IAAI;AAczB,MAAM,YAAY,OAAO,UA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,EAAE;AAC7D,MAAI,UAAkC,CAAC;AAEvC,MAAI,YAAY,cAAc;AAC5B,UAAM,oBACJ,UAAM,2BAAe,EAAE,KAAK,qBAAqB;AAEnD,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,kCAA8B,qDAAsB;AAAA,MACxD,SAAS,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,94 +0,0 @@
1
- import { readFileSync, writeFileSync } from "fs";
2
- import { join, relative } from "path";
3
- import { getIntlayerAPI } from "@intlayer/api";
4
- import {
5
- getConfiguration,
6
- logger
7
- } from "@intlayer/config";
8
- import pLimit from "p-limit";
9
- import { getContentDeclaration } from "./listContentDeclaration.mjs";
10
- const projectPath = process.cwd();
11
- const auditFile = async (filePath, options) => {
12
- try {
13
- const { defaultLocale, locales } = getConfiguration().internationalization;
14
- const relativePath = relative(projectPath, filePath);
15
- logger(`Auditing file: ${relativePath}`, {
16
- config: {
17
- prefix: options?.logPrefix
18
- }
19
- });
20
- const fileContent = readFileSync(filePath, "utf-8");
21
- const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(
22
- {
23
- fileContent,
24
- filePath,
25
- locales,
26
- defaultLocale,
27
- model: options?.model,
28
- openAiApiKey: options?.openAiApiKey,
29
- customPrompt: options?.customPrompt
30
- },
31
- {
32
- headers: options?.headers
33
- }
34
- );
35
- if (!auditFileResult.data) {
36
- throw new Error("Audit failed");
37
- }
38
- writeFileSync(filePath, auditFileResult.data.fileContent);
39
- logger(`File ${relativePath} updated`, {
40
- config: {
41
- prefix: options?.logPrefix
42
- }
43
- });
44
- logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {
45
- config: {
46
- prefix: options?.logPrefix
47
- }
48
- });
49
- } catch (error) {
50
- logger(error, {
51
- level: "error",
52
- config: {
53
- prefix: options?.logPrefix
54
- }
55
- });
56
- }
57
- };
58
- const getAbsolutePath = (filePath) => {
59
- if (filePath.startsWith(".")) {
60
- const absolutePath = join(process.cwd(), filePath);
61
- return absolutePath;
62
- }
63
- return filePath;
64
- };
65
- const audit = async (options) => {
66
- const { clientId, clientSecret } = getConfiguration(options).editor;
67
- let headers = {};
68
- if (clientId && clientSecret) {
69
- const oAuth2TokenResult = await getIntlayerAPI().auth.getOAuth2AccessToken();
70
- const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
71
- headers = { Authorization: `Bearer ${oAuth2AccessToken}` };
72
- } else if (!options?.openAiApiKey) {
73
- throw new Error(
74
- "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."
75
- );
76
- }
77
- let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);
78
- if (!contentDeclarationFilesList) {
79
- const contentDeclarationFilesPath = getContentDeclaration({
80
- exclude: options?.excludedGlobs
81
- });
82
- contentDeclarationFilesList = contentDeclarationFilesPath;
83
- }
84
- const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5);
85
- const pushPromises = contentDeclarationFilesList.map(
86
- (filePath) => limit(() => auditFile(filePath, { ...options, headers }))
87
- );
88
- await Promise.all(pushPromises);
89
- };
90
- export {
91
- audit,
92
- auditFile
93
- };
94
- //# sourceMappingURL=audit.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":"AAAA,SAAS,cAAc,qBAAqB;AAC5C,S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UAAM,eAAe,KAAK,QAAQ,IAAI,GAAG,QAAQ;AAEjD,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAaO,MAAM,QAAQ,OAAO,YAA0B;AACpD,QAAM,EAAE,UAAU,aAAa,IAAI,iBAAiB,OAAO,EAAE;AAC7D,MAAI,UAAkC,CAAC;AAEvC,MAAI,YAAY,cAAc;AAC5B,UAAM,oBACJ,MAAM,eAAe,EAAE,KAAK,qBAAqB;AAEnD,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,38 +0,0 @@
1
- import { GetConfigurationOptions } from '@intlayer/config';
2
- type AuditOptions = {
3
- files?: string[];
4
- model?: string;
5
- customPrompt?: string;
6
- asyncLimit?: number;
7
- openAiApiKey?: string;
8
- excludedGlobs?: string[];
9
- headers?: Record<string, string>;
10
- logPrefix?: string;
11
- } & GetConfigurationOptions;
12
- /**
13
- * Audits a content declaration file by constructing a prompt for ChatGPT.
14
- * The prompt includes details about the project's locales, file paths of content declarations,
15
- * and requests for identifying issues or inconsistencies. It prints the prompt for each file,
16
- * and could be adapted to send requests to the ChatGPT model.
17
- *
18
- * @async
19
- * @function
20
- * @param filePath - The relative or absolute path to the target file.
21
- * @param options - Optional configuration for the audit process.
22
- * @returns This function returns a Promise that resolves once the audit is complete.
23
- */
24
- export declare const auditFile: (filePath: string, options?: AuditOptions) => Promise<void>;
25
- /**
26
- * Audits the content declaration files by constructing a prompt for ChatGPT.
27
- * The prompt includes details about the project's locales, file paths of content declarations,
28
- * and requests for identifying issues or inconsistencies. It prints the prompt for each file,
29
- * and could be adapted to send requests to the ChatGPT model.
30
- *
31
- * @async
32
- * @function
33
- * @param options - Optional configuration for the audit process.
34
- * @returns This function returns a Promise that resolves once the audit is complete.
35
- */
36
- export declare const audit: (options: AuditOptions) => Promise<void>;
37
- export {};
38
- //# sourceMappingURL=audit.d.ts.map
@@ -1 +0,0 @@
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"}