@intlayer/chokidar 7.5.0 → 7.5.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +2 -2
- package/dist/cjs/cleanRemovedContentDeclaration.cjs +67 -0
- package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -0
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +1 -1
- package/dist/cjs/createType/createModuleAugmentation.cjs +1 -1
- package/dist/cjs/createType/createType.cjs +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +1 -1
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +2 -2
- package/dist/cjs/handleContentDeclarationFileChange.cjs +8 -3
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +8 -3
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -1
- package/dist/cjs/index.cjs +5 -5
- package/dist/cjs/listGitFiles.cjs +1 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +1 -1
- package/dist/cjs/prepareIntlayer.cjs +2 -2
- package/dist/cjs/transformFiles/transformFiles.cjs +3 -3
- package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +1 -1
- package/dist/cjs/watcher.cjs +12 -3
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +7 -2
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +2 -2
- package/dist/esm/cleanRemovedContentDeclaration.mjs +66 -0
- package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -0
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +1 -1
- package/dist/esm/createType/createModuleAugmentation.mjs +1 -1
- package/dist/esm/createType/createType.mjs +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +1 -1
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs +2 -2
- package/dist/esm/handleContentDeclarationFileChange.mjs +8 -3
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +8 -3
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -1
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/listGitFiles.mjs +1 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +1 -1
- package/dist/esm/prepareIntlayer.mjs +2 -2
- package/dist/esm/transformFiles/transformFiles.mjs +3 -3
- package/dist/esm/transformFiles/transformFiles.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +1 -1
- package/dist/esm/watcher.mjs +12 -3
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +7 -2
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +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/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
- package/dist/types/cleanRemovedContentDeclaration.d.ts +7 -0
- package/dist/types/cleanRemovedContentDeclaration.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
- package/dist/types/formatDictionary.d.ts +15 -15
- package/dist/types/handleContentDeclarationFileChange.d.ts.map +1 -1
- package/dist/types/handleUnlinkedContentDeclarationFile.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/transformFiles/transformFiles.d.ts.map +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/dist/types/watcher.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -3,8 +3,8 @@ const require_buildIntlayerDictionary_writeDynamicDictionary = require('./writeD
|
|
|
3
3
|
const require_buildIntlayerDictionary_writeFetchDictionary = require('./writeFetchDictionary.cjs');
|
|
4
4
|
const require_buildIntlayerDictionary_writeMergedDictionary = require('./writeMergedDictionary.cjs');
|
|
5
5
|
const require_buildIntlayerDictionary_writeUnmergedDictionary = require('./writeUnmergedDictionary.cjs');
|
|
6
|
-
let _intlayer_config = require("@intlayer/config");
|
|
7
6
|
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
7
|
+
let _intlayer_config = require("@intlayer/config");
|
|
8
8
|
|
|
9
9
|
//#region src/buildIntlayerDictionary/buildIntlayerDictionary.ts
|
|
10
10
|
/**
|
|
@@ -3,8 +3,8 @@ const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
|
3
3
|
const require_writeFileIfChanged = require('../writeFileIfChanged.cjs');
|
|
4
4
|
const require_writeJsonIfChanged = require('../writeJsonIfChanged.cjs');
|
|
5
5
|
let node_fs_promises = require("node:fs/promises");
|
|
6
|
-
let _intlayer_config = require("@intlayer/config");
|
|
7
6
|
let node_path = require("node:path");
|
|
7
|
+
let _intlayer_config = require("@intlayer/config");
|
|
8
8
|
let _intlayer_core = require("@intlayer/core");
|
|
9
9
|
|
|
10
10
|
//#region src/buildIntlayerDictionary/writeDynamicDictionary.ts
|
|
@@ -2,8 +2,8 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
3
3
|
const require_writeFileIfChanged = require('../writeFileIfChanged.cjs');
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
-
let _intlayer_config = require("@intlayer/config");
|
|
6
5
|
let node_path = require("node:path");
|
|
6
|
+
let _intlayer_config = require("@intlayer/config");
|
|
7
7
|
|
|
8
8
|
//#region src/buildIntlayerDictionary/writeFetchDictionary.ts
|
|
9
9
|
/**
|
|
@@ -2,8 +2,8 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
3
3
|
const require_writeJsonIfChanged = require('../writeJsonIfChanged.cjs');
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
-
let _intlayer_config = require("@intlayer/config");
|
|
6
5
|
let node_path = require("node:path");
|
|
6
|
+
let _intlayer_config = require("@intlayer/config");
|
|
7
7
|
let _intlayer_core = require("@intlayer/core");
|
|
8
8
|
|
|
9
9
|
//#region src/buildIntlayerDictionary/writeMergedDictionary.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
3
|
-
const require_filterInvalidDictionaries = require('../filterInvalidDictionaries.cjs');
|
|
4
3
|
const require_writeJsonIfChanged = require('../writeJsonIfChanged.cjs');
|
|
4
|
+
const require_filterInvalidDictionaries = require('../filterInvalidDictionaries.cjs');
|
|
5
5
|
const require_buildIntlayerDictionary_writeUnmergedDictionary = require('./writeUnmergedDictionary.cjs');
|
|
6
6
|
const require_loadDictionaries_loadRemoteDictionaries = require('../loadDictionaries/loadRemoteDictionaries.cjs');
|
|
7
7
|
let node_fs_promises = require("node:fs/promises");
|
|
8
|
-
let _intlayer_config = require("@intlayer/config");
|
|
9
8
|
let node_path = require("node:path");
|
|
9
|
+
let _intlayer_config = require("@intlayer/config");
|
|
10
10
|
let _intlayer_core = require("@intlayer/core");
|
|
11
11
|
|
|
12
12
|
//#region src/buildIntlayerDictionary/writeRemoteDictionary.ts
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
3
|
-
const require_filterInvalidDictionaries = require('../filterInvalidDictionaries.cjs');
|
|
4
3
|
const require_writeJsonIfChanged = require('../writeJsonIfChanged.cjs');
|
|
4
|
+
const require_filterInvalidDictionaries = require('../filterInvalidDictionaries.cjs');
|
|
5
5
|
let node_fs_promises = require("node:fs/promises");
|
|
6
|
-
let _intlayer_config = require("@intlayer/config");
|
|
7
6
|
let node_path = require("node:path");
|
|
7
|
+
let _intlayer_config = require("@intlayer/config");
|
|
8
8
|
let _intlayer_core = require("@intlayer/core");
|
|
9
9
|
|
|
10
10
|
//#region src/buildIntlayerDictionary/writeUnmergedDictionary.ts
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
3
|
+
const require_createType_createType = require('./createType/createType.cjs');
|
|
4
|
+
const require_writeJsonIfChanged = require('./writeJsonIfChanged.cjs');
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
let _intlayer_config_client = require("@intlayer/config/client");
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
9
|
+
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
10
|
+
|
|
11
|
+
//#region src/cleanRemovedContentDeclaration.ts
|
|
12
|
+
const cleanRemovedContentDeclaration = async (filePath, key, configuration) => {
|
|
13
|
+
const appLogger = (0, _intlayer_config_client.getAppLogger)(configuration);
|
|
14
|
+
const unmergedDictionaries = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
|
|
15
|
+
const relativeFilePath = (0, node_path.relative)(configuration.content.baseDir, filePath);
|
|
16
|
+
const filteredUnmergedDictionaries = Object.values(unmergedDictionaries).flat().filter((dictionary) => dictionary.filePath === relativeFilePath && dictionary.key !== key);
|
|
17
|
+
const changedDictionariesLocalIds = [];
|
|
18
|
+
const removedDictionariesLocalIds = [];
|
|
19
|
+
const removedDictionariesKeys = [];
|
|
20
|
+
filteredUnmergedDictionaries.forEach(async (dictionary) => {
|
|
21
|
+
const unmergedFilePath = (0, node_path.normalize)((0, node_path.join)(configuration.content.unmergedDictionariesDir, `${dictionary.key}.json`));
|
|
22
|
+
try {
|
|
23
|
+
const jsonContent = await (0, node_fs_promises.readFile)(unmergedFilePath, "utf8");
|
|
24
|
+
const parsedContent = JSON.parse(jsonContent);
|
|
25
|
+
if (parsedContent.length === 1) {
|
|
26
|
+
appLogger(`Removing outdated dictionary ${(0, _intlayer_config_client.colorizeKey)(dictionary.key)}`, { isVerbose: true });
|
|
27
|
+
await (0, node_fs_promises.rm)(unmergedFilePath);
|
|
28
|
+
removedDictionariesLocalIds.push(dictionary.localId);
|
|
29
|
+
} else {
|
|
30
|
+
await require_writeJsonIfChanged.writeJsonIfChanged(unmergedFilePath, parsedContent.filter((content) => content.filePath !== relativeFilePath));
|
|
31
|
+
changedDictionariesLocalIds.push(dictionary.localId);
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
appLogger(`Error while processing unmerged dictionary file ${(0, _intlayer_config_client.colorizeKey)(dictionary.key)}`, { isVerbose: true });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const dictionaries = (0, _intlayer_dictionaries_entry.getDictionaries)(configuration);
|
|
38
|
+
const flatDictionaries = Object.values(dictionaries);
|
|
39
|
+
(flatDictionaries?.filter((dictionary) => dictionary.key !== key && dictionary.localIds?.length === 1 && dictionary.localIds[0].endsWith(`::local::${relativeFilePath}`))).forEach(async (dictionary) => {
|
|
40
|
+
const mergedFilePath = (0, node_path.normalize)((0, node_path.join)(configuration.content.dictionariesDir, `${dictionary.key}.json`));
|
|
41
|
+
try {
|
|
42
|
+
const fileContent = await (0, node_fs_promises.readFile)(mergedFilePath, "utf8");
|
|
43
|
+
const parsedContent = JSON.parse(fileContent);
|
|
44
|
+
if (parsedContent.localIds?.length === 1) {
|
|
45
|
+
appLogger(`Removing outdated dictionary ${(0, _intlayer_config_client.colorizeKey)(dictionary.key)}`, { isVerbose: true });
|
|
46
|
+
(0, node_fs_promises.rm)(mergedFilePath);
|
|
47
|
+
(0, node_fs_promises.rm)((0, node_path.normalize)((0, node_path.join)(configuration.content.typesDir, `${dictionary.key}.ts`)));
|
|
48
|
+
removedDictionariesKeys.push(dictionary.key);
|
|
49
|
+
} else {
|
|
50
|
+
const localIds = parsedContent.localIds?.filter((localeId) => localeId !== relativeFilePath);
|
|
51
|
+
await require_writeJsonIfChanged.writeJsonIfChanged(mergedFilePath, {
|
|
52
|
+
...parsedContent,
|
|
53
|
+
localIds
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
appLogger([`Error while processing merged dictionary file ${(0, _intlayer_config_client.colorizeKey)(dictionary.key)}`, error], { isVerbose: true });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
await require_createType_createType.createTypes(flatDictionaries.filter((dictionary) => !removedDictionariesKeys.includes(dictionary.key)).map((dictionary) => (0, node_path.join)(configuration.content.dictionariesDir, `${dictionary.key}.json`)), configuration);
|
|
61
|
+
await require_createDictionaryEntryPoint_createDictionaryEntryPoint.createDictionaryEntryPoint(configuration);
|
|
62
|
+
return changedDictionariesLocalIds;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.cleanRemovedContentDeclaration = cleanRemovedContentDeclaration;
|
|
67
|
+
//# sourceMappingURL=cleanRemovedContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanRemovedContentDeclaration.cjs","names":["changedDictionariesLocalIds: string[]","removedDictionariesLocalIds: string[]","removedDictionariesKeys: string[]","writeJsonIfChanged","createTypes","createDictionaryEntryPoint"],"sources":["../../src/cleanRemovedContentDeclaration.ts"],"sourcesContent":["import { readFile, rm } from 'node:fs/promises';\nimport { join, normalize, relative } from 'node:path';\nimport { colorizeKey, getAppLogger } 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 { createDictionaryEntryPoint } from './createDictionaryEntryPoint';\nimport { createTypes } from './createType';\nimport { writeJsonIfChanged } from './writeJsonIfChanged';\n\nexport const cleanRemovedContentDeclaration = async (\n filePath: string,\n key: string,\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const appLogger = getAppLogger(configuration);\n\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const relativeFilePath = relative(configuration.content.baseDir, filePath);\n const flatUnmergedDictionaries = Object.values(unmergedDictionaries).flat();\n\n const filteredUnmergedDictionaries = flatUnmergedDictionaries.filter(\n (dictionary) =>\n dictionary.filePath === relativeFilePath && dictionary.key !== key\n );\n\n const changedDictionariesLocalIds: string[] = [];\n const removedDictionariesLocalIds: string[] = [];\n const removedDictionariesKeys: string[] = [];\n\n filteredUnmergedDictionaries.forEach(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 appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n\n await rm(unmergedFilePath);\n\n removedDictionariesLocalIds.push(dictionary.localId!);\n } else {\n const filteredContent = parsedContent.filter(\n (content: any) => content.filePath !== relativeFilePath\n );\n\n await writeJsonIfChanged(unmergedFilePath, filteredContent);\n\n changedDictionariesLocalIds.push(dictionary.localId!);\n }\n } catch {\n appLogger(\n `Error while processing unmerged dictionary file ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n }\n });\n\n const dictionaries = getDictionaries(configuration);\n const flatDictionaries = Object.values(dictionaries);\n\n const filteredMergedDictionaries = flatDictionaries?.filter(\n (dictionary) =>\n dictionary.key !== key &&\n dictionary.localIds?.length === 1 &&\n (dictionary.localIds[0] as string).endsWith(\n `::local::${relativeFilePath}`\n )\n );\n\n filteredMergedDictionaries.forEach(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 appLogger(\n `Removing outdated dictionary ${colorizeKey(dictionary.key)}`,\n {\n isVerbose: true,\n }\n );\n\n rm(mergedFilePath);\n\n const typesFilePath = normalize(\n join(configuration.content.typesDir, `${dictionary.key}.ts`)\n );\n\n rm(typesFilePath);\n\n removedDictionariesKeys.push(dictionary.key);\n } else {\n const localIds = parsedContent.localIds?.filter(\n (localeId) => localeId !== relativeFilePath\n );\n\n const newContent = { ...parsedContent, localIds };\n\n await writeJsonIfChanged(mergedFilePath, newContent);\n }\n } catch (error) {\n appLogger(\n [\n `Error while processing merged dictionary file ${colorizeKey(dictionary.key)}`,\n error,\n ],\n {\n isVerbose: true,\n }\n );\n }\n });\n\n const dictionariesPaths = flatDictionaries\n .filter((dictionary) => !removedDictionariesKeys.includes(dictionary.key))\n .map((dictionary) =>\n join(configuration.content.dictionariesDir, `${dictionary.key}.json`)\n );\n\n await createTypes(dictionariesPaths, configuration);\n\n await createDictionaryEntryPoint(configuration);\n\n return changedDictionariesLocalIds;\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,iCAAiC,OAC5C,UACA,KACA,kBACsB;CACtB,MAAM,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AA4C,WAAW,IAAI,IAC3D,EACE,WAAW,MACZ,CACF;AAED,6BAAG,eAAe;AAMlB,0EAHO,cAAc,QAAQ,UAAU,GAAG,WAAW,IAAI,KAAK,CAC7D,CAEgB;AAEjB,4BAAwB,KAAK,WAAW,IAAI;UACvC;IACL,MAAM,WAAW,cAAc,UAAU,QACtC,aAAa,aAAa,iBAC5B;AAID,UAAMA,8CAAmB,gBAFN;KAAE,GAAG;KAAe;KAAU,CAEG;;WAE/C,OAAO;AACd,aACE,CACE,0FAA6D,WAAW,IAAI,IAC5E,MACD,EACD,EACE,WAAW,MACZ,CACF;;GAEH;AAQF,OAAMC,0CANoB,iBACvB,QAAQ,eAAe,CAAC,wBAAwB,SAAS,WAAW,IAAI,CAAC,CACzE,KAAK,mCACC,cAAc,QAAQ,iBAAiB,GAAG,WAAW,IAAI,OAAO,CACtE,EAEkC,cAAc;AAEnD,OAAMC,yFAA2B,cAAc;AAE/C,QAAO"}
|
|
@@ -8,8 +8,8 @@ const require_createDictionaryEntryPoint_getBuiltFetchDictionariesPath = require
|
|
|
8
8
|
const require_createDictionaryEntryPoint_getBuiltRemoteDictionariesPath = require('./getBuiltRemoteDictionariesPath.cjs');
|
|
9
9
|
const require_createDictionaryEntryPoint_getBuiltUnmergedDictionariesPath = require('./getBuiltUnmergedDictionariesPath.cjs');
|
|
10
10
|
let node_fs_promises = require("node:fs/promises");
|
|
11
|
-
let _intlayer_config = require("@intlayer/config");
|
|
12
11
|
let node_path = require("node:path");
|
|
12
|
+
let _intlayer_config = require("@intlayer/config");
|
|
13
13
|
|
|
14
14
|
//#region src/createDictionaryEntryPoint/createDictionaryEntryPoint.ts
|
|
15
15
|
const writeDictionaryFiles = async (paths, fileName, importType, functionName, format, configuration = (0, _intlayer_config.getConfiguration)()) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_getFileHash = require('../utils/getFileHash.cjs');
|
|
3
|
-
let _intlayer_config = require("@intlayer/config");
|
|
4
3
|
let node_path = require("node:path");
|
|
4
|
+
let _intlayer_config = require("@intlayer/config");
|
|
5
5
|
|
|
6
6
|
//#region src/createDictionaryEntryPoint/generateDictionaryListContent.ts
|
|
7
7
|
/**
|
|
@@ -2,8 +2,8 @@ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
|
2
2
|
const require_writeFileIfChanged = require('../writeFileIfChanged.cjs');
|
|
3
3
|
const require_utils_getFileHash = require('../utils/getFileHash.cjs');
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
-
let _intlayer_config = require("@intlayer/config");
|
|
6
5
|
let node_path = require("node:path");
|
|
6
|
+
let _intlayer_config = require("@intlayer/config");
|
|
7
7
|
let fast_glob = require("fast-glob");
|
|
8
8
|
fast_glob = require_rolldown_runtime.__toESM(fast_glob);
|
|
9
9
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_parallelize = require('../utils/parallelize.cjs');
|
|
3
3
|
let node_fs_promises = require("node:fs/promises");
|
|
4
|
-
let _intlayer_config = require("@intlayer/config");
|
|
5
4
|
let node_path = require("node:path");
|
|
5
|
+
let _intlayer_config = require("@intlayer/config");
|
|
6
6
|
|
|
7
7
|
//#region src/createType/createType.ts
|
|
8
8
|
const generateTypeScriptType = (dictionary) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_utils_parallelize = require('./utils/parallelize.cjs');
|
|
3
|
-
let _intlayer_api = require("@intlayer/api");
|
|
4
3
|
let _intlayer_config = require("@intlayer/config");
|
|
4
|
+
let _intlayer_api = require("@intlayer/api");
|
|
5
5
|
|
|
6
6
|
//#region src/fetchDistantDictionaries.ts
|
|
7
7
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
3
|
-
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
4
2
|
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
5
3
|
const require_createType_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
|
|
6
4
|
const require_createType_createType = require('./createType/createType.cjs');
|
|
5
|
+
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
6
|
+
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
7
7
|
const require_loadDictionaries_loadLocalDictionaries = require('./loadDictionaries/loadLocalDictionaries.cjs');
|
|
8
8
|
let _intlayer_config = require("@intlayer/config");
|
|
9
9
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
3
|
-
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
4
2
|
const require_createDictionaryEntryPoint_getBuiltDictionariesPath = require('./createDictionaryEntryPoint/getBuiltDictionariesPath.cjs');
|
|
5
3
|
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
6
4
|
const require_createType_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
|
|
7
5
|
const require_createType_createType = require('./createType/createType.cjs');
|
|
6
|
+
const require_cleanRemovedContentDeclaration = require('./cleanRemovedContentDeclaration.cjs');
|
|
7
|
+
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
8
|
+
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
8
9
|
const require_loadDictionaries_loadLocalDictionaries = require('./loadDictionaries/loadLocalDictionaries.cjs');
|
|
9
10
|
let _intlayer_config = require("@intlayer/config");
|
|
10
11
|
|
|
@@ -12,7 +13,11 @@ let _intlayer_config = require("@intlayer/config");
|
|
|
12
13
|
const handleContentDeclarationFileChange = async (filePath, config) => {
|
|
13
14
|
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
14
15
|
appLogger(`Change detected: ${require_utils_formatter.formatPath(filePath)}`, { isVerbose: true });
|
|
15
|
-
const
|
|
16
|
+
const localeDictionaries = await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries(filePath, config);
|
|
17
|
+
localeDictionaries.forEach(async (dictionary) => {
|
|
18
|
+
await require_cleanRemovedContentDeclaration.cleanRemovedContentDeclaration(filePath, dictionary.key, config);
|
|
19
|
+
});
|
|
20
|
+
const dictionariesOutput = await require_buildIntlayerDictionary_buildIntlayerDictionary.buildDictionary(localeDictionaries, config);
|
|
16
21
|
const updatedDictionariesPaths = Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath);
|
|
17
22
|
const allDictionariesPaths = await require_createDictionaryEntryPoint_getBuiltDictionariesPath.getBuiltDictionariesPath(config);
|
|
18
23
|
require_createType_createType.createTypes(updatedDictionariesPaths, config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleContentDeclarationFileChange.cjs","names":["formatPath","
|
|
1
|
+
{"version":3,"file":"handleContentDeclarationFileChange.cjs","names":["formatPath","loadLocalDictionaries","cleanRemovedContentDeclaration","buildDictionary","allDictionariesPaths: string[]","getBuiltDictionariesPath","createDictionaryEntryPoint"],"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 localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n localeDictionaries.forEach(async (dictionary) => {\n await cleanRemovedContentDeclaration(filePath, dictionary.key, config);\n });\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n const updatedDictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n createTypes(updatedDictionariesPaths, config);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n await createDictionaryEntryPoint(config);\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n\n createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\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,+CAAyB,OAAO;AAGtC,WAAU,oBAAoBA,mCAAW,SAAS,IAAI,EACpD,WAAW,MACZ,CAAC;CAEF,MAAM,qBAAqB,MAAMC,qEAAsB,UAAU,OAAO;AAExE,oBAAmB,QAAQ,OAAO,eAAe;AAC/C,QAAMC,sEAA+B,UAAU,WAAW,KAAK,OAAO;GACtE;CAEF,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,OAAO;CAC5E,MAAM,2BAA2B,OAAO,OACtC,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe;CAEhD,MAAMC,uBAAiC,MAAMC,qFAAyB,OAAO;AAE7E,2CAAY,0BAA0B,OAAO;AAC7C,WAAU,0BAA0B,EAClC,WAAW,MACZ,CAAC;AAEF,KACE,yBAAyB,MACtB,0BACC,CAAC,qBAAqB,SAAS,sBAAsB,CACxD,EACD;AACA,QAAMC,yFAA2B,OAAO;AAExC,YAAU,yBAAyB,EACjC,WAAW,MACZ,CAAC;;AAGJ,sEAAyB,OAAO;AAEhC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,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,9 +1,10 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
3
|
-
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
4
2
|
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
5
3
|
const require_createType_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
|
|
6
4
|
const require_createType_createType = require('./createType/createType.cjs');
|
|
5
|
+
const require_cleanRemovedContentDeclaration = require('./cleanRemovedContentDeclaration.cjs');
|
|
6
|
+
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
7
|
+
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
7
8
|
const require_loadDictionaries_loadLocalDictionaries = require('./loadDictionaries/loadLocalDictionaries.cjs');
|
|
8
9
|
const require_listDictionariesPath = require('./listDictionariesPath.cjs');
|
|
9
10
|
let _intlayer_config = require("@intlayer/config");
|
|
@@ -12,7 +13,11 @@ let _intlayer_config = require("@intlayer/config");
|
|
|
12
13
|
const handleUnlinkedContentDeclarationFile = async (filePath, config) => {
|
|
13
14
|
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
14
15
|
appLogger(`Unlinked detected: ${require_utils_formatter.formatPath(filePath)}`, { isVerbose: true });
|
|
15
|
-
const
|
|
16
|
+
const localeDictionaries = await require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries(await require_listDictionariesPath.listDictionaries(config), config);
|
|
17
|
+
localeDictionaries.forEach(async (dictionary) => {
|
|
18
|
+
await require_cleanRemovedContentDeclaration.cleanRemovedContentDeclaration(filePath, dictionary.key, config);
|
|
19
|
+
});
|
|
20
|
+
const dictionariesOutput = await require_buildIntlayerDictionary_buildIntlayerDictionary.buildDictionary(localeDictionaries, config);
|
|
16
21
|
await require_createType_createType.createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath), config);
|
|
17
22
|
await require_createDictionaryEntryPoint_createDictionaryEntryPoint.createDictionaryEntryPoint();
|
|
18
23
|
appLogger("Dictionaries rebuilt", { isVerbose: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUnlinkedContentDeclarationFile.cjs","names":["formatPath","
|
|
1
|
+
{"version":3,"file":"handleUnlinkedContentDeclarationFile.cjs","names":["formatPath","loadLocalDictionaries","listDictionaries","cleanRemovedContentDeclaration","buildDictionary","createTypes","createDictionaryEntryPoint","createModuleAugmentation"],"sources":["../../src/handleUnlinkedContentDeclarationFile.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 { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { listDictionaries } from './listDictionariesPath';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleUnlinkedContentDeclarationFile = async (\n filePath: string,\n config: IntlayerConfig\n) => {\n const appLogger = getAppLogger(config);\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${formatPath(filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = await listDictionaries(config);\n\n const localeDictionaries = await loadLocalDictionaries(files, config);\n\n localeDictionaries.forEach(async (dictionary) => {\n await cleanRemovedContentDeclaration(filePath, dictionary.key, config);\n });\n\n const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths, config);\n\n await createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n await createModuleAugmentation(config);\n\n appLogger('Module augmentation built', {\n isVerbose: true,\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,uCAAuC,OAClD,UACA,WACG;CACH,MAAM,+CAAyB,OAAO;AAGtC,WAAU,sBAAsBA,mCAAW,SAAS,IAAI,EACtD,WAAW,MACZ,CAAC;CAIF,MAAM,qBAAqB,MAAMC,qEAFT,MAAMC,8CAAiB,OAAO,EAEQ,OAAO;AAErE,oBAAmB,QAAQ,OAAO,eAAe;AAC/C,QAAMC,sEAA+B,UAAU,WAAW,KAAK,OAAO;GACtE;CAEF,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,OAAO;AAM5E,OAAMC,0CAJoB,OAAO,OAC/B,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe,EAEX,OAAO;AAE5C,OAAMC,0FAA4B;AAElC,WAAU,wBAAwB,EAChC,WAAW,MACZ,CAAC;AAEF,OAAMC,qEAAyB,OAAO;AAEtC,WAAU,6BAA6B,EACrC,WAAW,MACZ,CAAC;AAIF,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"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
const require_cleanOutputDir = require('./cleanOutputDir.cjs');
|
|
2
2
|
const require_utils_pLimit = require('./utils/pLimit.cjs');
|
|
3
3
|
const require_utils_parallelize = require('./utils/parallelize.cjs');
|
|
4
|
-
const require_fetchDistantDictionaries = require('./fetchDistantDictionaries.cjs');
|
|
5
|
-
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
6
|
-
const require_filterInvalidDictionaries = require('./filterInvalidDictionaries.cjs');
|
|
7
|
-
const require_formatDictionary = require('./formatDictionary.cjs');
|
|
8
|
-
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
9
4
|
const require_utils_getFileHash = require('./utils/getFileHash.cjs');
|
|
10
5
|
const require_createDictionaryEntryPoint_generateDictionaryListContent = require('./createDictionaryEntryPoint/generateDictionaryListContent.cjs');
|
|
11
6
|
const require_createDictionaryEntryPoint_getBuiltDictionariesPath = require('./createDictionaryEntryPoint/getBuiltDictionariesPath.cjs');
|
|
@@ -16,6 +11,11 @@ const require_createDictionaryEntryPoint_getBuiltUnmergedDictionariesPath = requ
|
|
|
16
11
|
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
17
12
|
const require_createType_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
|
|
18
13
|
const require_createType_createType = require('./createType/createType.cjs');
|
|
14
|
+
const require_fetchDistantDictionaries = require('./fetchDistantDictionaries.cjs');
|
|
15
|
+
const require_utils_formatter = require('./utils/formatter.cjs');
|
|
16
|
+
const require_filterInvalidDictionaries = require('./filterInvalidDictionaries.cjs');
|
|
17
|
+
const require_formatDictionary = require('./formatDictionary.cjs');
|
|
18
|
+
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
19
19
|
const require_utils_resolveObjectPromises = require('./utils/resolveObjectPromises.cjs');
|
|
20
20
|
const require_loadDictionaries_loadContentDeclaration = require('./loadDictionaries/loadContentDeclaration.cjs');
|
|
21
21
|
const require_loadDictionaries_loadLocalDictionaries = require('./loadDictionaries/loadLocalDictionaries.cjs');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let node_fs = require("node:fs");
|
|
3
|
-
let _intlayer_config = require("@intlayer/config");
|
|
4
3
|
let node_path = require("node:path");
|
|
4
|
+
let _intlayer_config = require("@intlayer/config");
|
|
5
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
6
|
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
7
7
|
let simple_git = require("simple-git");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let node_fs_promises = require("node:fs/promises");
|
|
3
|
-
let _intlayer_config = require("@intlayer/config");
|
|
4
3
|
let node_path = require("node:path");
|
|
4
|
+
let _intlayer_config = require("@intlayer/config");
|
|
5
5
|
let node_module = require("node:module");
|
|
6
6
|
|
|
7
7
|
//#region src/loadDictionaries/getIntlayerBundle.ts
|
|
@@ -4,8 +4,8 @@ const require_filterInvalidDictionaries = require('../filterInvalidDictionaries.
|
|
|
4
4
|
const require_buildIntlayerDictionary_processContentDeclaration = require('../buildIntlayerDictionary/processContentDeclaration.cjs');
|
|
5
5
|
const require_loadDictionaries_getIntlayerBundle = require('./getIntlayerBundle.cjs');
|
|
6
6
|
let node_fs_promises = require("node:fs/promises");
|
|
7
|
-
let _intlayer_config = require("@intlayer/config");
|
|
8
7
|
let node_path = require("node:path");
|
|
8
|
+
let _intlayer_config = require("@intlayer/config");
|
|
9
9
|
|
|
10
10
|
//#region src/loadDictionaries/loadContentDeclaration.ts
|
|
11
11
|
const formatLocalDictionaries = (dictionariesRecord, configuration) => Object.entries(dictionariesRecord).filter(([_relativePath, dict]) => require_filterInvalidDictionaries.isInvalidDictionary(dict, configuration)).map(([relativePath, dict]) => ({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_fetchDistantDictionaries = require('../fetchDistantDictionaries.cjs');
|
|
3
3
|
const require_utils_sortAlphabetically = require('../utils/sortAlphabetically.cjs');
|
|
4
|
-
let _intlayer_api = require("@intlayer/api");
|
|
5
4
|
let _intlayer_config = require("@intlayer/config");
|
|
5
|
+
let _intlayer_api = require("@intlayer/api");
|
|
6
6
|
let _intlayer_remote_dictionaries_entry = require("@intlayer/remote-dictionaries-entry");
|
|
7
7
|
|
|
8
8
|
//#region src/loadDictionaries/loadRemoteDictionaries.ts
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_cleanOutputDir = require('./cleanOutputDir.cjs');
|
|
3
|
-
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
4
3
|
const require_createDictionaryEntryPoint_createDictionaryEntryPoint = require('./createDictionaryEntryPoint/createDictionaryEntryPoint.cjs');
|
|
5
4
|
const require_createType_createModuleAugmentation = require('./createType/createModuleAugmentation.cjs');
|
|
6
5
|
const require_createType_createType = require('./createType/createType.cjs');
|
|
6
|
+
const require_buildIntlayerDictionary_buildIntlayerDictionary = require('./buildIntlayerDictionary/buildIntlayerDictionary.cjs');
|
|
7
7
|
const require_listDictionariesPath = require('./listDictionariesPath.cjs');
|
|
8
8
|
const require_loadDictionaries_loadDictionaries = require('./loadDictionaries/loadDictionaries.cjs');
|
|
9
9
|
const require_buildIntlayerDictionary_writeRemoteDictionary = require('./buildIntlayerDictionary/writeRemoteDictionary.cjs');
|
|
10
10
|
const require_utils_runOnce = require('./utils/runOnce.cjs');
|
|
11
11
|
const require_writeConfiguration_index = require('./writeConfiguration/index.cjs');
|
|
12
12
|
let node_fs_promises = require("node:fs/promises");
|
|
13
|
-
let _intlayer_config = require("@intlayer/config");
|
|
14
13
|
let node_path = require("node:path");
|
|
14
|
+
let _intlayer_config = require("@intlayer/config");
|
|
15
15
|
let _intlayer_config_package_json = require("@intlayer/config/package.json");
|
|
16
16
|
_intlayer_config_package_json = require_rolldown_runtime.__toESM(_intlayer_config_package_json);
|
|
17
17
|
|
|
@@ -4,8 +4,8 @@ const require_writeContentDeclaration_detectFormatCommand = require('../writeCon
|
|
|
4
4
|
const require_writeContentDeclaration_writeContentDeclaration = require('../writeContentDeclaration/writeContentDeclaration.cjs');
|
|
5
5
|
let node_fs_promises = require("node:fs/promises");
|
|
6
6
|
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
|
|
7
|
-
let _intlayer_config = require("@intlayer/config");
|
|
8
7
|
let node_path = require("node:path");
|
|
8
|
+
let _intlayer_config = require("@intlayer/config");
|
|
9
9
|
let node_child_process = require("node:child_process");
|
|
10
10
|
let ts_morph = require("ts-morph");
|
|
11
11
|
|
|
@@ -46,11 +46,11 @@ const generateKey = (text, existingKeys) => {
|
|
|
46
46
|
};
|
|
47
47
|
const writeContentHelper = async (extractedContent, componentKey, filePath, configuration, outputDir) => {
|
|
48
48
|
const { defaultLocale } = configuration.internationalization;
|
|
49
|
-
const { baseDir } = configuration.content;
|
|
49
|
+
const { baseDir, fileExtensions } = configuration.content;
|
|
50
50
|
const isPerLocaleFile = configuration?.dictionary?.locale;
|
|
51
51
|
const dirName = outputDir ? (0, node_path.resolve)(outputDir) : (0, node_path.dirname)(filePath);
|
|
52
52
|
const baseName = (0, node_path.basename)(filePath, (0, node_path.extname)(filePath));
|
|
53
|
-
const contentFilePath = (0, node_path.join)(dirName, `${baseName.charAt(0).toLowerCase() + baseName.slice(1)}
|
|
53
|
+
const contentFilePath = (0, node_path.join)(dirName, `${baseName.charAt(0).toLowerCase() + baseName.slice(1)}.${fileExtensions[0]}`);
|
|
54
54
|
const relativeContentFilePath = (0, node_path.relative)(baseDir, contentFilePath);
|
|
55
55
|
let dictionary;
|
|
56
56
|
if (isPerLocaleFile) dictionary = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformFiles.cjs","names":["dictionary: Dictionary","multilingualContent: Record<string, TranslationNode>","writeContentDeclaration","extractedContent: Record<string, string>","replacements: TsReplacement[]","Node","sourceFile: SourceFile","SyntaxKind","Project","extractDictionaryKey","fs","extractedContent: Record<string, string> | null","error: any","ANSIColors","detectFormatCommand"],"sources":["../../../src/transformFiles/transformFiles.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\nimport {\n ANSIColors,\n camelCaseToKebabCase,\n colorizePath,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';\nimport { writeContentDeclaration } from '../writeContentDeclaration';\nimport { detectFormatCommand } from '../writeContentDeclaration/detectFormatCommand';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\n// ==========================================\n// 1. Shared Utilities (exported for reuse in babel plugin)\n// ==========================================\n\n/**\n * Attributes that should be extracted for localization\n */\nexport const ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\n/**\n * Default function to determine if a string should be extracted for localization\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n if (!trimmed) return false;\n if (!trimmed.includes(' ')) return false;\n // Starts with Capital letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n // Filter out template logic identifiers (simple check)\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n return true;\n};\n\n/**\n * Generate a unique key from text for use as a dictionary key\n */\nexport const generateKey = (\n text: string,\n existingKeys: Set<string>\n): string => {\n const maxWords = 5;\n let key = text\n .replace(/\\s+/g, ' ')\n .replace(/_+/g, ' ')\n .replace(/-+/g, ' ')\n .replace(/[^a-zA-Z0-9 ]/g, '')\n .trim()\n .split(' ')\n .filter(Boolean)\n .slice(0, maxWords)\n .map((word, index) =>\n index === 0\n ? word.toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n )\n .join('');\n\n if (!key) key = 'content';\n if (existingKeys.has(key)) {\n let i = 1;\n while (existingKeys.has(`${key}${i}`)) i++;\n key = `${key}${i}`;\n }\n return key;\n};\n\n/**\n * Translation node structure used in multilingual dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\nconst writeContentHelper = async (\n extractedContent: Record<string, string>,\n componentKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n outputDir?: string\n) => {\n const { defaultLocale } = configuration.internationalization;\n const { baseDir } = configuration.content;\n\n const isPerLocaleFile = configuration?.dictionary?.locale;\n\n const dirName = outputDir ? resolve(outputDir) : dirname(filePath);\n const ext = extname(filePath);\n const baseName = basename(filePath, ext);\n const contentBaseName = baseName.charAt(0).toLowerCase() + baseName.slice(1);\n\n const contentFilePath = join(dirName, `${contentBaseName}.content.ts`);\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n\n let dictionary: Dictionary;\n\n if (isPerLocaleFile) {\n // Per-locale format: simple string content with locale property\n dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes, no locale property\n const multilingualContent: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(extractedContent)) {\n multilingualContent[key] = {\n nodeType: 'translation',\n translation: {\n [defaultLocale]: value,\n },\n };\n }\n\n dictionary = {\n key: componentKey,\n content: multilingualContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, dirName);\n await writeContentDeclaration(dictionary, configuration, {\n newDictionariesPath: relativeDir,\n });\n\n return contentFilePath;\n};\n\ntype TsReplacement = {\n node: Node;\n key: string;\n type: 'jsx-text' | 'jsx-attribute' | 'string-literal';\n};\n\nconst extractTsContent = (\n sourceFile: SourceFile,\n existingKeys: Set<string>\n): {\n extractedContent: Record<string, string>;\n replacements: TsReplacement[];\n} => {\n const extractedContent: Record<string, string> = {};\n const replacements: TsReplacement[] = [];\n\n sourceFile.forEachDescendant((node) => {\n // 1. JSX Text\n if (Node.isJsxText(node)) {\n const text = node.getText();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.replace(/\\s+/g, ' ').trim();\n replacements.push({ node, key, type: 'jsx-text' });\n }\n }\n\n // 2. JSX Attributes\n else if (Node.isJsxAttribute(node)) {\n const name = node.getNameNode().getText();\n if (ATTRIBUTES_TO_EXTRACT.includes(name)) {\n const initializer = node.getInitializer();\n if (Node.isStringLiteral(initializer)) {\n const text = initializer.getLiteralValue();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'jsx-attribute' });\n }\n }\n }\n }\n\n // 3. String Literals (Variables, Arrays, etc.)\n else if (Node.isStringLiteral(node)) {\n const text = node.getLiteralValue();\n if (shouldExtract(text)) {\n const parent = node.getParent();\n\n // Skip if inside ImportDeclaration\n if (\n parent?.getKindName() === 'ImportDeclaration' ||\n parent?.getKindName() === 'ImportSpecifier' ||\n parent?.getKindName() === 'ModuleSpecifier'\n ) {\n return;\n }\n\n // Skip if it's a JSX Attribute value (handled above)\n if (Node.isJsxAttribute(parent)) return;\n\n // Skip console.log\n if (Node.isCallExpression(parent)) {\n const expression = parent.getExpression();\n if (expression.getText().includes('console.log')) return;\n }\n\n // Skip Object Keys: { key: \"value\" } -> \"key\" is PropertyAssignment name if not computed\n if (Node.isPropertyAssignment(parent)) {\n if (parent.getNameNode() === node) return; // It's the key\n }\n\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'string-literal' });\n }\n }\n });\n\n return { extractedContent, replacements };\n};\n\n// ==========================================\n// 2. React (TS-Morph) Strategy\n// ==========================================\n\nconst processReactFile = async (\n filePath: string,\n componentKey: string,\n packageName: string,\n project: Project,\n save: boolean = true\n) => {\n let sourceFile: SourceFile;\n try {\n sourceFile = project.addSourceFileAtPath(filePath);\n } catch {\n sourceFile = project.getSourceFileOrThrow(filePath);\n }\n\n const existingKeys = new Set<string>();\n const { extractedContent, replacements } = extractTsContent(\n sourceFile,\n existingKeys\n );\n\n if (Object.keys(extractedContent).length === 0) return null;\n\n for (const { node, key, type } of replacements) {\n if (type === 'jsx-text' && Node.isJsxText(node)) {\n node.replaceWithText(`{content.${key}}`);\n } else if (type === 'jsx-attribute' && Node.isJsxAttribute(node)) {\n node.setInitializer(`{content.${key}.value}`);\n } else if (type === 'string-literal' && Node.isStringLiteral(node)) {\n // For React/JS variables, we usually want the value\n node.replaceWithText(`content.${key}.value`);\n }\n }\n\n // Inject hook\n const importDecl = sourceFile.getImportDeclaration(\n (d) => d.getModuleSpecifierValue() === packageName\n );\n if (!importDecl) {\n sourceFile.addImportDeclaration({\n namedImports: ['useIntlayer'],\n moduleSpecifier: packageName,\n });\n } else if (\n !importDecl.getNamedImports().some((n) => n.getName() === 'useIntlayer')\n ) {\n importDecl.addNamedImport('useIntlayer');\n }\n\n // Insert hook at start of component\n sourceFile.getFunctions().forEach((f) => {\n f.getBody()\n ?.asKind(SyntaxKind.Block)\n ?.insertStatements(0, `const content = useIntlayer(\"${componentKey}\");`);\n });\n\n // Also handle const/arrow components\n sourceFile.getVariableDeclarations().forEach((v) => {\n const init = v.getInitializer();\n if (Node.isArrowFunction(init) || Node.isFunctionExpression(init)) {\n const body = init.getBody();\n if (Node.isBlock(body)) {\n // Heuristic: check if it returns JSX or uses hooks\n if (\n body.getText().includes('return') ||\n body.getText().includes('use')\n ) {\n body.insertStatements(\n 0,\n `const content = useIntlayer(\"${componentKey}\");`\n );\n }\n }\n }\n });\n\n if (save) {\n await sourceFile.save();\n }\n return extractedContent;\n};\n\n// ==========================================\n// 5. Main Dispatcher\n// ==========================================\n\nexport type PackageName =\n | 'next-intlayer'\n | 'react-intlayer'\n | 'vue-intlayer'\n | 'svelte-intlayer'\n | 'preact-intlayer'\n | 'solid-intlayer'\n | 'angular-intlayer'\n | 'express-intlayer';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n outputDir?: string;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extractIntlayer = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions,\n project?: Project\n) => {\n const saveComponent = !options?.declarationOnly;\n const writeContent = !options?.codeOnly;\n\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.content;\n\n // Setup Project for TS/React files if needed\n const _project =\n project || new Project({ skipAddingFilesFromTsConfig: true });\n\n const baseName = extractDictionaryKey(\n filePath,\n (await fs.readFile(filePath)).toString()\n );\n const componentKey = camelCaseToKebabCase(baseName);\n const ext = extname(filePath);\n\n let extractedContent: Record<string, string> | null = null;\n\n if (ext === '.vue') {\n try {\n const { processVueFile } = (await import(\n '@intlayer/vue-transformer'\n )) as any;\n extractedContent = await processVueFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-transformer', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n throw error;\n }\n } else if (ext === '.svelte') {\n try {\n const { processSvelteFile } = (await import(\n '@intlayer/svelte-transformer'\n )) as any;\n extractedContent = await processSvelteFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-transformer', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n throw error;\n }\n } else if (['.tsx', '.jsx', '.ts', '.js'].includes(ext)) {\n extractedContent = await processReactFile(\n filePath,\n componentKey,\n packageName,\n _project,\n saveComponent\n );\n }\n\n if (!extractedContent) {\n appLogger(`No extractable text found in ${baseName}`);\n return;\n }\n\n // Shared Write Logic\n if (writeContent) {\n const contentFilePath = await writeContentHelper(\n extractedContent,\n componentKey,\n filePath,\n configuration,\n options?.outputDir\n );\n\n const relativeContentFilePath = relative(\n configuration.content.baseDir,\n contentFilePath\n );\n appLogger(`Created content file: ${colorizePath(relativeContentFilePath)}`);\n }\n\n // Optional: Format\n if (saveComponent) {\n try {\n const formatCommand = detectFormatCommand(configuration);\n if (formatCommand) {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'ignore', // Silent\n cwd: baseDir,\n });\n }\n } catch {\n // Ignore format errors\n }\n\n appLogger(\n `Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\nexport const transformFiles = async (\n filePaths: string[],\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n for (const filePath of filePaths) {\n try {\n await extractIntlayer(filePath, packageName, options, project);\n } catch (error) {\n appLogger(`Failed to transform ${filePath}: ${(error as Error).message}`);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACD;;;;AAKD,MAAa,iBAAiB,SAA0B;CACtD,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAEnC,KAAI,CAAC,SAAS,KAAK,QAAQ,CAAE,QAAO;AAEpC,KAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,KAAK,CAAE,QAAO;AAChE,QAAO;;;;;AAMT,MAAa,eACX,MACA,iBACW;CAEX,IAAI,MAAM,KACP,QAAQ,QAAQ,IAAI,CACpB,QAAQ,OAAO,IAAI,CACnB,QAAQ,OAAO,IAAI,CACnB,QAAQ,kBAAkB,GAAG,CAC7B,MAAM,CACN,MAAM,IAAI,CACV,OAAO,QAAQ,CACf,MAAM,GATQ,EASI,CAClB,KAAK,MAAM,UACV,UAAU,IACN,KAAK,aAAa,GAClB,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,CAAC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C5B,kBACA,cACA,UACA,eACA,SAAS,UACV;AAMD,YAAU,oFAHR,cAAc,QAAQ,SACtB,gBACD,CACuE,GAAG;;AAI7E,KAAI,eAAe;AACjB,MAAI;GACF,MAAM,gBAAgBC,wEAAoB,cAAc;AACxD,OAAI,cACF,kCAAS,cAAc,QAAQ,YAAY,SAAS,EAAE;IACpD,OAAO;IACP,KAAK;IACN,CAAC;UAEE;AAIR,YACE,iFAA4C,SAAS,SAAS,CAAC,GAChE;;;AAIL,MAAa,iBAAiB,OAC5B,WACA,aACA,YACG;CAEH,MAAM,sFADiC,SAAS,cAAc,CACjB;CAE7C,MAAM,UAAU,IAAIN,iBAAQ,EAC1B,6BAA6B,MAC9B,CAAC;AAEF,MAAK,MAAM,YAAY,UACrB,KAAI;AACF,QAAM,gBAAgB,UAAU,aAAa,SAAS,QAAQ;UACvD,OAAO;AACd,YAAU,uBAAuB,SAAS,IAAK,MAAgB,UAAU"}
|
|
1
|
+
{"version":3,"file":"transformFiles.cjs","names":["dictionary: Dictionary","multilingualContent: Record<string, TranslationNode>","writeContentDeclaration","extractedContent: Record<string, string>","replacements: TsReplacement[]","Node","sourceFile: SourceFile","SyntaxKind","Project","extractDictionaryKey","fs","extractedContent: Record<string, string> | null","error: any","ANSIColors","detectFormatCommand"],"sources":["../../../src/transformFiles/transformFiles.ts"],"sourcesContent":["import { execSync } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport { basename, dirname, extname, join, relative, resolve } from 'node:path';\nimport {\n ANSIColors,\n camelCaseToKebabCase,\n colorizePath,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';\nimport { writeContentDeclaration } from '../writeContentDeclaration';\nimport { detectFormatCommand } from '../writeContentDeclaration/detectFormatCommand';\nimport { extractDictionaryKey } from './extractDictionaryKey';\n\n// ==========================================\n// 1. Shared Utilities (exported for reuse in babel plugin)\n// ==========================================\n\n/**\n * Attributes that should be extracted for localization\n */\nexport const ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\n/**\n * Default function to determine if a string should be extracted for localization\n */\nexport const shouldExtract = (text: string): boolean => {\n const trimmed = text.trim();\n if (!trimmed) return false;\n if (!trimmed.includes(' ')) return false;\n // Starts with Capital letter\n if (!/^[A-Z]/.test(trimmed)) return false;\n // Filter out template logic identifiers (simple check)\n if (trimmed.startsWith('{') || trimmed.startsWith('v-')) return false;\n return true;\n};\n\n/**\n * Generate a unique key from text for use as a dictionary key\n */\nexport const generateKey = (\n text: string,\n existingKeys: Set<string>\n): string => {\n const maxWords = 5;\n let key = text\n .replace(/\\s+/g, ' ')\n .replace(/_+/g, ' ')\n .replace(/-+/g, ' ')\n .replace(/[^a-zA-Z0-9 ]/g, '')\n .trim()\n .split(' ')\n .filter(Boolean)\n .slice(0, maxWords)\n .map((word, index) =>\n index === 0\n ? word.toLowerCase()\n : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()\n )\n .join('');\n\n if (!key) key = 'content';\n if (existingKeys.has(key)) {\n let i = 1;\n while (existingKeys.has(`${key}${i}`)) i++;\n key = `${key}${i}`;\n }\n return key;\n};\n\n/**\n * Translation node structure used in multilingual dictionaries\n */\ntype TranslationNode = {\n nodeType: 'translation';\n translation: Record<string, string>;\n};\n\nconst writeContentHelper = async (\n extractedContent: Record<string, string>,\n componentKey: string,\n filePath: string,\n configuration: IntlayerConfig,\n outputDir?: string\n) => {\n const { defaultLocale } = configuration.internationalization;\n const { baseDir, fileExtensions } = configuration.content;\n\n const isPerLocaleFile = configuration?.dictionary?.locale;\n\n const dirName = outputDir ? resolve(outputDir) : dirname(filePath);\n const ext = extname(filePath);\n const baseName = basename(filePath, ext);\n const contentBaseName = baseName.charAt(0).toLowerCase() + baseName.slice(1);\n\n const contentFilePath = join(\n dirName,\n `${contentBaseName}.${fileExtensions[0]}`\n );\n const relativeContentFilePath = relative(baseDir, contentFilePath);\n\n let dictionary: Dictionary;\n\n if (isPerLocaleFile) {\n // Per-locale format: simple string content with locale property\n dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\n };\n } else {\n // Multilingual format: content wrapped in translation nodes, no locale property\n const multilingualContent: Record<string, TranslationNode> = {};\n for (const [key, value] of Object.entries(extractedContent)) {\n multilingualContent[key] = {\n nodeType: 'translation',\n translation: {\n [defaultLocale]: value,\n },\n };\n }\n\n dictionary = {\n key: componentKey,\n content: multilingualContent,\n filePath: relativeContentFilePath,\n };\n }\n\n const relativeDir = relative(baseDir, dirName);\n await writeContentDeclaration(dictionary, configuration, {\n newDictionariesPath: relativeDir,\n });\n\n return contentFilePath;\n};\n\ntype TsReplacement = {\n node: Node;\n key: string;\n type: 'jsx-text' | 'jsx-attribute' | 'string-literal';\n};\n\nconst extractTsContent = (\n sourceFile: SourceFile,\n existingKeys: Set<string>\n): {\n extractedContent: Record<string, string>;\n replacements: TsReplacement[];\n} => {\n const extractedContent: Record<string, string> = {};\n const replacements: TsReplacement[] = [];\n\n sourceFile.forEachDescendant((node) => {\n // 1. JSX Text\n if (Node.isJsxText(node)) {\n const text = node.getText();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.replace(/\\s+/g, ' ').trim();\n replacements.push({ node, key, type: 'jsx-text' });\n }\n }\n\n // 2. JSX Attributes\n else if (Node.isJsxAttribute(node)) {\n const name = node.getNameNode().getText();\n if (ATTRIBUTES_TO_EXTRACT.includes(name)) {\n const initializer = node.getInitializer();\n if (Node.isStringLiteral(initializer)) {\n const text = initializer.getLiteralValue();\n if (shouldExtract(text)) {\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'jsx-attribute' });\n }\n }\n }\n }\n\n // 3. String Literals (Variables, Arrays, etc.)\n else if (Node.isStringLiteral(node)) {\n const text = node.getLiteralValue();\n if (shouldExtract(text)) {\n const parent = node.getParent();\n\n // Skip if inside ImportDeclaration\n if (\n parent?.getKindName() === 'ImportDeclaration' ||\n parent?.getKindName() === 'ImportSpecifier' ||\n parent?.getKindName() === 'ModuleSpecifier'\n ) {\n return;\n }\n\n // Skip if it's a JSX Attribute value (handled above)\n if (Node.isJsxAttribute(parent)) return;\n\n // Skip console.log\n if (Node.isCallExpression(parent)) {\n const expression = parent.getExpression();\n if (expression.getText().includes('console.log')) return;\n }\n\n // Skip Object Keys: { key: \"value\" } -> \"key\" is PropertyAssignment name if not computed\n if (Node.isPropertyAssignment(parent)) {\n if (parent.getNameNode() === node) return; // It's the key\n }\n\n const key = generateKey(text, existingKeys);\n existingKeys.add(key);\n extractedContent[key] = text.trim();\n replacements.push({ node, key, type: 'string-literal' });\n }\n }\n });\n\n return { extractedContent, replacements };\n};\n\n// ==========================================\n// 2. React (TS-Morph) Strategy\n// ==========================================\n\nconst processReactFile = async (\n filePath: string,\n componentKey: string,\n packageName: string,\n project: Project,\n save: boolean = true\n) => {\n let sourceFile: SourceFile;\n try {\n sourceFile = project.addSourceFileAtPath(filePath);\n } catch {\n sourceFile = project.getSourceFileOrThrow(filePath);\n }\n\n const existingKeys = new Set<string>();\n const { extractedContent, replacements } = extractTsContent(\n sourceFile,\n existingKeys\n );\n\n if (Object.keys(extractedContent).length === 0) return null;\n\n for (const { node, key, type } of replacements) {\n if (type === 'jsx-text' && Node.isJsxText(node)) {\n node.replaceWithText(`{content.${key}}`);\n } else if (type === 'jsx-attribute' && Node.isJsxAttribute(node)) {\n node.setInitializer(`{content.${key}.value}`);\n } else if (type === 'string-literal' && Node.isStringLiteral(node)) {\n // For React/JS variables, we usually want the value\n node.replaceWithText(`content.${key}.value`);\n }\n }\n\n // Inject hook\n const importDecl = sourceFile.getImportDeclaration(\n (d) => d.getModuleSpecifierValue() === packageName\n );\n if (!importDecl) {\n sourceFile.addImportDeclaration({\n namedImports: ['useIntlayer'],\n moduleSpecifier: packageName,\n });\n } else if (\n !importDecl.getNamedImports().some((n) => n.getName() === 'useIntlayer')\n ) {\n importDecl.addNamedImport('useIntlayer');\n }\n\n // Insert hook at start of component\n sourceFile.getFunctions().forEach((f) => {\n f.getBody()\n ?.asKind(SyntaxKind.Block)\n ?.insertStatements(0, `const content = useIntlayer(\"${componentKey}\");`);\n });\n\n // Also handle const/arrow components\n sourceFile.getVariableDeclarations().forEach((v) => {\n const init = v.getInitializer();\n if (Node.isArrowFunction(init) || Node.isFunctionExpression(init)) {\n const body = init.getBody();\n if (Node.isBlock(body)) {\n // Heuristic: check if it returns JSX or uses hooks\n if (\n body.getText().includes('return') ||\n body.getText().includes('use')\n ) {\n body.insertStatements(\n 0,\n `const content = useIntlayer(\"${componentKey}\");`\n );\n }\n }\n }\n });\n\n if (save) {\n await sourceFile.save();\n }\n return extractedContent;\n};\n\n// ==========================================\n// 5. Main Dispatcher\n// ==========================================\n\nexport type PackageName =\n | 'next-intlayer'\n | 'react-intlayer'\n | 'vue-intlayer'\n | 'svelte-intlayer'\n | 'preact-intlayer'\n | 'solid-intlayer'\n | 'angular-intlayer'\n | 'express-intlayer';\n\nexport type ExtractIntlayerOptions = {\n configOptions?: GetConfigurationOptions;\n outputDir?: string;\n codeOnly?: boolean;\n declarationOnly?: boolean;\n};\n\nexport const extractIntlayer = async (\n filePath: string,\n packageName: PackageName,\n options?: ExtractIntlayerOptions,\n project?: Project\n) => {\n const saveComponent = !options?.declarationOnly;\n const writeContent = !options?.codeOnly;\n\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n const { baseDir } = configuration.content;\n\n // Setup Project for TS/React files if needed\n const _project =\n project || new Project({ skipAddingFilesFromTsConfig: true });\n\n const baseName = extractDictionaryKey(\n filePath,\n (await fs.readFile(filePath)).toString()\n );\n const componentKey = camelCaseToKebabCase(baseName);\n const ext = extname(filePath);\n\n let extractedContent: Record<string, string> | null = null;\n\n if (ext === '.vue') {\n try {\n const { processVueFile } = (await import(\n '@intlayer/vue-transformer'\n )) as any;\n extractedContent = await processVueFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/vue-transformer', ANSIColors.YELLOW)} to process Vue files.`\n );\n }\n throw error;\n }\n } else if (ext === '.svelte') {\n try {\n const { processSvelteFile } = (await import(\n '@intlayer/svelte-transformer'\n )) as any;\n extractedContent = await processSvelteFile(\n filePath,\n componentKey,\n packageName,\n {\n generateKey,\n shouldExtract,\n extractTsContent,\n },\n saveComponent\n );\n } catch (error: any) {\n if (\n error.code === 'ERR_MODULE_NOT_FOUND' ||\n error.message?.includes('Cannot find module')\n ) {\n throw new Error(\n `Please install ${colorizePath('@intlayer/svelte-transformer', ANSIColors.YELLOW)} to process Svelte files.`\n );\n }\n throw error;\n }\n } else if (['.tsx', '.jsx', '.ts', '.js'].includes(ext)) {\n extractedContent = await processReactFile(\n filePath,\n componentKey,\n packageName,\n _project,\n saveComponent\n );\n }\n\n if (!extractedContent) {\n appLogger(`No extractable text found in ${baseName}`);\n return;\n }\n\n // Shared Write Logic\n if (writeContent) {\n const contentFilePath = await writeContentHelper(\n extractedContent,\n componentKey,\n filePath,\n configuration,\n options?.outputDir\n );\n\n const relativeContentFilePath = relative(\n configuration.content.baseDir,\n contentFilePath\n );\n appLogger(`Created content file: ${colorizePath(relativeContentFilePath)}`);\n }\n\n // Optional: Format\n if (saveComponent) {\n try {\n const formatCommand = detectFormatCommand(configuration);\n if (formatCommand) {\n execSync(formatCommand.replace('{{file}}', filePath), {\n stdio: 'ignore', // Silent\n cwd: baseDir,\n });\n }\n } catch {\n // Ignore format errors\n }\n\n appLogger(\n `Updated component: ${colorizePath(relative(baseDir, filePath))}`\n );\n }\n};\n\nexport const transformFiles = async (\n filePaths: string[],\n packageName: PackageName,\n options?: ExtractIntlayerOptions\n) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const project = new Project({\n skipAddingFilesFromTsConfig: true,\n });\n\n for (const filePath of filePaths) {\n try {\n await extractIntlayer(filePath, packageName, options, project);\n } catch (error) {\n appLogger(`Failed to transform ${filePath}: ${(error as Error).message}`);\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAwBA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACD;;;;AAKD,MAAa,iBAAiB,SAA0B;CACtD,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAEnC,KAAI,CAAC,SAAS,KAAK,QAAQ,CAAE,QAAO;AAEpC,KAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,KAAK,CAAE,QAAO;AAChE,QAAO;;;;;AAMT,MAAa,eACX,MACA,iBACW;CAEX,IAAI,MAAM,KACP,QAAQ,QAAQ,IAAI,CACpB,QAAQ,OAAO,IAAI,CACnB,QAAQ,OAAO,IAAI,CACnB,QAAQ,kBAAkB,GAAG,CAC7B,MAAM,CACN,MAAM,IAAI,CACV,OAAO,QAAQ,CACf,MAAM,GATQ,EASI,CAClB,KAAK,MAAM,UACV,UAAU,IACN,KAAK,aAAa,GAClB,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,CAAC,aAAa,CAC/D,CACA,KAAK,GAAG;AAEX,KAAI,CAAC,IAAK,OAAM;AAChB,KAAI,aAAa,IAAI,IAAI,EAAE;EACzB,IAAI,IAAI;AACR,SAAO,aAAa,IAAI,GAAG,MAAM,IAAI,CAAE;AACvC,QAAM,GAAG,MAAM;;AAEjB,QAAO;;AAWT,MAAM,qBAAqB,OACzB,kBACA,cACA,UACA,eACA,cACG;CACH,MAAM,EAAE,kBAAkB,cAAc;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FAA4C,SAAS,SAAS,CAAC,GAChE;;;AAIL,MAAa,iBAAiB,OAC5B,WACA,aACA,YACG;CAEH,MAAM,sFADiC,SAAS,cAAc,CACjB;CAE7C,MAAM,UAAU,IAAIN,iBAAQ,EAC1B,6BAA6B,MAC9B,CAAC;AAEF,MAAK,MAAM,YAAY,UACrB,KAAI;AACF,QAAM,gBAAgB,UAAU,aAAa,SAAS,QAAQ;UACvD,OAAO;AACd,YAAU,uBAAuB,SAAS,IAAK,MAAgB,UAAU"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let _intlayer_config = require("@intlayer/config");
|
|
3
2
|
let node_path = require("node:path");
|
|
3
|
+
let _intlayer_config = require("@intlayer/config");
|
|
4
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
5
|
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
6
6
|
let _intlayer_core = require("@intlayer/core");
|
package/dist/cjs/watcher.cjs
CHANGED
|
@@ -3,8 +3,10 @@ const require_handleAdditionalContentDeclarationFile = require('./handleAddition
|
|
|
3
3
|
const require_handleContentDeclarationFileChange = require('./handleContentDeclarationFileChange.cjs');
|
|
4
4
|
const require_handleUnlinkedContentDeclarationFile = require('./handleUnlinkedContentDeclarationFile.cjs');
|
|
5
5
|
const require_prepareIntlayer = require('./prepareIntlayer.cjs');
|
|
6
|
-
|
|
6
|
+
const require_writeContentDeclaration_writeContentDeclaration = require('./writeContentDeclaration/writeContentDeclaration.cjs');
|
|
7
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
8
|
let node_path = require("node:path");
|
|
9
|
+
let _intlayer_config = require("@intlayer/config");
|
|
8
10
|
let chokidar = require("chokidar");
|
|
9
11
|
|
|
10
12
|
//#region src/watcher.ts
|
|
@@ -13,8 +15,7 @@ const recentlyAddedFiles = /* @__PURE__ */ new Set();
|
|
|
13
15
|
const watch = (options) => {
|
|
14
16
|
const configuration = options?.configuration ?? (0, _intlayer_config.getConfiguration)(options?.configOptions);
|
|
15
17
|
const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
|
|
16
|
-
const { watch: isWatchMode, watchedFilesPatternWithPath } = configuration.content;
|
|
17
|
-
/** @ts-ignore remove error Expected 0-1 arguments, but got 2. */
|
|
18
|
+
const { watch: isWatchMode, watchedFilesPatternWithPath, fileExtensions } = configuration.content;
|
|
18
19
|
return (0, chokidar.watch)(watchedFilesPatternWithPath, {
|
|
19
20
|
persistent: isWatchMode,
|
|
20
21
|
ignoreInitial: true,
|
|
@@ -32,6 +33,14 @@ const watch = (options) => {
|
|
|
32
33
|
}).on("add", async (filePath) => {
|
|
33
34
|
const fileName = (0, node_path.basename)(filePath);
|
|
34
35
|
recentlyAddedFiles.add(fileName);
|
|
36
|
+
if (await (0, node_fs_promises.readFile)(filePath, "utf-8") === "") {
|
|
37
|
+
const extensionPattern = fileExtensions.map((ext) => ext.replace(/\./g, "\\.")).join("|");
|
|
38
|
+
await require_writeContentDeclaration_writeContentDeclaration.writeContentDeclaration({
|
|
39
|
+
key: fileName.replace(/* @__PURE__ */ new RegExp(`(${extensionPattern})$`), ""),
|
|
40
|
+
content: {},
|
|
41
|
+
filePath
|
|
42
|
+
}, configuration);
|
|
43
|
+
}
|
|
35
44
|
await require_handleAdditionalContentDeclarationFile.handleAdditionalContentDeclarationFile(filePath, configuration);
|
|
36
45
|
setTimeout(() => recentlyAddedFiles.delete(fileName), 1e3);
|
|
37
46
|
}).on("change", async (filePath) => await require_handleContentDeclarationFileChange.handleContentDeclarationFileChange(filePath, configuration)).on("unlink", async (filePath) => {
|