@intlayer/cli 5.4.1 → 5.5.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/build.cjs +1 -1
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +222 -19
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +3 -6
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/fill.cjs +360 -0
- package/dist/cjs/fill.cjs.map +1 -0
- package/dist/cjs/index.cjs +6 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listContentDeclaration.cjs +3 -7
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/pull.cjs +3 -3
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push.cjs +24 -54
- package/dist/cjs/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +1 -1
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/esm/build.mjs +1 -1
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +211 -18
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +4 -8
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/fill.mjs +338 -0
- package/dist/esm/fill.mjs.map +1 -0
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listContentDeclaration.mjs +5 -9
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/pull.mjs +5 -5
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push.mjs +26 -56
- package/dist/esm/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +1 -1
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/types/build.d.ts +2 -1
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +2 -2
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/fill.d.ts +27 -0
- package/dist/types/fill.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listContentDeclaration.d.ts +4 -3
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/pull.d.ts +2 -1
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push.d.ts +4 -2
- package/dist/types/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +2 -1
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/package.json +12 -11
- package/dist/cjs/audit.cjs +0 -126
- package/dist/cjs/audit.cjs.map +0 -1
- package/dist/esm/audit.mjs +0 -94
- package/dist/esm/audit.mjs.map +0 -1
- package/dist/types/audit.d.ts +0 -38
- package/dist/types/audit.d.ts.map +0 -1
package/dist/esm/audit.mjs
DELETED
|
@@ -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
|
package/dist/esm/audit.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/audit.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { getIntlayerAPI } from '@intlayer/api';\nimport {\n getConfiguration,\n GetConfigurationOptions,\n logger,\n} from '@intlayer/config';\nimport pLimit from 'p-limit';\nimport { getContentDeclaration } from './listContentDeclaration';\n\n// Depending on your implementation, you may need the OpenAI API client.\n// For instance, you can use `openai` npm package (https://www.npmjs.com/package/openai).\n\ntype AuditOptions = {\n files?: string[];\n model?: string;\n customPrompt?: string;\n asyncLimit?: number;\n openAiApiKey?: string;\n excludedGlobs?: string[];\n headers?: Record<string, string>;\n logPrefix?: string;\n} & GetConfigurationOptions;\n\nconst projectPath = process.cwd();\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditFile = async (filePath: string, options?: AuditOptions) => {\n try {\n const { defaultLocale, locales } = getConfiguration().internationalization;\n\n const relativePath = relative(projectPath, filePath);\n logger(`Auditing file: ${relativePath}`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n // Read the file's content.\n const fileContent = readFileSync(filePath, 'utf-8');\n\n // Example of how you might request a completion from ChatGPT:\n const auditFileResult = await getIntlayerAPI().ai.auditContentDeclaration(\n {\n fileContent,\n filePath,\n locales,\n defaultLocale,\n model: options?.model,\n openAiApiKey: options?.openAiApiKey,\n customPrompt: options?.customPrompt,\n },\n {\n headers: options?.headers,\n }\n );\n\n if (!auditFileResult.data) {\n throw new Error('Audit failed');\n }\n\n writeFileSync(filePath, auditFileResult.data.fileContent);\n\n logger(`File ${relativePath} updated`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n logger(`${auditFileResult.data.tokenUsed} tokens used in the request`, {\n config: {\n prefix: options?.logPrefix,\n },\n });\n } catch (error) {\n logger(error, {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n });\n }\n};\n\nconst getAbsolutePath = (filePath: string): string => {\n if (filePath.startsWith('.')) {\n const absolutePath = join(process.cwd(), filePath);\n\n return absolutePath;\n }\n return filePath;\n};\n\n/**\n * Audits the content declaration files by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const audit = async (options: AuditOptions) => {\n const { clientId, clientSecret } = getConfiguration(options).editor;\n let headers: Record<string, string> = {};\n\n if (clientId && clientSecret) {\n const oAuth2TokenResult =\n await getIntlayerAPI().auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n headers = { Authorization: `Bearer ${oAuth2AccessToken}` };\n } else if (!options?.openAiApiKey) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project. You can also provide your own OpenAI API key to audit the content declaration files. For that you need to provide the --openAiApiKey option.'\n );\n }\n\n let contentDeclarationFilesList = options?.files?.map(getAbsolutePath);\n\n if (!contentDeclarationFilesList) {\n // Retrieve all content declaration file paths using a helper function.\n const contentDeclarationFilesPath = getContentDeclaration({\n exclude: options?.excludedGlobs,\n });\n\n contentDeclarationFilesList = contentDeclarationFilesPath;\n }\n\n const limit = pLimit(options?.asyncLimit ? Number(options?.asyncLimit) : 5); // Limit the number of concurrent requests\n const pushPromises = contentDeclarationFilesList.map((filePath) =>\n limit(() => auditFile(filePath, { ...options, headers }))\n );\n await Promise.all(pushPromises);\n};\n"],"mappings":"AAAA,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,OA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AAA,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":[]}
|
package/dist/types/audit.d.ts
DELETED
|
@@ -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"}
|