@intlayer/chokidar 5.4.1 → 5.5.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chokidar/watcher.cjs +3 -3
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs +7 -9
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +4 -3
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/filterDictionaryLocales.cjs +58 -0
- package/dist/cjs/filterDictionaryLocales.cjs.map +1 -0
- package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs +51 -0
- package/dist/cjs/getBuiltUnmergedDictionariesPath.cjs.map +1 -0
- package/dist/cjs/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
- package/dist/cjs/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +62 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -0
- package/dist/cjs/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
- package/dist/cjs/index.cjs +21 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs +98 -0
- package/dist/cjs/listGitFiles.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -23
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs +7 -1
- package/dist/cjs/loadDictionaries/loadDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/mergeDictionaries.cjs +43 -23
- package/dist/cjs/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +1 -1
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/processPerLocaleDictionary.cjs +49 -0
- package/dist/cjs/processPerLocaleDictionary.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs +50 -0
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs +49 -0
- package/dist/cjs/reduceDictionaryContent/buildMask.cjs.map +1 -0
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +35 -0
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -0
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +56 -8
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs +4 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +21 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/formatCode.cjs +61 -0
- package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +36 -37
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +377 -0
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -0
- package/dist/esm/chokidar/watcher.mjs +5 -5
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +7 -9
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +5 -4
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/filterDictionaryLocales.mjs +37 -0
- package/dist/esm/filterDictionaryLocales.mjs.map +1 -0
- package/dist/esm/getBuiltUnmergedDictionariesPath.mjs +17 -0
- package/dist/esm/getBuiltUnmergedDictionariesPath.mjs.map +1 -0
- package/dist/esm/getContentDeclarationFileTemplate/cjsTemplate.md +9 -0
- package/dist/esm/getContentDeclarationFileTemplate/esmTemplate.md +9 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +37 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -0
- package/dist/esm/getContentDeclarationFileTemplate/tsTemplate.md +8 -0
- package/dist/esm/index.mjs +21 -9
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs +64 -0
- package/dist/esm/listGitFiles.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -13
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs +7 -1
- package/dist/esm/loadDictionaries/loadDistantDictionaries.mjs.map +1 -1
- package/dist/esm/mergeDictionaries.mjs +42 -22
- package/dist/esm/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +3 -3
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/processPerLocaleDictionary.mjs +25 -0
- package/dist/esm/processPerLocaleDictionary.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/applyMask.mjs +26 -0
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/buildMask.mjs +24 -0
- package/dist/esm/reduceDictionaryContent/buildMask.mjs.map +1 -0
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +11 -0
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -0
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +54 -8
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs +4 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +21 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/formatCode.mjs +37 -0
- package/dist/esm/writeContentDeclaration/formatCode.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +35 -36
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +345 -0
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -0
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/cleanOutputDir.d.ts.map +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/filterDictionaryLocales.d.ts +4 -0
- package/dist/types/filterDictionaryLocales.d.ts.map +1 -0
- package/dist/types/getBuiltUnmergedDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltUnmergedDictionariesPath.d.ts.map +1 -0
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +2 -0
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listGitFiles.d.ts +9 -0
- package/dist/types/listGitFiles.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadDistantDictionaries.d.ts.map +1 -1
- package/dist/types/mergeDictionaries.d.ts +2 -4
- package/dist/types/mergeDictionaries.d.ts.map +1 -1
- package/dist/types/processPerLocaleDictionary.d.ts +32 -0
- package/dist/types/processPerLocaleDictionary.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/applyMask.d.ts +3 -0
- package/dist/types/reduceDictionaryContent/applyMask.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/buildMask.d.ts +5 -0
- package/dist/types/reduceDictionaryContent/buildMask.d.ts.map +1 -0
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +3 -0
- package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts +38 -0
- package/dist/types/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.d.ts.map +1 -1
- package/dist/types/transpiler/dictionary_to_main/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/formatCode.d.ts +2 -0
- package/dist/types/writeContentDeclaration/formatCode.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +9 -0
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -0
- package/package.json +21 -13
package/dist/cjs/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.cjs
CHANGED
|
@@ -21,9 +21,9 @@ __export(writeDictionary_exports, {
|
|
|
21
21
|
writeDictionary: () => writeDictionary
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(writeDictionary_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
24
25
|
var import_promises = require("fs/promises");
|
|
25
26
|
var import_path = require("path");
|
|
26
|
-
var import_config = require("@intlayer/config");
|
|
27
27
|
const { content } = (0, import_config.getConfiguration)();
|
|
28
28
|
const { reactIntlMessagesDir } = content;
|
|
29
29
|
const writeDictionary = async (dictionariesDeclaration) => {
|
|
@@ -34,9 +34,9 @@ const writeDictionary = async (dictionariesDeclaration) => {
|
|
|
34
34
|
for await (const [locale, content2] of Object.entries(localContent)) {
|
|
35
35
|
const contentString = JSON.stringify(content2);
|
|
36
36
|
const outputFileName = `${nameSpace}.json`;
|
|
37
|
-
const
|
|
38
|
-
const resultFilePath = (0, import_path.resolve)(
|
|
39
|
-
await (0, import_promises.mkdir)(
|
|
37
|
+
const dictionariesDirPath = (0, import_path.resolve)(reactIntlMessagesDir, locale);
|
|
38
|
+
const resultFilePath = (0, import_path.resolve)(dictionariesDirPath, outputFileName);
|
|
39
|
+
await (0, import_promises.mkdir)(dictionariesDirPath, { recursive: true });
|
|
40
40
|
await (0, import_promises.writeFile)(resultFilePath, contentString, "utf8").catch((err) => {
|
|
41
41
|
console.error(`Error creating ${outputFileName}:`, err);
|
|
42
42
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/reactIntl_dictionary/writeDictionary.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport type { I18nextDictionariesOutput } from '../i18next_dictionary/convertContentDeclarationInto18nDictionaries';\n\nconst { content } = getConfiguration();\nconst { reactIntlMessagesDir } = content;\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n dictionariesDeclaration: DictionariesDeclaration\n) => {\n const resultDictionariesPaths: string[] = [];\n\n for (const [nameSpace, localContent] of Object.entries(\n dictionariesDeclaration\n )) {\n for await (const [locale, content] of Object.entries(localContent)) {\n const contentString = JSON.stringify(content);\n\n const outputFileName = `${nameSpace}.json`;\n const dictionariesDirPath = resolve(reactIntlMessagesDir, locale);\n const resultFilePath = resolve(dictionariesDirPath, outputFileName);\n\n // Create the dictionaries folder if it doesn't exist\n await mkdir(dictionariesDirPath, { recursive: true });\n\n // Create the json file\n await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n console.error(`Error creating ${outputFileName}:`, err);\n });\n\n resultDictionariesPaths.push(resultFilePath);\n }\n }\n\n return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,sBAAiC;AACjC,kBAAwB;AAGxB,MAAM,EAAE,QAAQ,QAAI,gCAAiB;AACrC,MAAM,EAAE,qBAAqB,IAAI;AAO1B,MAAM,kBAAkB,OAC7B,4BACG;AACH,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQA,QAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAUA,QAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,0BAAsB,qBAAQ,sBAAsB,MAAM;AAChE,YAAM,qBAAiB,qBAAQ,qBAAqB,cAAc;AAGlE,gBAAM,uBAAM,qBAAqB,EAAE,WAAW,KAAK,CAAC;AAGpD,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":["content"]}
|
|
@@ -21,10 +21,11 @@ __export(createDictionaryEntryPoint_exports, {
|
|
|
21
21
|
createDictionaryEntryPoint: () => createDictionaryEntryPoint
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(createDictionaryEntryPoint_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
24
25
|
var import_fs = require("fs");
|
|
25
26
|
var import_path = require("path");
|
|
26
|
-
var import_config = require("@intlayer/config");
|
|
27
27
|
var import_getBuiltDictionariesPath = require('../../getBuiltDictionariesPath.cjs');
|
|
28
|
+
var import_getBuiltUnmergedDictionariesPath = require('../../getBuiltUnmergedDictionariesPath.cjs');
|
|
28
29
|
var import_utils = require('../../utils.cjs');
|
|
29
30
|
const generateDictionaryListContent = (dictionaries, format = "esm", configuration = (0, import_config.getConfiguration)()) => {
|
|
30
31
|
const { mainDir } = configuration.content;
|
|
@@ -76,6 +77,25 @@ const createDictionaryEntryPoint = (configuration = (0, import_config.getConfigu
|
|
|
76
77
|
configuration
|
|
77
78
|
);
|
|
78
79
|
(0, import_fs.writeFileSync)((0, import_path.resolve)(mainDir, "dictionaries.mjs"), esmContent);
|
|
80
|
+
const unmergedDictionariesPath = (0, import_getBuiltUnmergedDictionariesPath.getBuiltUnmergedDictionariesPath)(configuration);
|
|
81
|
+
const unmergedCjsContent = generateDictionaryListContent(
|
|
82
|
+
unmergedDictionariesPath,
|
|
83
|
+
"cjs",
|
|
84
|
+
configuration
|
|
85
|
+
);
|
|
86
|
+
(0, import_fs.writeFileSync)(
|
|
87
|
+
(0, import_path.resolve)(mainDir, "unmerged_dictionaries.cjs"),
|
|
88
|
+
unmergedCjsContent
|
|
89
|
+
);
|
|
90
|
+
const unmergedEsmContent = generateDictionaryListContent(
|
|
91
|
+
unmergedDictionariesPath,
|
|
92
|
+
"esm",
|
|
93
|
+
configuration
|
|
94
|
+
);
|
|
95
|
+
(0, import_fs.writeFileSync)(
|
|
96
|
+
(0, import_path.resolve)(mainDir, "unmerged_dictionaries.mjs"),
|
|
97
|
+
unmergedEsmContent
|
|
98
|
+
);
|
|
79
99
|
};
|
|
80
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
101
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/dictionary_to_main/createDictionaryEntryPoint.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { basename, extname, relative, resolve } from 'path';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getBuiltUnmergedDictionariesPath } from '../../getBuiltUnmergedDictionariesPath';\nimport { getFileHash } from '../../utils';\n\n/**\n * This function generates the content of the dictionary list file\n */\nconst generateDictionaryListContent = (\n dictionaries: string[],\n format: 'cjs' | 'esm' = 'esm',\n configuration = getConfiguration()\n): string => {\n const { mainDir } = configuration.content;\n\n let content = '';\n\n const dictionariesRef = dictionaries.map((dictionaryPath) => ({\n relativePath: relative(mainDir, dictionaryPath),\n id: basename(dictionaryPath, extname(dictionaryPath)), // Get the base name as the dictionary id\n hash: `_${getFileHash(dictionaryPath)}`, // Get the hash of the dictionary to avoid conflicts\n }));\n\n // Import all dictionaries\n dictionariesRef.forEach((dictionary) => {\n if (format === 'esm')\n content += `import ${dictionary.hash} from '${dictionary.relativePath}';\\n`;\n if (format === 'cjs')\n content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\\n`;\n });\n\n content += '\\n';\n\n // Format Dictionary Map\n const formattedDictionaryMap: string = dictionariesRef\n .map((dictionary) => ` \"${dictionary.id}\": ${dictionary.hash}`)\n .join(',\\n');\n\n if (format === 'esm')\n content += `export default {\\n${formattedDictionaryMap}\\n};\\n`;\n if (format === 'cjs')\n content += `module.exports = {\\n${formattedDictionaryMap}\\n};\\n`;\n\n return content;\n};\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const createDictionaryEntryPoint = (\n configuration = getConfiguration()\n) => {\n const { mainDir } = configuration.content;\n\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getBuiltDictionariesPath(configuration);\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(\n dictionariesPath,\n 'cjs',\n configuration\n );\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(\n dictionariesPath,\n 'esm',\n configuration\n );\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n\n const unmergedDictionariesPath: string[] =\n getBuiltUnmergedDictionariesPath(configuration);\n\n const unmergedCjsContent = generateDictionaryListContent(\n unmergedDictionariesPath,\n 'cjs',\n configuration\n );\n writeFileSync(\n resolve(mainDir, 'unmerged_dictionaries.cjs'),\n unmergedCjsContent\n );\n\n const unmergedEsmContent = generateDictionaryListContent(\n unmergedDictionariesPath,\n 'esm',\n configuration\n );\n writeFileSync(\n resolve(mainDir, 'unmerged_dictionaries.mjs'),\n unmergedEsmContent\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,gBAAqD;AACrD,kBAAqD;AACrD,sCAAyC;AACzC,8CAAiD;AACjD,mBAA4B;AAK5B,MAAM,gCAAgC,CACpC,cACA,SAAwB,OACxB,oBAAgB,gCAAiB,MACtB;AACX,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,MAAI,UAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,kBAAc,sBAAS,SAAS,cAAc;AAAA,IAC9C,QAAI,sBAAS,oBAAgB,qBAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,QAAI,0BAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,iBAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,iBAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,aAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,eAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,eAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAO;AACT;AAKO,MAAM,6BAA6B,CACxC,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,QAAQ,IAAI,cAAc;AAGlC,MAAI,KAAC,sBAAW,OAAO,GAAG;AACxB,6BAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,uBAA6B,0DAAyB,aAAa;AAGzE,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,mCAAc,qBAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,+BACJ,0EAAiC,aAAa;AAEhD,QAAM,qBAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA;AAAA,QACE,qBAAQ,SAAS,2BAA2B;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,qBAAqB;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA;AAAA,QACE,qBAAQ,SAAS,2BAA2B;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var formatCode_exports = {};
|
|
20
|
+
__export(formatCode_exports, {
|
|
21
|
+
formatCode: () => formatCode
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(formatCode_exports);
|
|
24
|
+
var import_config = require("@intlayer/config");
|
|
25
|
+
const formatCode = async (filePath, code) => {
|
|
26
|
+
let prettier;
|
|
27
|
+
try {
|
|
28
|
+
prettier = require("prettier");
|
|
29
|
+
} catch (error) {
|
|
30
|
+
}
|
|
31
|
+
if (prettier) {
|
|
32
|
+
try {
|
|
33
|
+
const prettierConfig = await prettier.resolveConfig(filePath ?? "");
|
|
34
|
+
const formattedCode = await prettier.format(code, {
|
|
35
|
+
...prettierConfig,
|
|
36
|
+
filepath: filePath
|
|
37
|
+
// Explicitly provide the filepath so Prettier can infer the parser
|
|
38
|
+
});
|
|
39
|
+
(0, import_config.appLogger)(`Applied Prettier formatting to ${filePath}`, {
|
|
40
|
+
level: "info",
|
|
41
|
+
isVerbose: true
|
|
42
|
+
});
|
|
43
|
+
return formattedCode;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const err = error;
|
|
46
|
+
(0, import_config.appLogger)(
|
|
47
|
+
`Failed to apply Prettier formatting to ${filePath}: ${err.message}`,
|
|
48
|
+
{
|
|
49
|
+
level: "warn",
|
|
50
|
+
isVerbose: true
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return code;
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
formatCode
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=formatCode.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/formatCode.ts"],"sourcesContent":["import { appLogger } from '@intlayer/config';\n\nexport const formatCode = async (filePath: string, code: string) => {\n // Try to import prettier if it exists\n let prettier: any;\n try {\n prettier = require('prettier');\n } catch (error) {\n // Prettier is not installed, continue without it\n }\n\n // Apply Prettier formatting if it's available\n if (prettier) {\n try {\n // Try to find a prettier config file\n const prettierConfig = await prettier.resolveConfig(filePath ?? '');\n\n // Format the code with Prettier\n const formattedCode = await prettier.format(code, {\n ...prettierConfig,\n filepath: filePath, // Explicitly provide the filepath so Prettier can infer the parser\n });\n\n appLogger(`Applied Prettier formatting to ${filePath}`, {\n level: 'info',\n isVerbose: true,\n });\n\n return formattedCode;\n } catch (error) {\n const err = error as Error;\n appLogger(\n `Failed to apply Prettier formatting to ${filePath}: ${err.message}`,\n {\n level: 'warn',\n isVerbose: true,\n }\n );\n // Continue with unformatted code on prettier error\n }\n }\n\n return code;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0B;AAEnB,MAAM,aAAa,OAAO,UAAkB,SAAiB;AAElE,MAAI;AACJ,MAAI;AACF,eAAW,QAAQ,UAAU;AAAA,EAC/B,SAAS,OAAO;AAAA,EAEhB;AAGA,MAAI,UAAU;AACZ,QAAI;AAEF,YAAM,iBAAiB,MAAM,SAAS,cAAc,YAAY,EAAE;AAGlE,YAAM,gBAAgB,MAAM,SAAS,OAAO,MAAM;AAAA,QAChD,GAAG;AAAA,QACH,UAAU;AAAA;AAAA,MACZ,CAAC;AAED,mCAAU,kCAAkC,QAAQ,IAAI;AAAA,QACtD,OAAO;AAAA,QACP,WAAW;AAAA,MACb,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,YAAM,MAAM;AACZ;AAAA,QACE,0CAA0C,QAAQ,KAAK,IAAI,OAAO;AAAA,QAClE;AAAA,UACE,OAAO;AAAA,UACP,WAAW;AAAA,QACb;AAAA,MACF;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -31,26 +31,32 @@ __export(writeContentDeclaration_exports, {
|
|
|
31
31
|
writeContentDeclaration: () => writeContentDeclaration
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(writeContentDeclaration_exports);
|
|
34
|
-
var import_fs = require("fs");
|
|
35
|
-
var fsPromises = __toESM(require("fs/promises"));
|
|
36
|
-
var import_path = require("path");
|
|
37
|
-
var import_chokidar = require("@intlayer/chokidar");
|
|
38
34
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
39
|
-
var
|
|
35
|
+
var import_unmerged_dictionaries_entry = __toESM(require("@intlayer/unmerged-dictionaries-entry"));
|
|
40
36
|
var import_deep_equal = __toESM(require("deep-equal"));
|
|
37
|
+
var import_fs = require("fs");
|
|
38
|
+
var import_promises = require("fs/promises");
|
|
39
|
+
var import_path = require("path");
|
|
40
|
+
var import_prepareContentDeclaration = require('../prepareContentDeclaration.cjs');
|
|
41
|
+
var import_writeJSFile = require('./writeJSFile.cjs');
|
|
41
42
|
const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const { baseDir } = content;
|
|
45
|
-
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
46
|
-
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
47
|
-
const existingDictionary = import_dictionaries_entry.default[dictionary.key];
|
|
48
|
-
const preparedContentDeclaration = await (0, import_chokidar.prepareContentDeclaration)(dictionary);
|
|
43
|
+
const formatContentDeclaration = async (dictionary) => {
|
|
44
|
+
const preparedContentDeclaration = await (0, import_prepareContentDeclaration.prepareContentDeclaration)(dictionary);
|
|
49
45
|
const { filePath, $schema, ...dictionaryWithoutPath } = preparedContentDeclaration;
|
|
50
46
|
const formattedContentDeclaration = {
|
|
51
47
|
$schema: "https://intlayer.org/schema.json",
|
|
52
48
|
...dictionaryWithoutPath
|
|
53
49
|
};
|
|
50
|
+
return formattedContentDeclaration;
|
|
51
|
+
};
|
|
52
|
+
const writeContentDeclaration = async (dictionary, config = import_built.default, newDictionariesPath) => {
|
|
53
|
+
const { content } = config;
|
|
54
|
+
const { baseDir } = content;
|
|
55
|
+
const newDictionaryRelativeLocationPath = newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;
|
|
56
|
+
const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;
|
|
57
|
+
const existingDictionary = import_unmerged_dictionaries_entry.default[dictionary.key].filter((el) => el.filePath === dictionary.filePath);
|
|
58
|
+
const filePath = dictionary.filePath;
|
|
59
|
+
const formattedContentDeclaration = await formatContentDeclaration(dictionary);
|
|
54
60
|
if (existingDictionary) {
|
|
55
61
|
if ((0, import_deep_equal.default)(existingDictionary, dictionary)) {
|
|
56
62
|
return {
|
|
@@ -59,28 +65,8 @@ const writeContentDeclaration = async (dictionary, config = import_built.default
|
|
|
59
65
|
};
|
|
60
66
|
} else {
|
|
61
67
|
if (filePath) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const contentDeclarationPath = `${baseDir}/${filePath}`;
|
|
65
|
-
await writeFileWithDirectories(
|
|
66
|
-
contentDeclarationPath,
|
|
67
|
-
formattedContentDeclaration
|
|
68
|
-
);
|
|
69
|
-
return { status: "updated", path: contentDeclarationPath };
|
|
70
|
-
} else {
|
|
71
|
-
await fsPromises.rm(filePath);
|
|
72
|
-
const dictionariesDirPath = (0, import_path.dirname)(filePath);
|
|
73
|
-
const dictionariesFileName = (0, import_path.basename)(filePath, (0, import_path.extname)(filePath));
|
|
74
|
-
const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;
|
|
75
|
-
await writeFileWithDirectories(
|
|
76
|
-
newFilePath,
|
|
77
|
-
formattedContentDeclaration
|
|
78
|
-
);
|
|
79
|
-
return {
|
|
80
|
-
status: "replaced",
|
|
81
|
-
path: newFilePath
|
|
82
|
-
};
|
|
83
|
-
}
|
|
68
|
+
await writeFileWithDirectories(filePath, formattedContentDeclaration);
|
|
69
|
+
return { status: "updated", path: filePath };
|
|
84
70
|
} else {
|
|
85
71
|
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
86
72
|
await writeFileWithDirectories(
|
|
@@ -110,10 +96,23 @@ const writeFileWithDirectories = async (filePath, data) => {
|
|
|
110
96
|
const dir = (0, import_path.dirname)(filePath);
|
|
111
97
|
const directoryExists = (0, import_fs.existsSync)(dir);
|
|
112
98
|
if (!directoryExists) {
|
|
113
|
-
await
|
|
99
|
+
await (0, import_promises.mkdir)(dir, { recursive: true });
|
|
100
|
+
}
|
|
101
|
+
const extention = (0, import_path.extname)(filePath);
|
|
102
|
+
const acceptedExtensions = import_built.default.content.fileExtensions.map(
|
|
103
|
+
(extention2) => (0, import_path.extname)(extention2)
|
|
104
|
+
);
|
|
105
|
+
if (!acceptedExtensions.includes(extention)) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Invalid file extension: ${extention}, file: ${filePath}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (extention === ".json") {
|
|
111
|
+
const jsonDictionary = JSON.stringify(data, null, 2);
|
|
112
|
+
await (0, import_promises.writeFile)(filePath, jsonDictionary);
|
|
113
|
+
} else {
|
|
114
|
+
await (0, import_writeJSFile.writeJSFile)(filePath, data);
|
|
114
115
|
}
|
|
115
|
-
const jsonDictionary = JSON.stringify(data, null, 2);
|
|
116
|
-
await fsPromises.writeFile(filePath, jsonDictionary);
|
|
117
116
|
} catch (error) {
|
|
118
117
|
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
119
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport { existsSync } from 'fs';\nimport { mkdir, writeFile } from 'fs/promises';\nimport { dirname, extname } from 'path';\nimport { prepareContentDeclaration } from '../prepareContentDeclaration';\nimport type { DictionaryStatus } from './dictionaryStatus';\nimport { writeJSFile } from './writeJSFile';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\n\nconst formatContentDeclaration = async (dictionary: Dictionary) => {\n // Clean Markdown, Insertion, File, etc. node metadata\n const preparedContentDeclaration =\n await prepareContentDeclaration(dictionary);\n\n // Remove the filePath from the dictionary and set $schema\n const { filePath, $schema, ...dictionaryWithoutPath } =\n preparedContentDeclaration;\n\n const formattedContentDeclaration = {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n };\n\n return formattedContentDeclaration;\n};\n\nexport const writeContentDeclaration = async (\n dictionary: Dictionary,\n config: IntlayerConfig = configuration,\n newDictionariesPath?: string\n): Promise<{ status: DictionaryStatus; path: string }> => {\n const { content } = config;\n const { baseDir } = content;\n\n const newDictionaryRelativeLocationPath =\n newDictionariesPath ?? DEFAULT_NEW_DICTIONARY_PATH;\n const newDictionaryLocationPath = `${baseDir}/${newDictionaryRelativeLocationPath}`;\n\n const existingDictionary = (\n dictionariesRecord[dictionary.key] as Dictionary[]\n ).filter((el) => el.filePath === dictionary.filePath);\n\n const filePath = dictionary.filePath;\n const formattedContentDeclaration =\n await formatContentDeclaration(dictionary);\n\n if (existingDictionary) {\n // Compare existing dictionary with distant dictionary\n if (deepEqual(existingDictionary, dictionary)) {\n // Up to date, nothing to do\n return {\n status: 'up-to-date',\n path: filePath!,\n };\n } else {\n if (filePath) {\n await writeFileWithDirectories(filePath, formattedContentDeclaration);\n\n return { status: 'updated', path: filePath };\n } else {\n // Write the dictionary to the intlayer-dictionaries directory\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'reimported in new location',\n path: contentDeclarationPath,\n };\n }\n }\n } else {\n // No existing dictionary, write to new location\n const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n\n return {\n status: 'imported',\n path: contentDeclarationPath,\n };\n }\n};\n\nconst writeFileWithDirectories = async (\n filePath: string,\n data: string | Buffer\n): Promise<void> => {\n try {\n // Extract the directory from the file path\n const dir = dirname(filePath);\n\n // Check if the directory exists\n const directoryExists = existsSync(dir);\n\n if (!directoryExists) {\n // Create the directory recursively\n await mkdir(dir, { recursive: true });\n }\n\n const extention = extname(filePath);\n const acceptedExtensions = configuration.content.fileExtensions.map(\n (extention) => extname(extention)\n );\n\n if (!acceptedExtensions.includes(extention)) {\n throw new Error(\n `Invalid file extension: ${extention}, file: ${filePath}`\n );\n }\n\n if (extention === '.json') {\n const jsonDictionary = JSON.stringify(data, null, 2);\n\n // Write the file\n await writeFile(filePath, jsonDictionary);\n } else {\n await writeJSFile(filePath, data as unknown as Dictionary);\n }\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,yCAA+B;AAC/B,wBAAsB;AACtB,gBAA2B;AAC3B,sBAAiC;AACjC,kBAAiC;AACjC,uCAA0C;AAE1C,yBAA4B;AAE5B,MAAM,8BAA8B;AAEpC,MAAM,2BAA2B,OAAO,eAA2B;AAEjE,QAAM,6BACJ,UAAM,4DAA0B,UAAU;AAG5C,QAAM,EAAE,UAAU,SAAS,GAAG,sBAAsB,IAClD;AAEF,QAAM,8BAA8B;AAAA,IAClC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,SAAO;AACT;AAEO,MAAM,0BAA0B,OACrC,YACA,SAAyB,aAAAA,SACzB,wBACwD;AACxD,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,EAAE,QAAQ,IAAI;AAEpB,QAAM,oCACJ,uBAAuB;AACzB,QAAM,4BAA4B,GAAG,OAAO,IAAI,iCAAiC;AAEjF,QAAM,qBACJ,mCAAAC,QAAmB,WAAW,GAAG,EACjC,OAAO,CAAC,OAAO,GAAG,aAAa,WAAW,QAAQ;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,8BACJ,MAAM,yBAAyB,UAAU;AAE3C,MAAI,oBAAoB;AAEtB,YAAI,kBAAAC,SAAU,oBAAoB,UAAU,GAAG;AAE7C,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,MACR;AAAA,IACF,OAAO;AACL,UAAI,UAAU;AACZ,cAAM,yBAAyB,UAAU,2BAA2B;AAEpE,eAAO,EAAE,QAAQ,WAAW,MAAM,SAAS;AAAA,MAC7C,OAAO;AAEL,cAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,yBAAyB,GAAG,yBAAyB,IAAI,WAAW,GAAG;AAE7E,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAEA,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,MAAM,2BAA2B,OAC/B,UACA,SACkB;AAClB,MAAI;AAEF,UAAM,UAAM,qBAAQ,QAAQ;AAG5B,UAAM,sBAAkB,sBAAW,GAAG;AAEtC,QAAI,CAAC,iBAAiB;AAEpB,gBAAM,uBAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACtC;AAEA,UAAM,gBAAY,qBAAQ,QAAQ;AAClC,UAAM,qBAAqB,aAAAF,QAAc,QAAQ,eAAe;AAAA,MAC9D,CAACG,mBAAc,qBAAQA,UAAS;AAAA,IAClC;AAEA,QAAI,CAAC,mBAAmB,SAAS,SAAS,GAAG;AAC3C,YAAM,IAAI;AAAA,QACR,2BAA2B,SAAS,WAAW,QAAQ;AAAA,MACzD;AAAA,IACF;AAEA,QAAI,cAAc,SAAS;AACzB,YAAM,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC;AAGnD,gBAAM,2BAAU,UAAU,cAAc;AAAA,IAC1C,OAAO;AACL,gBAAM,gCAAY,UAAU,IAA6B;AAAA,IAC3D;AAAA,EACF,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["configuration","dictionariesRecord","deepEqual","extention"]}
|