@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
package/dist/cjs/push/push.cjs
CHANGED
|
@@ -1,207 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_utils_checkAccess = require('../utils/checkAccess.cjs');
|
|
4
|
-
const require_pushLog = require('../pushLog.cjs');
|
|
5
|
-
let _intlayer_api = require("@intlayer/api");
|
|
6
|
-
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
7
|
-
let _intlayer_config = require("@intlayer/config");
|
|
8
|
-
let node_path = require("node:path");
|
|
9
|
-
let node_fs_promises = require("node:fs/promises");
|
|
10
|
-
node_fs_promises = require_runtime.__toESM(node_fs_promises);
|
|
11
|
-
let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
|
|
12
|
-
|
|
13
|
-
//#region src/push/push.ts
|
|
14
|
-
const statusIconsAndColors = {
|
|
15
|
-
pushed: {
|
|
16
|
-
icon: "✔",
|
|
17
|
-
color: _intlayer_config.ANSIColors.GREEN
|
|
18
|
-
},
|
|
19
|
-
modified: {
|
|
20
|
-
icon: "✔",
|
|
21
|
-
color: _intlayer_config.ANSIColors.GREEN
|
|
22
|
-
},
|
|
23
|
-
error: {
|
|
24
|
-
icon: "✖",
|
|
25
|
-
color: _intlayer_config.ANSIColors.RED
|
|
26
|
-
},
|
|
27
|
-
default: {
|
|
28
|
-
icon: "⏲",
|
|
29
|
-
color: _intlayer_config.ANSIColors.BLUE
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const getIconAndColor = (status) => {
|
|
33
|
-
return statusIconsAndColors[status] ?? statusIconsAndColors.default;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Get all local dictionaries and push them simultaneously.
|
|
37
|
-
*/
|
|
38
|
-
const push = async (options) => {
|
|
39
|
-
const config = (0, _intlayer_config.getConfiguration)(options?.configOptions);
|
|
40
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
41
|
-
if (options?.build === true) await (0, _intlayer_chokidar.prepareIntlayer)(config, { forceRun: true });
|
|
42
|
-
else if (typeof options?.build === "undefined") await (0, _intlayer_chokidar.prepareIntlayer)(config);
|
|
43
|
-
try {
|
|
44
|
-
if (!await require_utils_checkAccess.checkCMSAuth(config)) return;
|
|
45
|
-
const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, config);
|
|
46
|
-
const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(config);
|
|
47
|
-
const allDictionaries = Object.values(unmergedDictionariesRecord).flat();
|
|
48
|
-
const customLocations = Array.from(new Set(allDictionaries.map((dictionary) => dictionary.location).filter((location) => location && ![
|
|
49
|
-
"remote",
|
|
50
|
-
"local",
|
|
51
|
-
"hybrid"
|
|
52
|
-
].includes(location))));
|
|
53
|
-
let selectedCustomLocations = [];
|
|
54
|
-
if (customLocations.length > 0) {
|
|
55
|
-
const { multiselect, confirm, isCancel } = await import("@clack/prompts");
|
|
56
|
-
if (customLocations.length === 1) {
|
|
57
|
-
const shouldPush = await confirm({
|
|
58
|
-
message: `Do you want to push dictionaries with custom location ${(0, _intlayer_config.colorize)(customLocations[0], _intlayer_config.ANSIColors.BLUE, _intlayer_config.ANSIColors.RESET)}?`,
|
|
59
|
-
initialValue: false
|
|
60
|
-
});
|
|
61
|
-
if (isCancel(shouldPush)) return;
|
|
62
|
-
if (shouldPush) selectedCustomLocations = [customLocations[0]];
|
|
63
|
-
} else {
|
|
64
|
-
const selected = await multiselect({
|
|
65
|
-
message: "Select custom locations to push:",
|
|
66
|
-
options: customLocations.map((location) => ({
|
|
67
|
-
value: location,
|
|
68
|
-
label: location
|
|
69
|
-
})),
|
|
70
|
-
required: false
|
|
71
|
-
});
|
|
72
|
-
if (isCancel(selected)) return;
|
|
73
|
-
selectedCustomLocations = selected;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
let dictionaries = allDictionaries.filter((dictionary) => {
|
|
77
|
-
const location = dictionary.location ?? config.dictionary?.location ?? "local";
|
|
78
|
-
return location === "remote" || location === "hybrid" || selectedCustomLocations.includes(location);
|
|
79
|
-
});
|
|
80
|
-
if (dictionaries.length === 0) {
|
|
81
|
-
appLogger(`No dictionaries found to push. Only dictionaries with location ${(0, _intlayer_config.colorize)("remote", _intlayer_config.ANSIColors.BLUE, _intlayer_config.ANSIColors.RESET)}, ${(0, _intlayer_config.colorize)("hybrid", _intlayer_config.ANSIColors.BLUE, _intlayer_config.ANSIColors.RESET)} or selected custom locations are pushed.`, { level: "warn" });
|
|
82
|
-
appLogger(`You can set the location in your dictionary file (e.g. ${(0, _intlayer_config.colorize)("{ key: 'my-key', location: 'hybrid', ... }", _intlayer_config.ANSIColors.BLUE, _intlayer_config.ANSIColors.RESET)} or globally in your intlayer.config.ts file (e.g. ${(0, _intlayer_config.colorize)("{ dictionary: { location: 'hybrid' } }", _intlayer_config.ANSIColors.BLUE, _intlayer_config.ANSIColors.RESET)}).`, { level: "info" });
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const existingDictionariesKeys = Object.keys(unmergedDictionariesRecord);
|
|
86
|
-
if (options?.dictionaries) {
|
|
87
|
-
const noneExistingDictionariesOption = options.dictionaries.filter((dictionaryId) => !existingDictionariesKeys.includes(dictionaryId));
|
|
88
|
-
if (noneExistingDictionariesOption.length > 0) appLogger(`The following dictionaries do not exist: ${noneExistingDictionariesOption.join(", ")} and have been ignored.`, { level: "error" });
|
|
89
|
-
dictionaries = dictionaries.filter((dictionary) => options.dictionaries?.includes(dictionary.key));
|
|
90
|
-
}
|
|
91
|
-
if (options?.gitOptions) {
|
|
92
|
-
const gitFiles = await (0, _intlayer_chokidar.listGitFiles)(options.gitOptions);
|
|
93
|
-
dictionaries = dictionaries.filter((dictionary) => gitFiles.includes((0, node_path.join)(config.content.baseDir, dictionary.filePath ?? "")));
|
|
94
|
-
}
|
|
95
|
-
if (dictionaries.length === 0) {
|
|
96
|
-
appLogger("No local dictionaries found", { level: "error" });
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
appLogger("Pushing dictionaries:");
|
|
100
|
-
const dictionariesStatuses = dictionaries.map((dictionary) => ({
|
|
101
|
-
dictionary,
|
|
102
|
-
status: "pending"
|
|
103
|
-
}));
|
|
104
|
-
const logger = new require_pushLog.PushLogger();
|
|
105
|
-
logger.update(dictionariesStatuses.map((s) => ({
|
|
106
|
-
dictionaryKey: s.dictionary.key,
|
|
107
|
-
status: "pending"
|
|
108
|
-
})));
|
|
109
|
-
const successfullyPushedDictionaries = [];
|
|
110
|
-
const processDictionary = async (statusObj) => {
|
|
111
|
-
statusObj.status = "pushing";
|
|
112
|
-
logger.update([{
|
|
113
|
-
dictionaryKey: statusObj.dictionary.key,
|
|
114
|
-
status: "pushing"
|
|
115
|
-
}]);
|
|
116
|
-
try {
|
|
117
|
-
const pushResult = await intlayerAPI.dictionary.pushDictionaries([statusObj.dictionary]);
|
|
118
|
-
const updatedDictionaries = pushResult.data?.updatedDictionaries ?? [];
|
|
119
|
-
const newDictionaries = pushResult.data?.newDictionaries ?? [];
|
|
120
|
-
const allDictionaries = [...updatedDictionaries, ...newDictionaries];
|
|
121
|
-
for (const remoteDictionaryData of allDictionaries) {
|
|
122
|
-
const localDictionary = unmergedDictionariesRecord[remoteDictionaryData.key]?.find((dictionary) => dictionary.localId === remoteDictionaryData.localId);
|
|
123
|
-
if (!localDictionary) continue;
|
|
124
|
-
await (0, _intlayer_chokidar.writeContentDeclaration)({
|
|
125
|
-
...localDictionary,
|
|
126
|
-
id: remoteDictionaryData.id
|
|
127
|
-
}, config);
|
|
128
|
-
}
|
|
129
|
-
if (updatedDictionaries.some((dictionary) => dictionary.key === statusObj.dictionary.key)) {
|
|
130
|
-
statusObj.status = "modified";
|
|
131
|
-
successfullyPushedDictionaries.push(statusObj.dictionary);
|
|
132
|
-
logger.update([{
|
|
133
|
-
dictionaryKey: statusObj.dictionary.key,
|
|
134
|
-
status: "modified"
|
|
135
|
-
}]);
|
|
136
|
-
} else if (newDictionaries.some((dictionary) => dictionary.key === statusObj.dictionary.key)) {
|
|
137
|
-
statusObj.status = "pushed";
|
|
138
|
-
successfullyPushedDictionaries.push(statusObj.dictionary);
|
|
139
|
-
logger.update([{
|
|
140
|
-
dictionaryKey: statusObj.dictionary.key,
|
|
141
|
-
status: "pushed"
|
|
142
|
-
}]);
|
|
143
|
-
} else statusObj.status = "unknown";
|
|
144
|
-
} catch (error) {
|
|
145
|
-
statusObj.status = "error";
|
|
146
|
-
statusObj.error = error;
|
|
147
|
-
statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;
|
|
148
|
-
logger.update([{
|
|
149
|
-
dictionaryKey: statusObj.dictionary.key,
|
|
150
|
-
status: "error"
|
|
151
|
-
}]);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
await (0, _intlayer_chokidar.parallelize)(dictionariesStatuses, processDictionary, 5);
|
|
155
|
-
logger.finish();
|
|
156
|
-
for (const dictionaryStatus of dictionariesStatuses) {
|
|
157
|
-
const { icon, color } = getIconAndColor(dictionaryStatus.status);
|
|
158
|
-
appLogger(` - ${(0, _intlayer_config.colorizeKey)(dictionaryStatus.dictionary.key)} ${_intlayer_config.ANSIColors.GREY}[${color}${icon} ${dictionaryStatus.status}${_intlayer_config.ANSIColors.GREY}]${_intlayer_config.ANSIColors.RESET}`);
|
|
159
|
-
}
|
|
160
|
-
for (const statusObj of dictionariesStatuses) if (statusObj.errorMessage) appLogger(statusObj.errorMessage, { level: "error" });
|
|
161
|
-
const deleteOption = options?.deleteLocaleDictionary;
|
|
162
|
-
const keepOption = options?.keepLocaleDictionary;
|
|
163
|
-
if (deleteOption && keepOption) throw new Error("Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.");
|
|
164
|
-
if (deleteOption) await deleteLocalDictionaries(successfullyPushedDictionaries, options);
|
|
165
|
-
else if (keepOption) {} else {
|
|
166
|
-
const remoteDictionaries = successfullyPushedDictionaries.filter((dictionary) => dictionary.location === "remote");
|
|
167
|
-
const remoteDictionariesKeys = remoteDictionaries.map((dictionary) => dictionary.key);
|
|
168
|
-
if (remoteDictionaries.length > 0) {
|
|
169
|
-
const { confirm, isCancel } = await import("@clack/prompts");
|
|
170
|
-
const shouldDelete = await confirm({
|
|
171
|
-
message: `Do you want to delete the local dictionaries that were successfully pushed? ${(0, _intlayer_config.colorize)("(Dictionaries:", _intlayer_config.ANSIColors.GREY, _intlayer_config.ANSIColors.RESET)} ${(0, _intlayer_config.colorizeKey)(remoteDictionariesKeys)}${(0, _intlayer_config.colorize)(")", _intlayer_config.ANSIColors.GREY, _intlayer_config.ANSIColors.RESET)}`,
|
|
172
|
-
initialValue: false
|
|
173
|
-
});
|
|
174
|
-
if (isCancel(shouldDelete)) return;
|
|
175
|
-
if (shouldDelete) await deleteLocalDictionaries(remoteDictionaries, options);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
} catch (error) {
|
|
179
|
-
appLogger(error, { level: "error" });
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
|
|
183
|
-
const appLogger = (0, _intlayer_config.getAppLogger)((0, _intlayer_config.getConfiguration)(options?.configOptions));
|
|
184
|
-
const filePathsSet = /* @__PURE__ */ new Set();
|
|
185
|
-
for (const dictionary of dictionariesToDelete) {
|
|
186
|
-
const { filePath } = dictionary;
|
|
187
|
-
if (!filePath) {
|
|
188
|
-
appLogger(`Dictionary ${(0, _intlayer_config.colorizeKey)(dictionary.key)} does not have a file path`, { level: "error" });
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
filePathsSet.add(filePath);
|
|
192
|
-
}
|
|
193
|
-
for (const filePath of filePathsSet) try {
|
|
194
|
-
const stats = await node_fs_promises.lstat(filePath);
|
|
195
|
-
if (stats.isFile()) {
|
|
196
|
-
await node_fs_promises.unlink(filePath);
|
|
197
|
-
appLogger(`Deleted file ${(0, _intlayer_chokidar.formatPath)(filePath)}`, {});
|
|
198
|
-
} else if (stats.isDirectory()) appLogger(`Path is a directory ${(0, _intlayer_chokidar.formatPath)(filePath)}, skipping.`, {});
|
|
199
|
-
else appLogger(`Unknown file type for ${(0, _intlayer_chokidar.formatPath)(filePath)}, skipping.`, {});
|
|
200
|
-
} catch (err) {
|
|
201
|
-
appLogger(`Error deleting ${(0, _intlayer_chokidar.formatPath)(filePath)}: ${err}`, { level: "error" });
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
exports.push = push;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/checkAccess.cjs`),n=require(`../pushLog.cjs`);let r=require(`@intlayer/api`),i=require(`@intlayer/chokidar/utils`),a=require(`@intlayer/config/node`),o=require(`node:path`),s=require(`@intlayer/chokidar/cli`),c=require(`@intlayer/config/logger`),l=require(`node:fs/promises`);l=e.__toESM(l);let u=require(`@intlayer/chokidar/build`),d=require(`@intlayer/unmerged-dictionaries-entry`);const f={pushed:{icon:`✔`,color:c.ANSIColors.GREEN},modified:{icon:`✔`,color:c.ANSIColors.GREEN},error:{icon:`✖`,color:c.ANSIColors.RED},default:{icon:`⏲`,color:c.ANSIColors.BLUE}},p=e=>f[e]??f.default,m=async e=>{let l=(0,a.getConfiguration)(e?.configOptions),f=(0,c.getAppLogger)(l);e?.build===!0?await(0,u.prepareIntlayer)(l,{forceRun:!0}):e?.build===void 0&&await(0,u.prepareIntlayer)(l);try{if(!await t.checkCMSAuth(l))return;let a=(0,r.getIntlayerAPIProxy)(void 0,l),m=(0,d.getUnmergedDictionaries)(l),g=Object.values(m).flat(),_=Array.from(new Set(g.map(e=>e.location).filter(e=>e&&![`remote`,`local`,`hybrid`].includes(e)))),v=[];if(_.length>0){let{multiselect:e,confirm:t,isCancel:n}=await import(`@clack/prompts`);if(_.length===1){let e=await t({message:`Do you want to push dictionaries with custom location ${(0,c.colorize)(_[0],c.ANSIColors.BLUE,c.ANSIColors.RESET)}?`,initialValue:!1});if(n(e))return;e&&(v=[_[0]])}else{let t=await e({message:`Select custom locations to push:`,options:_.map(e=>({value:e,label:e})),required:!1});if(n(t))return;v=t}}let y=g.filter(e=>{let t=e.location??l.dictionary?.location??`local`;return t===`remote`||t===`hybrid`||v.includes(t)});if(y.length===0){f(`No dictionaries found to push. Only dictionaries with location ${(0,c.colorize)(`remote`,c.ANSIColors.BLUE,c.ANSIColors.RESET)}, ${(0,c.colorize)(`hybrid`,c.ANSIColors.BLUE,c.ANSIColors.RESET)} or selected custom locations are pushed.`,{level:`warn`}),f(`You can set the location in your dictionary file (e.g. ${(0,c.colorize)(`{ key: 'my-key', location: 'hybrid', ... }`,c.ANSIColors.BLUE,c.ANSIColors.RESET)} or globally in your intlayer.config.ts file (e.g. ${(0,c.colorize)(`{ dictionary: { location: 'hybrid' } }`,c.ANSIColors.BLUE,c.ANSIColors.RESET)}).`,{level:`info`});return}let b=Object.keys(m);if(e?.dictionaries){let t=e.dictionaries.filter(e=>!b.includes(e));t.length>0&&f(`The following dictionaries do not exist: ${t.join(`, `)} and have been ignored.`,{level:`error`}),y=y.filter(t=>e.dictionaries?.includes(t.key))}if(e?.gitOptions){let t=await(0,s.listGitFiles)(e.gitOptions);y=y.filter(e=>t.includes((0,o.join)(l.content.baseDir,e.filePath??``)))}if(y.length===0){f(`No local dictionaries found`,{level:`error`});return}f(`Pushing dictionaries:`);let x=y.map(e=>({dictionary:e,status:`pending`})),S=new n.PushLogger;S.update(x.map(e=>({dictionaryKey:e.dictionary.key,status:`pending`})));let C=[];await(0,i.parallelize)(x,async e=>{e.status=`pushing`,S.update([{dictionaryKey:e.dictionary.key,status:`pushing`}]);try{let t=await a.dictionary.pushDictionaries([e.dictionary]),n=t.data?.updatedDictionaries??[],r=t.data?.newDictionaries??[],i=[...n,...r];for(let e of i){let t=m[e.key]?.find(t=>t.localId===e.localId);t&&await(0,u.writeContentDeclaration)({...t,id:e.id},l)}n.some(t=>t.key===e.dictionary.key)?(e.status=`modified`,C.push(e.dictionary),S.update([{dictionaryKey:e.dictionary.key,status:`modified`}])):r.some(t=>t.key===e.dictionary.key)?(e.status=`pushed`,C.push(e.dictionary),S.update([{dictionaryKey:e.dictionary.key,status:`pushed`}])):e.status=`unknown`}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error pushing dictionary ${e.dictionary.key}: ${t}`,S.update([{dictionaryKey:e.dictionary.key,status:`error`}])}},5),S.finish();for(let e of x){let{icon:t,color:n}=p(e.status);f(` - ${(0,c.colorizeKey)(e.dictionary.key)} ${c.ANSIColors.GREY}[${n}${t} ${e.status}${c.ANSIColors.GREY}]${c.ANSIColors.RESET}`)}for(let e of x)e.errorMessage&&f(e.errorMessage,{level:`error`});let w=e?.deleteLocaleDictionary,T=e?.keepLocaleDictionary;if(w&&T)throw Error(`Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.`);if(w)await h(C,e);else if(!T){let t=C.filter(e=>e.location===`remote`),n=t.map(e=>e.key);if(t.length>0){let{confirm:r,isCancel:i}=await import(`@clack/prompts`),a=await r({message:`Do you want to delete the local dictionaries that were successfully pushed? ${(0,c.colorize)(`(Dictionaries:`,c.ANSIColors.GREY,c.ANSIColors.RESET)} ${(0,c.colorizeKey)(n)}${(0,c.colorize)(`)`,c.ANSIColors.GREY,c.ANSIColors.RESET)}`,initialValue:!1});if(i(a))return;a&&await h(t,e)}}}catch(e){f(e,{level:`error`})}},h=async(e,t)=>{let n=(0,c.getAppLogger)((0,a.getConfiguration)(t?.configOptions)),r=new Set;for(let t of e){let{filePath:e}=t;if(!e){n(`Dictionary ${(0,c.colorizeKey)(t.key)} does not have a file path`,{level:`error`});continue}r.add(e)}for(let e of r)try{let t=await l.lstat(e);t.isFile()?(await l.unlink(e),n(`Deleted file ${(0,i.formatPath)(e)}`,{})):t.isDirectory()?n(`Path is a directory ${(0,i.formatPath)(e)}, skipping.`,{}):n(`Unknown file type for ${(0,i.formatPath)(e)}, skipping.`,{})}catch(t){n(`Error deleting ${(0,i.formatPath)(e)}: ${t}`,{level:`error`})}};exports.push=m;
|
|
207
2
|
//# sourceMappingURL=push.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.cjs","names":["ANSIColors","checkCMSAuth","PushLogger","fsPromises"],"sources":["../../../src/push/push.ts"],"sourcesContent":["import * as fsPromises from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n formatPath,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n colorizeKey,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PushLogger, type PushStatus } from '../pushLog';\nimport { checkCMSAuth } from '../utils/checkAccess';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n// Print per-dictionary summary similar to loadDictionaries\nconst statusIconsAndColors = {\n pushed: { icon: '✔', color: ANSIColors.GREEN },\n modified: { icon: '✔', color: ANSIColors.GREEN },\n error: { icon: '✖', color: ANSIColors.RED },\n default: { icon: '⏲', color: ANSIColors.BLUE },\n};\n\nconst getIconAndColor = (status: DictionariesStatus['status']) => {\n return (\n statusIconsAndColors[status as keyof typeof statusIconsAndColors] ??\n statusIconsAndColors.default\n );\n};\n\n/**\n * Get all local dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n try {\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n const allDictionaries = Object.values(unmergedDictionariesRecord).flat();\n\n const customLocations = Array.from(\n new Set(\n allDictionaries\n .map((dictionary) => dictionary.location)\n .filter(\n (location) =>\n location && !['remote', 'local', 'hybrid'].includes(location)\n )\n )\n ) as string[];\n\n let selectedCustomLocations: string[] = [];\n\n if (customLocations.length > 0) {\n const { multiselect, confirm, isCancel } = await import('@clack/prompts');\n\n if (customLocations.length === 1) {\n const shouldPush = await confirm({\n message: `Do you want to push dictionaries with custom location ${colorize(customLocations[0], ANSIColors.BLUE, ANSIColors.RESET)}?`,\n initialValue: false,\n });\n\n if (isCancel(shouldPush)) {\n return;\n }\n\n if (shouldPush) {\n selectedCustomLocations = [customLocations[0]];\n }\n } else {\n const selected = await multiselect({\n message: 'Select custom locations to push:',\n options: customLocations.map((location) => ({\n value: location,\n label: location,\n })),\n required: false,\n });\n\n if (isCancel(selected)) {\n return;\n }\n\n selectedCustomLocations = selected as string[];\n }\n }\n\n let dictionaries: Dictionary[] = allDictionaries.filter((dictionary) => {\n const location =\n dictionary.location ?? config.dictionary?.location ?? 'local';\n\n return (\n location === 'remote' ||\n location === 'hybrid' ||\n selectedCustomLocations.includes(location)\n );\n });\n\n // Check if the dictionaries list is empty after filtering by location\n if (dictionaries.length === 0) {\n appLogger(\n `No dictionaries found to push. Only dictionaries with location ${colorize('remote', ANSIColors.BLUE, ANSIColors.RESET)}, ${colorize('hybrid', ANSIColors.BLUE, ANSIColors.RESET)} or selected custom locations are pushed.`,\n { level: 'warn' }\n );\n appLogger(\n `You can set the location in your dictionary file (e.g. ${colorize(\"{ key: 'my-key', location: 'hybrid', ... }\", ANSIColors.BLUE, ANSIColors.RESET)} or globally in your intlayer.config.ts file (e.g. ${colorize(\"{ dictionary: { location: 'hybrid' } }\", ANSIColors.BLUE, ANSIColors.RESET)}).`,\n { level: 'info' }\n );\n return;\n }\n\n const existingDictionariesKeys: string[] = Object.keys(\n unmergedDictionariesRecord\n );\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries?.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n\n dictionaries = dictionaries.filter((dictionary) =>\n gitFiles.includes(\n join(config.content.baseDir, dictionary.filePath ?? '')\n )\n );\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary) => ({\n dictionary,\n status: 'pending',\n })\n );\n\n // Initialize aggregated logger similar to loadDictionaries\n const logger = new PushLogger();\n logger.update(\n dictionariesStatuses.map<PushStatus>((s) => ({\n dictionaryKey: s.dictionary.key,\n status: 'pending',\n }))\n );\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushing' },\n ]);\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries([\n statusObj.dictionary,\n ]);\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries ?? [];\n const newDictionaries = pushResult.data?.newDictionaries ?? [];\n\n const allDictionaries = [...updatedDictionaries, ...newDictionaries];\n\n for (const remoteDictionaryData of allDictionaries) {\n const localDictionary = unmergedDictionariesRecord[\n remoteDictionaryData.key\n ]?.find(\n (dictionary) => dictionary.localId === remoteDictionaryData.localId\n );\n\n if (!localDictionary) continue;\n\n await writeContentDeclaration(\n { ...localDictionary, id: remoteDictionaryData.id },\n config\n );\n }\n\n if (\n updatedDictionaries.some(\n (dictionary) => dictionary.key === statusObj.dictionary.key\n )\n ) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'modified' },\n ]);\n } else if (\n newDictionaries.some(\n (dictionary) => dictionary.key === statusObj.dictionary.key\n )\n ) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushed' },\n ]);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit (reuse parallelize)\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n for (const dictionaryStatus of dictionariesStatuses) {\n const { icon, color } = getIconAndColor(dictionaryStatus.status);\n appLogger(\n ` - ${colorizeKey(dictionaryStatus.dictionary.key)} ${ANSIColors.GREY}[${color}${icon} ${dictionaryStatus.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const remoteDictionaries = successfullyPushedDictionaries.filter(\n (dictionary) => dictionary.location === 'remote'\n );\n const remoteDictionariesKeys = remoteDictionaries.map(\n (dictionary) => dictionary.key\n );\n\n if (remoteDictionaries.length > 0) {\n const { confirm, isCancel } = await import('@clack/prompts');\n\n const shouldDelete = await confirm({\n message: `Do you want to delete the local dictionaries that were successfully pushed? ${colorize('(Dictionaries:', ANSIColors.GREY, ANSIColors.RESET)} ${colorizeKey(remoteDictionariesKeys)}${colorize(')', ANSIColors.GREY, ANSIColors.RESET)}`,\n initialValue: false,\n });\n\n if (isCancel(shouldDelete)) {\n return;\n }\n\n if (shouldDelete) {\n await deleteLocalDictionaries(remoteDictionaries, options);\n }\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(\n `Dictionary ${colorizeKey(dictionary.key)} does not have a file path`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${formatPath(filePath)}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${formatPath(filePath)}, skipping.`, {});\n } else {\n appLogger(\n `Unknown file type for ${formatPath(filePath)}, skipping.`,\n {}\n );\n }\n } catch (err) {\n appLogger(`Error deleting ${formatPath(filePath)}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAyCA,MAAM,uBAAuB;CAC3B,QAAQ;EAAE,MAAM;EAAK,OAAOA,4BAAW;EAAO;CAC9C,UAAU;EAAE,MAAM;EAAK,OAAOA,4BAAW;EAAO;CAChD,OAAO;EAAE,MAAM;EAAK,OAAOA,4BAAW;EAAK;CAC3C,SAAS;EAAE,MAAM;EAAK,OAAOA,4BAAW;EAAM;CAC/C;AAED,MAAM,mBAAmB,WAAyC;AAChE,QACE,qBAAqB,WACrB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C,MAAI,MAAM,QAAQ,EAAE;AAClB,SAAMA,iBAAW,OAAO,SAAS;AACjC,aAAU,mDAA2B,SAAS,IAAI,EAAE,CAAC;aAC5C,MAAM,aAAa,CAC5B,WAAU,0DAAkC,SAAS,CAAC,cAAc,EAAE,CAAC;MAEvE,WACE,4DAAoC,SAAS,CAAC,cAC9C,EAAE,CACH;UAEI,KAAK;AACZ,YAAU,qDAA6B,SAAS,CAAC,IAAI,OAAO,EAC1D,OAAO,SACR,CAAC"}
|
|
1
|
+
{"version":3,"file":"push.cjs","names":["ANSIColors","checkCMSAuth","PushLogger","fsPromises"],"sources":["../../../src/push/push.ts"],"sourcesContent":["import * as fsPromises from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport { type ListGitFilesOptions, listGitFiles } from '@intlayer/chokidar/cli';\nimport { formatPath, parallelize } from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeKey,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { Dictionary } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { PushLogger, type PushStatus } from '../pushLog';\nimport { checkCMSAuth } from '../utils/checkAccess';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n// Print per-dictionary summary similar to loadDictionaries\nconst statusIconsAndColors = {\n pushed: { icon: '✔', color: ANSIColors.GREEN },\n modified: { icon: '✔', color: ANSIColors.GREEN },\n error: { icon: '✖', color: ANSIColors.RED },\n default: { icon: '⏲', color: ANSIColors.BLUE },\n};\n\nconst getIconAndColor = (status: DictionariesStatus['status']) => {\n return (\n statusIconsAndColors[status as keyof typeof statusIconsAndColors] ??\n statusIconsAndColors.default\n );\n};\n\n/**\n * Get all local dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n try {\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(config);\n const allDictionaries = Object.values(unmergedDictionariesRecord).flat();\n\n const customLocations = Array.from(\n new Set(\n allDictionaries\n .map((dictionary) => dictionary.location)\n .filter(\n (location) =>\n location && !['remote', 'local', 'hybrid'].includes(location)\n )\n )\n ) as string[];\n\n let selectedCustomLocations: string[] = [];\n\n if (customLocations.length > 0) {\n const { multiselect, confirm, isCancel } = await import('@clack/prompts');\n\n if (customLocations.length === 1) {\n const shouldPush = await confirm({\n message: `Do you want to push dictionaries with custom location ${colorize(customLocations[0], ANSIColors.BLUE, ANSIColors.RESET)}?`,\n initialValue: false,\n });\n\n if (isCancel(shouldPush)) {\n return;\n }\n\n if (shouldPush) {\n selectedCustomLocations = [customLocations[0]];\n }\n } else {\n const selected = await multiselect({\n message: 'Select custom locations to push:',\n options: customLocations.map((location) => ({\n value: location,\n label: location,\n })),\n required: false,\n });\n\n if (isCancel(selected)) {\n return;\n }\n\n selectedCustomLocations = selected as string[];\n }\n }\n\n let dictionaries: Dictionary[] = allDictionaries.filter((dictionary) => {\n const location =\n dictionary.location ?? config.dictionary?.location ?? 'local';\n\n return (\n location === 'remote' ||\n location === 'hybrid' ||\n selectedCustomLocations.includes(location)\n );\n });\n\n // Check if the dictionaries list is empty after filtering by location\n if (dictionaries.length === 0) {\n appLogger(\n `No dictionaries found to push. Only dictionaries with location ${colorize('remote', ANSIColors.BLUE, ANSIColors.RESET)}, ${colorize('hybrid', ANSIColors.BLUE, ANSIColors.RESET)} or selected custom locations are pushed.`,\n { level: 'warn' }\n );\n appLogger(\n `You can set the location in your dictionary file (e.g. ${colorize(\"{ key: 'my-key', location: 'hybrid', ... }\", ANSIColors.BLUE, ANSIColors.RESET)} or globally in your intlayer.config.ts file (e.g. ${colorize(\"{ dictionary: { location: 'hybrid' } }\", ANSIColors.BLUE, ANSIColors.RESET)}).`,\n { level: 'info' }\n );\n return;\n }\n\n const existingDictionariesKeys: string[] = Object.keys(\n unmergedDictionariesRecord\n );\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries?.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n\n dictionaries = dictionaries.filter((dictionary) =>\n gitFiles.includes(\n join(config.content.baseDir, dictionary.filePath ?? '')\n )\n );\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary) => ({\n dictionary,\n status: 'pending',\n })\n );\n\n // Initialize aggregated logger similar to loadDictionaries\n const logger = new PushLogger();\n logger.update(\n dictionariesStatuses.map<PushStatus>((s) => ({\n dictionaryKey: s.dictionary.key,\n status: 'pending',\n }))\n );\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushing' },\n ]);\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries([\n statusObj.dictionary,\n ]);\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries ?? [];\n const newDictionaries = pushResult.data?.newDictionaries ?? [];\n\n const allDictionaries = [...updatedDictionaries, ...newDictionaries];\n\n for (const remoteDictionaryData of allDictionaries) {\n const localDictionary = unmergedDictionariesRecord[\n remoteDictionaryData.key\n ]?.find(\n (dictionary) => dictionary.localId === remoteDictionaryData.localId\n );\n\n if (!localDictionary) continue;\n\n await writeContentDeclaration(\n { ...localDictionary, id: remoteDictionaryData.id },\n config\n );\n }\n\n if (\n updatedDictionaries.some(\n (dictionary) => dictionary.key === statusObj.dictionary.key\n )\n ) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'modified' },\n ]);\n } else if (\n newDictionaries.some(\n (dictionary) => dictionary.key === statusObj.dictionary.key\n )\n ) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushed' },\n ]);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit (reuse parallelize)\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n for (const dictionaryStatus of dictionariesStatuses) {\n const { icon, color } = getIconAndColor(dictionaryStatus.status);\n appLogger(\n ` - ${colorizeKey(dictionaryStatus.dictionary.key)} ${ANSIColors.GREY}[${color}${icon} ${dictionaryStatus.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const remoteDictionaries = successfullyPushedDictionaries.filter(\n (dictionary) => dictionary.location === 'remote'\n );\n const remoteDictionariesKeys = remoteDictionaries.map(\n (dictionary) => dictionary.key\n );\n\n if (remoteDictionaries.length > 0) {\n const { confirm, isCancel } = await import('@clack/prompts');\n\n const shouldDelete = await confirm({\n message: `Do you want to delete the local dictionaries that were successfully pushed? ${colorize('(Dictionaries:', ANSIColors.GREY, ANSIColors.RESET)} ${colorizeKey(remoteDictionariesKeys)}${colorize(')', ANSIColors.GREY, ANSIColors.RESET)}`,\n initialValue: false,\n });\n\n if (isCancel(shouldDelete)) {\n return;\n }\n\n if (shouldDelete) {\n await deleteLocalDictionaries(remoteDictionaries, options);\n }\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(\n `Dictionary ${colorizeKey(dictionary.key)} does not have a file path`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${formatPath(filePath)}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${formatPath(filePath)}, skipping.`, {});\n } else {\n appLogger(\n `Unknown file type for ${formatPath(filePath)}, skipping.`,\n {}\n );\n }\n } catch (err) {\n appLogger(`Error deleting ${formatPath(filePath)}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n"],"mappings":"4gBAyCA,MAAM,EAAuB,CAC3B,OAAQ,CAAE,KAAM,IAAK,MAAOA,EAAAA,WAAW,MAAO,CAC9C,SAAU,CAAE,KAAM,IAAK,MAAOA,EAAAA,WAAW,MAAO,CAChD,MAAO,CAAE,KAAM,IAAK,MAAOA,EAAAA,WAAW,IAAK,CAC3C,QAAS,CAAE,KAAM,IAAK,MAAOA,EAAAA,WAAW,KAAM,CAC/C,CAEK,EAAmB,GAErB,EAAqB,IACrB,EAAqB,QAOZ,EAAO,KAAO,IAAyC,CAClE,IAAM,GAAA,EAAA,EAAA,kBAA0B,GAAS,cAAc,CACjD,GAAA,EAAA,EAAA,cAAyB,EAAO,CAElC,GAAS,QAAU,GACrB,MAAA,EAAA,EAAA,iBAAsB,EAAQ,CAAE,SAAU,GAAM,CAAC,CACjC,GAAS,QAAU,QACnC,MAAA,EAAA,EAAA,iBAAsB,EAAO,CAG/B,GAAI,CAGF,GAAI,CAFe,MAAMC,EAAAA,aAAa,EAAO,CAE5B,OAEjB,IAAM,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAO,CAEpD,GAAA,EAAA,EAAA,yBAAqD,EAAO,CAC5D,EAAkB,OAAO,OAAO,EAA2B,CAAC,MAAM,CAElE,EAAkB,MAAM,KAC5B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AA,EAAA,EAAA,YAA6B,EAAS,CAAC,IAAI,IAAO,CAC1D,MAAO,QACR,CAAC"}
|
package/dist/cjs/pushConfig.cjs
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_utils_checkAccess = require('./utils/checkAccess.cjs');
|
|
4
|
-
let _intlayer_api = require("@intlayer/api");
|
|
5
|
-
let _intlayer_config = require("@intlayer/config");
|
|
6
|
-
|
|
7
|
-
//#region src/pushConfig.ts
|
|
8
|
-
const pushConfig = async (options) => {
|
|
9
|
-
const config = (0, _intlayer_config.getConfiguration)(options?.configOptions);
|
|
10
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(config);
|
|
11
|
-
if (!await require_utils_checkAccess.checkCMSAuth(config, false)) return;
|
|
12
|
-
const getDictionariesKeysResult = await (0, _intlayer_api.getIntlayerAPIProxy)(void 0, config).project.pushProjectConfiguration(config);
|
|
13
|
-
if (!getDictionariesKeysResult.data) throw new Error("Error pushing project configuration");
|
|
14
|
-
appLogger("Project configuration pushed successfully");
|
|
15
|
-
appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
exports.pushConfig = pushConfig;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/checkAccess.cjs`);let t=require(`@intlayer/api`),n=require(`@intlayer/config/node`),r=require(`@intlayer/config/logger`);const i=async i=>{let a=(0,n.getConfiguration)(i?.configOptions),o=(0,r.getAppLogger)(a);if(!await e.checkCMSAuth(a,!1))return;let s=await(0,t.getIntlayerAPIProxy)(void 0,a).project.pushProjectConfiguration(a);if(!s.data)throw Error(`Error pushing project configuration`);o(`Project configuration pushed successfully`),o(JSON.stringify(s.data,null,2))};exports.pushConfig=i;
|
|
20
2
|
//# sourceMappingURL=pushConfig.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushConfig.cjs","names":["checkCMSAuth"],"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n type GetConfigurationOptions,\n
|
|
1
|
+
{"version":3,"file":"pushConfig.cjs","names":["checkCMSAuth"],"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PushOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n const hasCMSAuth = await checkCMSAuth(config, false);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Push the project configuration\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config);\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully');\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));\n};\n"],"mappings":"iQAYA,MAAa,EAAa,KAAO,IAA0B,CACzD,IAAM,GAAA,EAAA,EAAA,kBAA0B,GAAS,cAAc,CACjD,GAAA,EAAA,EAAA,cAAyB,EAAO,CAItC,GAAI,CAFe,MAAMA,EAAAA,aAAa,EAAQ,GAAM,CAEnC,OAKjB,IAAM,EACJ,MAAA,EAAA,EAAA,qBAJsC,IAAA,GAAW,EAAO,CAItC,QAAQ,yBAAyB,EAAO,CAE5D,GAAI,CAAC,EAA0B,KAC7B,MAAU,MAAM,sCAAsC,CAGxD,EAAU,4CAA4C,CAEtD,EAAU,KAAK,UAAU,EAA0B,KAAM,KAAM,EAAE,CAAC"}
|
package/dist/cjs/pushLog.cjs
CHANGED
|
@@ -1,85 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
//#region src/pushLog.ts
|
|
6
|
-
var PushLogger = class {
|
|
7
|
-
statuses = [];
|
|
8
|
-
spinnerTimer = null;
|
|
9
|
-
spinnerIndex = 0;
|
|
10
|
-
renderedLines = 0;
|
|
11
|
-
spinnerFrames = _intlayer_config.spinnerFrames;
|
|
12
|
-
isFinished = false;
|
|
13
|
-
lastRenderedState = "";
|
|
14
|
-
update(newStatuses) {
|
|
15
|
-
if (this.isFinished) return;
|
|
16
|
-
for (const status of newStatuses) {
|
|
17
|
-
const index = this.statuses.findIndex((s) => s.dictionaryKey === status.dictionaryKey);
|
|
18
|
-
if (index >= 0) this.statuses[index] = status;
|
|
19
|
-
else this.statuses.push(status);
|
|
20
|
-
}
|
|
21
|
-
this.startSpinner();
|
|
22
|
-
this.render();
|
|
23
|
-
}
|
|
24
|
-
finish() {
|
|
25
|
-
this.isFinished = true;
|
|
26
|
-
this.stopSpinner();
|
|
27
|
-
this.render();
|
|
28
|
-
}
|
|
29
|
-
startSpinner() {
|
|
30
|
-
if (this.spinnerTimer || this.isFinished) return;
|
|
31
|
-
this.spinnerTimer = setInterval(() => {
|
|
32
|
-
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
|
|
33
|
-
this.render();
|
|
34
|
-
}, 100);
|
|
35
|
-
}
|
|
36
|
-
stopSpinner() {
|
|
37
|
-
if (!this.spinnerTimer) return;
|
|
38
|
-
clearInterval(this.spinnerTimer);
|
|
39
|
-
this.spinnerTimer = null;
|
|
40
|
-
}
|
|
41
|
-
render() {
|
|
42
|
-
const { total, done, pushed, modified, errors } = this.computeProgress();
|
|
43
|
-
const frame = this.spinnerFrames[this.spinnerIndex];
|
|
44
|
-
const lines = [];
|
|
45
|
-
const isDone = done === total;
|
|
46
|
-
const progressLabel = `dictionaries: ${(0, _intlayer_config.colorizeNumber)(done)}/${(0, _intlayer_config.colorizeNumber)(total)}`;
|
|
47
|
-
const details = [];
|
|
48
|
-
if (pushed > 0) details.push(`new: ${(0, _intlayer_config.colorizeNumber)(pushed)}`);
|
|
49
|
-
if (modified > 0) details.push(`modified: ${(0, _intlayer_config.colorizeNumber)(modified)}`);
|
|
50
|
-
if (errors > 0) details.push((0, _intlayer_config.colorize)(`errors: ${(0, _intlayer_config.colorizeNumber)(errors)}`, _intlayer_config.ANSIColors.RED));
|
|
51
|
-
const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
52
|
-
if (isDone) lines.push(`${(0, _intlayer_config.colorize)("✔", _intlayer_config.ANSIColors.GREEN)} pushed ${progressLabel}${suffix}`);
|
|
53
|
-
else lines.push(`${(0, _intlayer_config.colorize)(frame, _intlayer_config.ANSIColors.BLUE)} pushing ${progressLabel}${suffix}`);
|
|
54
|
-
const currentState = lines.join("\n");
|
|
55
|
-
if (currentState === this.lastRenderedState) return;
|
|
56
|
-
this.lastRenderedState = currentState;
|
|
57
|
-
if (this.renderedLines > 0) process.stdout.write(`\x1b[${this.renderedLines}F`);
|
|
58
|
-
const totalLinesToClear = Math.max(this.renderedLines, lines.length);
|
|
59
|
-
for (let i = 0; i < totalLinesToClear; i++) {
|
|
60
|
-
process.stdout.write("\x1B[2K");
|
|
61
|
-
const line = lines[i];
|
|
62
|
-
if (line !== void 0) process.stdout.write(line);
|
|
63
|
-
process.stdout.write("\n");
|
|
64
|
-
}
|
|
65
|
-
this.renderedLines = lines.length;
|
|
66
|
-
}
|
|
67
|
-
computeProgress() {
|
|
68
|
-
const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
|
|
69
|
-
const pushed = this.statuses.filter((s) => s.status === "pushed").length;
|
|
70
|
-
const modified = this.statuses.filter((s) => s.status === "modified").length;
|
|
71
|
-
const errors = this.statuses.filter((s) => s.status === "error").length;
|
|
72
|
-
const done = pushed + modified + errors;
|
|
73
|
-
return {
|
|
74
|
-
total: keys.size,
|
|
75
|
-
done,
|
|
76
|
-
pushed,
|
|
77
|
-
modified,
|
|
78
|
-
errors
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
exports.PushLogger = PushLogger;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/config/logger`);var t=class{statuses=[];spinnerTimer=null;spinnerIndex=0;renderedLines=0;spinnerFrames=e.spinnerFrames;isFinished=!1;lastRenderedState=``;update(e){if(!this.isFinished){for(let t of e){let e=this.statuses.findIndex(e=>e.dictionaryKey===t.dictionaryKey);e>=0?this.statuses[e]=t:this.statuses.push(t)}this.startSpinner(),this.render()}}finish(){this.isFinished=!0,this.stopSpinner(),this.render()}startSpinner(){this.spinnerTimer||this.isFinished||(this.spinnerTimer=setInterval(()=>{this.spinnerIndex=(this.spinnerIndex+1)%this.spinnerFrames.length,this.render()},100))}stopSpinner(){this.spinnerTimer&&=(clearInterval(this.spinnerTimer),null)}render(){let{total:t,done:n,pushed:r,modified:i,errors:a}=this.computeProgress(),o=this.spinnerFrames[this.spinnerIndex],s=[],c=n===t,l=`dictionaries: ${(0,e.colorizeNumber)(n)}/${(0,e.colorizeNumber)(t)}`,u=[];r>0&&u.push(`new: ${(0,e.colorizeNumber)(r)}`),i>0&&u.push(`modified: ${(0,e.colorizeNumber)(i)}`),a>0&&u.push((0,e.colorize)(`errors: ${(0,e.colorizeNumber)(a)}`,e.ANSIColors.RED));let d=u.length>0?` (${u.join(`, `)})`:``;c?s.push(`${(0,e.colorize)(`✔`,e.ANSIColors.GREEN)} pushed ${l}${d}`):s.push(`${(0,e.colorize)(o,e.ANSIColors.BLUE)} pushing ${l}${d}`);let f=s.join(`
|
|
2
|
+
`);if(f===this.lastRenderedState)return;this.lastRenderedState=f,this.renderedLines>0&&process.stdout.write(`\x1b[${this.renderedLines}F`);let p=Math.max(this.renderedLines,s.length);for(let e=0;e<p;e++){process.stdout.write(`\x1B[2K`);let t=s[e];t!==void 0&&process.stdout.write(t),process.stdout.write(`
|
|
3
|
+
`)}this.renderedLines=s.length}computeProgress(){let e=new Set(this.statuses.map(e=>e.dictionaryKey)),t=this.statuses.filter(e=>e.status===`pushed`).length,n=this.statuses.filter(e=>e.status===`modified`).length,r=this.statuses.filter(e=>e.status===`error`).length,i=t+n+r;return{total:e.size,done:i,pushed:t,modified:n,errors:r}}};exports.PushLogger=t;
|
|
85
4
|
//# sourceMappingURL=pushLog.cjs.map
|
package/dist/cjs/pushLog.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pushLog.cjs","names":["spinnerFrames","ANSIColors"],"sources":["../../src/pushLog.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizeNumber,\n spinnerFrames,\n} from '@intlayer/config';\n\nexport type PushStatus = {\n dictionaryKey: string;\n status: 'pending' | 'pushing' | 'pushed' | 'modified' | 'error';\n errorMessage?: string;\n};\n\nexport class PushLogger {\n private statuses: PushStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private lastRenderedState: string = '';\n\n update(newStatuses: PushStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { total, done, pushed, modified, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n\n const progressLabel = `dictionaries: ${colorizeNumber(done)}/${colorizeNumber(total)}`;\n const details: string[] = [];\n if (pushed > 0) details.push(`new: ${colorizeNumber(pushed)}`);\n if (modified > 0) details.push(`modified: ${colorizeNumber(modified)}`);\n if (errors > 0)\n details.push(\n colorize(`errors: ${colorizeNumber(errors)}`, ANSIColors.RED)\n );\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${colorize('✔', ANSIColors.GREEN)} pushed ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${colorize(frame, ANSIColors.BLUE)} pushing ${progressLabel}${suffix}`\n );\n }\n\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const pushed = this.statuses.filter((s) => s.status === 'pushed').length;\n const modified = this.statuses.filter(\n (s) => s.status === 'modified'\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n const done = pushed + modified + errors;\n\n return {\n total: keys.size,\n done,\n pushed,\n modified,\n errors,\n } as const;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pushLog.cjs","names":["spinnerFrames","ANSIColors"],"sources":["../../src/pushLog.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizeNumber,\n spinnerFrames,\n} from '@intlayer/config/logger';\n\nexport type PushStatus = {\n dictionaryKey: string;\n status: 'pending' | 'pushing' | 'pushed' | 'modified' | 'error';\n errorMessage?: string;\n};\n\nexport class PushLogger {\n private statuses: PushStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private lastRenderedState: string = '';\n\n update(newStatuses: PushStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { total, done, pushed, modified, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n\n const progressLabel = `dictionaries: ${colorizeNumber(done)}/${colorizeNumber(total)}`;\n const details: string[] = [];\n if (pushed > 0) details.push(`new: ${colorizeNumber(pushed)}`);\n if (modified > 0) details.push(`modified: ${colorizeNumber(modified)}`);\n if (errors > 0)\n details.push(\n colorize(`errors: ${colorizeNumber(errors)}`, ANSIColors.RED)\n );\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${colorize('✔', ANSIColors.GREEN)} pushed ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${colorize(frame, ANSIColors.BLUE)} pushing ${progressLabel}${suffix}`\n );\n }\n\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const pushed = this.statuses.filter((s) => s.status === 'pushed').length;\n const modified = this.statuses.filter(\n (s) => s.status === 'modified'\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n const done = pushed + modified + errors;\n\n return {\n total: keys.size,\n done,\n pushed,\n modified,\n errors,\n } as const;\n }\n}\n"],"mappings":"wJAaA,IAAa,EAAb,KAAwB,CACtB,SAAiC,EAAE,CACnC,aAA8C,KAC9C,aAAuB,EACvB,cAAwB,EACxB,cAAiCA,EAAAA,cACjC,WAAqB,GACrB,kBAAoC,GAEpC,OAAO,EAA2B,CAC5B,SAAK,WACT,KAAK,IAAM,KAAU,EAAa,CAChC,IAAM,EAAQ,KAAK,SAAS,UACzB,GAAM,EAAE,gBAAkB,EAAO,cACnC,CACG,GAAS,EACX,KAAK,SAAS,GAAS,EAEvB,KAAK,SAAS,KAAK,EAAO,CAI9B,KAAK,cAAc,CACnB,KAAK,QAAQ,EAGf,QAAS,CACP,KAAK,WAAa,GAClB,KAAK,aAAa,CAClB,KAAK,QAAQ,CAGf,cAAuB,CACjB,KAAK,cAAgB,KAAK,aAC9B,KAAK,aAAe,gBAAkB,CACpC,KAAK,cAAgB,KAAK,aAAe,GAAK,KAAK,cAAc,OACjE,KAAK,QAAQ,EACZ,IAAI,EAGT,aAAsB,CACf,AAEL,KAAK,gBADL,cAAc,KAAK,aAAa,CAC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M,EAAO,IAAI,IAAI,KAAK,SAAS,IAAK,GAAM,EAAE,cAAc,CAAC,CAEzD,EAAS,KAAK,SAAS,OAAQ,GAAM,EAAE,SAAW,SAAS,CAAC,OAC5D,EAAW,KAAK,SAAS,OAC5B,GAAM,EAAE,SAAW,WACrB,CAAC,OACI,EAAS,KAAK,SAAS,OAAQ,GAAM,EAAE,SAAW,QAAQ,CAAC,OAC3D,EAAO,EAAS,EAAW,EAEjC,MAAO,CACL,MAAO,EAAK,KACZ,OACA,SACA,WACA,SACD"}
|
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_utils_setupAI = require('../utils/setupAI.cjs');
|
|
4
|
-
const require_utils_checkFileModifiedRange = require('../utils/checkFileModifiedRange.cjs');
|
|
5
|
-
const require_utils_getOutputFilePath = require('../utils/getOutputFilePath.cjs');
|
|
6
|
-
const require_reviewDoc_reviewDocBlockAware = require('./reviewDocBlockAware.cjs');
|
|
7
|
-
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
8
|
-
let _intlayer_config = require("@intlayer/config");
|
|
9
|
-
let node_path = require("node:path");
|
|
10
|
-
let node_fs = require("node:fs");
|
|
11
|
-
let fast_glob = require("fast-glob");
|
|
12
|
-
fast_glob = require_runtime.__toESM(fast_glob);
|
|
13
|
-
|
|
14
|
-
//#region src/reviewDoc/reviewDoc.ts
|
|
15
|
-
/**
|
|
16
|
-
* Main audit function: scans all .md files in "en/" (unless you specified DOC_LIST),
|
|
17
|
-
* then audits them to each locale in LOCALE_LIST.
|
|
18
|
-
*/
|
|
19
|
-
const reviewDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions }) => {
|
|
20
|
-
const configuration = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
21
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
|
|
22
|
-
const aiResult = await require_utils_setupAI.setupAI(configuration, aiOptions);
|
|
23
|
-
if (!aiResult?.hasAIAccess) return;
|
|
24
|
-
const { aiClient, aiConfig } = aiResult;
|
|
25
|
-
if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
|
|
26
|
-
appLogger(`Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`);
|
|
27
|
-
nbSimultaneousFileProcessed = 10;
|
|
28
|
-
}
|
|
29
|
-
let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
|
|
30
|
-
if (gitOptions) {
|
|
31
|
-
const gitChangedFiles = await (0, _intlayer_chokidar.listGitFiles)(gitOptions);
|
|
32
|
-
if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
|
|
33
|
-
}
|
|
34
|
-
appLogger(`Base locale is ${(0, _intlayer_chokidar.formatLocale)(baseLocale)}`);
|
|
35
|
-
appLogger(`Reviewing ${(0, _intlayer_config.colorizeNumber)(locales.length)} locales: [ ${(0, _intlayer_chokidar.formatLocale)(locales)} ]`);
|
|
36
|
-
appLogger(`Reviewing ${(0, _intlayer_config.colorizeNumber)(docList.length)} files:`);
|
|
37
|
-
appLogger(docList.map((path) => ` - ${(0, _intlayer_chokidar.formatPath)(path)}\n`));
|
|
38
|
-
await (0, _intlayer_chokidar.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
|
|
39
|
-
appLogger(`Reviewing file: ${(0, _intlayer_chokidar.formatPath)(docPath)} to ${(0, _intlayer_chokidar.formatLocale)(locale)}`);
|
|
40
|
-
const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
|
|
41
|
-
const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
|
|
42
|
-
if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) {
|
|
43
|
-
const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
|
|
44
|
-
appLogger(`${(0, _intlayer_config.colorize)("⊘", _intlayer_config.ANSIColors.YELLOW)} File ${(0, _intlayer_chokidar.formatPath)(relativePath)} already exists, skipping.`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if ((0, node_fs.existsSync)(outputFilePath)) {
|
|
48
|
-
const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
|
|
49
|
-
skipIfModifiedBefore,
|
|
50
|
-
skipIfModifiedAfter
|
|
51
|
-
});
|
|
52
|
-
if (fileModificationData.isSkipped) {
|
|
53
|
-
appLogger(fileModificationData.message);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
} else if (skipIfModifiedBefore || skipIfModifiedAfter) appLogger(`${(0, _intlayer_config.colorize)("!", _intlayer_config.ANSIColors.YELLOW)} File ${(0, _intlayer_chokidar.formatPath)(outputFilePath)} does not exist, skipping modification date check.`);
|
|
57
|
-
let changedLines;
|
|
58
|
-
if (gitOptions) {
|
|
59
|
-
const gitChangedLines = await (0, _intlayer_chokidar.listGitLines)(absoluteBaseFilePath, gitOptions);
|
|
60
|
-
appLogger(`Git changed lines: ${gitChangedLines.join(", ")}`);
|
|
61
|
-
changedLines = gitChangedLines;
|
|
62
|
-
}
|
|
63
|
-
await require_reviewDoc_reviewDocBlockAware.reviewFileBlockAware(absoluteBaseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines, aiClient, aiConfig);
|
|
64
|
-
})), (task) => task(), nbSimultaneousFileProcessed ?? 3);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
exports.reviewDoc = reviewDoc;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/setupAI.cjs`),n=require(`../utils/checkFileModifiedRange.cjs`),r=require(`../utils/getOutputFilePath.cjs`),i=require(`./reviewDocBlockAware.cjs`);let a=require(`@intlayer/chokidar/utils`),o=require(`@intlayer/config/node`),s=require(`node:path`),c=require(`@intlayer/chokidar/cli`),l=require(`@intlayer/config/logger`),u=require(`node:fs`),d=require(`fast-glob`);d=e.__toESM(d);const f=async({docPattern:e,locales:f,excludedGlobPattern:p,baseLocale:m,aiOptions:h,nbSimultaneousFileProcessed:g,configOptions:_,customInstructions:v,skipIfModifiedBefore:y,skipIfModifiedAfter:b,skipIfExists:x,gitOptions:S})=>{let C=(0,o.getConfiguration)(_),w=(0,l.getAppLogger)(C),T=await t.setupAI(C,h);if(!T?.hasAIAccess)return;let{aiClient:E,aiConfig:D}=T;g&&g>10&&(w(`Warning: nbSimultaneousFileProcessed is set to ${g}, which is greater than 10. Setting it to 10.`),g=10);let O=await(0,d.default)(e,{ignore:p});if(S){let e=await(0,c.listGitFiles)(S);e&&(O=O.filter(t=>e.some(e=>(0,s.join)(process.cwd(),t)===e)))}w(`Base locale is ${(0,a.formatLocale)(m)}`),w(`Reviewing ${(0,l.colorizeNumber)(f.length)} locales: [ ${(0,a.formatLocale)(f)} ]`),w(`Reviewing ${(0,l.colorizeNumber)(O.length)} files:`),w(O.map(e=>` - ${(0,a.formatPath)(e)}\n`)),await(0,a.parallelize)(O.flatMap(e=>f.map(t=>async()=>{w(`Reviewing file: ${(0,a.formatPath)(e)} to ${(0,a.formatLocale)(t)}`);let o=(0,s.join)(C.content.baseDir,e),d=r.getOutputFilePath(o,t,m);if(x&&(0,u.existsSync)(d)){let e=(0,s.relative)(C.content.baseDir,d);w(`${(0,l.colorize)(`⊘`,l.ANSIColors.YELLOW)} File ${(0,a.formatPath)(e)} already exists, skipping.`);return}if((0,u.existsSync)(d)){let e=n.checkFileModifiedRange(d,{skipIfModifiedBefore:y,skipIfModifiedAfter:b});if(e.isSkipped){w(e.message);return}}else (y||b)&&w(`${(0,l.colorize)(`!`,l.ANSIColors.YELLOW)} File ${(0,a.formatPath)(d)} does not exist, skipping modification date check.`);let f;if(S){let e=await(0,c.listGitLines)(o,S);w(`Git changed lines: ${e.join(`, `)}`),f=e}await i.reviewFileBlockAware(o,d,t,m,h,_,v,f,E,D)})),e=>e(),g??3)};exports.reviewDoc=f;
|
|
69
2
|
//# sourceMappingURL=reviewDoc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDoc.cjs","names":["setupAI","getOutputFilePath","ANSIColors","checkFileModifiedRange","reviewFileBlockAware"],"sources":["../../../src/reviewDoc/reviewDoc.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n
|
|
1
|
+
{"version":3,"file":"reviewDoc.cjs","names":["setupAI","getOutputFilePath","ANSIColors","checkFileModifiedRange","reviewFileBlockAware"],"sources":["../../../src/reviewDoc/reviewDoc.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n type ListGitFilesOptions,\n listGitFiles,\n listGitLines,\n} from '@intlayer/chokidar/cli';\nimport {\n formatLocale,\n formatPath,\n parallelize,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { reviewFileBlockAware } from './reviewDocBlockAware';\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n const aiResult = await setupAI(configuration, aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n // Check modification range only if the file exists\n if (existsSync(outputFilePath)) {\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n } else if (skipIfModifiedBefore || skipIfModifiedAfter) {\n // Log if we intended to check modification time but couldn't because the file doesn't exist\n appLogger(\n `${colorize('!', ANSIColors.YELLOW)} File ${formatPath(outputFilePath)} does not exist, skipping modification date check.`\n );\n }\n\n let changedLines: number[] | undefined;\n // FIXED: Enable git optimization that was previously commented out\n if (gitOptions) {\n const gitChangedLines = await listGitLines(\n absoluteBaseFilePath,\n gitOptions\n );\n\n appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n changedLines = gitChangedLines;\n }\n\n await reviewFileBlockAware(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions,\n changedLines,\n aiClient,\n aiConfig\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":"sgBAiDA,MAAa,EAAY,MAAO,CAC9B,aACA,UACA,sBACA,aACA,YACA,8BACA,gBACA,qBACA,uBACA,sBACA,eACA,gBACsB,CACtB,IAAM,GAAA,EAAA,EAAA,kBAAiC,EAAc,CAC/C,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,EAAW,MAAMA,EAAAA,QAAQ,EAAe,EAAU,CAExD,GA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