@intlayer/chokidar 7.2.3 → 7.3.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/index.cjs +12 -12
- package/dist/cjs/listDictionariesPath.cjs +9 -0
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +9 -2
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transformFiles/extractDictionaryKey.cjs +16 -0
- package/dist/cjs/transformFiles/extractDictionaryKey.cjs.map +1 -0
- package/dist/cjs/transformFiles/index.cjs +6 -0
- package/dist/cjs/transformFiles/transformFiles.cjs +218 -0
- package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +16 -14
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -1
- package/dist/esm/index.mjs +10 -9
- package/dist/esm/listDictionariesPath.mjs +9 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +10 -3
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transformFiles/extractDictionaryKey.mjs +15 -0
- package/dist/esm/transformFiles/extractDictionaryKey.mjs.map +1 -0
- package/dist/esm/transformFiles/index.mjs +4 -0
- package/dist/esm/transformFiles/transformFiles.mjs +215 -0
- package/dist/esm/transformFiles/transformFiles.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +16 -14
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
- 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/index.d.ts +5 -3
- package/dist/types/listDictionariesPath.d.ts +6 -1
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/transformFiles/extractDictionaryKey.d.ts +5 -0
- package/dist/types/transformFiles/extractDictionaryKey.d.ts.map +1 -0
- package/dist/types/transformFiles/index.d.ts +3 -0
- package/dist/types/transformFiles/transformFiles.d.ts +16 -0
- package/dist/types/transformFiles/transformFiles.d.ts.map +1 -0
- package/package.json +19 -10
- package/dist/cjs/compiler/extractDictionaryKey.cjs +0 -38
- package/dist/cjs/compiler/extractDictionaryKey.cjs.map +0 -1
- package/dist/cjs/compiler/index.cjs +0 -225
- package/dist/cjs/compiler/index.cjs.map +0 -1
- package/dist/esm/compiler/extractDictionaryKey.mjs +0 -36
- package/dist/esm/compiler/extractDictionaryKey.mjs.map +0 -1
- package/dist/esm/compiler/index.mjs +0 -219
- package/dist/esm/compiler/index.mjs.map +0 -1
- package/dist/types/compiler/extractDictionaryKey.d.ts +0 -13
- package/dist/types/compiler/extractDictionaryKey.d.ts.map +0 -1
- package/dist/types/compiler/index.d.ts +0 -36
- package/dist/types/compiler/index.d.ts.map +0 -1
|
@@ -3,11 +3,12 @@ import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictiona
|
|
|
3
3
|
import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
|
|
4
4
|
import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
|
|
5
5
|
import { createTypes } from "./createType/createType.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { listDictionariesWithStats } from "./listDictionariesPath.mjs";
|
|
7
7
|
import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
|
|
8
8
|
import { writeRemoteDictionary } from "./buildIntlayerDictionary/writeRemoteDictionary.mjs";
|
|
9
9
|
import { runOnce } from "./utils/runOnce.mjs";
|
|
10
10
|
import { isCachedConfigurationUpToDate, writeConfiguration } from "./writeConfiguration/index.mjs";
|
|
11
|
+
import { stat } from "node:fs/promises";
|
|
11
12
|
import { ANSIColors, cacheDisk, colorize, getAppLogger } from "@intlayer/config";
|
|
12
13
|
import { join } from "node:path";
|
|
13
14
|
import packageJson from "@intlayer/config/package.json" with { type: "json" };
|
|
@@ -25,9 +26,15 @@ const prepareIntlayer = async (configuration, options) => {
|
|
|
25
26
|
const intlayerCacheVersion = await versionCache.get();
|
|
26
27
|
const isCorrectVersion = Boolean(intlayerCacheVersion && intlayerCacheVersion === packageJson.version);
|
|
27
28
|
const isConfigSimilar = await isCachedConfigurationUpToDate(configuration);
|
|
29
|
+
const dictionariesWithStats = await listDictionariesWithStats(configuration);
|
|
30
|
+
let isDictionaryChanged = false;
|
|
31
|
+
try {
|
|
32
|
+
const sentinelStats = await stat(sentinelPath);
|
|
33
|
+
isDictionaryChanged = dictionariesWithStats.some((dictionary) => dictionary.stats.mtime.getTime() > sentinelStats.mtime.getTime());
|
|
34
|
+
} catch {}
|
|
28
35
|
const { clean, format, forceRun, onIsCached, cacheTimeoutMs } = {
|
|
29
36
|
...DEFAULT_PREPARE_INTLAYER_OPTIONS,
|
|
30
|
-
forceRun: !isCorrectVersion || !isConfigSimilar,
|
|
37
|
+
forceRun: !isCorrectVersion || !isConfigSimilar || isDictionaryChanged,
|
|
31
38
|
...options ?? {}
|
|
32
39
|
};
|
|
33
40
|
await runOnce(sentinelPath, async () => {
|
|
@@ -38,7 +45,7 @@ const prepareIntlayer = async (configuration, options) => {
|
|
|
38
45
|
await writeConfiguration(configuration);
|
|
39
46
|
const configurationWrittenTime = Date.now();
|
|
40
47
|
appLogger(["Configuration written", colorize(`(${configurationWrittenTime - preparationStartMs}ms)`, ANSIColors.GREY_DARK)], { isVerbose: true });
|
|
41
|
-
const dictionaries = await loadDictionaries(
|
|
48
|
+
const dictionaries = await loadDictionaries(dictionariesWithStats.map((dictionary) => dictionary.path), configuration);
|
|
42
49
|
const dictionariesLoadedTime = Date.now();
|
|
43
50
|
appLogger(["Content loaded", colorize([dictionaries.remoteDictionaries.length + dictionaries.pluginDictionaries.length > 0 ? [
|
|
44
51
|
`(Total: ${dictionariesLoadedTime - configurationWrittenTime}ms`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareIntlayer.mjs","names":[],"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import { join } from 'node:path';\nimport {\n ANSIColors,\n cacheDisk,\n // checkVersionsConsistency,\n colorize,\n getAppLogger,\n} from '@intlayer/config';\nimport packageJson from '@intlayer/config/package.json' with { type: 'json' };\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { writeRemoteDictionary } from './buildIntlayerDictionary/writeRemoteDictionary';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createModuleAugmentation, createTypes } from './createType/index';\nimport {
|
|
1
|
+
{"version":3,"file":"prepareIntlayer.mjs","names":[],"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport {\n ANSIColors,\n cacheDisk,\n // checkVersionsConsistency,\n colorize,\n getAppLogger,\n} from '@intlayer/config';\nimport packageJson from '@intlayer/config/package.json' with { type: 'json' };\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { writeRemoteDictionary } from './buildIntlayerDictionary/writeRemoteDictionary';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { createModuleAugmentation, createTypes } from './createType/index';\nimport { listDictionariesWithStats } from './listDictionariesPath';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { runOnce } from './utils/runOnce';\nimport {\n isCachedConfigurationUpToDate,\n writeConfiguration,\n} from './writeConfiguration';\n\ntype PrepareIntlayerOptions = {\n clean?: boolean;\n format?: ('cjs' | 'esm')[];\n forceRun?: boolean;\n cacheTimeoutMs?: number;\n onIsCached?: () => void | Promise<void>;\n};\n\nconst DEFAULT_PREPARE_INTLAYER_OPTIONS = {\n clean: false,\n format: ['cjs', 'esm'],\n cacheTimeoutMs: 1000 * 60 * 60, // 1 hour\n} satisfies PrepareIntlayerOptions;\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig,\n options?: PrepareIntlayerOptions\n) => {\n const appLogger = getAppLogger(configuration);\n\n const sentinelPath = join(\n configuration.content.cacheDir,\n 'intlayer-prepared.lock'\n );\n // Clean output dir if the intlayer version has changed\n const versionCache = cacheDisk(configuration, ['intlayer-version']);\n const intlayerCacheVersion = await versionCache.get();\n const isCorrectVersion = Boolean(\n intlayerCacheVersion && intlayerCacheVersion === packageJson.version\n );\n\n const isConfigSimilar = await isCachedConfigurationUpToDate(configuration);\n\n // Check if any dictionary has been changed to force a new rebuild\n const dictionariesWithStats = await listDictionariesWithStats(configuration);\n let isDictionaryChanged = false;\n try {\n // Try catch as sentinel file may not exist yet\n const sentinelStats = await stat(sentinelPath);\n isDictionaryChanged = dictionariesWithStats.some(\n (dictionary) =>\n dictionary.stats.mtime.getTime() > sentinelStats.mtime.getTime()\n );\n } catch {}\n\n const { clean, format, forceRun, onIsCached, cacheTimeoutMs } = {\n ...DEFAULT_PREPARE_INTLAYER_OPTIONS,\n forceRun: !isCorrectVersion || !isConfigSimilar || isDictionaryChanged,\n ...(options ?? {}),\n };\n\n // Skip preparation if it has already been done recently\n await runOnce(\n sentinelPath,\n async () => {\n // comment because of issue with next and webpack\n // await checkVersionsConsistency(configuration);\n\n if (clean || !isCorrectVersion) {\n await cleanOutputDir(configuration);\n }\n\n await versionCache.set(packageJson.version);\n\n const preparationStartMs = Date.now();\n\n appLogger([\n 'Preparing Intlayer',\n colorize(`(v${packageJson.version})`, ANSIColors.GREY_DARK),\n ]);\n\n await writeConfiguration(configuration);\n\n const configurationWrittenTime = Date.now();\n\n appLogger(\n [\n 'Configuration written',\n colorize(\n `(${configurationWrittenTime - preparationStartMs}ms)`,\n ANSIColors.GREY_DARK\n ),\n ],\n {\n isVerbose: true,\n }\n );\n\n const contentDeclarationPaths = dictionariesWithStats.map(\n (dictionary) => dictionary.path\n );\n\n const dictionaries = await loadDictionaries(\n contentDeclarationPaths,\n configuration\n );\n\n const dictionariesLoadedTime = Date.now();\n\n appLogger(\n [\n 'Content loaded',\n colorize(\n [\n dictionaries.remoteDictionaries.length +\n dictionaries.pluginDictionaries.length >\n 0\n ? [\n `(Total: ${dictionariesLoadedTime - configurationWrittenTime}ms`,\n dictionaries.localDictionaries.length > 0\n ? `- Local: ${dictionaries.time.localDictionaries}ms`\n : '',\n dictionaries.remoteDictionaries.length > 0\n ? `- Remote: ${dictionaries.time.remoteDictionaries}ms`\n : '',\n dictionaries.pluginDictionaries.length > 0\n ? `- Plugin: ${dictionaries.time.pluginDictionaries}ms`\n : '',\n `)`,\n ].join('')\n : `(${dictionariesLoadedTime - configurationWrittenTime}ms)`,\n ].join(''),\n ANSIColors.GREY_DARK\n ),\n ],\n {\n isVerbose: true,\n }\n );\n\n // Build local dictionaries\n const dictionariesOutput = await buildDictionary(\n [\n ...dictionaries.localDictionaries,\n ...dictionaries.remoteDictionaries,\n ...dictionaries.pluginDictionaries,\n ],\n configuration,\n format,\n false\n );\n\n // Write remote dictionaries\n // Used as cache for next fetch\n await writeRemoteDictionary(\n dictionaries.remoteDictionaries,\n configuration\n );\n\n const dictionariesPaths = Object.values(\n dictionariesOutput?.mergedDictionaries ?? {}\n ).map((dictionary) => dictionary.dictionaryPath);\n\n await createTypes(dictionariesPaths, configuration);\n\n await createDictionaryEntryPoint(configuration);\n\n const dictionariesBuiltTime = Date.now();\n\n appLogger([\n 'Dictionaries built',\n colorize(\n `(${dictionariesBuiltTime - preparationStartMs}ms)`,\n ANSIColors.GREY_DARK\n ),\n ]);\n\n await createModuleAugmentation(configuration);\n\n const moduleAugmentationBuiltTime = Date.now();\n\n appLogger(\n [\n 'Module augmentation built',\n colorize(\n `(${moduleAugmentationBuiltTime - dictionariesBuiltTime}ms)`,\n ANSIColors.GREY_DARK\n ),\n ],\n {\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 configuration.plugins ?? []) {\n const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n await plugin.afterBuild?.({\n dictionaries: {\n unmergedDictionaries,\n mergedDictionaries,\n },\n configuration,\n });\n }\n\n const preparationElapsedMs = Date.now() - preparationStartMs;\n appLogger(\n [`Done`, colorize(`${preparationElapsedMs}ms`, ANSIColors.GREEN)],\n {\n level: 'info',\n isVerbose: true,\n }\n );\n },\n {\n forceRun,\n onIsCached,\n cacheTimeoutMs,\n }\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,MAAM,mCAAmC;CACvC,OAAO;CACP,QAAQ,CAAC,OAAO,MAAM;CACtB,gBAAgB,MAAO,KAAK;CAC7B;AAED,MAAa,kBAAkB,OAC7B,eACA,YACG;CACH,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,eAAe,KACnB,cAAc,QAAQ,UACtB,yBACD;CAED,MAAM,eAAe,UAAU,eAAe,CAAC,mBAAmB,CAAC;CACnE,MAAM,uBAAuB,MAAM,aAAa,KAAK;CACrD,MAAM,mBAAmB,QACvB,wBAAwB,yBAAyB,YAAY,QAC9D;CAED,MAAM,kBAAkB,MAAM,8BAA8B,cAAc;CAG1E,MAAM,wBAAwB,MAAM,0BAA0B,cAAc;CAC5E,IAAI,sBAAsB;AAC1B,KAAI;EAEF,MAAM,gBAAgB,MAAM,KAAK,aAAa;AAC9C,wBAAsB,sBAAsB,MACzC,eACC,WAAW,MAAM,MAAM,SAAS,GAAG,c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b,cACD;AAMD,QAAM,YAJoB,OAAO,OAC/B,oBAAoB,sBAAsB,EAAE,CAC7C,CAAC,KAAK,eAAe,WAAW,eAAe,EAEX,cAAc;AAEnD,QAAM,2BAA2B,cAAc;EAE/C,MAAM,wBAAwB,KAAK,KAAK;AAExC,YAAU,CACR,sBACA,SACE,IAAI,wBAAwB,mBAAmB,MAC/C,WAAW,UACZ,CACF,CAAC;AAEF,QAAM,yBAAyB,cAAc;AAI7C,YACE,CACE,6BACA,SACE,IAN8B,KAAK,KAAK,GAMN,sBAAsB,MACxD,WAAW,UACZ,CACF,EACD,EACE,WAAW,MACZ,CACF;AAID,aAAW,MAAM,UAAU,cAAc,WAAW,EAAE,EAAE;GACtD,MAAM,EAAE,sBAAsB,uBAAuB;AAErD,SAAM,OAAO,aAAa;IACxB,cAAc;KACZ;KACA;KACD;IACD;IACD,CAAC;;AAIJ,YACE,CAAC,QAAQ,SAAS,GAFS,KAAK,KAAK,GAAG,mBAEE,KAAK,WAAW,MAAM,CAAC,EACjE;GACE,OAAO;GACP,WAAW;GACZ,CACF;IAEH;EACE;EACA;EACA;EACD,CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { detectExportedComponentName } from "../writeContentDeclaration/detectExportedComponentName.mjs";
|
|
2
|
+
import { basename, dirname, extname } from "node:path";
|
|
3
|
+
|
|
4
|
+
//#region src/transformFiles/extractDictionaryKey.ts
|
|
5
|
+
const extractDictionaryKey = (filePath, fileText) => {
|
|
6
|
+
const componentName = detectExportedComponentName(fileText);
|
|
7
|
+
if (componentName) return componentName;
|
|
8
|
+
let baseName = basename(filePath, extname(filePath));
|
|
9
|
+
if (baseName === "index") baseName = basename(dirname(filePath));
|
|
10
|
+
return baseName;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { extractDictionaryKey };
|
|
15
|
+
//# sourceMappingURL=extractDictionaryKey.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDictionaryKey.mjs","names":[],"sources":["../../../src/transformFiles/extractDictionaryKey.ts"],"sourcesContent":["import { basename, dirname, extname } from 'node:path';\nimport { detectExportedComponentName } from '../writeContentDeclaration/detectExportedComponentName';\n\nexport const extractDictionaryKey = (\n filePath: string,\n fileText: string\n): string => {\n const componentName = detectExportedComponentName(fileText);\n if (componentName) {\n return componentName;\n }\n\n const ext = extname(filePath);\n let baseName = basename(filePath, ext);\n\n if (baseName === 'index') {\n baseName = basename(dirname(filePath));\n }\n\n return baseName;\n};\n"],"mappings":";;;;AAGA,MAAa,wBACX,UACA,aACW;CACX,MAAM,gBAAgB,4BAA4B,SAAS;AAC3D,KAAI,cACF,QAAO;CAIT,IAAI,WAAW,SAAS,UADZ,QAAQ,SAAS,CACS;AAEtC,KAAI,aAAa,QACf,YAAW,SAAS,QAAQ,SAAS,CAAC;AAGxC,QAAO"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { extractDictionaryKey } from "./extractDictionaryKey.mjs";
|
|
2
|
+
import { detectFormatCommand } from "../writeContentDeclaration/detectFormatCommand.mjs";
|
|
3
|
+
import { writeContentDeclaration } from "../writeContentDeclaration/writeContentDeclaration.mjs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import { ANSIColors, camelCaseToKebabCase, colorizePath, getAppLogger, getConfiguration } from "@intlayer/config";
|
|
6
|
+
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
7
|
+
import { execSync } from "node:child_process";
|
|
8
|
+
import { Node, Project, SyntaxKind } from "ts-morph";
|
|
9
|
+
|
|
10
|
+
//#region src/transformFiles/transformFiles.ts
|
|
11
|
+
const ATTRIBUTES_TO_EXTRACT = [
|
|
12
|
+
"title",
|
|
13
|
+
"placeholder",
|
|
14
|
+
"alt",
|
|
15
|
+
"aria-label",
|
|
16
|
+
"label"
|
|
17
|
+
];
|
|
18
|
+
const shouldExtract = (text) => {
|
|
19
|
+
const trimmed = text.trim();
|
|
20
|
+
if (!trimmed) return false;
|
|
21
|
+
if (!trimmed.includes(" ")) return false;
|
|
22
|
+
if (!/^[A-Z]/.test(trimmed)) return false;
|
|
23
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("v-")) return false;
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
const generateKey = (text, existingKeys) => {
|
|
27
|
+
let key = text.replace(/\s+/g, " ").replace(/_+/g, " ").replace(/-+/g, " ").replace(/[^a-zA-Z0-9 ]/g, "").trim().split(" ").filter(Boolean).slice(0, 5).map((word, index) => index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
28
|
+
if (!key) key = "content";
|
|
29
|
+
if (existingKeys.has(key)) {
|
|
30
|
+
let i = 1;
|
|
31
|
+
while (existingKeys.has(`${key}${i}`)) i++;
|
|
32
|
+
key = `${key}${i}`;
|
|
33
|
+
}
|
|
34
|
+
return key;
|
|
35
|
+
};
|
|
36
|
+
const writeContentHelper = async (extractedContent, componentKey, filePath, configuration, outputDir) => {
|
|
37
|
+
const { defaultLocale } = configuration.internationalization;
|
|
38
|
+
const { baseDir } = configuration.content;
|
|
39
|
+
const dirName = outputDir ? resolve(outputDir) : dirname(filePath);
|
|
40
|
+
const baseName = basename(filePath, extname(filePath));
|
|
41
|
+
const contentFilePath = join(dirName, `${baseName.charAt(0).toLowerCase() + baseName.slice(1)}.content.ts`);
|
|
42
|
+
await writeContentDeclaration({
|
|
43
|
+
key: componentKey,
|
|
44
|
+
content: extractedContent,
|
|
45
|
+
locale: defaultLocale,
|
|
46
|
+
filePath: relative(baseDir, contentFilePath)
|
|
47
|
+
}, configuration, { newDictionariesPath: relative(baseDir, dirName) });
|
|
48
|
+
return contentFilePath;
|
|
49
|
+
};
|
|
50
|
+
const extractTsContent = (sourceFile, existingKeys) => {
|
|
51
|
+
const extractedContent = {};
|
|
52
|
+
const replacements = [];
|
|
53
|
+
sourceFile.forEachDescendant((node) => {
|
|
54
|
+
if (Node.isJsxText(node)) {
|
|
55
|
+
const text = node.getText();
|
|
56
|
+
if (shouldExtract(text)) {
|
|
57
|
+
const key = generateKey(text, existingKeys);
|
|
58
|
+
existingKeys.add(key);
|
|
59
|
+
extractedContent[key] = text.replace(/\s+/g, " ").trim();
|
|
60
|
+
replacements.push({
|
|
61
|
+
node,
|
|
62
|
+
key,
|
|
63
|
+
type: "jsx-text"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
} else if (Node.isJsxAttribute(node)) {
|
|
67
|
+
const name = node.getNameNode().getText();
|
|
68
|
+
if (ATTRIBUTES_TO_EXTRACT.includes(name)) {
|
|
69
|
+
const initializer = node.getInitializer();
|
|
70
|
+
if (Node.isStringLiteral(initializer)) {
|
|
71
|
+
const text = initializer.getLiteralValue();
|
|
72
|
+
if (shouldExtract(text)) {
|
|
73
|
+
const key = generateKey(text, existingKeys);
|
|
74
|
+
existingKeys.add(key);
|
|
75
|
+
extractedContent[key] = text.trim();
|
|
76
|
+
replacements.push({
|
|
77
|
+
node,
|
|
78
|
+
key,
|
|
79
|
+
type: "jsx-attribute"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (Node.isStringLiteral(node)) {
|
|
85
|
+
const text = node.getLiteralValue();
|
|
86
|
+
if (shouldExtract(text)) {
|
|
87
|
+
const parent = node.getParent();
|
|
88
|
+
if (parent?.getKindName() === "ImportDeclaration" || parent?.getKindName() === "ImportSpecifier" || parent?.getKindName() === "ModuleSpecifier") return;
|
|
89
|
+
if (Node.isJsxAttribute(parent)) return;
|
|
90
|
+
if (Node.isCallExpression(parent)) {
|
|
91
|
+
if (parent.getExpression().getText().includes("console.log")) return;
|
|
92
|
+
}
|
|
93
|
+
if (Node.isPropertyAssignment(parent)) {
|
|
94
|
+
if (parent.getNameNode() === node) return;
|
|
95
|
+
}
|
|
96
|
+
const key = generateKey(text, existingKeys);
|
|
97
|
+
existingKeys.add(key);
|
|
98
|
+
extractedContent[key] = text.trim();
|
|
99
|
+
replacements.push({
|
|
100
|
+
node,
|
|
101
|
+
key,
|
|
102
|
+
type: "string-literal"
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
extractedContent,
|
|
109
|
+
replacements
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const processReactFile = async (filePath, componentKey, packageName, project, save = true) => {
|
|
113
|
+
let sourceFile;
|
|
114
|
+
try {
|
|
115
|
+
sourceFile = project.addSourceFileAtPath(filePath);
|
|
116
|
+
} catch {
|
|
117
|
+
sourceFile = project.getSourceFileOrThrow(filePath);
|
|
118
|
+
}
|
|
119
|
+
const { extractedContent, replacements } = extractTsContent(sourceFile, /* @__PURE__ */ new Set());
|
|
120
|
+
if (Object.keys(extractedContent).length === 0) return null;
|
|
121
|
+
for (const { node, key, type } of replacements) if (type === "jsx-text" && Node.isJsxText(node)) node.replaceWithText(`{content.${key}}`);
|
|
122
|
+
else if (type === "jsx-attribute" && Node.isJsxAttribute(node)) node.setInitializer(`{content.${key}.value}`);
|
|
123
|
+
else if (type === "string-literal" && Node.isStringLiteral(node)) node.replaceWithText(`content.${key}.value`);
|
|
124
|
+
const importDecl = sourceFile.getImportDeclaration((d) => d.getModuleSpecifierValue() === packageName);
|
|
125
|
+
if (!importDecl) sourceFile.addImportDeclaration({
|
|
126
|
+
namedImports: ["useIntlayer"],
|
|
127
|
+
moduleSpecifier: packageName
|
|
128
|
+
});
|
|
129
|
+
else if (!importDecl.getNamedImports().some((n) => n.getName() === "useIntlayer")) importDecl.addNamedImport("useIntlayer");
|
|
130
|
+
sourceFile.getFunctions().forEach((f) => {
|
|
131
|
+
f.getBody()?.asKind(SyntaxKind.Block)?.insertStatements(0, `const content = useIntlayer("${componentKey}");`);
|
|
132
|
+
});
|
|
133
|
+
sourceFile.getVariableDeclarations().forEach((v) => {
|
|
134
|
+
const init = v.getInitializer();
|
|
135
|
+
if (Node.isArrowFunction(init) || Node.isFunctionExpression(init)) {
|
|
136
|
+
const body = init.getBody();
|
|
137
|
+
if (Node.isBlock(body)) {
|
|
138
|
+
if (body.getText().includes("return") || body.getText().includes("use")) body.insertStatements(0, `const content = useIntlayer("${componentKey}");`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (save) await sourceFile.save();
|
|
143
|
+
return extractedContent;
|
|
144
|
+
};
|
|
145
|
+
const extractIntlayer = async (filePath, packageName, options, project) => {
|
|
146
|
+
const saveComponent = !options?.declarationOnly;
|
|
147
|
+
const writeContent = !options?.codeOnly;
|
|
148
|
+
const configuration = getConfiguration(options?.configOptions);
|
|
149
|
+
const appLogger = getAppLogger(configuration);
|
|
150
|
+
const { baseDir } = configuration.content;
|
|
151
|
+
const _project = project || new Project({ skipAddingFilesFromTsConfig: true });
|
|
152
|
+
const baseName = extractDictionaryKey(filePath, (await fs.readFile(filePath)).toString());
|
|
153
|
+
const componentKey = camelCaseToKebabCase(baseName);
|
|
154
|
+
const ext = extname(filePath);
|
|
155
|
+
let extractedContent = null;
|
|
156
|
+
if (ext === ".vue") try {
|
|
157
|
+
const { processVueFile } = await import("@intlayer/vue-transformer");
|
|
158
|
+
extractedContent = await processVueFile(filePath, componentKey, packageName, {
|
|
159
|
+
generateKey,
|
|
160
|
+
shouldExtract,
|
|
161
|
+
extractTsContent
|
|
162
|
+
}, saveComponent);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error.code === "ERR_MODULE_NOT_FOUND" || error.message?.includes("Cannot find module")) throw new Error(`Please install ${colorizePath("@intlayer/vue-transformer", ANSIColors.YELLOW)} to process Vue files.`);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
else if (ext === ".svelte") try {
|
|
168
|
+
const { processSvelteFile } = await import("@intlayer/svelte-transformer");
|
|
169
|
+
extractedContent = await processSvelteFile(filePath, componentKey, packageName, {
|
|
170
|
+
generateKey,
|
|
171
|
+
shouldExtract,
|
|
172
|
+
extractTsContent
|
|
173
|
+
}, saveComponent);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error.code === "ERR_MODULE_NOT_FOUND" || error.message?.includes("Cannot find module")) throw new Error(`Please install ${colorizePath("@intlayer/svelte-transformer", ANSIColors.YELLOW)} to process Svelte files.`);
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
else if ([
|
|
179
|
+
".tsx",
|
|
180
|
+
".jsx",
|
|
181
|
+
".ts",
|
|
182
|
+
".js"
|
|
183
|
+
].includes(ext)) extractedContent = await processReactFile(filePath, componentKey, packageName, _project, saveComponent);
|
|
184
|
+
if (!extractedContent) {
|
|
185
|
+
appLogger(`No extractable text found in ${baseName}`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (writeContent) {
|
|
189
|
+
const contentFilePath = await writeContentHelper(extractedContent, componentKey, filePath, configuration, options?.outputDir);
|
|
190
|
+
appLogger(`Created content file: ${colorizePath(relative(configuration.content.baseDir, contentFilePath))}`);
|
|
191
|
+
}
|
|
192
|
+
if (saveComponent) {
|
|
193
|
+
try {
|
|
194
|
+
const formatCommand = detectFormatCommand(configuration);
|
|
195
|
+
if (formatCommand) execSync(formatCommand.replace("{{file}}", filePath), {
|
|
196
|
+
stdio: "ignore",
|
|
197
|
+
cwd: baseDir
|
|
198
|
+
});
|
|
199
|
+
} catch {}
|
|
200
|
+
appLogger(`Updated component: ${colorizePath(relative(baseDir, filePath))}`);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const transformFiles = async (filePaths, packageName, options) => {
|
|
204
|
+
const appLogger = getAppLogger(getConfiguration(options?.configOptions));
|
|
205
|
+
const project = new Project({ skipAddingFilesFromTsConfig: true });
|
|
206
|
+
for (const filePath of filePaths) try {
|
|
207
|
+
await extractIntlayer(filePath, packageName, options, project);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
appLogger(`Failed to transform ${filePath}: ${error.message}`);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
export { extractIntlayer, transformFiles };
|
|
215
|
+
//# sourceMappingURL=transformFiles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformFiles.mjs","names":["extractedContent: Record<string, string>","replacements: TsReplacement[]","sourceFile: SourceFile","extractedContent: Record<string, string> | null","error: any"],"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\n// ==========================================\n\nconst ATTRIBUTES_TO_EXTRACT = [\n 'title',\n 'placeholder',\n 'alt',\n 'aria-label',\n 'label',\n];\n\nconst 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\nconst generateKey = (text: string, existingKeys: Set<string>): 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\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 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 const dictionary: Dictionary = {\n key: componentKey,\n content: extractedContent,\n locale: defaultLocale,\n filePath: relativeContentFilePath,\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":";;;;;;;;;;AAqBA,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,iBAAiB,SAA0B;CAC/C,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;;AAGT,MAAM,eAAe,MAAc,iBAAsC;CAEvE,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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M,UAAU,IAAI,QAAQ,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"}
|
|
@@ -2,21 +2,23 @@ import { getProjectRequire } from "@intlayer/config";
|
|
|
2
2
|
|
|
3
3
|
//#region src/writeContentDeclaration/detectFormatCommand.ts
|
|
4
4
|
const detectFormatCommand = (configuration) => {
|
|
5
|
-
const { formatCommand } = configuration.content;
|
|
6
|
-
const projectRequire = getProjectRequire();
|
|
7
|
-
if (formatCommand) return formatCommand;
|
|
8
5
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const { formatCommand, baseDir } = configuration.content;
|
|
7
|
+
const projectRequire = getProjectRequire(baseDir);
|
|
8
|
+
if (formatCommand) return formatCommand;
|
|
9
|
+
try {
|
|
10
|
+
projectRequire.resolve("prettier");
|
|
11
|
+
return "prettier --write \"{{file}}\" --log-level silent";
|
|
12
|
+
} catch (_error) {}
|
|
13
|
+
try {
|
|
14
|
+
projectRequire.resolve("biome");
|
|
15
|
+
return "biome format \"{{file}}\" --write --log-level none";
|
|
16
|
+
} catch (_error) {}
|
|
17
|
+
try {
|
|
18
|
+
projectRequire.resolve("eslint");
|
|
19
|
+
return "eslint --fix \"{{file}}\" --quiet";
|
|
20
|
+
} catch (_error) {}
|
|
21
|
+
} catch {}
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { getProjectRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const detectFormatCommand = (configuration: IntlayerConfig) => {\n const { formatCommand } = configuration.content;\n
|
|
1
|
+
{"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { getProjectRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const detectFormatCommand = (configuration: IntlayerConfig) => {\n try {\n const { formatCommand, baseDir } = configuration.content;\n const projectRequire = getProjectRequire(baseDir);\n\n if (formatCommand) {\n return formatCommand;\n }\n\n // Try Prettier\n try {\n projectRequire.resolve('prettier');\n\n return 'prettier --write \"{{file}}\" --log-level silent';\n } catch (_error) {\n // Prettier not found, continue to next option\n }\n\n // Try Biome\n try {\n projectRequire.resolve('biome');\n\n return 'biome format \"{{file}}\" --write --log-level none';\n } catch (_error) {\n // Biome not found, continue to next option\n }\n\n // Try ESLint\n try {\n projectRequire.resolve('eslint');\n\n return 'eslint --fix \"{{file}}\" --quiet';\n } catch (_error) {\n // ESLint not found, no formatter available\n }\n } catch {}\n\n // No formatter found\n return undefined;\n};\n"],"mappings":";;;AAGA,MAAa,uBAAuB,kBAAkC;AACpE,KAAI;EACF,MAAM,EAAE,eAAe,YAAY,cAAc;EACjD,MAAM,iBAAiB,kBAAkB,QAAQ;AAEjD,MAAI,cACF,QAAO;AAIT,MAAI;AACF,kBAAe,QAAQ,WAAW;AAElC,UAAO;WACA,QAAQ;AAKjB,MAAI;AACF,kBAAe,QAAQ,QAAQ;AAE/B,UAAO;WACA,QAAQ;AAKjB,MAAI;AACF,kBAAe,QAAQ,SAAS;AAEhC,UAAO;WACA,QAAQ;SAGX"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { getContentDeclarationFileTemplate } from "../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
|
|
1
2
|
import { transformJSFile } from "./transformJSFile.mjs";
|
|
2
3
|
import { getFormatFromExtension } from "../utils/getFormatFromExtension.mjs";
|
|
3
|
-
import { getContentDeclarationFileTemplate } from "../getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
|
|
4
4
|
import { detectFormatCommand } from "./detectFormatCommand.mjs";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { readFile, writeFile } from "node:fs/promises";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MergedDictionaryOutput } from "./writeMergedDictionary.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _intlayer_types2 from "@intlayer/types";
|
|
3
3
|
import { Dictionary, Locale } from "@intlayer/types";
|
|
4
4
|
|
|
5
5
|
//#region src/buildIntlayerDictionary/writeDynamicDictionary.d.ts
|
|
@@ -12,7 +12,7 @@ type LocalizedDictionaryOutput = Record<string, LocalizedDictionaryResult>;
|
|
|
12
12
|
/**
|
|
13
13
|
* This function generates the content of the dictionary list file
|
|
14
14
|
*/
|
|
15
|
-
declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?:
|
|
15
|
+
declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types2.IntlayerConfig) => string;
|
|
16
16
|
/**
|
|
17
17
|
* Write the localized dictionaries to the dictionariesDir
|
|
18
18
|
* @param mergedDictionaries - The merged dictionaries
|
|
@@ -29,7 +29,7 @@ declare const generateDictionaryEntryPoint: (localizedDictionariesPathsRecord: L
|
|
|
29
29
|
* // { key: 'home', content: { ... } },
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
declare const writeDynamicDictionary: (mergedDictionaries: MergedDictionaryOutput, configuration?:
|
|
32
|
+
declare const writeDynamicDictionary: (mergedDictionaries: MergedDictionaryOutput, configuration?: _intlayer_types2.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
|
|
33
33
|
//#endregion
|
|
34
34
|
export { DictionaryResult, LocalizedDictionaryOutput, LocalizedDictionaryResult, generateDictionaryEntryPoint, writeDynamicDictionary };
|
|
35
35
|
//# sourceMappingURL=writeDynamicDictionary.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LocalizedDictionaryOutput, LocalizedDictionaryResult } from "./writeDynamicDictionary.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _intlayer_types0 from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/buildIntlayerDictionary/writeFetchDictionary.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* This function generates the content of the dictionary list file
|
|
7
7
|
*/
|
|
8
|
-
declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?:
|
|
8
|
+
declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: LocalizedDictionaryResult, format?: "cjs" | "esm", configuration?: _intlayer_types0.IntlayerConfig) => string;
|
|
9
9
|
/**
|
|
10
10
|
* Write the localized dictionaries to the dictionariesDir
|
|
11
11
|
* @param mergedDictionaries - The merged dictionaries
|
|
@@ -22,7 +22,7 @@ declare const generateDictionaryEntryPoint: (localedDictionariesPathsRecord: Loc
|
|
|
22
22
|
* // { key: 'home', content: { ... } },
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
declare const writeFetchDictionary: (dynamicDictionaries: LocalizedDictionaryOutput, configuration?:
|
|
25
|
+
declare const writeFetchDictionary: (dynamicDictionaries: LocalizedDictionaryOutput, configuration?: _intlayer_types0.IntlayerConfig, formats?: ("cjs" | "esm")[]) => Promise<LocalizedDictionaryOutput>;
|
|
26
26
|
//#endregion
|
|
27
27
|
export { generateDictionaryEntryPoint, writeFetchDictionary };
|
|
28
28
|
//# sourceMappingURL=writeFetchDictionary.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnmergedDictionaryOutput } from "./writeUnmergedDictionary.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _intlayer_types4 from "@intlayer/types";
|
|
3
3
|
import { Dictionary } from "@intlayer/types";
|
|
4
4
|
|
|
5
5
|
//#region src/buildIntlayerDictionary/writeMergedDictionary.d.ts
|
|
@@ -24,7 +24,7 @@ type MergedDictionaryOutput = Record<string, MergedDictionaryResult>;
|
|
|
24
24
|
* // { key: 'home', content: { ... } },
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
declare const writeMergedDictionaries: (groupedDictionaries: UnmergedDictionaryOutput, configuration?:
|
|
27
|
+
declare const writeMergedDictionaries: (groupedDictionaries: UnmergedDictionaryOutput, configuration?: _intlayer_types4.IntlayerConfig) => Promise<MergedDictionaryOutput>;
|
|
28
28
|
//#endregion
|
|
29
29
|
export { MergedDictionaryOutput, MergedDictionaryResult, writeMergedDictionaries };
|
|
30
30
|
//# sourceMappingURL=writeMergedDictionary.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _intlayer_types5 from "@intlayer/types";
|
|
2
2
|
import { Dictionary } from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/buildIntlayerDictionary/writeRemoteDictionary.d.ts
|
|
@@ -23,7 +23,7 @@ type RemoteDictionaryOutput = Record<string, RemoteDictionaryResult>;
|
|
|
23
23
|
* // { key: 'home', content: { ... } },
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
declare const writeRemoteDictionary: (remoteDictionaries: Dictionary[], configuration?:
|
|
26
|
+
declare const writeRemoteDictionary: (remoteDictionaries: Dictionary[], configuration?: _intlayer_types5.IntlayerConfig) => Promise<RemoteDictionaryOutput>;
|
|
27
27
|
//#endregion
|
|
28
28
|
export { RemoteDictionaryOutput, RemoteDictionaryResult, writeRemoteDictionary };
|
|
29
29
|
//# sourceMappingURL=writeRemoteDictionary.d.ts.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.js";
|
|
2
2
|
import { cleanOutputDir } from "./cleanOutputDir.js";
|
|
3
|
-
import { PackageName, extractContent, extractIntlayer, transformComponent, transformFiles, writeContent } from "./compiler/index.js";
|
|
4
3
|
import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.js";
|
|
5
4
|
import { generateDictionaryListContent } from "./createDictionaryEntryPoint/generateDictionaryListContent.js";
|
|
6
5
|
import { getBuiltDictionariesPath } from "./createDictionaryEntryPoint/getBuiltDictionariesPath.js";
|
|
@@ -24,10 +23,13 @@ import { getContentDeclarationFileTemplate } from "./getContentDeclarationFileTe
|
|
|
24
23
|
import { handleAdditionalContentDeclarationFile } from "./handleAdditionalContentDeclarationFile.js";
|
|
25
24
|
import { handleContentDeclarationFileChange } from "./handleContentDeclarationFileChange.js";
|
|
26
25
|
import { handleUnlinkedContentDeclarationFile } from "./handleUnlinkedContentDeclarationFile.js";
|
|
27
|
-
import { listDictionaries } from "./listDictionariesPath.js";
|
|
26
|
+
import { listDictionaries, listDictionariesWithStats } from "./listDictionariesPath.js";
|
|
28
27
|
import { DiffMode, ListGitFilesOptions, ListGitLinesOptions, listGitFiles, listGitLines } from "./listGitFiles.js";
|
|
29
28
|
import { prepareIntlayer } from "./prepareIntlayer.js";
|
|
30
29
|
import { reduceDictionaryContent } from "./reduceDictionaryContent/reduceDictionaryContent.js";
|
|
30
|
+
import { extractDictionaryKey } from "./transformFiles/extractDictionaryKey.js";
|
|
31
|
+
import { PackageName, extractIntlayer, transformFiles } from "./transformFiles/transformFiles.js";
|
|
32
|
+
import "./transformFiles/index.js";
|
|
31
33
|
import { JSONObject, JsonChunk, assembleJSON, chunkJSON, reconstructFromSingleChunk } from "./utils/chunkJSON.js";
|
|
32
34
|
import { formatLocale, formatPath } from "./utils/formatter.js";
|
|
33
35
|
import { getChunk } from "./utils/getChunk.js";
|
|
@@ -50,4 +52,4 @@ import { writeContentDeclaration } from "./writeContentDeclaration/writeContentD
|
|
|
50
52
|
import { writeJSFile } from "./writeContentDeclaration/writeJSFile.js";
|
|
51
53
|
import "./writeContentDeclaration/index.js";
|
|
52
54
|
import { detectFormatCommand } from "./writeContentDeclaration/detectFormatCommand.js";
|
|
53
|
-
export { type DictionaryStatus, type DiffMode, type Extension, type Format, type JSONObject, type JsonChunk, type ListGitFilesOptions, type ListGitLinesOptions, type PackageName, type ParallelHandle, assembleJSON, buildAndWatchIntlayer, buildDictionary, chunkJSON, cleanOutputDir, createDictionaryEntryPoint, createModuleAugmentation, createTypes, detectExportedComponentName, detectFormatCommand,
|
|
55
|
+
export { type DictionaryStatus, type DiffMode, type Extension, type Format, type JSONObject, type JsonChunk, type ListGitFilesOptions, type ListGitLinesOptions, type PackageName, type ParallelHandle, assembleJSON, buildAndWatchIntlayer, buildDictionary, chunkJSON, cleanOutputDir, createDictionaryEntryPoint, createModuleAugmentation, createTypes, detectExportedComponentName, detectFormatCommand, extractDictionaryKey, extractIntlayer, fetchDistantDictionaries, formatLocale, formatPath, generateDictionaryListContent, getBuiltDictionariesPath, getBuiltDynamicDictionariesPath, getBuiltFetchDictionariesPath, getBuiltRemoteDictionariesPath, getBuiltUnmergedDictionariesPath, getChunk, getContentDeclarationFileTemplate, getExtensionFromFormat, getFileHash, getFormatFromExtension, getGlobalLimiter, getTaskLimiter, handleAdditionalContentDeclarationFile, handleContentDeclarationFileChange, handleUnlinkedContentDeclarationFile, isInvalidDictionary, listDictionaries, listDictionariesWithStats, listGitFiles, listGitLines, loadContentDeclarations, loadDictionaries, loadLocalDictionaries, loadRemoteDictionaries, pLimit, parallelize, parallelizeGlobal, prepareIntlayer, reconstructFromSingleChunk, reduceDictionaryContent, reduceObjectFormat, resolveObjectPromises, runOnce, runParallel, sortAlphabetically, splitTextByLines, transformFiles, transformJSFile, verifyIdenticObjectFormat, watch, writeContentDeclaration, writeJSFile };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IntlayerConfig } from "@intlayer/types";
|
|
2
|
+
import * as fs0 from "fs";
|
|
2
3
|
|
|
3
4
|
//#region src/listDictionariesPath.d.ts
|
|
4
5
|
|
|
@@ -8,6 +9,10 @@ import { IntlayerConfig } from "@intlayer/types";
|
|
|
8
9
|
* @returns An array of dictionary paths
|
|
9
10
|
*/
|
|
10
11
|
declare const listDictionaries: (configuration: IntlayerConfig) => Promise<string[]>;
|
|
12
|
+
declare const listDictionariesWithStats: (configuration: IntlayerConfig) => Promise<{
|
|
13
|
+
path: string;
|
|
14
|
+
stats: fs0.Stats;
|
|
15
|
+
}[]>;
|
|
11
16
|
//#endregion
|
|
12
|
-
export { listDictionaries };
|
|
17
|
+
export { listDictionaries, listDictionariesWithStats };
|
|
13
18
|
//# sourceMappingURL=listDictionariesPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listDictionariesPath.d.ts","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listDictionariesPath.d.ts","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":[],"mappings":";;;;;;;;AASA;AAaA;AACiB,cAdJ,gBAcI,EAAA,CAAA,aAAA,EAbA,cAaA,EAAA,GAZd,OAYc,CAAA,MAAA,EAAA,CAAA;AAAc,cADlB,yBACkB,EAAA,CAAA,aAAA,EAAd,cAAc,EAAA,GAAA,OAAA,CAAA;EAAA,IAAA,EAAA,MAAA;EAAA,KAAA,EAAA,GAAA,CAAA,KAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareIntlayer.d.ts","names":[],"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"prepareIntlayer.d.ts","names":[],"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":[],"mappings":";;;KAwBK,sBAAA;;EAAA,MAAA,CAAA,EAAA,CAAA,KAAA,GAAA,KAAA,CAAA,EAAsB;EAcd,QAAA,CAAA,EAAA,OAuMZ;EAtMgB,cAAA,CAAA,EAAA,MAAA;EACL,UAAA,CAAA,EAAA,GAAA,GAAA,IAAA,GAXgB,OAWhB,CAAA,IAAA,CAAA;CAAsB;AAAA,cAFrB,eAEqB,EAAA,CAAA,aAAA,EADjB,cACiB,EAAA,OAAA,CAAA,EAAtB,sBAAsB,EAAA,GAAA,OAAA,CAAA,IAAA,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractDictionaryKey.d.ts","names":[],"sources":["../../../src/transformFiles/extractDictionaryKey.ts"],"sourcesContent":[],"mappings":";cAGa"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { extractDictionaryKey } from "./extractDictionaryKey.js";
|
|
2
|
+
import { ExtractIntlayerOptions, PackageName, extractIntlayer, transformFiles } from "./transformFiles.js";
|
|
3
|
+
export { ExtractIntlayerOptions, PackageName, extractDictionaryKey, extractIntlayer, transformFiles };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GetConfigurationOptions } from "@intlayer/config";
|
|
2
|
+
import { Project } from "ts-morph";
|
|
3
|
+
|
|
4
|
+
//#region src/transformFiles/transformFiles.d.ts
|
|
5
|
+
type PackageName = 'next-intlayer' | 'react-intlayer' | 'vue-intlayer' | 'svelte-intlayer' | 'preact-intlayer' | 'solid-intlayer' | 'angular-intlayer' | 'express-intlayer';
|
|
6
|
+
type ExtractIntlayerOptions = {
|
|
7
|
+
configOptions?: GetConfigurationOptions;
|
|
8
|
+
outputDir?: string;
|
|
9
|
+
codeOnly?: boolean;
|
|
10
|
+
declarationOnly?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const extractIntlayer: (filePath: string, packageName: PackageName, options?: ExtractIntlayerOptions, project?: Project) => Promise<void>;
|
|
13
|
+
declare const transformFiles: (filePaths: string[], packageName: PackageName, options?: ExtractIntlayerOptions) => Promise<void>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ExtractIntlayerOptions, PackageName, extractIntlayer, transformFiles };
|
|
16
|
+
//# sourceMappingURL=transformFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformFiles.d.ts","names":[],"sources":["../../../src/transformFiles/transformFiles.ts"],"sourcesContent":[],"mappings":";;;;KAkRY,WAAA;KAUA,sBAAA;EAVA,aAAA,CAAW,EAWL,uBAXK;EAUX,SAAA,CAAA,EAAA,MAAA;EAOC,QAAA,CAAA,EAAA,OAkIZ;EAhIc,eAAA,CAAA,EAAA,OAAA;CACH;AACA,cAJC,eAID,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,WAAA,EAFG,WAEH,EAAA,OAAA,CAAA,EADA,sBACA,EAAA,OAAA,CAAA,EAAA,OAAA,EAAA,GAAO,OAAP,CAAA,IAAA,CAAA;AAAO,cAgIN,cAhIM,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,EAAA,WAAA,EAkIJ,WAlII,EAAA,OAAA,CAAA,EAmIP,sBAnIO,EAAA,GAmIe,OAnIf,CAAA,IAAA,CAAA"}
|