@intlayer/cli 8.1.2 → 8.1.3-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/IntlayerEventListener.cjs +1 -186
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/_virtual/_utils_asset.cjs +2 -98
- package/dist/cjs/auth/login.cjs +2 -85
- package/dist/cjs/auth/login.cjs.map +1 -1
- package/dist/cjs/build.cjs +1 -27
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/ci.cjs +1 -73
- package/dist/cjs/ci.cjs.map +1 -1
- package/dist/cjs/cli.cjs +1 -476
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +1 -12
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +1 -50
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/extract.cjs +1 -96
- package/dist/cjs/extract.cjs.map +1 -1
- package/dist/cjs/fill/deepMergeContent.cjs +1 -27
- package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +1 -78
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +1 -29
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +1 -50
- package/dist/cjs/fill/formatFillData.cjs.map +1 -1
- package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +1 -26
- package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
- package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +1 -50
- package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
- package/dist/cjs/fill/index.cjs +1 -6
- package/dist/cjs/fill/listTranslationsTasks.cjs +1 -70
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
- package/dist/cjs/fill/mergeChunks.cjs +1 -28
- package/dist/cjs/fill/mergeChunks.cjs.map +1 -1
- package/dist/cjs/fill/translateDictionary.cjs +1 -205
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
- package/dist/cjs/fill/writeFill.cjs +1 -54
- package/dist/cjs/fill/writeFill.cjs.map +1 -1
- package/dist/cjs/getTargetDictionary.cjs +1 -36
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -39
- package/dist/cjs/init.cjs +1 -322
- package/dist/cjs/init.cjs.map +1 -1
- package/dist/cjs/listContentDeclaration.cjs +1 -41
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +1 -28
- package/dist/cjs/listProjects.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +8 -151
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +1 -146
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +3 -102
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +1 -206
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +1 -19
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +3 -84
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -68
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -94
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
- package/dist/cjs/searchDoc.cjs +1 -38
- package/dist/cjs/searchDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +1 -7
- package/dist/cjs/test/listMissingTranslations.cjs +1 -49
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/test/test.cjs +1 -53
- package/dist/cjs/test/test.cjs.map +1 -1
- package/dist/cjs/translateDoc/index.cjs +1 -9
- package/dist/cjs/translateDoc/translateDoc.cjs +1 -74
- package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
- package/dist/cjs/translateDoc/translateFile.cjs +2 -103
- package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
- package/dist/cjs/translateDoc/validation.cjs +5 -49
- package/dist/cjs/translateDoc/validation.cjs.map +1 -1
- package/dist/cjs/translation-alignment/alignBlocks.cjs +1 -67
- package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
- package/dist/cjs/translation-alignment/computeSimilarity.cjs +1 -25
- package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs +1 -23
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
- package/dist/cjs/translation-alignment/index.cjs +1 -22
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +1 -18
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
- package/dist/cjs/translation-alignment/normalizeBlock.cjs +1 -22
- package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
- package/dist/cjs/translation-alignment/pipeline.cjs +1 -37
- package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
- package/dist/cjs/translation-alignment/planActions.cjs +1 -46
- package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
- package/dist/cjs/translation-alignment/rebuildDocument.cjs +2 -49
- package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
- package/dist/cjs/translation-alignment/segmentDocument.cjs +5 -66
- package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +2 -89
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +1 -81
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkConfigConsistency.cjs +1 -16
- package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +1 -81
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +1 -19
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +1 -45
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +3 -27
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +1 -20
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +1 -16
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +1 -74
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +1 -20
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +2 -54
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +1 -102
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/openBrowser.cjs +1 -19
- package/dist/cjs/utils/openBrowser.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +3 -91
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/utils/setupAI.cjs +1 -64
- package/dist/cjs/utils/setupAI.cjs.map +1 -1
- package/dist/cjs/watch.cjs +1 -43
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +1 -183
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +1 -8
- package/dist/esm/_virtual/_utils_asset.mjs +2 -97
- package/dist/esm/auth/login.mjs +2 -82
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/build.mjs +1 -25
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/ci.mjs +1 -71
- package/dist/esm/ci.mjs.map +1 -1
- package/dist/esm/cli.mjs +1 -473
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +1 -10
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +1 -49
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/extract.mjs +1 -93
- package/dist/esm/extract.mjs.map +1 -1
- package/dist/esm/fill/deepMergeContent.mjs +1 -25
- package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +1 -76
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +1 -27
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +1 -49
- package/dist/esm/fill/formatFillData.mjs.map +1 -1
- package/dist/esm/fill/getAvailableLocalesInDictionary.mjs +1 -24
- package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
- package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +1 -48
- package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
- package/dist/esm/fill/index.mjs +1 -4
- package/dist/esm/fill/listTranslationsTasks.mjs +1 -68
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
- package/dist/esm/fill/mergeChunks.mjs +1 -26
- package/dist/esm/fill/mergeChunks.mjs.map +1 -1
- package/dist/esm/fill/translateDictionary.mjs +1 -203
- package/dist/esm/fill/translateDictionary.mjs.map +1 -1
- package/dist/esm/fill/writeFill.mjs +1 -52
- package/dist/esm/fill/writeFill.mjs.map +1 -1
- package/dist/esm/getTargetDictionary.mjs +1 -33
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -18
- package/dist/esm/init.mjs +1 -317
- package/dist/esm/init.mjs.map +1 -1
- package/dist/esm/listContentDeclaration.mjs +1 -38
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +1 -26
- package/dist/esm/listProjects.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +8 -148
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +1 -144
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +3 -100
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +1 -203
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +1 -17
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +3 -82
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs +1 -65
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -92
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
- package/dist/esm/searchDoc.mjs +1 -36
- package/dist/esm/searchDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +1 -4
- package/dist/esm/test/listMissingTranslations.mjs +1 -46
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/test/test.mjs +1 -51
- package/dist/esm/test/test.mjs.map +1 -1
- package/dist/esm/translateDoc/index.mjs +1 -5
- package/dist/esm/translateDoc/translateDoc.mjs +1 -71
- package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
- package/dist/esm/translateDoc/translateFile.mjs +2 -101
- package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
- package/dist/esm/translateDoc/validation.mjs +5 -46
- package/dist/esm/translateDoc/validation.mjs.map +1 -1
- package/dist/esm/translation-alignment/alignBlocks.mjs +1 -66
- package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
- package/dist/esm/translation-alignment/computeSimilarity.mjs +1 -22
- package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
- package/dist/esm/translation-alignment/fingerprintBlock.mjs +1 -20
- package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
- package/dist/esm/translation-alignment/index.mjs +1 -11
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +1 -16
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
- package/dist/esm/translation-alignment/normalizeBlock.mjs +1 -20
- package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
- package/dist/esm/translation-alignment/pipeline.mjs +1 -35
- package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
- package/dist/esm/translation-alignment/planActions.mjs +1 -44
- package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
- package/dist/esm/translation-alignment/rebuildDocument.mjs +2 -46
- package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
- package/dist/esm/translation-alignment/segmentDocument.mjs +5 -64
- package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +2 -87
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +1 -78
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkConfigConsistency.mjs +1 -14
- package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +1 -80
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +1 -17
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +1 -43
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +3 -25
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +1 -18
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +1 -14
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +1 -72
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +1 -18
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +2 -52
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +1 -100
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/openBrowser.mjs +1 -17
- package/dist/esm/utils/openBrowser.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +3 -90
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/utils/setupAI.mjs +1 -62
- package/dist/esm/utils/setupAI.mjs.map +1 -1
- package/dist/esm/watch.mjs +1 -41
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/auth/login.d.ts +1 -1
- package/dist/types/auth/login.d.ts.map +1 -1
- package/dist/types/build.d.ts +1 -1
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/extract.d.ts +1 -1
- package/dist/types/extract.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +1 -1
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/translateDictionary.d.ts +2 -2
- package/dist/types/fill/translateDictionary.d.ts.map +1 -1
- package/dist/types/fill/writeFill.d.ts.map +1 -1
- package/dist/types/getTargetDictionary.d.ts +2 -2
- package/dist/types/index.d.ts +4 -1
- package/dist/types/listContentDeclaration.d.ts +1 -1
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +1 -1
- package/dist/types/pull.d.ts +1 -1
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +1 -1
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +2 -2
- package/dist/types/pushConfig.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts +2 -2
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
- package/dist/types/searchDoc.d.ts +1 -1
- package/dist/types/searchDoc.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +1 -1
- package/dist/types/test/test.d.ts +1 -1
- package/dist/types/test/test.d.ts.map +1 -1
- package/dist/types/translateDoc/translateDoc.d.ts.map +1 -1
- package/dist/types/translateDoc/types.d.ts +2 -2
- package/dist/types/translateDoc/validation.d.ts +1 -1
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/watch.d.ts +1 -1
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkFileModifiedRange.mjs","names":[],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkFileModifiedRange.mjs","names":[],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":"sHAcA,MAiBM,GACJ,EACA,EAAY,IAAI,OACO,CAEvB,GAAI,aAAgB,KAClB,MAAO,CACL,aAAc,EACd,aAAc,IAAI,KAAK,EAAI,SAAS,CAAG,EAAK,SAAS,CAAC,CACvD,CAIH,GAAI,OAAO,GAAS,SAAU,CAC5B,GAAI,EAAO,QAAwB,CAEjC,IAAM,EAAe,IAAI,KAAK,EAAK,CACnC,MAAO,CACL,eACA,aAAc,IAAI,KAAK,EAAI,SAAS,CAAG,EAAa,SAAS,CAAC,CAC/D,CAIH,IAAM,EAAa,EACnB,MAAO,CAEL,aAAc,IAAI,KAAK,EAAW,CAElC,aAAc,IAAI,KAAK,EAAI,SAAS,CAAG,EAAW,CACnD,CAIH,GAAI,OAAO,GAAS,SAAU,CAC5B,IAAM,EAAe,IAAI,KAAK,EAAK,CACnC,GAAI,OAAO,MAAM,EAAa,SAAS,CAAC,CACtC,MAAU,MAAM,iCAAiC,IAAO,CAG1D,MAAO,CACL,eACA,aAAc,IAAI,KAAK,EAAI,SAAS,CAAG,EAAa,SAAS,CAAC,CAC/D,CAGH,MAAU,MAAM,4BAA4B,IAAO,EAaxC,GACX,EACA,IACiC,CACjC,IAAM,EAAqB,EAAoB,EAAS,CAClD,CAAE,uBAAsB,uBAAwB,EAGhD,EAAM,IAAI,KACV,EAAU,EACZ,EAAmB,EAAsB,EAAI,CAAC,aAC9C,IAAA,GACE,EAAU,EACZ,EAAmB,EAAqB,EAAI,CAAC,aAC7C,IAAA,GAGA,EAAa,GAajB,GAXI,aAAmB,MAAQ,aAAmB,KAEhD,EAAa,GAAsB,GAAW,GAAsB,EAC3D,aAAmB,KAE5B,EAAa,GAAsB,EAC1B,IAET,EAAa,GAAsB,GAGjC,EAAY,CAGd,IAAM,EACJ,GAAW,EAGP,IAAI,KAAK,KAAK,IAAI,EAAQ,SAAS,CAAG,EAAQ,SAAS,CAAC,CAAC,CACxD,GAAW,EAKlB,MAAO,CACL,UAAW,GACX,QAAS,8DAA8D,EAJpD,IAAI,KAAK,EAAI,SAAS,CAAG,EAAc,SAAS,CAAC,CAI+B,CAAC,KAAK,IAC1G,CAGH,MAAO,CACL,UAAW,GACX,QAAS,QAAQ,EAAS,sBAAsB,IACjD"}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/utils/checkLastUpdateTime.ts
|
|
4
|
-
/**
|
|
5
|
-
* Returns the last modification date of a file.
|
|
6
|
-
*
|
|
7
|
-
* @param filePath - Absolute or relative path to the file to inspect.
|
|
8
|
-
* @returns Date instance representing the file's last modified time (mtime).
|
|
9
|
-
* @throws Will propagate any error thrown by fs.statSync (e.g., file not found).
|
|
10
|
-
*/
|
|
11
|
-
const checkLastUpdateTime = (filePath) => {
|
|
12
|
-
const stats = statSync(filePath);
|
|
13
|
-
return new Date(stats.mtime);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { checkLastUpdateTime };
|
|
1
|
+
import{statSync as e}from"node:fs";const t=t=>{let n=e(t);return new Date(n.mtime)};export{t as checkLastUpdateTime};
|
|
18
2
|
//# sourceMappingURL=checkLastUpdateTime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkLastUpdateTime.mjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkLastUpdateTime.mjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":"mCASA,MAAa,EAAuB,GAA2B,CAC7D,IAAM,EAAQ,EAAS,EAAS,CAChC,OAAO,IAAI,KAAK,EAAM,MAAM"}
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { retryManager } from "@intlayer/config";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/chunkInference.ts
|
|
5
|
-
/**
|
|
6
|
-
* Translates a single chunk via the OpenAI API.
|
|
7
|
-
* Includes retry logic if the call fails.
|
|
8
|
-
*/
|
|
9
|
-
const chunkInference = async (messages, aiOptions, configuration, aiClient, aiConfig) => {
|
|
10
|
-
let lastResult;
|
|
11
|
-
await retryManager(async () => {
|
|
12
|
-
if (aiClient && aiConfig) {
|
|
13
|
-
const response = await aiClient.customQuery({
|
|
14
|
-
aiConfig,
|
|
15
|
-
messages
|
|
16
|
-
});
|
|
17
|
-
if (!response) throw new Error("No response from AI API");
|
|
18
|
-
const { fileContent, tokenUsed } = response;
|
|
19
|
-
lastResult = {
|
|
20
|
-
fileContent: processContent(fileContent),
|
|
21
|
-
tokenUsed
|
|
22
|
-
};
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const response = await getIntlayerAPIProxy(void 0, configuration).ai.customQuery({
|
|
26
|
-
aiOptions,
|
|
27
|
-
messages
|
|
28
|
-
});
|
|
29
|
-
if (!response.data) throw new Error("No response from AI API");
|
|
30
|
-
const { fileContent, tokenUsed } = response.data;
|
|
31
|
-
lastResult = {
|
|
32
|
-
fileContent: processContent(fileContent),
|
|
33
|
-
tokenUsed
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
return lastResult;
|
|
37
|
-
};
|
|
38
|
-
const processContent = (content) => {
|
|
39
|
-
return content.replaceAll("///chunksStart///", "").replaceAll("///chunkStart///", "").replaceAll("///chunksEnd///", "").replaceAll("///chunkEnd///", "").replaceAll("///chunksStart///", "").replaceAll("chunkStart///", "").replaceAll("chunksEnd///", "").replaceAll("chunkEnd///", "").replaceAll("///chunksStart", "").replaceAll("///chunkStart", "").replaceAll("///chunksEnd", "").replaceAll("///chunkEnd", "").replaceAll("chunksStart", "").replaceAll("chunkStart", "").replaceAll("chunksEnd", "").replaceAll("chunkEnd", "");
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { chunkInference };
|
|
1
|
+
import{getIntlayerAPIProxy as e}from"@intlayer/api";import{retryManager as t}from"@intlayer/config/utils";const n=async(n,i,a,o,s)=>{let c;return await t(async()=>{if(o&&s){let e=await o.customQuery({aiConfig:s,messages:n});if(!e)throw Error(`No response from AI API`);let{fileContent:t,tokenUsed:i}=e;c={fileContent:r(t),tokenUsed:i};return}let t=await e(void 0,a).ai.customQuery({aiOptions:i,messages:n});if(!t.data)throw Error(`No response from AI API`);let{fileContent:l,tokenUsed:u}=t.data;c={fileContent:r(l),tokenUsed:u}})(),c},r=e=>e.replaceAll(`///chunksStart///`,``).replaceAll(`///chunkStart///`,``).replaceAll(`///chunksEnd///`,``).replaceAll(`///chunkEnd///`,``).replaceAll(`///chunksStart///`,``).replaceAll(`chunkStart///`,``).replaceAll(`chunksEnd///`,``).replaceAll(`chunkEnd///`,``).replaceAll(`///chunksStart`,``).replaceAll(`///chunkStart`,``).replaceAll(`///chunksEnd`,``).replaceAll(`///chunkEnd`,``).replaceAll(`chunksStart`,``).replaceAll(`chunkStart`,``).replaceAll(`chunksEnd`,``).replaceAll(`chunkEnd`,``);export{n as chunkInference};
|
|
44
2
|
//# sourceMappingURL=chunkInference.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunkInference.mjs","names":[],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type { AIConfig, AIOptions } from '@intlayer/ai';\nimport { getIntlayerAPIProxy, type Messages } from '@intlayer/api';\nimport { retryManager } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = getIntlayerAPIProxy(undefined, configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chunkInference.mjs","names":[],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import type { AIConfig, AIOptions } from '@intlayer/ai';\nimport { getIntlayerAPIProxy, type Messages } from '@intlayer/api';\nimport { retryManager } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { AIClient } from './setupAI';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n if (aiClient && aiConfig) {\n const response = await aiClient.customQuery({\n aiConfig,\n messages,\n });\n\n if (!response) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n\n return;\n }\n\n const api = getIntlayerAPIProxy(undefined, configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n lastResult = {\n fileContent: processContent(fileContent),\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n\nconst processContent = (content: string) => {\n return content\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n};\n"],"mappings":"0GAeA,MAAa,EAAiB,MAC5B,EACA,EACA,EACA,EACA,IACkC,CAClC,IAAI,EA0CJ,OAxCA,MAAM,EAAa,SAAY,CAC7B,GAAI,GAAY,EAAU,CACxB,IAAM,EAAW,MAAM,EAAS,YAAY,CAC1C,WACA,WACD,CAAC,CAEF,GAAI,CAAC,EACH,MAAU,MAAM,0BAA0B,CAG5C,GAAM,CAAE,cAAa,aAAc,EAEnC,EAAa,CACX,YAAa,EAAe,EAAY,CACxC,YACD,CAED,OAKF,IAAM,EAAW,MAFL,EAAoB,IAAA,GAAW,EAAc,CAE9B,GAAG,YAAY,CACxC,YACA,WACD,CAAC,CAEF,GAAI,CAAC,EAAS,KACZ,MAAU,MAAM,0BAA0B,CAG5C,GAAM,CAAE,cAAa,aAAc,EAAS,KAE5C,EAAa,CACX,YAAa,EAAe,EAAY,CACxC,YACD,EACD,EAAE,CAEG,GAGH,EAAkB,GACf,EACJ,WAAW,oBAAqB,GAAG,CACnC,WAAW,mBAAoB,GAAG,CAClC,WAAW,kBAAmB,GAAG,CACjC,WAAW,iBAAkB,GAAG,CAChC,WAAW,oBAAqB,GAAG,CACnC,WAAW,gBAAiB,GAAG,CAC/B,WAAW,eAAgB,GAAG,CAC9B,WAAW,cAAe,GAAG,CAC7B,WAAW,iBAAkB,GAAG,CAChC,WAAW,gBAAiB,GAAG,CAC/B,WAAW,eAAgB,GAAG,CAC9B,WAAW,cAAe,GAAG,CAC7B,WAAW,cAAe,GAAG,CAC7B,WAAW,aAAc,GAAG,CAC5B,WAAW,YAAa,GAAG,CAC3B,WAAW,WAAY,GAAG"}
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const CHAR_TO_CHECK_FORMATTING = [
|
|
3
|
-
"```",
|
|
4
|
-
"\n\n",
|
|
5
|
-
"\n",
|
|
6
|
-
"---",
|
|
7
|
-
"{{",
|
|
8
|
-
"}}"
|
|
9
|
-
];
|
|
10
|
-
const escapeForRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\n/g, "\\n");
|
|
11
|
-
const FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join("|")})+`;
|
|
12
|
-
const LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);
|
|
13
|
-
const TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);
|
|
14
|
-
const fixChunkStartEndChars = (reviewedChunkResult, baseChunkContext) => {
|
|
15
|
-
let result = reviewedChunkResult;
|
|
16
|
-
const baseLeading = baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
|
|
17
|
-
const baseTrailing = baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
|
|
18
|
-
const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
|
|
19
|
-
const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
|
|
20
|
-
if (baseLeading !== resultLeading) result = baseLeading + result.slice(resultLeading.length);
|
|
21
|
-
if (baseTrailing !== resultTrailing) result = result.slice(0, result.length - resultTrailing.length) + baseTrailing;
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
1
|
+
const e=`(?:${["```",`
|
|
24
2
|
|
|
25
|
-
|
|
26
|
-
export
|
|
3
|
+
`,`
|
|
4
|
+
`,`---`,`{{`,`}}`].map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\n/g,`\\n`)).join(`|`)})+`,t=RegExp(`^${e}`),n=RegExp(`${e}$`),r=(e,r)=>{let i=e,a=r.match(t)?.[0]??``,o=r.match(n)?.[0]??``,s=i.match(t)?.[0]??``,c=i.match(n)?.[0]??``;return a!==s&&(i=a+i.slice(s.length)),o!==c&&(i=i.slice(0,i.length-c.length)+o),i};export{r as fixChunkStartEndChars};
|
|
27
5
|
//# sourceMappingURL=fixChunkStartEndChars.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixChunkStartEndChars.mjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixChunkStartEndChars.mjs","names":[],"sources":["../../../src/utils/fixChunkStartEndChars.ts"],"sourcesContent":["const CHAR_TO_CHECK_FORMATTING = ['```', '\\n\\n', '\\n', '---', '{{', '}}'];\n\n// Escape a string for use in RegExp\nconst escapeForRegExp = (str: string) =>\n str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\n/g, '\\\\n');\n\n// Build once the regex that matches any combination of the formatting chars appearing\n// sequentially at the beginning or at the end of a string.\nconst FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join('|')})+`;\nconst LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);\nconst TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);\n\nexport const fixChunkStartEndChars = (\n reviewedChunkResult: string,\n baseChunkContext: string\n) => {\n let result = reviewedChunkResult;\n\n const baseLeading =\n baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const baseTrailing =\n baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? '';\n const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? '';\n\n // Fix leading formatting\n if (baseLeading !== resultLeading) {\n // Remove current leading formatting found in result and prepend the correct one\n result = baseLeading + result.slice(resultLeading.length);\n }\n\n // Fix trailing formatting\n if (baseTrailing !== resultTrailing) {\n // Remove current trailing formatting found in result and append the correct one\n result =\n result.slice(0, result.length - resultTrailing.length) + baseTrailing;\n }\n\n return result;\n};\n"],"mappings":"AAQA,MAAM,EAA0B,MARC,CAAC,MAAO;;EAAQ;EAAM,MAAO,KAAM,KAAK,CAQV,IALtC,GACvB,EAAI,QAAQ,sBAAuB,OAAO,CAAC,QAAQ,MAAO,MAAM,CAIiB,CAAC,KAAK,IAAI,CAAC,IACxF,EAA+B,OAAO,IAAI,IAA0B,CACpE,EAAgC,OAAO,GAAG,EAAwB,GAAG,CAE9D,GACX,EACA,IACG,CACH,IAAI,EAAS,EAEP,EACJ,EAAiB,MAAM,EAAyB,GAAG,IAAM,GACrD,EACJ,EAAiB,MAAM,EAA0B,GAAG,IAAM,GAEtD,EAAgB,EAAO,MAAM,EAAyB,GAAG,IAAM,GAC/D,EAAiB,EAAO,MAAM,EAA0B,GAAG,IAAM,GAevE,OAZI,IAAgB,IAElB,EAAS,EAAc,EAAO,MAAM,EAAc,OAAO,EAIvD,IAAiB,IAEnB,EACE,EAAO,MAAM,EAAG,EAAO,OAAS,EAAe,OAAO,CAAG,GAGtD"}
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
const formatTimeDiff = (realtiveTime) => {
|
|
3
|
-
const diff = realtiveTime.getTime();
|
|
4
|
-
const MS_IN_SECOND = 1e3;
|
|
5
|
-
const MS_IN_MINUTE = 60 * MS_IN_SECOND;
|
|
6
|
-
const MS_IN_HOUR = 60 * MS_IN_MINUTE;
|
|
7
|
-
const MS_IN_DAY = 24 * MS_IN_HOUR;
|
|
8
|
-
const days = Math.floor(diff / MS_IN_DAY);
|
|
9
|
-
const hours = Math.floor(diff % MS_IN_DAY / MS_IN_HOUR);
|
|
10
|
-
const minutes = Math.floor(diff % MS_IN_HOUR / MS_IN_MINUTE);
|
|
11
|
-
const seconds = Math.floor(diff % MS_IN_MINUTE / MS_IN_SECOND);
|
|
12
|
-
if (days > 0) return `${days}d ${hours}h ${minutes}m ${seconds}s`;
|
|
13
|
-
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
|
|
14
|
-
return `${minutes}m ${seconds}s`;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { formatTimeDiff };
|
|
1
|
+
const e=e=>{let t=e.getTime(),n=1e3,r=60*n,i=60*r,a=24*i,o=Math.floor(t/a),s=Math.floor(t%a/i),c=Math.floor(t%i/r),l=Math.floor(t%r/n);return o>0?`${o}d ${s}h ${c}m ${l}s`:s>0?`${s}h ${c}m ${l}s`:`${c}m ${l}s`};export{e as formatTimeDiff};
|
|
19
2
|
//# sourceMappingURL=formatTimeDiff.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatTimeDiff.mjs","names":[],"sources":["../../../src/utils/formatTimeDiff.ts"],"sourcesContent":["export const formatTimeDiff = (realtiveTime: Date): string => {\n const diff = realtiveTime.getTime();\n\n const MS_IN_SECOND = 1000;\n const MS_IN_MINUTE = 60 * MS_IN_SECOND;\n const MS_IN_HOUR = 60 * MS_IN_MINUTE;\n const MS_IN_DAY = 24 * MS_IN_HOUR;\n\n const days = Math.floor(diff / MS_IN_DAY);\n const hours = Math.floor((diff % MS_IN_DAY) / MS_IN_HOUR);\n const minutes = Math.floor((diff % MS_IN_HOUR) / MS_IN_MINUTE);\n const seconds = Math.floor((diff % MS_IN_MINUTE) / MS_IN_SECOND);\n\n if (days > 0) {\n return `${days}d ${hours}h ${minutes}m ${seconds}s`;\n }\n if (hours > 0) {\n return `${hours}h ${minutes}m ${seconds}s`;\n }\n\n return `${minutes}m ${seconds}s`;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatTimeDiff.mjs","names":[],"sources":["../../../src/utils/formatTimeDiff.ts"],"sourcesContent":["export const formatTimeDiff = (realtiveTime: Date): string => {\n const diff = realtiveTime.getTime();\n\n const MS_IN_SECOND = 1000;\n const MS_IN_MINUTE = 60 * MS_IN_SECOND;\n const MS_IN_HOUR = 60 * MS_IN_MINUTE;\n const MS_IN_DAY = 24 * MS_IN_HOUR;\n\n const days = Math.floor(diff / MS_IN_DAY);\n const hours = Math.floor((diff % MS_IN_DAY) / MS_IN_HOUR);\n const minutes = Math.floor((diff % MS_IN_HOUR) / MS_IN_MINUTE);\n const seconds = Math.floor((diff % MS_IN_MINUTE) / MS_IN_SECOND);\n\n if (days > 0) {\n return `${days}d ${hours}h ${minutes}m ${seconds}s`;\n }\n if (hours > 0) {\n return `${hours}h ${minutes}m ${seconds}s`;\n }\n\n return `${minutes}m ${seconds}s`;\n};\n"],"mappings":"AAAA,MAAa,EAAkB,GAA+B,CAC5D,IAAM,EAAO,EAAa,SAAS,CAE7B,EAAe,IACf,EAAe,GAAK,EACpB,EAAa,GAAK,EAClB,EAAY,GAAK,EAEjB,EAAO,KAAK,MAAM,EAAO,EAAU,CACnC,EAAQ,KAAK,MAAO,EAAO,EAAa,EAAW,CACnD,EAAU,KAAK,MAAO,EAAO,EAAc,EAAa,CACxD,EAAU,KAAK,MAAO,EAAO,EAAgB,EAAa,CAShE,OAPI,EAAO,EACF,GAAG,EAAK,IAAI,EAAM,IAAI,EAAQ,IAAI,EAAQ,GAE/C,EAAQ,EACH,GAAG,EAAM,IAAI,EAAQ,IAAI,EAAQ,GAGnC,GAAG,EAAQ,IAAI,EAAQ"}
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/utils/getIsFileUpdatedRecently.ts
|
|
4
|
-
const SKIP_RANGE_OF_LAST_UPDATE_TIME = 0;
|
|
5
|
-
/**
|
|
6
|
-
* Check if file was updated recently, to skip re-translation
|
|
7
|
-
*/
|
|
8
|
-
const getIsFileUpdatedRecently = (localeFilePath) => {
|
|
9
|
-
const stats = statSync(localeFilePath);
|
|
10
|
-
return new Date(stats.mtime) > new Date(Date.now() - SKIP_RANGE_OF_LAST_UPDATE_TIME);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { getIsFileUpdatedRecently };
|
|
1
|
+
import{statSync as e}from"node:fs";const t=t=>{let n=e(t);return new Date(n.mtime)>new Date(Date.now()-0)};export{t as getIsFileUpdatedRecently};
|
|
15
2
|
//# sourceMappingURL=getIsFileUpdatedRecently.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIsFileUpdatedRecently.mjs","names":[],"sources":["../../../src/utils/getIsFileUpdatedRecently.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\nconst SKIP_RANGE_OF_LAST_UPDATE_TIME: number = 0; //2 * 60 * 60 * 1000; // 2 hours\n\n/**\n * Check if file was updated recently, to skip re-translation\n */\nexport const getIsFileUpdatedRecently = (localeFilePath: string): boolean => {\n const stats = statSync(localeFilePath);\n const lastModified = new Date(stats.mtime);\n const threshold = new Date(Date.now() - SKIP_RANGE_OF_LAST_UPDATE_TIME);\n\n return lastModified > threshold;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIsFileUpdatedRecently.mjs","names":[],"sources":["../../../src/utils/getIsFileUpdatedRecently.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\nconst SKIP_RANGE_OF_LAST_UPDATE_TIME: number = 0; //2 * 60 * 60 * 1000; // 2 hours\n\n/**\n * Check if file was updated recently, to skip re-translation\n */\nexport const getIsFileUpdatedRecently = (localeFilePath: string): boolean => {\n const stats = statSync(localeFilePath);\n const lastModified = new Date(stats.mtime);\n const threshold = new Date(Date.now() - SKIP_RANGE_OF_LAST_UPDATE_TIME);\n\n return lastModified > threshold;\n};\n"],"mappings":"mCAEA,MAKa,EAA4B,GAAoC,CAC3E,IAAM,EAAQ,EAAS,EAAe,CAItC,OAHqB,IAAI,KAAK,EAAM,MAAM,CACxB,IAAI,KAAK,KAAK,KAAK,CAAG,EAA+B"}
|
|
@@ -1,73 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Get the output file path by replacing the base locale with the target locale
|
|
4
|
-
*
|
|
5
|
-
* This function handles two types of replacements:
|
|
6
|
-
* 1. Actual locale values (e.g., `/en/` → `/fr/`)
|
|
7
|
-
* 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)
|
|
8
|
-
*
|
|
9
|
-
* Replacement patterns:
|
|
10
|
-
* - `/baseLocale/` → `/locale/`
|
|
11
|
-
* - `\baseLocale\` → `\locale\`
|
|
12
|
-
* - `_baseLocale.` → `_locale.`
|
|
13
|
-
* - `baseLocale_` → `locale_`
|
|
14
|
-
* - `.baseLocaleName.` → `.localeName.`
|
|
15
|
-
* - `{{baseLocale}}` → `{{locale}}`
|
|
16
|
-
* - `{{baseLocaleName}}` → `{{localeName}}`
|
|
17
|
-
*
|
|
18
|
-
* If no patterns match, appends `.locale` to the file extension.
|
|
19
|
-
*
|
|
20
|
-
* @param filePath - The input file path
|
|
21
|
-
* @param locale - The target locale
|
|
22
|
-
* @param baseLocale - The base locale to replace
|
|
23
|
-
* @returns The output file path with locale replacements
|
|
24
|
-
*/
|
|
25
|
-
const getOutputFilePath = (filePath, locale, baseLocale) => {
|
|
26
|
-
if (!filePath || !locale || !baseLocale) throw new Error("filePath, locale, and baseLocale are required");
|
|
27
|
-
let outputFilePath = filePath;
|
|
28
|
-
const replacements = [
|
|
29
|
-
{
|
|
30
|
-
pattern: /\{\{baseLocale\}\}/g,
|
|
31
|
-
replacement: "{{locale}}"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
pattern: /\{\{baseLocaleName\}\}/g,
|
|
35
|
-
replacement: "{{localeName}}"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
pattern: new RegExp(`/${baseLocale}/`, "g"),
|
|
39
|
-
replacement: `/${locale}/`
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
pattern: new RegExp(`\\\\${baseLocale}\\\\`, "g"),
|
|
43
|
-
replacement: `\\${locale}\\`
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
pattern: new RegExp(`_${baseLocale}\\.`, "g"),
|
|
47
|
-
replacement: `_${locale}.`
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
pattern: new RegExp(`/${baseLocale}_`, "g"),
|
|
51
|
-
replacement: `/${locale}_`
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
pattern: new RegExp(`(^|[\\/])${baseLocale}_`, "g"),
|
|
55
|
-
replacement: `$1${locale}_`
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
pattern: new RegExp(`\\.${baseLocale}\\.`, "g"),
|
|
59
|
-
replacement: `.${locale}.`
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
for (const { pattern, replacement } of replacements) outputFilePath = outputFilePath.replace(pattern, replacement);
|
|
63
|
-
if (outputFilePath === filePath) {
|
|
64
|
-
const lastDotIndex = filePath.lastIndexOf(".");
|
|
65
|
-
if (lastDotIndex > 0) return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;
|
|
66
|
-
else return `${filePath}.${locale}`;
|
|
67
|
-
}
|
|
68
|
-
return outputFilePath;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { getOutputFilePath };
|
|
1
|
+
const e=(e,t,n)=>{if(!e||!t||!n)throw Error(`filePath, locale, and baseLocale are required`);let r=e,i=[{pattern:/\{\{baseLocale\}\}/g,replacement:`{{locale}}`},{pattern:/\{\{baseLocaleName\}\}/g,replacement:`{{localeName}}`},{pattern:RegExp(`/${n}/`,`g`),replacement:`/${t}/`},{pattern:RegExp(`\\\\${n}\\\\`,`g`),replacement:`\\${t}\\`},{pattern:RegExp(`_${n}\\.`,`g`),replacement:`_${t}.`},{pattern:RegExp(`/${n}_`,`g`),replacement:`/${t}_`},{pattern:RegExp(`(^|[\\/])${n}_`,`g`),replacement:`$1${t}_`},{pattern:RegExp(`\\.${n}\\.`,`g`),replacement:`.${t}.`}];for(let{pattern:e,replacement:t}of i)r=r.replace(e,t);if(r===e){let n=e.lastIndexOf(`.`);return n>0?`${e.slice(0,n)}.${t}${e.slice(n)}`:`${e}.${t}`}return r};export{e as getOutputFilePath};
|
|
73
2
|
//# sourceMappingURL=getOutputFilePath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOutputFilePath.mjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getOutputFilePath.mjs","names":[],"sources":["../../../src/utils/getOutputFilePath.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types';\n\n/**\n * Get the output file path by replacing the base locale with the target locale\n *\n * This function handles two types of replacements:\n * 1. Actual locale values (e.g., `/en/` → `/fr/`)\n * 2. Template placeholders (e.g., `{{baseLocale}}` → `{{locale}}`, `{{baseLocaleName}}` → `{{localeName}}`)\n *\n * Replacement patterns:\n * - `/baseLocale/` → `/locale/`\n * - `\\baseLocale\\` → `\\locale\\`\n * - `_baseLocale.` → `_locale.`\n * - `baseLocale_` → `locale_`\n * - `.baseLocaleName.` → `.localeName.`\n * - `{{baseLocale}}` → `{{locale}}`\n * - `{{baseLocaleName}}` → `{{localeName}}`\n *\n * If no patterns match, appends `.locale` to the file extension.\n *\n * @param filePath - The input file path\n * @param locale - The target locale\n * @param baseLocale - The base locale to replace\n * @returns The output file path with locale replacements\n */\nexport const getOutputFilePath = (\n filePath: string,\n locale: LocalesValues,\n baseLocale: LocalesValues\n): string => {\n if (!filePath || !locale || !baseLocale) {\n throw new Error('filePath, locale, and baseLocale are required');\n }\n\n let outputFilePath = filePath;\n\n // Define replacement patterns with global flag to replace all occurrences\n const replacements = [\n // Template placeholders (processed first)\n {\n pattern: /\\{\\{baseLocale\\}\\}/g,\n replacement: '{{locale}}',\n },\n {\n pattern: /\\{\\{baseLocaleName\\}\\}/g,\n replacement: '{{localeName}}',\n },\n\n // Path separators (most specific first)\n {\n // Unix path separators\n pattern: new RegExp(`/${baseLocale}/`, 'g'),\n replacement: `/${locale}/`,\n },\n {\n // Windows path separators\n pattern: new RegExp(`\\\\\\\\${baseLocale}\\\\\\\\`, 'g'),\n replacement: `\\\\${locale}\\\\`,\n },\n\n // File naming patterns\n {\n // file_en.md → file_fr.md\n pattern: new RegExp(`_${baseLocale}\\\\.`, 'g'),\n replacement: `_${locale}.`,\n },\n {\n // /file_en.md → /file_fr.md\n pattern: new RegExp(`/${baseLocale}_`, 'g'),\n replacement: `/${locale}_`,\n },\n {\n // Start of filename pattern en_guide.md → fr_guide.md (or after path separator)\n pattern: new RegExp(`(^|[\\\\/])${baseLocale}_`, 'g'),\n replacement: `$1${locale}_`,\n },\n {\n // Dot delimited pattern guide.en.md → guide.fr.md\n pattern: new RegExp(`\\\\.${baseLocale}\\\\.`, 'g'),\n replacement: `.${locale}.`,\n },\n ];\n\n // Apply all replacements\n for (const { pattern, replacement } of replacements) {\n outputFilePath = outputFilePath.replace(pattern, replacement);\n }\n\n // If no changes were made, append locale as extension\n if (outputFilePath === filePath) {\n const lastDotIndex = filePath.lastIndexOf('.');\n if (lastDotIndex > 0) {\n // Insert locale before the file extension\n return `${filePath.slice(0, lastDotIndex)}.${locale}${filePath.slice(lastDotIndex)}`;\n } else {\n // No extension found, just append\n return `${filePath}.${locale}`;\n }\n }\n\n return outputFilePath;\n};\n"],"mappings":"AAyBA,MAAa,GACX,EACA,EACA,IACW,CACX,GAAI,CAAC,GAAY,CAAC,GAAU,CAAC,EAC3B,MAAU,MAAM,gDAAgD,CAGlE,IAAI,EAAiB,EAGf,EAAe,CAEnB,CACE,QAAS,sBACT,YAAa,aACd,CACD,CACE,QAAS,0BACT,YAAa,iBACd,CAGD,CAEE,QAAa,OAAO,IAAI,EAAW,GAAI,IAAI,CAC3C,YAAa,IAAI,EAAO,GACzB,CACD,CAEE,QAAa,OAAO,OAAO,EAAW,MAAO,IAAI,CACjD,YAAa,KAAK,EAAO,IAC1B,CAGD,CAEE,QAAa,OAAO,IAAI,EAAW,KAAM,IAAI,CAC7C,YAAa,IAAI,EAAO,GACzB,CACD,CAEE,QAAa,OAAO,IAAI,EAAW,GAAI,IAAI,CAC3C,YAAa,IAAI,EAAO,GACzB,CACD,CAEE,QAAa,OAAO,YAAY,EAAW,GAAI,IAAI,CACnD,YAAa,KAAK,EAAO,GAC1B,CACD,CAEE,QAAa,OAAO,MAAM,EAAW,KAAM,IAAI,CAC/C,YAAa,IAAI,EAAO,GACzB,CACF,CAGD,IAAK,GAAM,CAAE,UAAS,iBAAiB,EACrC,EAAiB,EAAe,QAAQ,EAAS,EAAY,CAI/D,GAAI,IAAmB,EAAU,CAC/B,IAAM,EAAe,EAAS,YAAY,IAAI,CAM5C,OALE,EAAe,EAEV,GAAG,EAAS,MAAM,EAAG,EAAa,CAAC,GAAG,IAAS,EAAS,MAAM,EAAa,GAG3E,GAAG,EAAS,GAAG,IAI1B,OAAO"}
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/getParentPackageJSON.ts
|
|
5
|
-
const getParentPackageJSON = (startDir) => {
|
|
6
|
-
let currentDir = startDir;
|
|
7
|
-
while (currentDir !== dirname(currentDir)) {
|
|
8
|
-
const packageJsonPath = resolve(currentDir, "package.json");
|
|
9
|
-
if (existsSync(packageJsonPath)) return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
10
|
-
currentDir = dirname(currentDir);
|
|
11
|
-
}
|
|
12
|
-
const rootPackageJsonPath = resolve(currentDir, "package.json");
|
|
13
|
-
if (existsSync(rootPackageJsonPath)) return JSON.parse(readFileSync(rootPackageJsonPath, "utf8"));
|
|
14
|
-
throw new Error(`No package.json found in any parent directory of ${startDir}`);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { getParentPackageJSON };
|
|
1
|
+
import{dirname as e,resolve as t}from"node:path";import{existsSync as n,readFileSync as r}from"node:fs";const i=i=>{let a=i;for(;a!==e(a);){let i=t(a,`package.json`);if(n(i))return JSON.parse(r(i,`utf8`));a=e(a)}let o=t(a,`package.json`);if(n(o))return JSON.parse(r(o,`utf8`));throw Error(`No package.json found in any parent directory of ${i}`)};export{i as getParentPackageJSON};
|
|
19
2
|
//# sourceMappingURL=getParentPackageJSON.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getParentPackageJSON.mjs","names":[],"sources":["../../../src/utils/getParentPackageJSON.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\n\ntype PackageJSON = {\n name?: string;\n version?: string;\n private: boolean;\n description?: string;\n homepage?: string;\n bugs: {\n url?: string;\n };\n repository: {\n type?: string;\n url?: string;\n };\n license?: string;\n author: {\n name?: string;\n url?: string;\n };\n contributors?: {\n name?: string;\n email?: string;\n url?: string;\n }[];\n type?: string;\n scripts: Record<string, string>;\n devDependencies: Record<string, string>;\n packageManager?: string;\n engines: Record<string, string>;\n};\n\nexport const getParentPackageJSON = (startDir: string): PackageJSON => {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Stop when we reach the root\n const packageJsonPath = resolve(currentDir, 'package.json');\n\n if (existsSync(packageJsonPath)) {\n return JSON.parse(readFileSync(packageJsonPath, 'utf8'));\n }\n\n // Move up one directory level\n currentDir = dirname(currentDir);\n }\n\n // Check the root directory as well\n const rootPackageJsonPath = resolve(currentDir, 'package.json');\n if (existsSync(rootPackageJsonPath)) {\n return JSON.parse(readFileSync(rootPackageJsonPath, 'utf8'));\n }\n\n // If no package.json is found in any parent directory\n throw new Error(\n `No package.json found in any parent directory of ${startDir}`\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getParentPackageJSON.mjs","names":[],"sources":["../../../src/utils/getParentPackageJSON.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\n\ntype PackageJSON = {\n name?: string;\n version?: string;\n private: boolean;\n description?: string;\n homepage?: string;\n bugs: {\n url?: string;\n };\n repository: {\n type?: string;\n url?: string;\n };\n license?: string;\n author: {\n name?: string;\n url?: string;\n };\n contributors?: {\n name?: string;\n email?: string;\n url?: string;\n }[];\n type?: string;\n scripts: Record<string, string>;\n devDependencies: Record<string, string>;\n packageManager?: string;\n engines: Record<string, string>;\n};\n\nexport const getParentPackageJSON = (startDir: string): PackageJSON => {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Stop when we reach the root\n const packageJsonPath = resolve(currentDir, 'package.json');\n\n if (existsSync(packageJsonPath)) {\n return JSON.parse(readFileSync(packageJsonPath, 'utf8'));\n }\n\n // Move up one directory level\n currentDir = dirname(currentDir);\n }\n\n // Check the root directory as well\n const rootPackageJsonPath = resolve(currentDir, 'package.json');\n if (existsSync(rootPackageJsonPath)) {\n return JSON.parse(readFileSync(rootPackageJsonPath, 'utf8'));\n }\n\n // If no package.json is found in any parent directory\n throw new Error(\n `No package.json found in any parent directory of ${startDir}`\n );\n};\n"],"mappings":"wGAiCA,MAAa,EAAwB,GAAkC,CACrE,IAAI,EAAa,EAEjB,KAAO,IAAe,EAAQ,EAAW,EAAE,CAEzC,IAAM,EAAkB,EAAQ,EAAY,eAAe,CAE3D,GAAI,EAAW,EAAgB,CAC7B,OAAO,KAAK,MAAM,EAAa,EAAiB,OAAO,CAAC,CAI1D,EAAa,EAAQ,EAAW,CAIlC,IAAM,EAAsB,EAAQ,EAAY,eAAe,CAC/D,GAAI,EAAW,EAAoB,CACjC,OAAO,KAAK,MAAM,EAAa,EAAqB,OAAO,CAAC,CAI9D,MAAU,MACR,oDAAoD,IACrD"}
|
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
" ",
|
|
4
|
-
"\\",
|
|
5
|
-
"|",
|
|
6
|
-
"(",
|
|
7
|
-
")",
|
|
8
|
-
"{",
|
|
9
|
-
"}",
|
|
10
|
-
"[",
|
|
11
|
-
"]",
|
|
12
|
-
"<",
|
|
13
|
-
">",
|
|
14
|
-
"\"",
|
|
15
|
-
"=",
|
|
16
|
-
"+",
|
|
17
|
-
"*",
|
|
18
|
-
"&",
|
|
19
|
-
"#",
|
|
20
|
-
"%",
|
|
21
|
-
"$",
|
|
22
|
-
"!",
|
|
23
|
-
"?",
|
|
24
|
-
":",
|
|
25
|
-
";",
|
|
26
|
-
"~"
|
|
27
|
-
];
|
|
28
|
-
const listSpecialChars = (text) => {
|
|
29
|
-
const results = [];
|
|
30
|
-
let lineIndex = 0;
|
|
31
|
-
for (let i = 0; i < text.length; i++) {
|
|
32
|
-
const currentChar = text[i];
|
|
33
|
-
if (currentChar === "\n") {
|
|
34
|
-
results.push({
|
|
35
|
-
char: "\\",
|
|
36
|
-
lineStart: lineIndex,
|
|
37
|
-
charStart: i
|
|
38
|
-
});
|
|
39
|
-
lineIndex++;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (SPECIAL_CHARS.includes(currentChar)) results.push({
|
|
43
|
-
char: currentChar,
|
|
44
|
-
lineStart: lineIndex,
|
|
45
|
-
charStart: i
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return results;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
export { listSpecialChars };
|
|
1
|
+
const e=[` `,`\\`,`|`,`(`,`)`,`{`,`}`,`[`,`]`,`<`,`>`,`"`,`=`,`+`,`*`,`&`,`#`,`%`,`$`,`!`,`?`,`:`,`;`,`~`],t=t=>{let n=[],r=0;for(let i=0;i<t.length;i++){let a=t[i];if(a===`
|
|
2
|
+
`){n.push({char:`\\`,lineStart:r,charStart:i}),r++;continue}e.includes(a)&&n.push({char:a,lineStart:r,charStart:i})}return n};export{t as listSpecialChars};
|
|
53
3
|
//# sourceMappingURL=listSpecialChars.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listSpecialChars.mjs","names":[],"sources":["../../../src/utils/listSpecialChars.ts"],"sourcesContent":["type ListCharResult = {\n char: string;\n /** First line index contained in this chunk (0-based) */\n lineStart: number;\n /** Start character index in the original text (0-based, inclusive)*/\n charStart: number;\n}[];\n\nconst SPECIAL_CHARS = [\n ' ',\n '\\\\',\n '|',\n '(',\n ')',\n '{',\n '}',\n '[',\n ']',\n '<',\n '>',\n '\"',\n '=',\n '+',\n '*',\n '&',\n '#',\n '%',\n '$',\n '!',\n '?',\n ':',\n ';',\n '~',\n];\n\nexport const listSpecialChars = (text: string): ListCharResult => {\n const results: ListCharResult = [];\n\n let lineIndex = 0;\n\n for (let i = 0; i < text.length; i++) {\n const currentChar = text[i];\n\n // Handle newline characters (\"\\n\"): treat them as a \"\\\\\" special char\n if (currentChar === '\\n') {\n results.push({\n char: '\\\\',\n lineStart: lineIndex,\n charStart: i,\n });\n\n // Move to the next line after recording the special char\n lineIndex++;\n continue;\n }\n\n // Check if the current character is one of the special characters\n if (SPECIAL_CHARS.includes(currentChar)) {\n results.push({\n char: currentChar,\n lineStart: lineIndex,\n charStart: i,\n });\n }\n }\n\n return results;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"listSpecialChars.mjs","names":[],"sources":["../../../src/utils/listSpecialChars.ts"],"sourcesContent":["type ListCharResult = {\n char: string;\n /** First line index contained in this chunk (0-based) */\n lineStart: number;\n /** Start character index in the original text (0-based, inclusive)*/\n charStart: number;\n}[];\n\nconst SPECIAL_CHARS = [\n ' ',\n '\\\\',\n '|',\n '(',\n ')',\n '{',\n '}',\n '[',\n ']',\n '<',\n '>',\n '\"',\n '=',\n '+',\n '*',\n '&',\n '#',\n '%',\n '$',\n '!',\n '?',\n ':',\n ';',\n '~',\n];\n\nexport const listSpecialChars = (text: string): ListCharResult => {\n const results: ListCharResult = [];\n\n let lineIndex = 0;\n\n for (let i = 0; i < text.length; i++) {\n const currentChar = text[i];\n\n // Handle newline characters (\"\\n\"): treat them as a \"\\\\\" special char\n if (currentChar === '\\n') {\n results.push({\n char: '\\\\',\n lineStart: lineIndex,\n charStart: i,\n });\n\n // Move to the next line after recording the special char\n lineIndex++;\n continue;\n }\n\n // Check if the current character is one of the special characters\n if (SPECIAL_CHARS.includes(currentChar)) {\n results.push({\n char: currentChar,\n lineStart: lineIndex,\n charStart: i,\n });\n }\n }\n\n return results;\n};\n"],"mappings":"AAQA,MAAM,EAAgB,CACpB,KACA,KACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IACD,CAEY,EAAoB,GAAiC,CAChE,IAAM,EAA0B,EAAE,CAE9B,EAAY,EAEhB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,CACpC,IAAM,EAAc,EAAK,GAGzB,GAAI,IAAgB;EAAM,CACxB,EAAQ,KAAK,CACX,KAAM,KACN,UAAW,EACX,UAAW,EACZ,CAAC,CAGF,IACA,SAIE,EAAc,SAAS,EAAY,EACrC,EAAQ,KAAK,CACX,KAAM,EACN,UAAW,EACX,UAAW,EACZ,CAAC,CAIN,OAAO"}
|
|
@@ -1,101 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { splitTextByLines } from "@intlayer/chokidar";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/mapChunksBetweenFiles.ts
|
|
5
|
-
/**
|
|
6
|
-
* Maps chunks from base file to corresponding chunks in updated file,
|
|
7
|
-
* handling insertions, deletions, and modifications properly.
|
|
8
|
-
*/
|
|
9
|
-
const mapChunksBetweenFiles = (baseFileContent, updatedFileContent, maxCharsPerChunk = 800, changedLines) => {
|
|
10
|
-
const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);
|
|
11
|
-
const baseLines = splitTextByLines(baseFileContent);
|
|
12
|
-
const updatedLines = splitTextByLines(updatedFileContent);
|
|
13
|
-
const lineMapping = createLineMapping(baseLines, updatedLines);
|
|
14
|
-
return baseChunks.map((baseChunk) => {
|
|
15
|
-
const mappedRange = mapLineRange(baseChunk.lineStart, baseChunk.lineLength, lineMapping);
|
|
16
|
-
if (!mappedRange) return {
|
|
17
|
-
baseChunk,
|
|
18
|
-
updatedChunk: null,
|
|
19
|
-
hasChanges: true
|
|
20
|
-
};
|
|
21
|
-
const updatedChunk = {
|
|
22
|
-
lineStart: mappedRange.start,
|
|
23
|
-
lineLength: mappedRange.length,
|
|
24
|
-
charStart: 0,
|
|
25
|
-
charLength: 0,
|
|
26
|
-
content: extractLinesFromRange(updatedLines, mappedRange.start, mappedRange.length)
|
|
27
|
-
};
|
|
28
|
-
updatedChunk.charStart = getCharStartForLine(updatedFileContent, updatedChunk.lineStart);
|
|
29
|
-
updatedChunk.charLength = updatedChunk.content.length;
|
|
30
|
-
return {
|
|
31
|
-
baseChunk,
|
|
32
|
-
updatedChunk,
|
|
33
|
-
hasChanges: determineIfChunkHasChanges(baseChunk, updatedChunk, changedLines)
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Creates a mapping between line numbers in base file and updated file
|
|
39
|
-
* Returns a map where key = base line number, value = updated line number (or null if deleted)
|
|
40
|
-
*/
|
|
41
|
-
const createLineMapping = (baseLines, updatedLines) => {
|
|
42
|
-
const mapping = /* @__PURE__ */ new Map();
|
|
43
|
-
const dp = Array(baseLines.length + 1).fill(null).map(() => Array(updatedLines.length + 1).fill(0));
|
|
44
|
-
for (let i = 1; i <= baseLines.length; i++) for (let j = 1; j <= updatedLines.length; j++) if (baseLines[i - 1] === updatedLines[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
45
|
-
else dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
46
|
-
let i = baseLines.length;
|
|
47
|
-
let j = updatedLines.length;
|
|
48
|
-
while (i > 0 || j > 0) if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {
|
|
49
|
-
mapping.set(i - 1, j - 1);
|
|
50
|
-
i--;
|
|
51
|
-
j--;
|
|
52
|
-
} else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {
|
|
53
|
-
mapping.set(i - 1, null);
|
|
54
|
-
i--;
|
|
55
|
-
} else j--;
|
|
56
|
-
return mapping;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Maps a line range from base file to updated file using the line mapping
|
|
60
|
-
*/
|
|
61
|
-
const mapLineRange = (baseStart, baseLength, lineMapping) => {
|
|
62
|
-
const mappedLines = [];
|
|
63
|
-
for (let i = baseStart; i < baseStart + baseLength; i++) {
|
|
64
|
-
const mappedLine = lineMapping.get(i);
|
|
65
|
-
if (mappedLine !== null && mappedLine !== void 0) mappedLines.push(mappedLine);
|
|
66
|
-
}
|
|
67
|
-
if (mappedLines.length === 0) return null;
|
|
68
|
-
mappedLines.sort((a, b) => a - b);
|
|
69
|
-
const start = mappedLines[0];
|
|
70
|
-
return {
|
|
71
|
-
start,
|
|
72
|
-
length: mappedLines[mappedLines.length - 1] - start + 1
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Extracts lines from a range in the lines array
|
|
77
|
-
*/
|
|
78
|
-
const extractLinesFromRange = (lines, start, length) => {
|
|
79
|
-
const endIndex = Math.min(start + length, lines.length);
|
|
80
|
-
return lines.slice(start, endIndex).join("");
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Gets the character position where a line starts in the text
|
|
84
|
-
*/
|
|
85
|
-
const getCharStartForLine = (text, lineNumber) => {
|
|
86
|
-
const lines = splitTextByLines(text);
|
|
87
|
-
let charStart = 0;
|
|
88
|
-
for (let i = 0; i < Math.min(lineNumber, lines.length); i++) charStart += lines[i].length;
|
|
89
|
-
return charStart;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Determines if a chunk has changes based on git changed lines or content comparison
|
|
93
|
-
*/
|
|
94
|
-
const determineIfChunkHasChanges = (baseChunk, updatedChunk, changedLines) => {
|
|
95
|
-
if (changedLines && changedLines.length > 0) return changedLines.some((line) => line >= updatedChunk.lineStart && line < updatedChunk.lineStart + updatedChunk.lineLength);
|
|
96
|
-
return baseChunk.content !== updatedChunk.content;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
//#endregion
|
|
100
|
-
export { mapChunksBetweenFiles };
|
|
1
|
+
import{chunkText as e}from"./calculateChunks.mjs";import{splitTextByLines as t}from"@intlayer/chokidar/utils";const n=(n,c,l=800,u)=>{let d=e(n,l,0),f=t(n),p=t(c),m=r(f,p);return d.map(e=>{let t=i(e.lineStart,e.lineLength,m);if(!t)return{baseChunk:e,updatedChunk:null,hasChanges:!0};let n={lineStart:t.start,lineLength:t.length,charStart:0,charLength:0,content:a(p,t.start,t.length)};return n.charStart=o(c,n.lineStart),n.charLength=n.content.length,{baseChunk:e,updatedChunk:n,hasChanges:s(e,n,u)}})},r=(e,t)=>{let n=new Map,r=Array(e.length+1).fill(null).map(()=>Array(t.length+1).fill(0));for(let n=1;n<=e.length;n++)for(let i=1;i<=t.length;i++)e[n-1]===t[i-1]?r[n][i]=r[n-1][i-1]+1:r[n][i]=Math.max(r[n-1][i],r[n][i-1]);let i=e.length,a=t.length;for(;i>0||a>0;)i>0&&a>0&&e[i-1]===t[a-1]?(n.set(i-1,a-1),i--,a--):i>0&&(a===0||r[i-1][a]>=r[i][a-1])?(n.set(i-1,null),i--):a--;return n},i=(e,t,n)=>{let r=[];for(let i=e;i<e+t;i++){let e=n.get(i);e!=null&&r.push(e)}if(r.length===0)return null;r.sort((e,t)=>e-t);let i=r[0];return{start:i,length:r[r.length-1]-i+1}},a=(e,t,n)=>{let r=Math.min(t+n,e.length);return e.slice(t,r).join(``)},o=(e,n)=>{let r=t(e),i=0;for(let e=0;e<Math.min(n,r.length);e++)i+=r[e].length;return i},s=(e,t,n)=>n&&n.length>0?n.some(e=>e>=t.lineStart&&e<t.lineStart+t.lineLength):e.content!==t.content;export{n as mapChunksBetweenFiles};
|
|
101
2
|
//# sourceMappingURL=mapChunksBetweenFiles.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapChunksBetweenFiles.mjs","names":[],"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar';\nimport { type ChunkLineResult, chunkText } from './calculateChunks';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapChunksBetweenFiles.mjs","names":[],"sources":["../../../src/utils/mapChunksBetweenFiles.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar/utils';\nimport { type ChunkLineResult, chunkText } from './calculateChunks';\n\nexport interface ChunkMapping {\n baseChunk: ChunkLineResult;\n updatedChunk: ChunkLineResult | null; // null if the chunk was deleted\n hasChanges: boolean;\n}\n\n/**\n * Maps chunks from base file to corresponding chunks in updated file,\n * handling insertions, deletions, and modifications properly.\n */\nexport const mapChunksBetweenFiles = (\n baseFileContent: string,\n updatedFileContent: string,\n maxCharsPerChunk: number = 800,\n changedLines?: number[]\n): ChunkMapping[] => {\n const baseChunks = chunkText(baseFileContent, maxCharsPerChunk, 0);\n const baseLines = splitTextByLines(baseFileContent);\n const updatedLines = splitTextByLines(updatedFileContent);\n\n // Create a simple line mapping using LCS (Longest Common Subsequence) approach\n const lineMapping = createLineMapping(baseLines, updatedLines);\n\n return baseChunks.map((baseChunk): ChunkMapping => {\n // Map the base chunk's line range to the updated file\n const mappedRange = mapLineRange(\n baseChunk.lineStart,\n baseChunk.lineLength,\n lineMapping\n );\n\n if (!mappedRange) {\n // This chunk was completely deleted\n return {\n baseChunk,\n updatedChunk: null,\n hasChanges: true,\n };\n }\n\n // Create the corresponding chunk in the updated file\n const updatedChunk: ChunkLineResult = {\n lineStart: mappedRange.start,\n lineLength: mappedRange.length,\n charStart: 0, // Will be calculated when needed\n charLength: 0, // Will be calculated when needed\n content: extractLinesFromRange(\n updatedLines,\n mappedRange.start,\n mappedRange.length\n ),\n };\n\n // Calculate character positions\n updatedChunk.charStart = getCharStartForLine(\n updatedFileContent,\n updatedChunk.lineStart\n );\n updatedChunk.charLength = updatedChunk.content.length;\n\n // Determine if this chunk has changes\n const hasChanges = determineIfChunkHasChanges(\n baseChunk,\n updatedChunk,\n changedLines\n );\n\n return {\n baseChunk,\n updatedChunk,\n hasChanges,\n };\n });\n};\n\n/**\n * Creates a mapping between line numbers in base file and updated file\n * Returns a map where key = base line number, value = updated line number (or null if deleted)\n */\nconst createLineMapping = (\n baseLines: string[],\n updatedLines: string[]\n): Map<number, number | null> => {\n const mapping = new Map<number, number | null>();\n\n // Use a simple diff algorithm (similar to Myers algorithm but simplified)\n const dp: number[][] = Array(baseLines.length + 1)\n .fill(null)\n .map(() => Array(updatedLines.length + 1).fill(0));\n\n // Fill the DP table\n for (let i = 1; i <= baseLines.length; i++) {\n for (let j = 1; j <= updatedLines.length; j++) {\n if (baseLines[i - 1] === updatedLines[j - 1]) {\n dp[i][j] = dp[i - 1][j - 1] + 1;\n } else {\n dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n }\n }\n }\n\n // Backtrack to create the mapping\n let i = baseLines.length;\n let j = updatedLines.length;\n\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && baseLines[i - 1] === updatedLines[j - 1]) {\n // Lines match\n mapping.set(i - 1, j - 1);\n i--;\n j--;\n } else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {\n // Line was deleted from base\n mapping.set(i - 1, null);\n i--;\n } else {\n // Line was added to updated (no mapping needed for base)\n j--;\n }\n }\n\n return mapping;\n};\n\n/**\n * Maps a line range from base file to updated file using the line mapping\n */\nconst mapLineRange = (\n baseStart: number,\n baseLength: number,\n lineMapping: Map<number, number | null>\n): { start: number; length: number } | null => {\n const mappedLines: number[] = [];\n\n for (let i = baseStart; i < baseStart + baseLength; i++) {\n const mappedLine = lineMapping.get(i);\n if (mappedLine !== null && mappedLine !== undefined) {\n mappedLines.push(mappedLine);\n }\n }\n\n if (mappedLines.length === 0) {\n return null; // All lines were deleted\n }\n\n // Find the continuous range in the mapped lines\n mappedLines.sort((a, b) => a - b);\n const start = mappedLines[0];\n const end = mappedLines[mappedLines.length - 1];\n\n return {\n start,\n length: end - start + 1,\n };\n};\n\n/**\n * Extracts lines from a range in the lines array\n */\nconst extractLinesFromRange = (\n lines: string[],\n start: number,\n length: number\n): string => {\n const endIndex = Math.min(start + length, lines.length);\n return lines.slice(start, endIndex).join('');\n};\n\n/**\n * Gets the character position where a line starts in the text\n */\nconst getCharStartForLine = (text: string, lineNumber: number): number => {\n const lines = splitTextByLines(text);\n let charStart = 0;\n\n for (let i = 0; i < Math.min(lineNumber, lines.length); i++) {\n charStart += lines[i].length;\n }\n\n return charStart;\n};\n\n/**\n * Determines if a chunk has changes based on git changed lines or content comparison\n */\nconst determineIfChunkHasChanges = (\n baseChunk: ChunkLineResult,\n updatedChunk: ChunkLineResult,\n changedLines?: number[]\n): boolean => {\n // If we have git changed lines, use them for precise detection\n if (changedLines && changedLines.length > 0) {\n return changedLines.some(\n (line) =>\n line >= updatedChunk.lineStart &&\n line < updatedChunk.lineStart + updatedChunk.lineLength\n );\n }\n\n // Fallback to content comparison\n return baseChunk.content !== updatedChunk.content;\n};\n"],"mappings":"8GAaA,MAAa,GACX,EACA,EACA,EAA2B,IAC3B,IACmB,CACnB,IAAM,EAAa,EAAU,EAAiB,EAAkB,EAAE,CAC5D,EAAY,EAAiB,EAAgB,CAC7C,EAAe,EAAiB,EAAmB,CAGnD,EAAc,EAAkB,EAAW,EAAa,CAE9D,OAAO,EAAW,IAAK,GAA4B,CAEjD,IAAM,EAAc,EAClB,EAAU,UACV,EAAU,WACV,EACD,CAED,GAAI,CAAC,EAEH,MAAO,CACL,YACA,aAAc,KACd,WAAY,GACb,CAIH,IAAM,EAAgC,CACpC,UAAW,EAAY,MACvB,WAAY,EAAY,OACxB,UAAW,EACX,WAAY,EACZ,QAAS,EACP,EACA,EAAY,MACZ,EAAY,OACb,CACF,CAgBD,MAbA,GAAa,UAAY,EACvB,EACA,EAAa,UACd,CACD,EAAa,WAAa,EAAa,QAAQ,OASxC,CACL,YACA,eACA,WATiB,EACjB,EACA,EACA,EACD,CAMA,EACD,EAOE,GACJ,EACA,IAC+B,CAC/B,IAAM,EAAU,IAAI,IAGd,EAAiB,MAAM,EAAU,OAAS,EAAE,CAC/C,KAAK,KAAK,CACV,QAAU,MAAM,EAAa,OAAS,EAAE,CAAC,KAAK,EAAE,CAAC,CAGpD,IAAK,IAAI,EAAI,EAAG,GAAK,EAAU,OAAQ,IACrC,IAAK,IAAI,EAAI,EAAG,GAAK,EAAa,OAAQ,IACpC,EAAU,EAAI,KAAO,EAAa,EAAI,GACxC,EAAG,GAAG,GAAK,EAAG,EAAI,GAAG,EAAI,GAAK,EAE9B,EAAG,GAAG,GAAK,KAAK,IAAI,EAAG,EAAI,GAAG,GAAI,EAAG,GAAG,EAAI,GAAG,CAMrD,IAAI,EAAI,EAAU,OACd,EAAI,EAAa,OAErB,KAAO,EAAI,GAAK,EAAI,GACd,EAAI,GAAK,EAAI,GAAK,EAAU,EAAI,KAAO,EAAa,EAAI,IAE1D,EAAQ,IAAI,EAAI,EAAG,EAAI,EAAE,CACzB,IACA,KACS,EAAI,IAAM,IAAM,GAAK,EAAG,EAAI,GAAG,IAAM,EAAG,GAAG,EAAI,KAExD,EAAQ,IAAI,EAAI,EAAG,KAAK,CACxB,KAGA,IAIJ,OAAO,GAMH,GACJ,EACA,EACA,IAC6C,CAC7C,IAAM,EAAwB,EAAE,CAEhC,IAAK,IAAI,EAAI,EAAW,EAAI,EAAY,EAAY,IAAK,CACvD,IAAM,EAAa,EAAY,IAAI,EAAE,CACjC,GAAe,MACjB,EAAY,KAAK,EAAW,CAIhC,GAAI,EAAY,SAAW,EACzB,OAAO,KAIT,EAAY,MAAM,EAAG,IAAM,EAAI,EAAE,CACjC,IAAM,EAAQ,EAAY,GAG1B,MAAO,CACL,QACA,OAJU,EAAY,EAAY,OAAS,GAI7B,EAAQ,EACvB,EAMG,GACJ,EACA,EACA,IACW,CACX,IAAM,EAAW,KAAK,IAAI,EAAQ,EAAQ,EAAM,OAAO,CACvD,OAAO,EAAM,MAAM,EAAO,EAAS,CAAC,KAAK,GAAG,EAMxC,GAAuB,EAAc,IAA+B,CACxE,IAAM,EAAQ,EAAiB,EAAK,CAChC,EAAY,EAEhB,IAAK,IAAI,EAAI,EAAG,EAAI,KAAK,IAAI,EAAY,EAAM,OAAO,CAAE,IACtD,GAAa,EAAM,GAAG,OAGxB,OAAO,GAMH,GACJ,EACA,EACA,IAGI,GAAgB,EAAa,OAAS,EACjC,EAAa,KACjB,GACC,GAAQ,EAAa,WACrB,EAAO,EAAa,UAAY,EAAa,WAChD,CAII,EAAU,UAAY,EAAa"}
|