@intlayer/chokidar 7.5.12 → 7.5.14
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/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
- package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/createType/createType.cjs.map +1 -1
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +2 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileMoved.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/init/index.cjs +1 -1
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
- package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -1
- package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
- package/dist/cjs/utils/getFormatFromExtension.cjs +3 -0
- package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
- package/dist/cjs/utils/pLimit.cjs.map +1 -1
- package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -1
- package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -1
- package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
- package/dist/cjs/utils/runOnce.cjs +13 -6
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/bin.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/ps.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -1
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +21 -17
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/index.cjs +2 -0
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +77 -0
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +10 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -1
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
- package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/createType/createType.mjs.map +1 -1
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +2 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileMoved.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/init/index.mjs +1 -1
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/log.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
- package/dist/esm/transformFiles/transformFiles.mjs.map +1 -1
- package/dist/esm/utils/chunkJSON.mjs.map +1 -1
- package/dist/esm/utils/getFormatFromExtension.mjs +3 -0
- package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
- package/dist/esm/utils/pLimit.mjs.map +1 -1
- package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -1
- package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -1
- package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
- package/dist/esm/utils/runOnce.mjs +13 -6
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/utils/runParallel/bin.mjs.map +1 -1
- package/dist/esm/utils/runParallel/index.mjs.map +1 -1
- package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
- package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
- package/dist/esm/utils/runParallel/runTask.mjs.map +1 -1
- package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +21 -17
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/index.mjs +2 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +76 -0
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +11 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -1
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
- package/dist/types/formatDictionary.d.ts +15 -15
- package/dist/types/index.d.ts +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts +2 -2
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts +1 -1
- package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/index.d.ts +2 -1
- package/dist/types/writeContentDeclaration/transformJSONFile.d.ts +7 -0
- package/dist/types/writeContentDeclaration/transformJSONFile.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let ts_morph = require("ts-morph");
|
|
3
|
+
|
|
4
|
+
//#region src/writeContentDeclaration/transformJSONFile.ts
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a value is a plain object (and not null/array)
|
|
7
|
+
*/
|
|
8
|
+
const isPlainObject = (value) => {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Safely formats a key for use in object literals.
|
|
13
|
+
* Always quotes keys to ensure compatibility with standard JSON files.
|
|
14
|
+
*/
|
|
15
|
+
const stringifyKey = (objectKey) => {
|
|
16
|
+
return JSON.stringify(objectKey);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Robustly finds a property in an ObjectLiteralExpression.
|
|
20
|
+
* Handles cases where the property name in the source file is quoted ("key") or unquoted (key).
|
|
21
|
+
*/
|
|
22
|
+
const getMatchingProperty = (node, key) => {
|
|
23
|
+
return node.getProperties().find((prop) => {
|
|
24
|
+
if (ts_morph.Node.isPropertyAssignment(prop)) {
|
|
25
|
+
const propName = prop.getName();
|
|
26
|
+
return propName === key || propName === `"${key}"` || propName === `'${key}'`;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Recursively updates the AST object literal with new data.
|
|
33
|
+
*/
|
|
34
|
+
const updateObjectLiteral = (node, data) => {
|
|
35
|
+
for (const [key, val] of Object.entries(data)) {
|
|
36
|
+
if (val === void 0) continue;
|
|
37
|
+
const stringifiedValue = JSON.stringify(val, null, 2);
|
|
38
|
+
if (stringifiedValue === void 0 && !isPlainObject(val)) continue;
|
|
39
|
+
const existingProp = getMatchingProperty(node, key);
|
|
40
|
+
if (isPlainObject(val)) if (existingProp && ts_morph.Node.isPropertyAssignment(existingProp)) {
|
|
41
|
+
const initializer = existingProp.getInitializer();
|
|
42
|
+
if (ts_morph.Node.isObjectLiteralExpression(initializer)) updateObjectLiteral(initializer, val);
|
|
43
|
+
else existingProp.setInitializer(stringifiedValue);
|
|
44
|
+
} else if (existingProp) existingProp.replaceWithText(`${stringifyKey(key)}: ${stringifiedValue}`);
|
|
45
|
+
else node.addPropertyAssignment({
|
|
46
|
+
name: stringifyKey(key),
|
|
47
|
+
initializer: stringifiedValue
|
|
48
|
+
});
|
|
49
|
+
else if (existingProp && ts_morph.Node.isPropertyAssignment(existingProp)) existingProp.setInitializer(stringifiedValue);
|
|
50
|
+
else if (existingProp) existingProp.replaceWithText(`${stringifyKey(key)}: ${stringifiedValue}`);
|
|
51
|
+
else node.addPropertyAssignment({
|
|
52
|
+
name: stringifyKey(key),
|
|
53
|
+
initializer: stringifiedValue
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const transformJSONFile = (fileContent, dictionary) => {
|
|
58
|
+
const project = new ts_morph.Project({
|
|
59
|
+
useInMemoryFileSystem: true,
|
|
60
|
+
manipulationSettings: {
|
|
61
|
+
indentationText: ts_morph.IndentationText.TwoSpaces,
|
|
62
|
+
quoteKind: ts_morph.QuoteKind.Double
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const dummyFileName = "temp.ts";
|
|
66
|
+
const wrappedContent = `const _config = ${fileContent.trim() || "{}"}`;
|
|
67
|
+
const sourceFile = project.createSourceFile(dummyFileName, wrappedContent);
|
|
68
|
+
const objectLiteral = sourceFile.getVariableDeclaration("_config")?.getInitializerIfKind(ts_morph.SyntaxKind.ObjectLiteralExpression);
|
|
69
|
+
if (!objectLiteral) return JSON.stringify(dictionary, null, 2);
|
|
70
|
+
updateObjectLiteral(objectLiteral, dictionary);
|
|
71
|
+
sourceFile.formatText();
|
|
72
|
+
return objectLiteral.getText();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.transformJSONFile = transformJSONFile;
|
|
77
|
+
//# sourceMappingURL=transformJSONFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformJSONFile.cjs","names":["Node","Project","IndentationText","QuoteKind","SyntaxKind"],"sources":["../../../src/writeContentDeclaration/transformJSONFile.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport {\n IndentationText,\n Node,\n type ObjectLiteralExpression,\n Project,\n QuoteKind,\n SyntaxKind,\n} from 'ts-morph';\n\n/**\n * Checks if a value is a plain object (and not null/array)\n */\nconst isPlainObject = (value: unknown): value is Record<string, unknown> => {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n};\n\n/**\n * Safely formats a key for use in object literals.\n * Always quotes keys to ensure compatibility with standard JSON files.\n */\nconst stringifyKey = (objectKey: string): string => {\n return JSON.stringify(objectKey);\n};\n\n/**\n * Robustly finds a property in an ObjectLiteralExpression.\n * Handles cases where the property name in the source file is quoted (\"key\") or unquoted (key).\n */\nconst getMatchingProperty = (node: ObjectLiteralExpression, key: string) => {\n return node.getProperties().find((prop) => {\n // We only care about property assignments (key: value)\n if (Node.isPropertyAssignment(prop)) {\n const propName = prop.getName();\n // Check for strict match (unquoted identifier) or quoted match (string literal)\n // We check both double and single quotes to handle JSONC/JSON5 variations.\n return (\n propName === key || propName === `\"${key}\"` || propName === `'${key}'`\n );\n }\n return false;\n });\n};\n\n/**\n * Recursively updates the AST object literal with new data.\n */\nconst updateObjectLiteral = (\n node: ObjectLiteralExpression,\n data: Record<string, any>\n) => {\n for (const [key, val] of Object.entries(data)) {\n // Skip undefined values.\n if (val === undefined) continue;\n\n const stringifiedValue = JSON.stringify(val, null, 2);\n\n // Safety check: ensure we have a string unless we are recursing into an object\n if (stringifiedValue === undefined && !isPlainObject(val)) continue;\n\n // Use robust lookup instead of node.getProperty(key)\n const existingProp = getMatchingProperty(node, key);\n\n if (isPlainObject(val)) {\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n const initializer = existingProp.getInitializer();\n\n if (Node.isObjectLiteralExpression(initializer)) {\n // Recurse into nested object\n updateObjectLiteral(initializer, val);\n } else {\n // Property exists but is not an object (e.g. was null or number), overwrite with new object\n existingProp.setInitializer(stringifiedValue!);\n }\n } else if (existingProp) {\n // Property exists but isn't a simple assignment, overwrite it safely\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n // Property doesn't exist, add it\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n } else {\n // Handling Primitives / Arrays\n if (existingProp && Node.isPropertyAssignment(existingProp)) {\n existingProp.setInitializer(stringifiedValue!);\n } else if (existingProp) {\n existingProp.replaceWithText(\n `${stringifyKey(key)}: ${stringifiedValue}`\n );\n } else {\n node.addPropertyAssignment({\n name: stringifyKey(key),\n initializer: stringifiedValue!,\n });\n }\n }\n }\n};\n\nexport const transformJSONFile = (\n fileContent: string,\n dictionary: Dictionary\n): string => {\n // Initialize a virtual project\n const project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: {\n indentationText: IndentationText.TwoSpaces,\n quoteKind: QuoteKind.Double,\n },\n });\n\n // Wrap content in a variable declaration so it acts as a valid SourceFile\n const dummyFileName = 'temp.ts';\n const wrappedContent = `const _config = ${fileContent.trim() || '{}'}`;\n const sourceFile = project.createSourceFile(dummyFileName, wrappedContent);\n\n // Locate the object literal\n const varDecl = sourceFile.getVariableDeclaration('_config');\n const objectLiteral = varDecl?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression\n );\n\n if (!objectLiteral) {\n // Fallback if parsing failed\n return JSON.stringify(dictionary, null, 2);\n }\n\n // Update the AST\n updateObjectLiteral(objectLiteral, dictionary);\n\n // Format text to ensure new properties are aligned\n sourceFile.formatText();\n\n // Extract the object literal text.\n return objectLiteral.getText();\n};\n"],"mappings":";;;;;;;AAaA,MAAM,iBAAiB,UAAqD;AAC1E,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;AAO7E,MAAM,gBAAgB,cAA8B;AAClD,QAAO,KAAK,UAAU,UAAU;;;;;;AAOlC,MAAM,uBAAuB,MAA+B,QAAgB;AAC1E,QAAO,KAAK,eAAe,CAAC,MAAM,SAAS;AAEzC,MAAIA,cAAK,qBAAqB,KAAK,EAAE;GACnC,MAAM,WAAW,KAAK,SAAS;AAG/B,UACE,aAAa,OAAO,aAAa,IAAI,IAAI,MAAM,aAAa,IAAI,IAAI;;AAGxE,SAAO;GACP;;;;;AAMJ,MAAM,uBACJ,MACA,SACG;AACH,MAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,QAAQ,KAAK,EAAE;AAE7C,MAAI,QAAQ,OAAW;EAEvB,MAAM,mBAAmB,KAAK,UAAU,KAAK,MAAM,EAAE;AAGrD,MAAI,qBAAqB,UAAa,CAAC,cAAc,IAAI,CAAE;EAG3D,MAAM,eAAe,oBAAoB,MAAM,IAAI;AAEnD,MAAI,cAAc,IAAI,CACpB,KAAI,gBAAgBA,cAAK,qBAAqB,aAAa,EAAE;GAC3D,MAAM,cAAc,aAAa,gBAAgB;AAEjD,OAAIA,cAAK,0BAA0B,YAAY,CAE7C,qBAAoB,aAAa,IAAI;OAGrC,cAAa,eAAe,iBAAkB;aAEvC,aAET,cAAa,gBACX,GAAG,aAAa,IAAI,CAAC,IAAI,mBAC1B;MAGD,MAAK,sBAAsB;GACzB,MAAM,aAAa,IAAI;GACvB,aAAa;GACd,CAAC;WAIA,gBAAgBA,cAAK,qBAAqB,aAAa,CACzD,cAAa,eAAe,iBAAkB;WACrC,aACT,cAAa,gBACX,GAAG,aAAa,IAAI,CAAC,IAAI,mBAC1B;MAED,MAAK,sBAAsB;GACzB,MAAM,aAAa,IAAI;GACvB,aAAa;GACd,CAAC;;;AAMV,MAAa,qBACX,aACA,eACW;CAEX,MAAM,UAAU,IAAIC,iBAAQ;EAC1B,uBAAuB;EACvB,sBAAsB;GACpB,iBAAiBC,yBAAgB;GACjC,WAAWC,mBAAU;GACtB;EACF,CAAC;CAGF,MAAM,gBAAgB;CACtB,MAAM,iBAAiB,mBAAmB,YAAY,MAAM,IAAI;CAChE,MAAM,aAAa,QAAQ,iBAAiB,eAAe,eAAe;CAI1E,MAAM,gBADU,WAAW,uBAAuB,UAAU,EAC7B,qBAC7BC,oBAAW,wBACZ;AAED,KAAI,CAAC,cAEH,QAAO,KAAK,UAAU,YAAY,MAAM,EAAE;AAI5C,qBAAoB,eAAe,WAAW;AAG9C,YAAW,YAAY;AAGvB,QAAO,cAAc,SAAS"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_getFormatFromExtension = require('../utils/getFormatFromExtension.cjs');
|
|
3
3
|
const require_writeContentDeclaration_processContentDeclarationContent = require('./processContentDeclarationContent.cjs');
|
|
4
|
+
const require_writeContentDeclaration_transformJSONFile = require('./transformJSONFile.cjs');
|
|
4
5
|
const require_writeContentDeclaration_writeJSFile = require('./writeJSFile.cjs');
|
|
6
|
+
let node_fs = require("node:fs");
|
|
5
7
|
let node_fs_promises = require("node:fs/promises");
|
|
6
8
|
let node_path = require("node:path");
|
|
7
9
|
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
@@ -102,6 +104,14 @@ const writeFileWithDirectories = async (absoluteFilePath, dictionary, configurat
|
|
|
102
104
|
await (0, node_fs_promises.writeFile)(absoluteFilePath, `${JSON.stringify(dictionary, null, 2)}\n`);
|
|
103
105
|
return;
|
|
104
106
|
}
|
|
107
|
+
if ([".jsonc", ".json5"].includes(extension)) {
|
|
108
|
+
let fileContent = "{}";
|
|
109
|
+
if ((0, node_fs.existsSync)(absoluteFilePath)) try {
|
|
110
|
+
fileContent = await (0, node_fs_promises.readFile)(absoluteFilePath, "utf-8");
|
|
111
|
+
} catch {}
|
|
112
|
+
await (0, node_fs_promises.writeFile)(absoluteFilePath, require_writeContentDeclaration_transformJSONFile.transformJSONFile(fileContent, dictionary), "utf-8");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
105
115
|
await require_writeContentDeclaration_writeJSFile.writeJSFile(absoluteFilePath, dictionary, configuration);
|
|
106
116
|
try {
|
|
107
117
|
await (0, node_fs_promises.rm)((0, node_path.join)(configuration.content.cacheDir, "intlayer-prepared.lock"), { recursive: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeContentDeclaration.cjs","names":["processContentDeclarationContent","
|
|
1
|
+
{"version":3,"file":"writeContentDeclaration.cjs","names":["processContentDeclarationContent","getFormatFromExtension","extension","transformJSONFile","writeJSFile"],"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { dirname, extname, join, resolve } from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\nimport {\n getFilteredLocalesDictionary,\n getPerLocaleDictionary,\n} from '@intlayer/core';\nimport type {\n Dictionary,\n IntlayerConfig,\n Locale,\n LocalesValues,\n} from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type Extension,\n getFormatFromExtension,\n} from '../utils/getFormatFromExtension';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { processContentDeclarationContent } from './processContentDeclarationContent';\nimport { transformJSONFile } from './transformJSONFile';\nimport { writeJSFile } from './writeJSFile';\n\nconst formatContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n localeList?: LocalesValues[]\n) => {\n /**\n * Clean Markdown, Insertion, File, etc. node metadata\n */\n const processedDictionary =\n await processContentDeclarationContent(dictionary);\n\n let content = processedDictionary.content;\n\n /**\n * Filter locales content\n */\n\n if (dictionary.locale) {\n content = getPerLocaleDictionary(\n processedDictionary,\n dictionary.locale\n ).content;\n } else if (localeList) {\n content = getFilteredLocalesDictionary(\n processedDictionary,\n localeList\n ).content;\n }\n\n let pluginFormatResult: any = {\n ...dictionary,\n content,\n } satisfies Dictionary;\n\n /**\n * Format the dictionary with the plugins\n */\n\n for await (const plugin of configuration.plugins ?? []) {\n if (plugin.formatOutput) {\n const formattedResult = await plugin.formatOutput?.({\n dictionary: pluginFormatResult,\n configuration,\n });\n\n if (formattedResult) {\n pluginFormatResult = formattedResult;\n }\n }\n }\n\n const isDictionaryFormat =\n pluginFormatResult.content && pluginFormatResult.key;\n\n if (!isDictionaryFormat) return pluginFormatResult;\n\n let result: Dictionary = {\n key: dictionary.key,\n id: dictionary.id,\n title: dictionary.title,\n description: dictionary.description,\n tags: dictionary.tags,\n locale: dictionary.locale,\n fill: dictionary.fill,\n filled: dictionary.filled,\n priority: dictionary.priority,\n live: dictionary.live,\n version: dictionary.version,\n content,\n };\n\n /**\n * Add $schema to JSON dictionaries\n */\n const extension = (\n dictionary.filePath ? extname(dictionary.filePath) : '.json'\n ) as Extension;\n const format = getFormatFromExtension(extension);\n\n if (\n format === 'json' &&\n pluginFormatResult.content &&\n pluginFormatResult.key\n ) {\n result = {\n $schema: 'https://intlayer.org/schema.json',\n ...result,\n };\n }\n\n return result;\n};\n\ntype WriteContentDeclarationOptions = {\n newDictionariesPath?: string;\n localeList?: LocalesValues[];\n fallbackLocale?: Locale;\n};\n\nconst defaultOptions = {\n newDictionariesPath: 'intlayer-dictionaries',\n} satisfies WriteContentDeclarationOptions;\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n configuration: IntlayerConfig,\n options?: WriteContentDeclarationOptions\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = configuration;\n const { baseDir } = content;\n const { newDictionariesPath, localeList } = {\n ...defaultOptions,\n ...options,\n };\n\n const newDictionaryLocationPath = join(baseDir, newDictionariesPath);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const unmergedDictionaries = unmergedDictionariesRecord[\n dictionary.key\n ] as Dictionary[];\n\n const existingDictionary = unmergedDictionaries?.find(\n (el) => el.localId === dictionary.localId\n );\n\n const formattedContentDeclaration = await formatContentDeclaration(\n dictionary,\n configuration,\n localeList\n );\n\n if (existingDictionary?.filePath) {\n // Compare existing dictionary content with new dictionary content\n const isSameContent = isDeepStrictEqual(existingDictionary, dictionary);\n\n const filePath = resolve(\n configuration.content.baseDir,\n existingDictionary.filePath\n );\n\n // Up to date, nothing to do\n if (isSameContent) {\n return {\n status: 'up-to-date',\n path: filePath,\n };\n }\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'updated', path: filePath };\n }\n\n if (dictionary.filePath) {\n const filePath = resolve(\n configuration.content.baseDir,\n dictionary.filePath\n );\n\n await writeFileWithDirectories(\n filePath,\n formattedContentDeclaration,\n configuration\n );\n\n return { status: 'created', path: filePath };\n }\n\n // No existing dictionary, write to new location\n const contentDeclarationPath = join(\n newDictionaryLocationPath,\n `${dictionary.key}.content.json`\n );\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration,\n configuration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n};\n\nconst writeFileWithDirectories = async (\n absoluteFilePath: string,\n dictionary: Dictionary,\n configuration: IntlayerConfig\n): Promise<void> => {\n // Extract the directory from the file path\n const dir = dirname(absoluteFilePath);\n\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n\n const extension = extname(absoluteFilePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extension) => extname(extension)\n );\n\n if (!acceptedExtensions.includes(extension)) {\n throw new Error(\n `Invalid file extension: ${extension}, file: ${absoluteFilePath}`\n );\n }\n\n if (extension === '.json') {\n const jsonDictionary = JSON.stringify(dictionary, null, 2);\n\n // Write the file\n await writeFile(absoluteFilePath, `${jsonDictionary}\\n`); // Add a new line at the end of the file to avoid formatting issues with VSCode\n\n return;\n }\n\n // Handle JSONC, and JSON5 via the AST transformer\n if (['.jsonc', '.json5'].includes(extension)) {\n let fileContent = '{}';\n\n if (existsSync(absoluteFilePath)) {\n try {\n fileContent = await readFile(absoluteFilePath, 'utf-8');\n } catch {\n // ignore read errors, start with empty object\n }\n }\n\n const transformedContent = transformJSONFile(fileContent, dictionary);\n\n // We use standard writeFile because transformedContent is already a string\n await writeFile(absoluteFilePath, transformedContent, 'utf-8');\n return;\n }\n\n await writeJSFile(absoluteFilePath, dictionary, configuration);\n\n // remove the cache as content has changed\n // Will force a new preparation of the intlayer on next build\n try {\n const sentinelPath = join(\n configuration.content.cacheDir,\n 'intlayer-prepared.lock'\n );\n await rm(sentinelPath, { recursive: true });\n } catch {}\n};\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,2BAA2B,OAC/B,YACA,eACA,eACG;;;;CAIH,MAAM,sBACJ,MAAMA,kGAAiC,WAAW;CAEpD,IAAI,UAAU,oBAAoB;;;;AAMlC,KAAI,WAAW,OACb,sDACE,qBACA,WAAW,OACZ,CAAC;UACO,WACT,4DACE,qBACA,WACD,CAAC;CAGJ,IAAI,qBAA0B;EAC5B,GAAG;EACH;EACD;;;;AAMD,YAAW,MAAM,UAAU,cAAc,WAAW,EAAE,CACpD,KAAI,OAAO,cAAc;EACvB,MAAM,kBAAkB,MAAM,OAAO,eAAe;GAClD,YAAY;GACZ;GACD,CAAC;AAEF,MAAI,gBACF,sBAAqB;;AAQ3B,KAAI,EAFF,mBAAmB,WAAW,mBAAmB,KAE1B,QAAO;CAEhC,IAAI,SAAqB;EACvB,KAAK,WAAW;EAChB,IAAI,WAAW;EACf,OAAO,WAAW;EAClB,aAAa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oB,iBAAiB,EAGpB,EAAE,WAAW,MAAM,CAAC;CAErC,MAAM,mCAAoB,iBAAiB;AAK3C,KAAI,CAJuB,cAAc,QAAQ,eAAe,KAC7D,uCAAsBC,YAAU,CAClC,CAEuB,SAAS,UAAU,CACzC,OAAM,IAAI,MACR,2BAA2B,UAAU,UAAU,mBAChD;AAGH,KAAI,cAAc,SAAS;AAIzB,wCAAgB,kBAAkB,GAHX,KAAK,UAAU,YAAY,MAAM,EAAE,CAGN,IAAI;AAExD;;AAIF,KAAI,CAAC,UAAU,SAAS,CAAC,SAAS,UAAU,EAAE;EAC5C,IAAI,cAAc;AAElB,8BAAe,iBAAiB,CAC9B,KAAI;AACF,iBAAc,qCAAe,kBAAkB,QAAQ;UACjD;AAQV,wCAAgB,kBAHWC,oEAAkB,aAAa,WAAW,EAGf,QAAQ;AAC9D;;AAGF,OAAMC,wDAAY,kBAAkB,YAAY,cAAc;AAI9D,KAAI;AAKF,qDAHE,cAAc,QAAQ,UACtB,yBACD,EACsB,EAAE,WAAW,MAAM,CAAC;SACrC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate = require('../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs');
|
|
3
|
+
const require_writeContentDeclaration_detectFormatCommand = require('./detectFormatCommand.cjs');
|
|
3
4
|
const require_writeContentDeclaration_transformJSFile = require('./transformJSFile.cjs');
|
|
4
5
|
const require_utils_getFormatFromExtension = require('../utils/getFormatFromExtension.cjs');
|
|
5
|
-
const require_writeContentDeclaration_detectFormatCommand = require('./detectFormatCommand.cjs');
|
|
6
6
|
let node_fs = require("node:fs");
|
|
7
7
|
let node_fs_promises = require("node:fs/promises");
|
|
8
8
|
let node_path = require("node:path");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildIntlayerDictionary.mjs","names":[
|
|
1
|
+
{"version":3,"file":"buildIntlayerDictionary.mjs","names":[],"sources":["../../../src/buildIntlayerDictionary/buildIntlayerDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport {\n type LocalizedDictionaryOutput,\n writeDynamicDictionary,\n} from './writeDynamicDictionary';\nimport { writeFetchDictionary } from './writeFetchDictionary';\nimport { writeMergedDictionaries } from './writeMergedDictionary';\nimport { writeUnmergedDictionaries } from './writeUnmergedDictionary';\n\n/**\n * This function transpile the bundled code to to make dictionaries as JSON files\n */\nexport const buildDictionary = async (\n localDictionariesEntries: Dictionary[],\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm'],\n importOtherDictionaries = true\n) => {\n const { importMode } = configuration.build;\n\n const unmergedDictionariesToUpdate: Dictionary[] = [\n ...localDictionariesEntries,\n ];\n\n if (importOtherDictionaries) {\n const prevUnmergedDictionaries: Record<string, Dictionary[]> =\n getUnmergedDictionaries(configuration);\n\n // Reinsert other dictionaries with the same key to avoid merging errors\n for (const dictionaryToWrite of localDictionariesEntries) {\n const allPrebuiltUnmergedDictionaries =\n prevUnmergedDictionaries[dictionaryToWrite.key];\n\n if (allPrebuiltUnmergedDictionaries?.length > 0) {\n // Do not add the same dictionary again by filtering out the one with the same localId\n const otherUnmergedDictionaries =\n allPrebuiltUnmergedDictionaries.filter(\n (unmergedDictionary) =>\n unmergedDictionary.localId !== dictionaryToWrite.localId\n );\n\n unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries);\n }\n }\n }\n\n const unmergedDictionaries = await writeUnmergedDictionaries(\n unmergedDictionariesToUpdate,\n configuration\n );\n\n const mergedDictionaries = await writeMergedDictionaries(\n unmergedDictionaries,\n configuration\n );\n\n let dynamicDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'dynamic' || importMode === 'live') {\n dynamicDictionaries = await writeDynamicDictionary(\n mergedDictionaries,\n configuration,\n formats\n );\n }\n\n let fetchDictionaries: LocalizedDictionaryOutput | null = null;\n\n if (importMode === 'live') {\n fetchDictionaries = await writeFetchDictionary(\n dynamicDictionaries!,\n configuration,\n formats\n );\n }\n\n return {\n unmergedDictionaries,\n mergedDictionaries,\n dynamicDictionaries,\n fetchDictionaries,\n };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,kBAAkB,OAC7B,0BACA,gBAAgB,kBAAkB,EAClC,UAA6B,CAAC,OAAO,MAAM,EAC3C,0BAA0B,SACvB;CACH,MAAM,EAAE,eAAe,cAAc;CAErC,MAAM,+BAA6C,CACjD,GAAG,yBACJ;AAED,KAAI,yBAAyB;EAC3B,MAAM,2BACJ,wBAAwB,cAAc;AAGxC,OAAK,MAAM,qBAAqB,0BAA0B;GACxD,MAAM,kCACJ,yBAAyB,kBAAkB;AAE7C,OAAI,iCAAiC,SAAS,GAAG;IAE/C,MAAM,4BACJ,gCAAgC,QAC7B,uBACC,mBAAmB,YAAY,kBAAkB,QACpD;AAEH,iCAA6B,KAAK,GAAG,0BAA0B;;;;CAKrE,MAAM,uBAAuB,MAAM,0BACjC,8BACA,cACD;CAED,MAAM,qBAAqB,MAAM,wBAC/B,sBACA,cACD;CAED,IAAI,sBAAwD;AAE5D,KAAI,eAAe,aAAa,eAAe,OAC7C,uBAAsB,MAAM,uBAC1B,oBACA,eACA,QACD;CAGH,IAAI,oBAAsD;AAE1D,KAAI,eAAe,OACjB,qBAAoB,MAAM,qBACxB,qBACA,eACA,QACD;AAGH,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeDynamicDictionary.mjs","names":[
|
|
1
|
+
{"version":3,"file":"writeDynamicDictionary.mjs","names":[],"sources":["../../../src/buildIntlayerDictionary/writeDynamicDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\nimport {\n colorizePath,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { getPerLocaleDictionary } from '@intlayer/core';\nimport type { Dictionary, Locale } from '@intlayer/types';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport { writeJsonIfChanged } from '../writeJsonIfChanged';\nimport type { MergedDictionaryOutput } from './writeMergedDictionary';\n\nexport type DictionaryResult = {\n dictionaryPath: string;\n dictionary: Dictionary;\n};\n\nexport type LocalizedDictionaryResult = Partial<\n Record<Locale, DictionaryResult>\n>;\n\nexport type LocalizedDictionaryOutput = Record<\n string,\n LocalizedDictionaryResult\n>;\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localizedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { dynamicDictionariesDir } = configuration.content;\n\n let content = '';\n\n // Format Dictionary Map - map locales to functions\n const formattedDictionaryMap: string = Object.entries(\n localizedDictionariesPathsRecord\n )\n // The following filter/sort preserve determinism of the generated map\n // when files are built in parallel or across different Node versions.\n .filter((entry): entry is [string, DictionaryResult] => Boolean(entry[1]))\n .sort(([a], [b]) => String(a).localeCompare(String(b)))\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(dynamicDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)`;\n }\n\n return ` '${locale}': () => Promise.resolve(require('./${relativePath}'))`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/dynamic_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeDynamicDictionary = async (\n mergedDictionaries: MergedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { locales, defaultLocale } = configuration.internationalization;\n const { dynamicDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(dynamicDictionariesDir), { recursive: true });\n\n const resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Merge dictionaries with the same key and write to dictionariesDir\n await parallelize(\n Object.entries(mergedDictionaries).sort(([a], [b]) =>\n String(a).localeCompare(String(b))\n ),\n async ([key, dictionaryEntry]) => {\n if (key === 'undefined') return;\n\n const localizedDictionariesPathsRecord: LocalizedDictionaryResult = {};\n\n await parallelize(locales, async (locale) => {\n const localizedDictionary = getPerLocaleDictionary(\n dictionaryEntry.dictionary,\n locale,\n defaultLocale\n );\n\n const outputFileName = `${key}.${locale}.json`;\n const resultFilePath = resolve(dynamicDictionariesDir, outputFileName);\n\n // Write the localized dictionary\n await writeJsonIfChanged(resultFilePath, localizedDictionary).catch(\n (err) => {\n console.error(`Error creating localized ${outputFileName}:`, err);\n }\n );\n\n localizedDictionariesPathsRecord[locale] = {\n dictionaryPath: resultFilePath,\n dictionary: localizedDictionary,\n };\n });\n\n resultDictionariesPaths[key] = localizedDictionariesPathsRecord;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localizedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFileIfChanged(\n resolve(dynamicDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating dynamic ${colorizePath(resolve(dynamicDictionariesDir, `${key}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B,YAChB,QACA,cACD;GAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,OAAO;GACxC,MAAM,iBAAiB,QAAQ,wBAAwB,eAAe;AAGtE,SAAM,mBAAmB,gBAAgB,oBAAoB,CAAC,OAC3D,QAAQ;AACP,YAAQ,MAAM,4BAA4B,eAAe,IAAI,IAAI;KAEpE;AAED,oCAAiC,UAAU;IACzC,gBAAgB;IAChB,YAAY;IACb;IACD;AAEF,0BAAwB,OAAO;AAE/B,QAAM,YAAY,SAAS,OAAO,WAAW;GAC3C,MAAM,YAAY,WAAW,QAAQ,QAAQ;GAC7C,MAAM,UAAU,6BACd,kCACA,QACA,cACD;AAED,SAAM,mBACJ,QAAQ,wBAAwB,GAAG,IAAI,GAAG,YAAY,EACtD,QACD,CAAC,OAAO,QAAQ;AACf,YAAQ,MACN,0BAA0B,aAAa,QAAQ,wBAAwB,GAAG,IAAI,GAAG,YAAY,CAAC,CAAC,IAC/F,IACD;KACD;IACF;GAEL;AAED,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeFetchDictionary.mjs","names":[
|
|
1
|
+
{"version":3,"file":"writeFetchDictionary.mjs","names":[],"sources":["../../../src/buildIntlayerDictionary/writeFetchDictionary.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\nimport {\n colorizePath,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { parallelize } from '../utils/parallelize';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\nimport type {\n LocalizedDictionaryOutput,\n LocalizedDictionaryResult,\n} from './writeDynamicDictionary';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryEntryPoint = (\n localedDictionariesPathsRecord: LocalizedDictionaryResult,\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { fetchDictionariesDir } = configuration.content;\n const { liveSyncURL } = configuration.editor;\n\n let content = '';\n\n const formattedDictionaryMap: string = Object.entries(\n localedDictionariesPathsRecord\n )\n .map(([locale, dictionary]) => {\n const relativePath = normalizePath(\n relative(fetchDictionariesDir, dictionary.dictionaryPath)\n );\n\n if (format === 'esm') {\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return await import('./${relativePath}', { assert: { type: 'json' }}).then(mod => mod.default)}})()`;\n }\n\n return ` '${locale}': () => (async () => { try {return await fetch('${liveSyncURL}/dictionaries/${dictionary.dictionary.key}/${locale}').then(res => res.json())} catch (_error) {return Promise.resolve(require('./${relativePath}'))}})()`;\n })\n .join(',\\n');\n\n content += `const content = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n if (format === 'esm') content += `export default content;\\n`;\n if (format === 'cjs') content += `module.exports = content;\\n`;\n\n return content;\n};\n\n/**\n * Write the localized dictionaries to the dictionariesDir\n * @param mergedDictionaries - The merged dictionaries\n * @param configuration - The configuration\n * @returns The final dictionaries\n *\n * @example\n * ```ts\n * const unmergedDictionaries = await writeUnmergedDictionaries(dictionaries);\n * const finalDictionaries = await writeFinalDictionaries(unmergedDictionaries);\n * console.log(finalDictionaries);\n *\n * // .intlayer/fetch_dictionaries/home.json\n * // { key: 'home', content: { ... } },\n * ```\n */\nexport const writeFetchDictionary = async (\n dynamicDictionaries: LocalizedDictionaryOutput,\n configuration = getConfiguration(),\n formats: ('cjs' | 'esm')[] = ['cjs', 'esm']\n): Promise<LocalizedDictionaryOutput> => {\n const { fetchDictionariesDir } = configuration.content;\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(resolve(fetchDictionariesDir), { recursive: true });\n\n const resultDictionariesPaths: LocalizedDictionaryOutput = {};\n\n // Write entry points for each dictionary in parallel\n await parallelize(\n Object.entries(dynamicDictionaries),\n async ([key, localedDictionariesPathsRecord]) => {\n if (key === 'undefined') return;\n\n await parallelize(formats, async (format) => {\n const extension = format === 'cjs' ? 'cjs' : 'mjs';\n const content = generateDictionaryEntryPoint(\n localedDictionariesPathsRecord,\n format,\n configuration\n );\n\n await writeFileIfChanged(\n resolve(fetchDictionariesDir, `${key}.${extension}`),\n content\n ).catch((err) => {\n console.error(\n `Error creating fetch ${colorizePath(resolve(fetchDictionariesDir, `${key}.${extension}`))}:`,\n err\n );\n });\n });\n }\n );\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;AAiBA,MAAa,gCACX,gCACA,SAAwB,OACxB,gBAAgB,kBAAkB,KACvB;CACX,MAAM,EAAE,yBAAyB,cAAc;CAC/C,MAAM,EAAE,gBAAgB,cAAc;CAEtC,IAAI,UAAU;CAEd,MAAM,yBAAiC,OAAO,QAC5C,+BACD,CACE,KAAK,CAAC,QAAQ,gBAAgB;EAC7B,MAAM,eAAe,cACnB,SAAS,sBAAsB,WAAW,eAAe,CAC1D;AAED,MAAI,WAAW,MACb,QAAO,MAAM,OAAO,mDAAmD,YAAY,gBAAgB,WAAW,WAAW,IAAI,GAAG,OAAO,qEAAqE,aAAa;AAG3N,SAAO,MAAM,OAAO,mDAAmD,YAAY,gBAAgB,WAAW,WAAW,IAAI,GAAG,OAAO,gFAAgF,aAAa;GACpO,CACD,KAAK,MAAM;AAEd,YAAW,sBAAsB,uBAAuB;AAExD,KAAI,WAAW,MAAO,YAAW;AACjC,KAAI,WAAW,MAAO,YAAW;AAEjC,QAAO;;;;;;;;;;;;;;;;;;AAmBT,MAAa,uBAAuB,OAClC,qBACA,gBAAgB,kBAAkB,EAClC,UAA6B,CAAC,OAAO,MAAM,KACJ;CACvC,MAAM,EAAE,yBAAyB,cAAc;AAG/C,OAAM,MAAM,QAAQ,qBAAqB,EAAE,EAAE,WAAW,MAAM,CAAC;CAE/D,MAAM,0BAAqD,EAAE;AAG7D,OAAM,YACJ,OAAO,QAAQ,oBAAoB,EACnC,OAAO,CAAC,KAAK,oCAAoC;AAC/C,MAAI,QAAQ,YAAa;AAEzB,QAAM,YAAY,SAAS,OAAO,WAAW;GAC3C,MAAM,YAAY,WAAW,QAAQ,QAAQ;GAC7C,MAAM,UAAU,6BACd,gCACA,QACA,cACD;AAED,SAAM,mBACJ,QAAQ,sBAAsB,GAAG,IAAI,GAAG,YAAY,EACpD,QACD,CAAC,OAAO,QAAQ;AACf,YAAQ,MACN,wBAAwB,aAAa,QAAQ,sBAAsB,GAAG,IAAI,GAAG,YAAY,CAAC,CAAC,IAC3F,IACD;KACD;IACF;GAEL;AAED,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleanOutputDir.mjs","names":[
|
|
1
|
+
{"version":3,"file":"cleanOutputDir.mjs","names":[],"sources":["../../src/cleanOutputDir.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { rm } from 'node:fs/promises';\nimport { getAppLogger } from '@intlayer/config/client';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const cleanOutputDir = async (configuration: IntlayerConfig) => {\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n remoteDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n typesDir,\n configDir,\n cacheDir,\n } = configuration.content;\n\n const appLogger = getAppLogger(configuration);\n\n const directoriesToClean: string[] = [\n dictionariesDir, // Merged dictionaries\n unmergedDictionariesDir, // Unmerged dictionaries\n dynamicDictionariesDir, // Dynamic dictionaries\n remoteDictionariesDir, // Remote dictionaries\n fetchDictionariesDir, // Fetch dictionaries\n mainDir, // Main files\n typesDir, // Types\n configDir, // Configuration\n cacheDir, // Cache\n ];\n\n // Execute all deletions in parallel\n await Promise.all(\n directoriesToClean\n .filter((dir) => existsSync(dir))\n .map((dir) => rm(dir, { recursive: true, force: true }))\n );\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n};\n"],"mappings":";;;;;AAKA,MAAa,iBAAiB,OAAO,kBAAkC;CACrE,MAAM,EACJ,iBACA,yBACA,wBACA,uBACA,sBACA,SACA,UACA,WACA,aACE,cAAc;CAElB,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,qBAA+B;EACnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;AAGD,OAAM,QAAQ,IACZ,mBACG,QAAQ,QAAQ,WAAW,IAAI,CAAC,CAChC,KAAK,QAAQ,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;EAAM,CAAC,CAAC,CAC3D;AAED,WAAU,4BAA4B,EACpC,WAAW,MACZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cleanRemovedContentDeclaration.mjs","names":["changedDictionariesLocalIds: string[]","filesToRemove: string[]","excludeKeys: string[]","error: any","path"],"sources":["../../src/cleanRemovedContentDeclaration.ts"],"sourcesContent":["import { readFile, rm } from 'node:fs/promises';\nimport { join, normalize, relative } from 'node:path';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n normalizePath,\n} from '@intlayer/config/client';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport fg from 'fast-glob';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint';\nimport { writeJsonIfChanged } from './writeJsonIfChanged';\n\nexport const cleanRemovedContentDeclaration = async (\n filePath: string,\n keysToKeep: string[],\n configuration: IntlayerConfig\n): Promise<{\n changedDictionariesLocalIds: string[];\n excludeKeys: string[];\n hasRebuilt: boolean;\n}> => {\n const appLogger = getAppLogger(configuration);\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const baseDir = configuration.content.baseDir;\n\n const relativeFilePath = relative(baseDir, filePath);\n const flatUnmergedDictionaries = Object.values(unmergedDictionaries).flat();\n\n const filteredUnmergedDictionaries = flatUnmergedDictionaries.filter(\n (dictionary) =>\n dictionary.filePath === relativeFilePath &&\n !keysToKeep.includes(dictionary.key)\n );\n\n // Deduplicate dictionaries by key\n const uniqueUnmergedDictionaries = filteredUnmergedDictionaries.filter(\n (dictionary, index, self) =>\n index === self.findIndex((t) => t.key === dictionary.key)\n );\n\n const changedDictionariesLocalIds: string[] = [];\n const filesToRemove: string[] = [];\n const excludeKeys: string[] = [];\n\n // Identify Unmerged Dictionaries to remove or clean\n await Promise.all(\n uniqueUnmergedDictionaries.map(async (dictionary) => {\n const unmergedFilePath = normalize(\n join(\n configuration.content.unmergedDictionariesDir,\n `${dictionary.key}.json`\n )\n );\n\n try {\n const jsonContent = await readFile(unmergedFilePath, 'utf8');\n const parsedContent = JSON.parse(jsonContent);\n\n if (parsedContent.length === 1) {\n if (parsedContent[0].filePath === relativeFilePath) {\n appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n { isVerbose: true }\n );\n filesToRemove.push(unmergedFilePath);\n excludeKeys.push(dictionary.key);\n }\n } else {\n const filteredContent = parsedContent.filter(\n (content: any) => content.filePath !== relativeFilePath\n );\n await writeJsonIfChanged(unmergedFilePath, filteredContent);\n changedDictionariesLocalIds.push(dictionary.localId!);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n }\n }\n })\n );\n\n const dictionaries = getDictionaries(configuration);\n const flatDictionaries = Object.values(dictionaries) as Dictionary[];\n\n const filteredMergedDictionaries = flatDictionaries?.filter(\n (dictionary) =>\n !keysToKeep.includes(dictionary.key) &&\n dictionary.localIds?.length === 1 &&\n (dictionary.localIds[0] as string).endsWith(\n `::local::${relativeFilePath}`\n )\n );\n\n const uniqueMergedDictionaries = filteredMergedDictionaries.filter(\n (dictionary, index, self) =>\n index === self.findIndex((t) => t.key === dictionary.key)\n );\n\n // Identify Merged Dictionaries, Types, and Dynamic Dictionaries to remove\n await Promise.all(\n uniqueMergedDictionaries.map(async (dictionary) => {\n const mergedFilePath = normalize(\n join(configuration.content.dictionariesDir, `${dictionary.key}.json`)\n );\n\n try {\n const fileContent = await readFile(mergedFilePath, 'utf8');\n const parsedContent = JSON.parse(fileContent) as Dictionary;\n\n if (parsedContent.localIds?.length === 1) {\n if (\n parsedContent.localIds[0].endsWith(`::local::${relativeFilePath}`)\n ) {\n appLogger(\n `Removing outdated unmerged dictionary ${colorizeKey(dictionary.key)}`,\n { isVerbose: true }\n );\n\n // Mark JSON for removal\n filesToRemove.push(mergedFilePath);\n\n // Mark TS Types for removal\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n filesToRemove.push(typesFilePath);\n\n // Mark Dynamic Dictionaries for removal\n // We use glob to catch the loader files (.cjs, .mjs) AND the split locale files (.en.json, etc.)\n const dynamicFilesGlob = join(\n configuration.content.dynamicDictionariesDir,\n `${dictionary.key}.*`\n );\n const dynamicFiles = await fg(normalizePath(dynamicFilesGlob), {\n absolute: true,\n });\n filesToRemove.push(...dynamicFiles);\n\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n }\n } else {\n const localIds = parsedContent.localIds?.filter(\n (localeId) => !localeId.endsWith(`::local::${relativeFilePath}`)\n ) as string[];\n const newContent = { ...parsedContent, localIds };\n await writeJsonIfChanged(mergedFilePath, newContent);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n filesToRemove.push(typesFilePath);\n }\n }\n })\n );\n\n // Execute Cleanup\n if (filesToRemove.length > 0 || excludeKeys.length > 0) {\n // Update entry points (indexes) first so the app doesn't import dead files\n await createDictionaryEntryPoint(configuration, { excludeKeys });\n\n // Remove the files synchronously (awaited) immediately after.\n if (filesToRemove.length > 0) {\n await Promise.all(\n filesToRemove.map(async (path) => {\n const relativePath = relative(baseDir, path);\n try {\n await rm(path, { force: true });\n\n appLogger(`Deleted artifact: ${colorizePath(relativePath)}`, {\n isVerbose: true,\n });\n } catch {\n appLogger(\n `Error while removing file ${colorizePath(relativePath)}`,\n {\n isVerbose: true,\n }\n );\n }\n })\n );\n }\n }\n\n return {\n changedDictionariesLocalIds,\n excludeKeys,\n hasRebuilt: filesToRemove.length > 0 || excludeKeys.length > 0,\n };\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,iCAAiC,OAC5C,UACA,YACA,kBAKI;CACJ,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,uBAAuB,wBAAwB,cAAc;CAEnE,MAAM,UAAU,cAAc,QAAQ;CAEtC,MAAM,mBAAmB,SAAS,SAAS,SAAS;CAUpD,MAAM,6BAT2B,OAAO,OAAO,qBAAqB,CAAC,MAAM,CAEb,QAC3D,eACC,WAAW,aAAa,oBACxB,CAAC,WAAW,SAAS,WAAW,IAAI,CACvC,CAG+D,QAC7D,YAAY,OAAO,SAClB,UAAU,KAAK,WAAW,MAAM,EAAE,QAAQ,WAAW,IAAI,CAC5D;CAED,MAAMA,8BAAwC,EAAE;CAChD,MAAMC,gBAA0B,EAAE;CAClC,MAAMC,cAAwB,EAAE;AAGhC,OAAM,QAAQ,IACZ,2BAA2B,IAAI,OAAO,eAAe;EACnD,MAAM,mBAAmB,UACvB,KACE,cAAc,QAAQ,yBACtB,GAAG,WAAW,IAAI,OACnB,CACF;AAED,MAAI;GACF,MAAM,cAAc,MAAM,SAAS,kBAAkB,OAAO;GAC5D,MAAM,gBAAgB,KAAK,MAAM,YAAY;AAE7C,OAAI,cAAc,WAAW,GAC3B;QAAI,cAAc,GAAG,aAAa,kBAAkB;AAClD,eACE,gCAAgC,YAAY,WAAW,IAAI,IAC3D,EAAE,WAAW,MAAM,CACpB;AACD,mBAAc,KAAK,iBAAiB;AACpC,iBAAY,KAAK,WAAW,IAAI;;UAE7B;AAIL,UAAM,mBAAmB,kBAHD,cAAc,QACnC,YAAiB,QAAQ,aAAa,iBACxC,CAC0D;AAC3D,gCAA4B,KAAK,WAAW,QAAS;;WAEhDC,OAAY;AACnB,OAAI,MAAM,SAAS,UACjB;QAAI,CAAC,YAAY,SAAS,WAAW,I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nB,OAAI,MAAM,SAAS,UAAU;AAC3B,QAAI,CAAC,YAAY,SAAS,WAAW,IAAI,CACvC,aAAY,KAAK,WAAW,IAAI;IAElC,MAAM,gBAAgB,UACpB,KAAK,cAAc,QAAQ,UAAU,GAAG,WAAW,IAAI,KAAK,CAC7D;AACD,kBAAc,KAAK,cAAc;;;GAGrC,CACH;AAGD,KAAI,cAAc,SAAS,KAAK,YAAY,SAAS,GAAG;AAEtD,QAAM,2BAA2B,eAAe,EAAE,aAAa,CAAC;AAGhE,MAAI,cAAc,SAAS,EACzB,OAAM,QAAQ,IACZ,cAAc,IAAI,OAAO,WAAS;GAChC,MAAM,eAAe,SAAS,SAASC,OAAK;AAC5C,OAAI;AACF,UAAM,GAAGA,QAAM,EAAE,OAAO,MAAM,CAAC;AAE/B,cAAU,qBAAqB,aAAa,aAAa,IAAI,EAC3D,WAAW,MACZ,CAAC;WACI;AACN,cACE,6BAA6B,aAAa,aAAa,IACvD,EACE,WAAW,MACZ,CACF;;IAEH,CACH;;AAIL,QAAO;EACL;EACA;EACA,YAAY,cAAc,SAAS,KAAK,YAAY,SAAS;EAC9D"}
|
|
1
|
+
{"version":3,"file":"cleanRemovedContentDeclaration.mjs","names":["path"],"sources":["../../src/cleanRemovedContentDeclaration.ts"],"sourcesContent":["import { readFile, rm } from 'node:fs/promises';\nimport { join, normalize, relative } from 'node:path';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n normalizePath,\n} from '@intlayer/config/client';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport fg from 'fast-glob';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint';\nimport { writeJsonIfChanged } from './writeJsonIfChanged';\n\nexport const cleanRemovedContentDeclaration = async (\n filePath: string,\n keysToKeep: string[],\n configuration: IntlayerConfig\n): Promise<{\n changedDictionariesLocalIds: string[];\n excludeKeys: string[];\n hasRebuilt: boolean;\n}> => {\n const appLogger = getAppLogger(configuration);\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const baseDir = configuration.content.baseDir;\n\n const relativeFilePath = relative(baseDir, filePath);\n const flatUnmergedDictionaries = Object.values(unmergedDictionaries).flat();\n\n const filteredUnmergedDictionaries = flatUnmergedDictionaries.filter(\n (dictionary) =>\n dictionary.filePath === relativeFilePath &&\n !keysToKeep.includes(dictionary.key)\n );\n\n // Deduplicate dictionaries by key\n const uniqueUnmergedDictionaries = filteredUnmergedDictionaries.filter(\n (dictionary, index, self) =>\n index === self.findIndex((t) => t.key === dictionary.key)\n );\n\n const changedDictionariesLocalIds: string[] = [];\n const filesToRemove: string[] = [];\n const excludeKeys: string[] = [];\n\n // Identify Unmerged Dictionaries to remove or clean\n await Promise.all(\n uniqueUnmergedDictionaries.map(async (dictionary) => {\n const unmergedFilePath = normalize(\n join(\n configuration.content.unmergedDictionariesDir,\n `${dictionary.key}.json`\n )\n );\n\n try {\n const jsonContent = await readFile(unmergedFilePath, 'utf8');\n const parsedContent = JSON.parse(jsonContent);\n\n if (parsedContent.length === 1) {\n if (parsedContent[0].filePath === relativeFilePath) {\n appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n { isVerbose: true }\n );\n filesToRemove.push(unmergedFilePath);\n excludeKeys.push(dictionary.key);\n }\n } else {\n const filteredContent = parsedContent.filter(\n (content: any) => content.filePath !== relativeFilePath\n );\n await writeJsonIfChanged(unmergedFilePath, filteredContent);\n changedDictionariesLocalIds.push(dictionary.localId!);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n }\n }\n })\n );\n\n const dictionaries = getDictionaries(configuration);\n const flatDictionaries = Object.values(dictionaries) as Dictionary[];\n\n const filteredMergedDictionaries = flatDictionaries?.filter(\n (dictionary) =>\n !keysToKeep.includes(dictionary.key) &&\n dictionary.localIds?.length === 1 &&\n (dictionary.localIds[0] as string).endsWith(\n `::local::${relativeFilePath}`\n )\n );\n\n const uniqueMergedDictionaries = filteredMergedDictionaries.filter(\n (dictionary, index, self) =>\n index === self.findIndex((t) => t.key === dictionary.key)\n );\n\n // Identify Merged Dictionaries, Types, and Dynamic Dictionaries to remove\n await Promise.all(\n uniqueMergedDictionaries.map(async (dictionary) => {\n const mergedFilePath = normalize(\n join(configuration.content.dictionariesDir, `${dictionary.key}.json`)\n );\n\n try {\n const fileContent = await readFile(mergedFilePath, 'utf8');\n const parsedContent = JSON.parse(fileContent) as Dictionary;\n\n if (parsedContent.localIds?.length === 1) {\n if (\n parsedContent.localIds[0].endsWith(`::local::${relativeFilePath}`)\n ) {\n appLogger(\n `Removing outdated unmerged dictionary ${colorizeKey(dictionary.key)}`,\n { isVerbose: true }\n );\n\n // Mark JSON for removal\n filesToRemove.push(mergedFilePath);\n\n // Mark TS Types for removal\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n filesToRemove.push(typesFilePath);\n\n // Mark Dynamic Dictionaries for removal\n // We use glob to catch the loader files (.cjs, .mjs) AND the split locale files (.en.json, etc.)\n const dynamicFilesGlob = join(\n configuration.content.dynamicDictionariesDir,\n `${dictionary.key}.*`\n );\n const dynamicFiles = await fg(normalizePath(dynamicFilesGlob), {\n absolute: true,\n });\n filesToRemove.push(...dynamicFiles);\n\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n }\n } else {\n const localIds = parsedContent.localIds?.filter(\n (localeId) => !localeId.endsWith(`::local::${relativeFilePath}`)\n ) as string[];\n const newContent = { ...parsedContent, localIds };\n await writeJsonIfChanged(mergedFilePath, newContent);\n }\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n if (!excludeKeys.includes(dictionary.key)) {\n excludeKeys.push(dictionary.key);\n }\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n filesToRemove.push(typesFilePath);\n }\n }\n })\n );\n\n // Execute Cleanup\n if (filesToRemove.length > 0 || excludeKeys.length > 0) {\n // Update entry points (indexes) first so the app doesn't import dead files\n await createDictionaryEntryPoint(configuration, { excludeKeys });\n\n // Remove the files synchronously (awaited) immediately after.\n if (filesToRemove.length > 0) {\n await Promise.all(\n filesToRemove.map(async (path) => {\n const relativePath = relative(baseDir, path);\n try {\n await rm(path, { force: true });\n\n appLogger(`Deleted artifact: ${colorizePath(relativePath)}`, {\n isVerbose: true,\n });\n } catch {\n appLogger(\n `Error while removing file ${colorizePath(relativePath)}`,\n {\n isVerbose: true,\n }\n );\n }\n })\n );\n }\n }\n\n return {\n changedDictionariesLocalIds,\n excludeKeys,\n hasRebuilt: filesToRemove.length > 0 || excludeKeys.length > 0,\n };\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,iCAAiC,OAC5C,UACA,YACA,kBAKI;CACJ,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,uBAAuB,wBAAwB,cAAc;CAEnE,MAAM,UAAU,cAAc,QAAQ;CAEtC,MAAM,mBAAmB,SAAS,SAAS,SAAS;CAUpD,MAAM,6BAT2B,OAAO,OAAO,qBAAqB,CAAC,MAAM,CAEb,QAC3D,eACC,WAAW,aAAa,oBACxB,CAAC,WAAW,SAAS,WAAW,IAAI,CACvC,CAG+D,QAC7D,YAAY,OAAO,SAClB,UAAU,KAAK,WAAW,MAAM,EAAE,QAAQ,WAAW,IAAI,CAC5D;CAED,MAAM,8BAAwC,EAAE;CAChD,MAAM,gBAA0B,EAAE;CAClC,MAAM,cAAwB,EAAE;AAGhC,OAAM,QAAQ,IACZ,2BAA2B,IAAI,OAAO,eAAe;EACnD,MAAM,mBAAmB,UACvB,KACE,cAAc,QAAQ,yBACtB,GAAG,WAAW,IAAI,OACnB,CACF;AAED,MAAI;GACF,MAAM,cAAc,MAAM,SAAS,kBAAkB,OAAO;GAC5D,MAAM,gBAAgB,KAAK,MAAM,YAAY;AAE7C,OAAI,c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MAAM,GAAG,cAJL,KACvB,cAAc,QAAQ,wBACtB,GAAG,WAAW,IAAI,IACnB,CAC4D,EAAE,EAC7D,UAAU,MACX,CAAC;AACF,mBAAc,KAAK,GAAG,aAAa;AAEnC,SAAI,CAAC,YAAY,SAAS,WAAW,IAAI,CACvC,aAAY,KAAK,WAAW,IAAI;;UAG/B;IACL,MAAM,WAAW,cAAc,UAAU,QACtC,aAAa,CAAC,SAAS,SAAS,YAAY,mBAAmB,CACjE;AAED,UAAM,mBAAmB,gBADN;KAAE,GAAG;KAAe;KAAU,CACG;;WAE/C,OAAY;AACnB,OAAI,MAAM,SAAS,UAAU;AAC3B,QAAI,CAAC,YAAY,SAAS,WAAW,IAAI,CACvC,aAAY,KAAK,WAAW,IAAI;IAElC,MAAM,gBAAgB,UACpB,KAAK,cAAc,QAAQ,UAAU,GAAG,WAAW,IAAI,KAAK,CAC7D;AACD,kBAAc,KAAK,cAAc;;;GAGrC,CACH;AAGD,KAAI,cAAc,SAAS,KAAK,YAAY,SAAS,GAAG;AAEtD,QAAM,2BAA2B,eAAe,EAAE,aAAa,CAAC;AAGhE,MAAI,cAAc,SAAS,EACzB,OAAM,QAAQ,IACZ,cAAc,IAAI,OAAO,WAAS;GAChC,MAAM,eAAe,SAAS,SAASA,OAAK;AAC5C,OAAI;AACF,UAAM,GAAGA,QAAM,EAAE,OAAO,MAAM,CAAC;AAE/B,cAAU,qBAAqB,aAAa,aAAa,IAAI,EAC3D,WAAW,MACZ,CAAC;WACI;AACN,cACE,6BAA6B,aAAa,aAAa,IACvD,EACE,WAAW,MACZ,CACF;;IAEH,CACH;;AAIL,QAAO;EACL;EACA;EACA,YAAY,cAAc,SAAS,KAAK,YAAY,SAAS;EAC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateDictionaryListContent.mjs","names":[
|
|
1
|
+
{"version":3,"file":"generateDictionaryListContent.mjs","names":[],"sources":["../../../src/createDictionaryEntryPoint/generateDictionaryListContent.ts"],"sourcesContent":["import { basename, extname, relative } from 'node:path';\nimport { getConfiguration, normalizePath } from '@intlayer/config';\nimport { getFileHash } from '../utils/getFileHash';\n\n/**\n * This function generates the content of the dictionary list file\n */\nexport const generateDictionaryListContent = (\n dictionaries: string[],\n functionName: string,\n importType: 'json' | 'javascript',\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { mainDir } = configuration.content;\n\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: normalizePath(relative(mainDir, dictionaryPath)),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}'${importType === 'json' ? \" with { type: 'json' }\" : ''};\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n content += `const dictionaries = {\\n${formattedDictionaryMap}\\n};\\n`;\n content += `const ${functionName} = () => dictionaries;\\n`;\n\n if (format === 'esm') {\n content += `\\n`;\n content += `export { ${functionName} };\\n`;\n content += `export default dictionaries;\\n`;\n }\n\n if (format === 'cjs') {\n content += `\\n`;\n content += `module.exports.${functionName} = ${functionName};\\n`;\n content += `module.exports = dictionaries;\\n`;\n }\n\n return content;\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,iCACX,cACA,cACA,YACA,SAAwB,OACxB,gBAAgB,kBAAkB,KACvB;CACX,MAAM,EAAE,YAAY,cAAc;CAElC,IAAI,UAAU;CAEd,MAAM,kBAAkB,aAAa,KAAK,oBAAoB;EAC5D,cAAc,cAAc,SAAS,SAAS,eAAe,CAAC;EAC9D,IAAI,SAAS,gBAAgB,QAAQ,eAAe,CAAC;EACrD,MAAM,IAAI,YAAY,eAAe;EACtC,EAAE;AAGH,iBAAgB,SAAS,eAAe;AACtC,MAAI,WAAW,MACb,YAAW,UAAU,WAAW,KAAK,SAAS,WAAW,aAAa,GAAG,eAAe,SAAS,2BAA2B,GAAG;AACjI,MAAI,WAAW,MACb,YAAW,SAAS,WAAW,KAAK,cAAc,WAAW,aAAa;GAC5E;AAEF,YAAW;CAGX,MAAM,yBAAiC,gBACpC,KAAK,eAAe,MAAM,WAAW,GAAG,KAAK,WAAW,OAAO,CAC/D,KAAK,MAAM;AAEd,YAAW,2BAA2B,uBAAuB;AAC7D,YAAW,SAAS,aAAa;AAEjC,KAAI,WAAW,OAAO;AACpB,aAAW;AACX,aAAW,YAAY,aAAa;AACpC,aAAW;;AAGb,KAAI,WAAW,OAAO;AACpB,aAAW;AACX,aAAW,kBAAkB,aAAa,KAAK,aAAa;AAC5D,aAAW;;AAGb,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createModuleAugmentation.mjs","names":["
|
|
1
|
+
{"version":3,"file":"createModuleAugmentation.mjs","names":["requiredLocales"],"sources":["../../../src/createType/createModuleAugmentation.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { basename, extname, join, relative } from 'node:path';\nimport { kebabCaseToCamelCase, normalizePath } from '@intlayer/config';\nimport type { IntlayerConfig, Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { getFileHash } from '../utils/getFileHash';\nimport { writeFileIfChanged } from '../writeFileIfChanged';\n\nexport const getTypeName = (key: string): string =>\n `${kebabCaseToCamelCase(key)}Content`;\n\n/** Returns lines like: [Locales.FRENCH]: 1; */\nconst formatLocales = (locales: Locale[]) =>\n locales.map((locale) => ` \"${locale}\": 1;`).join('\\n');\n\n/** Generate the content of the module augmentation file */\nconst generateTypeIndexContent = (\n typeFiles: string[],\n configuration: IntlayerConfig\n): string => {\n const { content, internationalization } = configuration;\n const { moduleAugmentationDir } = content;\n const { locales, requiredLocales, strictMode } = internationalization;\n\n let fileContent = 'import \"intlayer\";\\n';\n\n // Build dictionary refs\n const dictionariesRef = typeFiles.map((dictionaryPath) => ({\n relativePath: `./${relative(moduleAugmentationDir, dictionaryPath)}`,\n id: basename(dictionaryPath, extname(dictionaryPath)),\n hash: `_${getFileHash(dictionaryPath)}`,\n }));\n\n // Import all dictionaries\n for (const dictionary of dictionariesRef) {\n fileContent += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n }\n fileContent += '\\n';\n\n // Dictionary map entries (id: typeof <hash>)\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": typeof ${dictionary.hash};`)\n .join('\\n');\n\n // Ensure required ⊆ declared; if empty, default required = declared\n const declared = locales;\n const requiredSanitized = requiredLocales?.length\n ? requiredLocales.filter((requiredLocales) =>\n declared.includes(requiredLocales)\n )\n : declared;\n\n const formattedDeclaredLocales = formatLocales(declared);\n const formattedRequiredLocales = formatLocales(requiredSanitized);\n\n // Choose strict mode registry key\n const strictKey =\n strictMode === 'strict'\n ? 'strict'\n : strictMode === 'inclusive'\n ? 'inclusive'\n : 'loose';\n\n /**\n * Module augmentation that ONLY adds keys to registries.\n * No types/aliases redefined here—avoids merge conflicts.\n */\n fileContent += `declare module 'intlayer' {\\n`;\n // Dictionaries registry\n fileContent += ` interface __DictionaryRegistry {\\n${formattedDictionaryMap}\\n }\\n\\n`;\n // Locales registries\n fileContent += ` interface __DeclaredLocalesRegistry {\\n${formattedDeclaredLocales}\\n }\\n\\n`;\n fileContent += ` interface __RequiredLocalesRegistry {\\n${formattedRequiredLocales}\\n }\\n\\n`;\n // Resolved strict mode (narrow the literal at build time)\n fileContent += ` interface __StrictModeRegistry { mode: '${strictKey}' }\\n`;\n fileContent += `}\\n`;\n\n return fileContent;\n};\n\n/** Generate the index file merging all the types */\nexport const createModuleAugmentation = async (\n configuration: IntlayerConfig\n) => {\n const { moduleAugmentationDir, typesDir } = configuration.content;\n\n await mkdir(moduleAugmentationDir, { recursive: true });\n\n const dictionariesTypesDefinitions: string[] = await fg(\n normalizePath(`${typesDir}/*.ts`),\n { ignore: ['**/*.d.ts'] }\n );\n\n const tsContent = generateTypeIndexContent(\n dictionariesTypesDefinitions,\n configuration\n );\n\n const tsFilePath = join(moduleAugmentationDir, 'intlayer.d.ts');\n await writeFileIfChanged(tsFilePath, tsContent);\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,eAAe,QAC1B,GAAG,qBAAqB,IAAI,CAAC;;AAG/B,MAAM,iBAAiB,YACrB,QAAQ,KAAK,WAAW,QAAQ,OAAO,OAAO,CAAC,KAAK,KAAK;;AAG3D,MAAM,4BACJ,WACA,kBACW;CACX,MAAM,EAAE,SAAS,yBAAyB;CAC1C,MAAM,EAAE,0BAA0B;CAClC,MAAM,EAAE,SAAS,iBAAiB,eAAe;CAEjD,IAAI,cAAc;CAGlB,MAAM,kBAAkB,UAAU,KAAK,oBAAoB;EACzD,cAAc,KAAK,SAAS,uBAAuB,eAAe;EAClE,IAAI,SAAS,gBAAgB,QAAQ,eAAe,CAAC;EACrD,MAAM,IAAI,YAAY,eAAe;EACtC,EAAE;AAGH,MAAK,MAAM,cAAc,gBACvB,gBAAe,UAAU,WAAW,KAAK,SAAS,WAAW,aAAa;AAE5E,gBAAe;CAGf,MAAM,yBAAiC,gBACpC,KAAK,eAAe,QAAQ,WAAW,GAAG,YAAY,WAAW,KAAK,GAAG,CACzE,KAAK,KAAK;CAGb,MAAM,WAAW;CACjB,MAAM,oBAAoB,iBAAiB,SACvC,gBAAgB,QAAQ,sBACtB,SAAS,SAASA,kBAAgB,CACnC,GACD;CAEJ,MAAM,2BAA2B,cAAc,SAAS;CACxD,MAAM,2BAA2B,cAAc,kBAAkB;CAGjE,MAAM,YACJ,eAAe,WACX,WACA,eAAe,cACb,cACA;;;;;AAMR,gBAAe;AAEf,gBAAe,uCAAuC,uBAAuB;AAE7E,gBAAe,4CAA4C,yBAAyB;AACpF,gBAAe,4CAA4C,yBAAyB;AAEpF,gBAAe,6CAA6C,UAAU;AACtE,gBAAe;AAEf,QAAO;;;AAIT,MAAa,2BAA2B,OACtC,kBACG;CACH,MAAM,EAAE,uBAAuB,aAAa,cAAc;AAE1D,OAAM,MAAM,uBAAuB,EAAE,WAAW,MAAM,CAAC;CAOvD,MAAM,YAAY,yBAL6B,MAAM,GACnD,cAAc,GAAG,SAAS,OAAO,EACjC,EAAE,QAAQ,CAAC,YAAY,EAAE,CAC1B,EAIC,cACD;AAGD,OAAM,mBADa,KAAK,uBAAuB,gBAAgB,EAC1B,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createType.mjs","names":[
|
|
1
|
+
{"version":3,"file":"createType.mjs","names":[],"sources":["../../../src/createType/createType.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { resolve } from 'node:path';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { parallelize } from '../utils/parallelize';\n\nexport const generateTypeScriptType = (dictionary: Dictionary) => {\n const jsonString = JSON.stringify(dictionary, null, 2);\n\n return `/* eslint-disable */\\nexport default ${jsonString} as const;\\n`;\n};\n/**\n * This function generates a TypeScript type definition from a JSON object\n */\nexport const createTypes = async (\n dictionaries: Dictionary[],\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const { content } = configuration;\n const { typesDir } = content;\n\n // Create type folders if they don't exist\n await mkdir(typesDir, { recursive: true });\n\n const results = await parallelize(\n dictionaries,\n async (dictionary): Promise<string | undefined> => {\n if (!dictionary.key) {\n return undefined;\n }\n\n const typeDefinition: string = generateTypeScriptType(dictionary);\n\n const outputPath: string = resolve(typesDir, `${dictionary.key}.ts`);\n\n await writeFile(outputPath, typeDefinition);\n\n return outputPath;\n }\n );\n\n return results.filter(Boolean) as string[];\n};\n"],"mappings":";;;;;AAKA,MAAa,0BAA0B,eAA2B;AAGhE,QAAO,wCAFY,KAAK,UAAU,YAAY,MAAM,EAAE,CAEI;;;;;AAK5D,MAAa,cAAc,OACzB,cACA,kBACsB;CACtB,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,aAAa;AAGrB,OAAM,MAAM,UAAU,EAAE,WAAW,MAAM,CAAC;AAmB1C,SAjBgB,MAAM,YACpB,cACA,OAAO,eAA4C;AACjD,MAAI,CAAC,WAAW,IACd;EAGF,MAAM,iBAAyB,uBAAuB,WAAW;EAEjE,MAAM,aAAqB,QAAQ,UAAU,GAAG,WAAW,IAAI,KAAK;AAEpE,QAAM,UAAU,YAAY,eAAe;AAE3C,SAAO;GAEV,EAEc,OAAO,QAAQ"}
|
package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContentDeclarationFileTemplate.mjs","names":["
|
|
1
|
+
{"version":3,"file":"getContentDeclarationFileTemplate.mjs","names":["key"],"sources":["../../../src/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.ts"],"sourcesContent":["import { readAsset } from 'utils:asset';\nimport { kebabCaseToCamelCase } from '@intlayer/config';\nimport type { Format } from '../utils/getFormatFromExtension';\n\nexport const getContentDeclarationFileTemplate = async (\n key: string,\n format: Format,\n fileParams: Record<string, any> = {}\n) => {\n let fileTemplate: string;\n\n switch (format) {\n case 'ts':\n fileTemplate = './tsTemplate.txt';\n break;\n case 'cjs':\n fileTemplate = './cjsTemplate.txt';\n break;\n case 'json':\n case 'jsonc':\n case 'json5':\n fileTemplate = './jsonTemplate.txt';\n break;\n default:\n fileTemplate = './esmTemplate.txt';\n break;\n }\n\n const fileContent = readAsset(fileTemplate);\n const camelCaseKey = kebabCaseToCamelCase(key);\n const nonCapitalizedCamelCaseKey =\n camelCaseKey.charAt(0).toLowerCase() + camelCaseKey.slice(1);\n\n const fileParamsString = Object.entries(fileParams)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)\n ? key\n : JSON.stringify(key);\n\n if (typeof value === 'object') {\n return `\\n ${formattedKey}: ${JSON.stringify(value)},`;\n }\n\n if (typeof value === 'boolean' || typeof value === 'number') {\n return `\\n ${formattedKey}: ${value},`;\n }\n\n if (typeof value === 'string') {\n return `\\n ${formattedKey}: ${JSON.stringify(value)},`;\n }\n\n return `\\n ${formattedKey}: ${value},`;\n })\n .join('');\n\n return fileContent\n .replace('{{key}}', key)\n .replaceAll('{{name}}', nonCapitalizedCamelCaseKey)\n .replace('{{fileParams}}', fileParamsString);\n};\n"],"mappings":";;;;AAIA,MAAa,oCAAoC,OAC/C,KACA,QACA,aAAkC,EAAE,KACjC;CACH,IAAI;AAEJ,SAAQ,QAAR;EACE,KAAK;AACH,kBAAe;AACf;EACF,KAAK;AACH,kBAAe;AACf;EACF,KAAK;EACL,KAAK;EACL,KAAK;AACH,kBAAe;AACf;EACF;AACE,kBAAe;AACf;;CAGJ,MAAM,cAAc,UAAU,aAAa;CAC3C,MAAM,eAAe,qBAAqB,IAAI;CAC9C,MAAM,6BACJ,aAAa,OAAO,EAAE,CAAC,aAAa,GAAG,aAAa,MAAM,EAAE;CAE9D,MAAM,mBAAmB,OAAO,QAAQ,WAAW,CAChD,QAAQ,GAAG,WAAW,UAAU,OAAU,CAC1C,KAAK,CAACA,OAAK,WAAW;EACrB,MAAM,eAAe,6BAA6B,KAAKA,MAAI,GACvDA,QACA,KAAK,UAAUA,MAAI;AAEvB,MAAI,OAAO,UAAU,SACnB,QAAO,OAAO,aAAa,IAAI,KAAK,UAAU,MAAM,CAAC;AAGvD,MAAI,OAAO,UAAU,aAAa,OAAO,UAAU,SACjD,QAAO,OAAO,aAAa,IAAI,MAAM;AAGvC,MAAI,OAAO,UAAU,SACnB,QAAO,OAAO,aAAa,IAAI,KAAK,UAAU,MAAM,CAAC;AAGvD,SAAO,OAAO,aAAa,IAAI,MAAM;GACrC,CACD,KAAK,GAAG;AAEX,QAAO,YACJ,QAAQ,WAAW,IAAI,CACvB,WAAW,YAAY,2BAA2B,CAClD,QAAQ,kBAAkB,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleContentDeclarationFileChange.mjs","names":[
|
|
1
|
+
{"version":3,"file":"handleContentDeclarationFileChange.mjs","names":[],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionaries = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n );\n const updatedDictionariesPaths = updatedDictionaries.map(\n (dictionary) => dictionary.dictionaryPath\n );\n\n const { excludeKeys, hasRebuilt } = await cleanRemovedContentDeclaration(\n filePath,\n localeDictionaries.map((dictionary) => dictionary.key),\n config\n );\n\n const hasNewDictionaries = updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n );\n\n // Rebuild Entry Point & Module Augmentation\n // These only need to be updated if the *list* of dictionaries changed (Add/Remove/Rename)\n if (hasRebuilt || hasNewDictionaries) {\n // If hasRebuilt is true, cleanRemovedContentDeclaration has already updated the entry point\n // to remove the old keys (and it likely included the new ones if they were already on disk).\n // If NOT hasRebuilt, we explicitly need to update the entry point to include the new dictionaries.\n if (!hasRebuilt) {\n await createDictionaryEntryPoint(config, { excludeKeys });\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n }\n\n // Rebuild Types\n // Always regenerate types when a file changes, as the content structure (interface) might have changed\n // even if the key is the same.\n const dictionariesToBuild = updatedDictionaries.map(\n (dictionary) => dictionary.dictionary\n );\n\n await createTypes(dictionariesToBuild, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (hasNewDictionaries) {\n await createModuleAugmentation(config);\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n }\n\n // Plugin transformation\n // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n for await (const plugin of config.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration: config,\n });\n }\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAGtC,WAAU,oBAAoB,WAAW,SAAS,IAAI,EACpD,WAAW,MACZ,CAAC;CAEF,MAAM,uBAAiC,MAAM,yBAAyB,OAAO;CAE7E,MAAM,qBAAqB,MAAM,sBAAsB,UAAU,OAAO;CAExE,MAAM,qBAAqB,MAAM,gBAAgB,oBAAoB,OAAO;CAC5E,MAAM,sBAAsB,OAAO,OACjC,oBAAoB,sBAAsB,EAAE,CAC7C;CACD,MAAM,2BAA2B,oBAAoB,KAClD,eAAe,WAAW,eAC5B;CAED,MAAM,EAAE,aAAa,eAAe,MAAM,+BACxC,UACA,mBAAmB,KAAK,eAAe,WAAW,IAAI,EACtD,OACD;CAED,MAAM,qBAAqB,yBAAyB,MACjD,0BACC,CAAC,qBAAqB,SAAS,sBAAsB,CACxD;AAID,KAAI,cAAc,oBAIhB;MAAI,CAAC,YAAY;AACf,SAAM,2BAA2B,QAAQ,EAAE,aAAa,CAAC;AACzD,aAAU,yBAAyB,EACjC,WAAW,MACZ,CAAC;;;AAWN,OAAM,YAJsB,oBAAoB,KAC7C,eAAe,WAAW,WAC5B,EAEsC,OAAO;AAC9C,WAAU,0BAA0B,EAClC,WAAW,MACZ,CAAC;AAEF,KAAI,oBAAoB;AACtB,QAAM,yBAAyB,OAAO;AACtC,YAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;;AAKJ,YAAW,MAAM,UAAU,OAAO,WAAW,EAAE,EAAE;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,QAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;IACD;GACD,eAAe;GAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleContentDeclarationFileMoved.mjs","names":[
|
|
1
|
+
{"version":3,"file":"handleContentDeclarationFileMoved.mjs","names":[],"sources":["../../src/handleContentDeclarationFileMoved.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileMoved = async (\n oldFilePath: string,\n newFilePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n appLogger(\n `File moved from ${formatPath(oldFilePath)} to ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n\n let keysToKeep: string[] = [];\n\n try {\n // Pre-load the new file to identify the keys inside it.\n // We need to pass these keys to the cleaner so it knows NOT to completely delete\n // the dictionary artifacts (types/json) if the key has simply moved to a new file.\n const newLocaleDictionaries = await loadLocalDictionaries(\n newFilePath,\n config\n );\n keysToKeep = newLocaleDictionaries.map((d) => d.key);\n } catch {\n appLogger(\n `Error parsing new file during move operation: ${formatPath(newFilePath)}`,\n {\n isVerbose: true,\n }\n );\n // Proceed with empty keysToKeep; this will result in the old dictionary being cleaned up\n // entirely, and the new one being re-created in the next step.\n }\n\n // Clean up the artifacts associated with the old file path.\n // By passing 'keysToKeep', we instruct the cleaner to remove the specific file association\n // (filePath reference) from the dictionaries, but preserve the dictionary Entry Point and Types\n // if the key is still present in the new file.\n await cleanRemovedContentDeclaration(oldFilePath, keysToKeep, config);\n\n // Process the new file.\n // This will add the new file association, rebuild the dictionary JSONs with the new path,\n // and ensure types and module augmentation are up to date.\n await handleContentDeclarationFileChange(newFilePath, config);\n};\n"],"mappings":";;;;;;;AAOA,MAAa,oCAAoC,OAC/C,aACA,aACA,WACG;CACH,MAAM,YAAY,aAAa,OAAO;AAEtC,WACE,mBAAmB,WAAW,YAAY,CAAC,MAAM,WAAW,YAAY,IACxE,EACE,WAAW,MACZ,CACF;CAED,IAAI,aAAuB,EAAE;AAE7B,KAAI;AAQF,gBAJ8B,MAAM,sBAClC,aACA,OACD,EACkC,KAAK,MAAM,EAAE,IAAI;SAC9C;AACN,YACE,iDAAiD,WAAW,YAAY,IACxE,EACE,WAAW,MACZ,CACF;;AASH,OAAM,+BAA+B,aAAa,YAAY,OAAO;AAKrE,OAAM,mCAAmC,aAAa,OAAO"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -35,9 +35,9 @@ import { prepareIntlayer } from "./prepareIntlayer.mjs";
|
|
|
35
35
|
import { reduceDictionaryContent } from "./reduceDictionaryContent/reduceDictionaryContent.mjs";
|
|
36
36
|
import { detectExportedComponentName } from "./writeContentDeclaration/detectExportedComponentName.mjs";
|
|
37
37
|
import { extractDictionaryKey } from "./transformFiles/extractDictionaryKey.mjs";
|
|
38
|
+
import { detectFormatCommand } from "./writeContentDeclaration/detectFormatCommand.mjs";
|
|
38
39
|
import { transformJSFile } from "./writeContentDeclaration/transformJSFile.mjs";
|
|
39
40
|
import { getExtensionFromFormat, getFormatFromExtension } from "./utils/getFormatFromExtension.mjs";
|
|
40
|
-
import { detectFormatCommand } from "./writeContentDeclaration/detectFormatCommand.mjs";
|
|
41
41
|
import { writeJSFile } from "./writeContentDeclaration/writeJSFile.mjs";
|
|
42
42
|
import { writeContentDeclaration } from "./writeContentDeclaration/writeContentDeclaration.mjs";
|
|
43
43
|
import { ATTRIBUTES_TO_EXTRACT, extractIntlayer, generateKey, shouldExtract, transformFiles } from "./transformFiles/transformFiles.mjs";
|
package/dist/esm/init/index.mjs
CHANGED
|
@@ -157,7 +157,7 @@ const initIntlayer = async (rootDir) => {
|
|
|
157
157
|
]) if (await exists(rootDir, file)) {
|
|
158
158
|
let content = await readFileFromRoot(rootDir, file);
|
|
159
159
|
if (!content.includes("next-intlayer")) {
|
|
160
|
-
content = `import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\n${content}`;
|
|
160
|
+
content = `import { withIntlayer } from 'next-intlayer/server'; // Add the plugin to the Next.js configuration\n${content}`;
|
|
161
161
|
await writeFileToRoot(rootDir, file, content);
|
|
162
162
|
logger(`${v} Injected import into ${colorizePath(file)}`);
|
|
163
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["packageJson: Record<string, any>"],"sources":["../../../src/init/index.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\nimport {\n exists,\n findTsConfigFiles,\n parseJSONWithComments,\n readFileFromRoot,\n writeFileToRoot,\n} from './utils';\n\n/**\n * Documentation URL Constants\n */\nconst DocumentationRouter = {\n NextJS: 'https://intlayer.org/doc/environment/nextjs.md',\n NextJS_15: 'https://intlayer.org/doc/environment/nextjs/15.md',\n NextJS_14: 'https://intlayer.org/doc/environment/nextjs/14.md',\n CRA: 'https://intlayer.org/doc/environment/create-react-app.md',\n Astro: 'https://intlayer.org/doc/environment/astro.md',\n ViteAndReact: 'https://intlayer.org/doc/environment/vite-and-react.md',\n ViteAndReact_ReactRouterV7:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7.md',\n ViteAndReact_ReactRouterV7_FSRoutes:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7-fs-routes.md',\n ViteAndVue: 'https://intlayer.org/doc/environment/vite-and-vue.md',\n ViteAndSolid: 'https://intlayer.org/doc/environment/vite-and-solid.md',\n ViteAndSvelte: 'https://intlayer.org/doc/environment/vite-and-svelte.md',\n ViteAndPreact: 'https://intlayer.org/doc/environment/vite-and-preact.md',\n TanStackRouter: 'https://intlayer.org/doc/environment/tanstack.md',\n NuxtAndVue: 'https://intlayer.org/doc/environment/nuxt-and-vue.md',\n Angular: 'https://intlayer.org/doc/environment/angular.md',\n SvelteKit: 'https://intlayer.org/doc/environment/sveltekit.md',\n ReactNativeAndExpo:\n 'https://intlayer.org/doc/environment/react-native-and-expo.md',\n Lynx: 'https://intlayer.org/doc/environment/lynx-and-react.md',\n Express: 'https://intlayer.org/doc/environment/express.md',\n NestJS: 'https://intlayer.org/doc/environment/nestjs.md',\n Fastify: 'https://intlayer.org/doc/environment/fastify.md',\n Default: 'https://intlayer.org/doc/get-started',\n\n // Check for competitors libs\n NextIntl: 'https://intlayer.org/blog/intlayer-with-next-intl.md',\n ReactI18Next: 'https://intlayer.org/blog/intlayer-with-react-i18next.md',\n ReactIntl: 'https://intlayer.org/blog/intlayer-with-react-intl.md',\n NextI18Next: 'https://intlayer.org/blog/intlayer-with-next-i18next.md',\n VueI18n: 'https://intlayer.org/blog/intlayer-with-vue-i18n.md',\n};\n\n/**\n * Helper: Detects the environment and returns the doc URL\n */\nconst getDocumentationUrl = (packageJson: any): string => {\n const deps = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n };\n\n /**\n * Helper to check if a version string matches a specific major version\n * Matches: \"15\", \"^15.0.0\", \"~15.2\", \"15.0.0-beta\"\n */\n const isVersion = (versionString: string, major: number): boolean => {\n if (!versionString || typeof versionString !== 'string') return false;\n const regex = new RegExp(`^[\\\\^~]?${major}(?:\\\\.|$)`);\n return regex.test(versionString);\n };\n\n // Mobile / Cross-platform\n if (deps['@lynx-js/react'] || deps['@lynx-js/core']) {\n return DocumentationRouter.Lynx;\n }\n if (deps['react-native'] || deps['expo']) {\n return DocumentationRouter.ReactNativeAndExpo;\n }\n\n // Meta-frameworks (Next, Nuxt, Astro, SvelteKit)\n if (deps['next']) {\n const version = deps['next'];\n\n if (isVersion(version, 14)) {\n return DocumentationRouter.NextJS_14;\n }\n\n if (isVersion(version, 15)) {\n return DocumentationRouter.NextJS_15;\n }\n\n return DocumentationRouter.NextJS;\n }\n\n if (deps['nuxt']) return DocumentationRouter.NuxtAndVue;\n if (deps['astro']) return DocumentationRouter.Astro;\n if (deps['@sveltejs/kit']) return DocumentationRouter.SvelteKit;\n\n // Routers (TanStack & React Router v7)\n if (deps['@tanstack/react-router']) {\n return DocumentationRouter.TanStackRouter;\n }\n\n // Check for React Router v7\n const reactRouterVersion = deps['react-router'];\n if (reactRouterVersion && typeof reactRouterVersion === 'string') {\n // Distinguish between standard v7 and v7 with FS routes\n if (deps['@react-router/fs-routes']) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7_FSRoutes;\n }\n\n // Use Regex to ensure it is v7\n if (isVersion(reactRouterVersion, 7)) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7;\n }\n }\n\n // Vite Ecosystem (General)\n if (deps['vite']) {\n if (deps['vue']) return DocumentationRouter.ViteAndVue;\n if (deps['solid-js']) return DocumentationRouter.ViteAndSolid;\n if (deps['svelte']) return DocumentationRouter.ViteAndSvelte;\n if (deps['preact']) return DocumentationRouter.ViteAndPreact;\n\n // Default to React if Vite is present but specific other frameworks aren't found\n return DocumentationRouter.ViteAndReact;\n }\n\n // Other Web Frameworks\n if (deps['react-scripts']) return DocumentationRouter.CRA;\n if (deps['@angular/core']) return DocumentationRouter.Angular;\n\n // Backend\n if (deps['@nestjs/core']) return DocumentationRouter.NestJS;\n if (deps['express']) return DocumentationRouter.Express;\n if (deps['fastify']) return DocumentationRouter.Fastify;\n\n // Competitor Libs (Migration Guides)\n // We check these last as specific environment setup is usually higher priority,\n // but if no specific framework logic matched (or as a fallback), we guide to migration.\n if (deps['next-intl']) return DocumentationRouter.NextIntl;\n if (deps['react-i18next'] || deps['i18next'])\n return DocumentationRouter.ReactI18Next;\n if (deps['react-intl']) return DocumentationRouter.ReactIntl;\n if (deps['next-i18next']) return DocumentationRouter.NextI18Next;\n if (deps['vue-i18n']) return DocumentationRouter.VueI18n;\n\n return DocumentationRouter.Default;\n};\n\n/**\n * MAIN LOGIC\n */\nexport const initIntlayer = async (rootDir: string) => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // READ PACKAGE.JSON\n const packageJsonPath = 'package.json';\n if (!(await exists(rootDir, packageJsonPath))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n const packageJsonContent = await readFileFromRoot(rootDir, packageJsonPath);\n let packageJson: Record<string, any>;\n try {\n packageJson = JSON.parse(packageJsonContent);\n } catch {\n logger(`${x} Could not parse ${colorizePath('package.json')}.`, {\n level: 'error',\n });\n process.exit(1);\n }\n\n // Determine the correct documentation URL based on dependencies\n const guideUrl = getDocumentationUrl(packageJson);\n\n // 2. CHECK .GITIGNORE\n const gitignorePath = '.gitignore';\n if (await exists(rootDir, gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(rootDir, gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // CHECK TSCONFIGS\n const tsConfigFiles = await findTsConfigFiles(rootDir);\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(rootDir, fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(rootDir, fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n let updated = false;\n\n if (!config.include) {\n // Skip if no include array (solution-style)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((pattern: string) =>\n pattern.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n await writeFileToRoot(\n rootDir,\n fileName,\n JSON.stringify(config, null, 2)\n );\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // INITIALIZE CONFIG FILE\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // CHECK VITE CONFIG\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n for (const file of viteConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // CHECK NEXT CONFIG\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n for (const file of nextConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\";\n\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // FINAL SUCCESS MESSAGE\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n logger([\n colorize('Next →', ANSIColors.MAGENTA),\n colorize(\n `Follow the instructions in the documentation to complete the setup:`,\n ANSIColors.GREY_LIGHT\n ),\n colorizePath(guideUrl),\n ]);\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,sBAAsB;CAC1B,QAAQ;CACR,WAAW;CACX,WAAW;CACX,KAAK;CACL,OAAO;CACP,cAAc;CACd,4BACE;CACF,qCACE;CACF,YAAY;CACZ,cAAc;CACd,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,YAAY;CACZ,SAAS;CACT,WAAW;CACX,oBACE;CACF,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CAGT,UAAU;CACV,cAAc;CACd,WAAW;CACX,aAAa;CACb,SAAS;CACV;;;;AAKD,MAAM,uBAAuB,gBAA6B;CACxD,MAAM,OAAO;EACX,GAAG,YAAY;EACf,GAAG,YAAY;EAChB;;;;;CAMD,MAAM,aAAa,eAAuB,UAA2B;AACnE,MAAI,CAAC,iBAAiB,OAAO,kBAAkB,SAAU,QAAO;AAEhE,0BADc,IAAI,OAAO,WAAW,MAAM,WAAW,EACxC,KAAK,cAAc;;AAIlC,KAAI,KAAK,qBAAqB,KAAK,iBACjC,QAAO,oBAAoB;AAE7B,KAAI,KAAK,mBAAmB,KAAK,QAC/B,QAAO,oBAAoB;AAI7B,KAAI,KAAK,SAAS;EAChB,MAAM,UAAU,KAAK;AAErB,MAAI,UAAU,SAAS,GAAG,CACxB,QAAO,oBAAoB;AAG7B,MAAI,UAAU,SA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ACD,WACE,GAAG,EAAE,WAAW,aAAa,SAAS,CAAC,4BACxC;;UAEG;AACN,UACE,GAAG,EAAE,6BAA6B,aAAa,SAAS,CAAC,wBAAwB,aAAa,0BAA0B,CAAC,aACzH,EAAE,OAAO,QAAQ,CAClB;;;AAOP,OAAM,WADS,cAAc,uBAAuB,uBAC3B,QAAQ;AAIjC,MAAK,MAAM,QADS;EAAC;EAAkB;EAAkB;EAAkB,CAEzE,KAAI,MAAM,OAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAM,iBAAiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAItC,aAAU,wFAAkB;AAC5B,SAAM,gBAAgB,SAAS,MAAM,QAAQ;AAC7C,UAAO,GAAG,EAAE,wBAAwB,aAAa,KAAK,GAAG;;AAE3D;;AAMJ,MAAK,MAAM,QADS;EAAC;EAAkB;EAAmB;EAAiB,CAEzE,KAAI,MAAM,OAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAM,iBAAiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAItC,aAAU,iGAAkB;AAC5B,SAAM,gBAAgB,SAAS,MAAM,QAAQ;AAC7C,UAAO,GAAG,EAAE,wBAAwB,aAAa,KAAK,GAAG;;AAE3D;;AAKJ,QAAO,GAAG,EAAE,GAAG,SAAS,iCAAiC,WAAW,MAAM,GAAG;AAC7E,QAAO;EACL,SAAS,UAAU,WAAW,QAAQ;EACtC,SACE,uEACA,WAAW,WACZ;EACD,aAAa,SAAS;EACvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/init/index.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\nimport {\n exists,\n findTsConfigFiles,\n parseJSONWithComments,\n readFileFromRoot,\n writeFileToRoot,\n} from './utils';\n\n/**\n * Documentation URL Constants\n */\nconst DocumentationRouter = {\n NextJS: 'https://intlayer.org/doc/environment/nextjs.md',\n NextJS_15: 'https://intlayer.org/doc/environment/nextjs/15.md',\n NextJS_14: 'https://intlayer.org/doc/environment/nextjs/14.md',\n CRA: 'https://intlayer.org/doc/environment/create-react-app.md',\n Astro: 'https://intlayer.org/doc/environment/astro.md',\n ViteAndReact: 'https://intlayer.org/doc/environment/vite-and-react.md',\n ViteAndReact_ReactRouterV7:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7.md',\n ViteAndReact_ReactRouterV7_FSRoutes:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7-fs-routes.md',\n ViteAndVue: 'https://intlayer.org/doc/environment/vite-and-vue.md',\n ViteAndSolid: 'https://intlayer.org/doc/environment/vite-and-solid.md',\n ViteAndSvelte: 'https://intlayer.org/doc/environment/vite-and-svelte.md',\n ViteAndPreact: 'https://intlayer.org/doc/environment/vite-and-preact.md',\n TanStackRouter: 'https://intlayer.org/doc/environment/tanstack.md',\n NuxtAndVue: 'https://intlayer.org/doc/environment/nuxt-and-vue.md',\n Angular: 'https://intlayer.org/doc/environment/angular.md',\n SvelteKit: 'https://intlayer.org/doc/environment/sveltekit.md',\n ReactNativeAndExpo:\n 'https://intlayer.org/doc/environment/react-native-and-expo.md',\n Lynx: 'https://intlayer.org/doc/environment/lynx-and-react.md',\n Express: 'https://intlayer.org/doc/environment/express.md',\n NestJS: 'https://intlayer.org/doc/environment/nestjs.md',\n Fastify: 'https://intlayer.org/doc/environment/fastify.md',\n Default: 'https://intlayer.org/doc/get-started',\n\n // Check for competitors libs\n NextIntl: 'https://intlayer.org/blog/intlayer-with-next-intl.md',\n ReactI18Next: 'https://intlayer.org/blog/intlayer-with-react-i18next.md',\n ReactIntl: 'https://intlayer.org/blog/intlayer-with-react-intl.md',\n NextI18Next: 'https://intlayer.org/blog/intlayer-with-next-i18next.md',\n VueI18n: 'https://intlayer.org/blog/intlayer-with-vue-i18n.md',\n};\n\n/**\n * Helper: Detects the environment and returns the doc URL\n */\nconst getDocumentationUrl = (packageJson: any): string => {\n const deps = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n };\n\n /**\n * Helper to check if a version string matches a specific major version\n * Matches: \"15\", \"^15.0.0\", \"~15.2\", \"15.0.0-beta\"\n */\n const isVersion = (versionString: string, major: number): boolean => {\n if (!versionString || typeof versionString !== 'string') return false;\n const regex = new RegExp(`^[\\\\^~]?${major}(?:\\\\.|$)`);\n return regex.test(versionString);\n };\n\n // Mobile / Cross-platform\n if (deps['@lynx-js/react'] || deps['@lynx-js/core']) {\n return DocumentationRouter.Lynx;\n }\n if (deps['react-native'] || deps['expo']) {\n return DocumentationRouter.ReactNativeAndExpo;\n }\n\n // Meta-frameworks (Next, Nuxt, Astro, SvelteKit)\n if (deps['next']) {\n const version = deps['next'];\n\n if (isVersion(version, 14)) {\n return DocumentationRouter.NextJS_14;\n }\n\n if (isVersion(version, 15)) {\n return DocumentationRouter.NextJS_15;\n }\n\n return DocumentationRouter.NextJS;\n }\n\n if (deps['nuxt']) return DocumentationRouter.NuxtAndVue;\n if (deps['astro']) return DocumentationRouter.Astro;\n if (deps['@sveltejs/kit']) return DocumentationRouter.SvelteKit;\n\n // Routers (TanStack & React Router v7)\n if (deps['@tanstack/react-router']) {\n return DocumentationRouter.TanStackRouter;\n }\n\n // Check for React Router v7\n const reactRouterVersion = deps['react-router'];\n if (reactRouterVersion && typeof reactRouterVersion === 'string') {\n // Distinguish between standard v7 and v7 with FS routes\n if (deps['@react-router/fs-routes']) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7_FSRoutes;\n }\n\n // Use Regex to ensure it is v7\n if (isVersion(reactRouterVersion, 7)) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7;\n }\n }\n\n // Vite Ecosystem (General)\n if (deps['vite']) {\n if (deps['vue']) return DocumentationRouter.ViteAndVue;\n if (deps['solid-js']) return DocumentationRouter.ViteAndSolid;\n if (deps['svelte']) return DocumentationRouter.ViteAndSvelte;\n if (deps['preact']) return DocumentationRouter.ViteAndPreact;\n\n // Default to React if Vite is present but specific other frameworks aren't found\n return DocumentationRouter.ViteAndReact;\n }\n\n // Other Web Frameworks\n if (deps['react-scripts']) return DocumentationRouter.CRA;\n if (deps['@angular/core']) return DocumentationRouter.Angular;\n\n // Backend\n if (deps['@nestjs/core']) return DocumentationRouter.NestJS;\n if (deps['express']) return DocumentationRouter.Express;\n if (deps['fastify']) return DocumentationRouter.Fastify;\n\n // Competitor Libs (Migration Guides)\n // We check these last as specific environment setup is usually higher priority,\n // but if no specific framework logic matched (or as a fallback), we guide to migration.\n if (deps['next-intl']) return DocumentationRouter.NextIntl;\n if (deps['react-i18next'] || deps['i18next'])\n return DocumentationRouter.ReactI18Next;\n if (deps['react-intl']) return DocumentationRouter.ReactIntl;\n if (deps['next-i18next']) return DocumentationRouter.NextI18Next;\n if (deps['vue-i18n']) return DocumentationRouter.VueI18n;\n\n return DocumentationRouter.Default;\n};\n\n/**\n * MAIN LOGIC\n */\nexport const initIntlayer = async (rootDir: string) => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // READ PACKAGE.JSON\n const packageJsonPath = 'package.json';\n if (!(await exists(rootDir, packageJsonPath))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n const packageJsonContent = await readFileFromRoot(rootDir, packageJsonPath);\n let packageJson: Record<string, any>;\n try {\n packageJson = JSON.parse(packageJsonContent);\n } catch {\n logger(`${x} Could not parse ${colorizePath('package.json')}.`, {\n level: 'error',\n });\n process.exit(1);\n }\n\n // Determine the correct documentation URL based on dependencies\n const guideUrl = getDocumentationUrl(packageJson);\n\n // 2. CHECK .GITIGNORE\n const gitignorePath = '.gitignore';\n if (await exists(rootDir, gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(rootDir, gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // CHECK TSCONFIGS\n const tsConfigFiles = await findTsConfigFiles(rootDir);\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(rootDir, fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(rootDir, fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n let updated = false;\n\n if (!config.include) {\n // Skip if no include array (solution-style)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((pattern: string) =>\n pattern.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n await writeFileToRoot(\n rootDir,\n fileName,\n JSON.stringify(config, null, 2)\n );\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // INITIALIZE CONFIG FILE\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // CHECK VITE CONFIG\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n for (const file of viteConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // CHECK NEXT CONFIG\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n for (const file of nextConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer/server'; // Add the plugin to the Next.js configuration\";\n\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // FINAL SUCCESS MESSAGE\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n logger([\n colorize('Next →', ANSIColors.MAGENTA),\n colorize(\n `Follow the instructions in the documentation to complete the setup:`,\n ANSIColors.GREY_LIGHT\n ),\n colorizePath(guideUrl),\n ]);\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,sBAAsB;CAC1B,QAAQ;CACR,WAAW;CACX,WAAW;CACX,KAAK;CACL,OAAO;CACP,cAAc;CACd,4BACE;CACF,qCACE;CACF,YAAY;CACZ,cAAc;CACd,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,YAAY;CACZ,SAAS;CACT,WAAW;CACX,oBACE;CACF,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CAGT,UAAU;CACV,cAAc;CACd,WAAW;CACX,aAAa;CACb,SAAS;CACV;;;;AAKD,MAAM,uBAAuB,gBAA6B;CACxD,MAAM,OAAO;EACX,GAAG,YAAY;EACf,GAAG,YAAY;EAChB;;;;;CAMD,MAAM,aAAa,eAAuB,UAA2B;AACnE,MAAI,CAAC,iBAAiB,OAAO,kBAAkB,SAAU,QAAO;AAEhE,0BADc,IAAI,OAAO,WAAW,MAAM,WAAW,EACxC,KAAK,cAAc;;AAIlC,KAAI,KAAK,qBAAqB,KAAK,iBACjC,QAAO,oBAAoB;AAE7B,KAAI,KA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