@intlayer/chokidar 5.3.3 → 5.3.4
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 +46 -15
- package/dist/cjs/chokidar/watcher.cjs.map +1 -1
- package/dist/cjs/{getDictionariesPath.cjs → getBuiltDictionariesPath.cjs} +7 -7
- package/dist/cjs/getBuiltDictionariesPath.cjs.map +1 -0
- package/dist/cjs/index.cjs +11 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/listDictionariesPath.cjs +61 -0
- package/dist/cjs/listDictionariesPath.cjs.map +1 -0
- package/dist/cjs/prepareContentDeclaration.cjs +90 -0
- package/dist/cjs/prepareContentDeclaration.cjs.map +1 -0
- package/dist/cjs/prepareIntlayer.cjs +2 -29
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs +2 -4
- package/dist/cjs/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.cjs.map +1 -1
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs +2 -2
- package/dist/cjs/transpiler/dictionary_to_main/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs +17 -0
- package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/index.cjs +25 -0
- package/dist/cjs/writeContentDeclaration/index.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +125 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -0
- package/dist/esm/chokidar/watcher.mjs +46 -16
- package/dist/esm/chokidar/watcher.mjs.map +1 -1
- package/dist/esm/{getDictionariesPath.mjs → getBuiltDictionariesPath.mjs} +3 -3
- package/dist/esm/getBuiltDictionariesPath.mjs.map +1 -0
- package/dist/esm/index.mjs +9 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs +27 -0
- package/dist/esm/listDictionariesPath.mjs.map +1 -0
- package/dist/esm/prepareContentDeclaration.mjs +69 -0
- package/dist/esm/prepareContentDeclaration.mjs.map +1 -0
- package/dist/esm/prepareIntlayer.mjs +2 -19
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs +2 -4
- package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs.map +1 -1
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs +2 -2
- package/dist/esm/transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs +1 -0
- package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/index.mjs +3 -0
- package/dist/esm/writeContentDeclaration/index.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +91 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -0
- package/dist/types/chokidar/watcher.d.ts +1 -0
- package/dist/types/chokidar/watcher.d.ts.map +1 -1
- package/dist/types/getBuiltDictionariesPath.d.ts +5 -0
- package/dist/types/getBuiltDictionariesPath.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/listDictionariesPath.d.ts +3 -0
- package/dist/types/listDictionariesPath.d.ts.map +1 -0
- package/dist/types/prepareContentDeclaration.d.ts +3 -0
- package/dist/types/prepareContentDeclaration.d.ts.map +1 -0
- package/dist/types/prepareIntlayer.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +2 -0
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/index.d.ts +3 -0
- package/dist/types/writeContentDeclaration/index.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +8 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -0
- package/package.json +16 -12
- package/dist/cjs/getDictionariesPath.cjs.map +0 -1
- package/dist/esm/getDictionariesPath.mjs.map +0 -1
- package/dist/types/getDictionariesPath.d.ts +0 -5
- package/dist/types/getDictionariesPath.d.ts.map +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var writeContentDeclaration_exports = {};
|
|
30
|
+
__export(writeContentDeclaration_exports, {
|
|
31
|
+
writeContentDeclaration: () => writeContentDeclaration
|
|
32
|
+
});
|
|
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
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
39
|
+
var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
|
|
40
|
+
var import_deep_equal = __toESM(require("deep-equal"));
|
|
41
|
+
const DEFAULT_NEW_DICTIONARY_PATH = "intlayer-dictionaries";
|
|
42
|
+
const writeContentDeclaration = async (dictionary, config = import_built.default, newDictionariesPath) => {
|
|
43
|
+
const { content } = config;
|
|
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);
|
|
49
|
+
const { filePath, $schema, ...dictionaryWithoutPath } = preparedContentDeclaration;
|
|
50
|
+
const formattedContentDeclaration = {
|
|
51
|
+
$schema: "https://intlayer.org/schema.json",
|
|
52
|
+
...dictionaryWithoutPath
|
|
53
|
+
};
|
|
54
|
+
if (existingDictionary) {
|
|
55
|
+
if ((0, import_deep_equal.default)(existingDictionary, dictionary)) {
|
|
56
|
+
return {
|
|
57
|
+
status: "up-to-date",
|
|
58
|
+
path: filePath
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
if (filePath) {
|
|
62
|
+
const isDictionaryJSON = filePath.endsWith(".json");
|
|
63
|
+
if (isDictionaryJSON) {
|
|
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
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
86
|
+
await writeFileWithDirectories(
|
|
87
|
+
contentDeclarationPath,
|
|
88
|
+
formattedContentDeclaration
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
status: "reimported in new location",
|
|
92
|
+
path: contentDeclarationPath
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
const contentDeclarationPath = `${newDictionaryLocationPath}/${dictionary.key}.content.json`;
|
|
98
|
+
await writeFileWithDirectories(
|
|
99
|
+
contentDeclarationPath,
|
|
100
|
+
formattedContentDeclaration
|
|
101
|
+
);
|
|
102
|
+
return {
|
|
103
|
+
status: "imported",
|
|
104
|
+
path: contentDeclarationPath
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const writeFileWithDirectories = async (filePath, data) => {
|
|
109
|
+
try {
|
|
110
|
+
const dir = (0, import_path.dirname)(filePath);
|
|
111
|
+
const directoryExists = (0, import_fs.existsSync)(dir);
|
|
112
|
+
if (!directoryExists) {
|
|
113
|
+
await fsPromises.mkdir(dir, { recursive: true });
|
|
114
|
+
}
|
|
115
|
+
const jsonDictionary = JSON.stringify(data, null, 2);
|
|
116
|
+
await fsPromises.writeFile(filePath, jsonDictionary);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
writeContentDeclaration
|
|
124
|
+
});
|
|
125
|
+
//# sourceMappingURL=writeContentDeclaration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/writeContentDeclaration.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport * as fsPromises from 'fs/promises';\nimport { basename, dirname, extname } from 'path';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { prepareContentDeclaration } from '@intlayer/chokidar';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport deepEqual from 'deep-equal';\nimport type { DictionaryStatus } from './dictionaryStatus';\n\nconst DEFAULT_NEW_DICTIONARY_PATH = 'intlayer-dictionaries';\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 = dictionariesRecord[dictionary.key];\n\n const preparedContentDeclaration =\n await prepareContentDeclaration(dictionary);\n\n const { filePath, $schema, ...dictionaryWithoutPath } =\n preparedContentDeclaration;\n const formattedContentDeclaration = {\n $schema: 'https://intlayer.org/schema.json',\n ...dictionaryWithoutPath,\n };\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 const isDictionaryJSON = filePath.endsWith('.json');\n\n if (isDictionaryJSON) {\n const contentDeclarationPath = `${baseDir}/${filePath}`;\n\n await writeFileWithDirectories(\n contentDeclarationPath,\n formattedContentDeclaration\n );\n return { status: 'updated', path: contentDeclarationPath };\n } else {\n // Remove the existing dictionary file\n await fsPromises.rm(filePath);\n\n // Write the dictionary to the intlayer-dictionaries directory\n const dictionariesDirPath = dirname(filePath);\n const dictionariesFileName = basename(filePath, extname(filePath));\n\n const newFilePath = `${dictionariesDirPath}/${dictionariesFileName}.json`;\n\n await writeFileWithDirectories(\n newFilePath,\n formattedContentDeclaration\n );\n\n return {\n status: 'replaced',\n path: newFilePath,\n };\n }\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 fsPromises.mkdir(dir, { recursive: true });\n }\n\n const jsonDictionary = JSON.stringify(data, null, 2);\n\n // Write the file\n await fsPromises.writeFile(filePath, jsonDictionary);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,iBAA4B;AAC5B,kBAA2C;AAE3C,sBAA0C;AAC1C,mBAA0B;AAE1B,gCAA+B;AAC/B,wBAAsB;AAGtB,MAAM,8BAA8B;AAE7B,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,qBAAqB,0BAAAC,QAAmB,WAAW,GAAG;AAE5D,QAAM,6BACJ,UAAM,2CAA0B,UAAU;AAE5C,QAAM,EAAE,UAAU,SAAS,GAAG,sBAAsB,IAClD;AACF,QAAM,8BAA8B;AAAA,IAClC,SAAS;AAAA,IACT,GAAG;AAAA,EACL;AAEA,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,mBAAmB,SAAS,SAAS,OAAO;AAElD,YAAI,kBAAkB;AACpB,gBAAM,yBAAyB,GAAG,OAAO,IAAI,QAAQ;AAErD,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,UACF;AACA,iBAAO,EAAE,QAAQ,WAAW,MAAM,uBAAuB;AAAA,QAC3D,OAAO;AAEL,gBAAM,WAAW,GAAG,QAAQ;AAG5B,gBAAM,0BAAsB,qBAAQ,QAAQ;AAC5C,gBAAM,2BAAuB,sBAAS,cAAU,qBAAQ,QAAQ,CAAC;AAEjE,gBAAM,cAAc,GAAG,mBAAmB,IAAI,oBAAoB;AAElE,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF,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,YAAM,WAAW,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACjD;AAEA,UAAM,iBAAiB,KAAK,UAAU,MAAM,MAAM,CAAC;AAGnD,UAAM,WAAW,UAAU,UAAU,cAAc;AAAA,EACrD,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,EAC/D;AACF;","names":["configuration","dictionariesRecord","deepEqual"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { relative } from "path";
|
|
1
|
+
import { basename, relative } from "path";
|
|
2
2
|
import {
|
|
3
3
|
appLogger,
|
|
4
4
|
getConfiguration
|
|
5
5
|
} from "@intlayer/config";
|
|
6
6
|
import { watch as chokidarWatch } from "chokidar";
|
|
7
|
-
import {
|
|
7
|
+
import { getBuiltDictionariesPath } from "../getBuiltDictionariesPath.mjs";
|
|
8
8
|
import { loadLocalDictionaries } from "../loadDictionaries/loadLocalDictionaries.mjs";
|
|
9
9
|
import { buildDictionary } from "../transpiler/declaration_file_to_dictionary/index.mjs";
|
|
10
10
|
import { createDictionaryEntryPoint } from "../transpiler/dictionary_to_main/createDictionaryEntryPoint.mjs";
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
createModuleAugmentation
|
|
14
14
|
} from "../transpiler/dictionary_to_type/index.mjs";
|
|
15
15
|
import { prepareIntlayer } from "../prepareIntlayer.mjs";
|
|
16
|
+
import { listDictionaries } from "../listDictionariesPath.mjs";
|
|
17
|
+
const recentlyAddedFiles = /* @__PURE__ */ new Set();
|
|
16
18
|
const handleAdditionalContentDeclarationFile = async (filePath, configuration) => {
|
|
17
19
|
const { content } = configuration ?? getConfiguration({
|
|
18
20
|
verbose: true
|
|
@@ -35,6 +37,26 @@ const handleAdditionalContentDeclarationFile = async (filePath, configuration) =
|
|
|
35
37
|
isVerbose: true
|
|
36
38
|
});
|
|
37
39
|
};
|
|
40
|
+
const handleUnlikedContentDeclarationFile = async (filePath, configuration) => {
|
|
41
|
+
const { content } = configuration ?? getConfiguration({
|
|
42
|
+
verbose: true
|
|
43
|
+
});
|
|
44
|
+
appLogger(`Unlinked detected: ${relative(content.baseDir, filePath)}`, {
|
|
45
|
+
isVerbose: true
|
|
46
|
+
});
|
|
47
|
+
const files = listDictionaries(configuration);
|
|
48
|
+
const localeDictionaries = await loadLocalDictionaries(files);
|
|
49
|
+
const dictionariesPaths = await buildDictionary(localeDictionaries);
|
|
50
|
+
createTypes(dictionariesPaths);
|
|
51
|
+
createDictionaryEntryPoint();
|
|
52
|
+
appLogger("Dictionaries rebuilt", {
|
|
53
|
+
isVerbose: true
|
|
54
|
+
});
|
|
55
|
+
createModuleAugmentation();
|
|
56
|
+
appLogger("Module augmentation built", {
|
|
57
|
+
isVerbose: true
|
|
58
|
+
});
|
|
59
|
+
};
|
|
38
60
|
const handleContentDeclarationFileChange = async (filePath, configuration) => {
|
|
39
61
|
const { content } = configuration ?? getConfiguration({
|
|
40
62
|
verbose: true
|
|
@@ -44,22 +66,18 @@ const handleContentDeclarationFileChange = async (filePath, configuration) => {
|
|
|
44
66
|
});
|
|
45
67
|
const localeDictionaries = await loadLocalDictionaries(filePath);
|
|
46
68
|
const updatedDictionariesPaths = await buildDictionary(localeDictionaries);
|
|
47
|
-
const allDictionariesPaths =
|
|
69
|
+
const allDictionariesPaths = getBuiltDictionariesPath();
|
|
48
70
|
createTypes(updatedDictionariesPaths);
|
|
49
71
|
appLogger("TypeScript types built", {
|
|
50
72
|
isVerbose: true
|
|
51
73
|
});
|
|
52
74
|
if (updatedDictionariesPaths.some(
|
|
53
|
-
(updatedDictionaryPath) => allDictionariesPaths.includes(updatedDictionaryPath)
|
|
75
|
+
(updatedDictionaryPath) => !allDictionariesPaths.includes(updatedDictionaryPath)
|
|
54
76
|
)) {
|
|
55
77
|
createDictionaryEntryPoint();
|
|
56
78
|
appLogger("Dictionary list built", {
|
|
57
79
|
isVerbose: true
|
|
58
80
|
});
|
|
59
|
-
createModuleAugmentation();
|
|
60
|
-
appLogger("Module augmentation built", {
|
|
61
|
-
isVerbose: true
|
|
62
|
-
});
|
|
63
81
|
}
|
|
64
82
|
};
|
|
65
83
|
const watch = (options) => {
|
|
@@ -73,18 +91,29 @@ const watch = (options) => {
|
|
|
73
91
|
ignoreInitial: true,
|
|
74
92
|
// Process existing files
|
|
75
93
|
...options
|
|
94
|
+
}).on("add", async (filePath) => {
|
|
95
|
+
const fileName = basename(filePath);
|
|
96
|
+
recentlyAddedFiles.add(fileName);
|
|
97
|
+
await handleAdditionalContentDeclarationFile(filePath, configuration);
|
|
98
|
+
setTimeout(() => recentlyAddedFiles.delete(fileName), 1e3);
|
|
76
99
|
}).on(
|
|
77
|
-
"add",
|
|
78
|
-
async (filePath) => await handleAdditionalContentDeclarationFile(filePath, configuration)
|
|
79
|
-
).on(
|
|
80
100
|
"change",
|
|
81
101
|
async (filePath) => await handleContentDeclarationFileChange(filePath, configuration)
|
|
82
|
-
).on(
|
|
83
|
-
|
|
84
|
-
|
|
102
|
+
).on("unlink", async (filePath) => {
|
|
103
|
+
setTimeout(async () => {
|
|
104
|
+
const fileName = basename(filePath);
|
|
105
|
+
if (recentlyAddedFiles.has(fileName)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
await handleUnlikedContentDeclarationFile(filePath, configuration);
|
|
109
|
+
}, 300);
|
|
110
|
+
}).on("error", async (error) => {
|
|
111
|
+
appLogger("Watcher error: " + error, {
|
|
85
112
|
level: "error"
|
|
86
|
-
})
|
|
87
|
-
|
|
113
|
+
});
|
|
114
|
+
appLogger("Restarting watcher");
|
|
115
|
+
await prepareIntlayer(configuration);
|
|
116
|
+
});
|
|
88
117
|
};
|
|
89
118
|
const buildAndWatchIntlayer = async (options) => {
|
|
90
119
|
const configuration = options?.configuration ?? getConfiguration();
|
|
@@ -97,6 +126,7 @@ export {
|
|
|
97
126
|
buildAndWatchIntlayer,
|
|
98
127
|
handleAdditionalContentDeclarationFile,
|
|
99
128
|
handleContentDeclarationFileChange,
|
|
129
|
+
handleUnlikedContentDeclarationFile,
|
|
100
130
|
watch
|
|
101
131
|
};
|
|
102
132
|
//# sourceMappingURL=watcher.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/chokidar/watcher.ts"],"sourcesContent":["import { basename, relative } from 'path';\nimport {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { getBuiltDictionariesPath } from '../getBuiltDictionariesPath';\nimport { loadLocalDictionaries } from '../loadDictionaries/loadLocalDictionaries';\nimport { buildDictionary } from '../transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from '../transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from '../transpiler/dictionary_to_type/index';\nimport { prepareIntlayer } from '../prepareIntlayer';\nimport { listDictionaries } from '../listDictionariesPath';\n\nconst recentlyAddedFiles = new Set<string>();\n\nexport const handleAdditionalContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(\n `Additional file detected: ${relative(content.baseDir, filePath)}`,\n {\n isVerbose: true,\n }\n );\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleUnlikedContentDeclarationFile = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Unlinked detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const localeDictionaries = await loadLocalDictionaries(files);\n\n const dictionariesPaths = await buildDictionary(localeDictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries rebuilt', {\n isVerbose: true,\n });\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n};\n\nexport const handleContentDeclarationFileChange = async (\n filePath: string,\n configuration?: IntlayerConfig\n) => {\n const { content } =\n configuration ??\n getConfiguration({\n verbose: true,\n });\n\n // Process the file with the functionToRun\n appLogger(`Change detected: ${relative(content.baseDir, filePath)}`, {\n isVerbose: true,\n });\n\n const localeDictionaries = await loadLocalDictionaries(filePath);\n\n const updatedDictionariesPaths = await buildDictionary(localeDictionaries);\n const allDictionariesPaths: string[] = getBuiltDictionariesPath();\n\n createTypes(updatedDictionariesPaths);\n appLogger('TypeScript types built', {\n isVerbose: true,\n });\n\n if (\n updatedDictionariesPaths.some(\n (updatedDictionaryPath) =>\n !allDictionariesPaths.includes(updatedDictionaryPath)\n )\n ) {\n createDictionaryEntryPoint();\n\n appLogger('Dictionary list built', {\n isVerbose: true,\n });\n }\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration =\n options?.configuration ??\n getConfiguration({\n verbose: true,\n });\n\n const { watch: isWatchMode, watchedFilesPatternWithPath } =\n configuration.content;\n\n /** @ts-ignore remove error Expected 0-1 arguments, but got 2. */\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n recentlyAddedFiles.add(fileName);\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n\n setTimeout(() => recentlyAddedFiles.delete(fileName), 1000); // Allow time for unlink to trigger if it's a move\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n setTimeout(async () => {\n const fileName = basename(filePath);\n\n if (recentlyAddedFiles.has(fileName)) {\n // The file was moved, so ignore unlink\n return;\n }\n\n await handleUnlikedContentDeclarationFile(filePath, configuration);\n }, 300); // Allow time for unlink to trigger if it's a move\n })\n .on('error', async (error) => {\n appLogger('Watcher error: ' + error, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const configuration = options?.configuration ?? getConfiguration();\n\n await prepareIntlayer(configuration);\n\n if (configuration.content.watch || options.persistent) {\n // Start watching (assuming watch is also async)\n watch({ ...options, configuration });\n }\n};\n"],"mappings":"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","names":[]}
|
|
@@ -3,7 +3,7 @@ import { getConfiguration } from "@intlayer/config";
|
|
|
3
3
|
import fg from "fast-glob";
|
|
4
4
|
const { content } = getConfiguration();
|
|
5
5
|
const { dictionariesDir, mainDir } = content;
|
|
6
|
-
const
|
|
6
|
+
const getBuiltDictionariesPath = () => {
|
|
7
7
|
if (!existsSync(mainDir)) {
|
|
8
8
|
mkdirSync(mainDir, { recursive: true });
|
|
9
9
|
}
|
|
@@ -11,6 +11,6 @@ const getDictionariesPath = () => {
|
|
|
11
11
|
return dictionariesPath;
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
|
-
|
|
14
|
+
getBuiltDictionariesPath
|
|
15
15
|
};
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=getBuiltDictionariesPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getBuiltDictionariesPath.ts"],"sourcesContent":["import { existsSync, mkdirSync } from 'fs';\nimport { getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\nconst { content } = getConfiguration();\nconst { dictionariesDir, mainDir } = content;\n\n/**\n * This function generates a list of dictionaries in the main directory\n */\nexport const getBuiltDictionariesPath = () => {\n // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = fg.sync(`${dictionariesDir}/**/*.json`);\n\n return dictionariesPath;\n};\n"],"mappings":"AAAA,SAAS,YAAY,iBAAiB;AACtC,SAAS,wBAAwB;AACjC,OAAO,QAAQ;AAEf,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,iBAAiB,QAAQ,IAAI;AAK9B,MAAM,2BAA2B,MAAM;AAE5C,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,GAAG,KAAK,GAAG,eAAe,YAAY;AAEzE,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -15,6 +15,11 @@ import {
|
|
|
15
15
|
loadLocalDictionaries
|
|
16
16
|
} from "./loadDictionaries/index.mjs";
|
|
17
17
|
import { checkDictionaryChanges } from "./checkDictionaryChanges.mjs";
|
|
18
|
+
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
19
|
+
import { prepareContentDeclaration } from "./prepareContentDeclaration.mjs";
|
|
20
|
+
import {
|
|
21
|
+
writeContentDeclaration
|
|
22
|
+
} from "./writeContentDeclaration/index.mjs";
|
|
18
23
|
export {
|
|
19
24
|
buildAndWatchIntlayer,
|
|
20
25
|
buildDictionary,
|
|
@@ -24,10 +29,13 @@ export {
|
|
|
24
29
|
fetchDistantDictionaries,
|
|
25
30
|
handleAdditionalContentDeclarationFile,
|
|
26
31
|
handleContentDeclarationFileChange,
|
|
32
|
+
listDictionaries,
|
|
27
33
|
loadDictionaries,
|
|
28
34
|
loadDistantDictionaries,
|
|
29
35
|
loadLocalDictionaries,
|
|
36
|
+
prepareContentDeclaration,
|
|
30
37
|
prepareIntlayer,
|
|
31
|
-
watch
|
|
38
|
+
watch,
|
|
39
|
+
writeContentDeclaration
|
|
32
40
|
};
|
|
33
41
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n watch,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n buildAndWatchIntlayer,\n} from './chokidar/watcher';\nexport { prepareIntlayer } from './prepareIntlayer';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\nexport { checkDictionaryChanges } from './checkDictionaryChanges';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n watch,\n handleAdditionalContentDeclarationFile,\n handleContentDeclarationFileChange,\n buildAndWatchIntlayer,\n} from './chokidar/watcher';\nexport { prepareIntlayer } from './prepareIntlayer';\nexport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nexport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nexport { createModuleAugmentation } from './transpiler/dictionary_to_type/createModuleAugmentation';\nexport { fetchDistantDictionaries } from './fetchDistantDictionaries';\nexport {\n loadDistantDictionaries,\n loadDictionaries,\n loadLocalDictionaries,\n} from './loadDictionaries/index';\nexport { checkDictionaryChanges } from './checkDictionaryChanges';\nexport { listDictionaries } from './listDictionariesPath';\nexport { prepareContentDeclaration } from './prepareContentDeclaration';\nexport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from './writeContentDeclaration';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,gCAAgC;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;AAC1C;AAAA,EACE;AAAA,OAEK;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getConfiguration } from "@intlayer/config";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
const listDictionaries = (configuration = getConfiguration()) => {
|
|
4
|
+
const files = fg.sync(
|
|
5
|
+
configuration.content.watchedFilesPatternWithPath,
|
|
6
|
+
{
|
|
7
|
+
ignore: [
|
|
8
|
+
"**/node_modules/**",
|
|
9
|
+
"**/.git/**",
|
|
10
|
+
"**/.github/**",
|
|
11
|
+
"**/.next/**",
|
|
12
|
+
"**/.expo/**",
|
|
13
|
+
"**/.expo-shared/**",
|
|
14
|
+
"**/.vercel/**",
|
|
15
|
+
"**/.cache/**",
|
|
16
|
+
"**/dist/**",
|
|
17
|
+
"**/build/**",
|
|
18
|
+
"**/.intlayer/**"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
return files;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
listDictionaries
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=listDictionariesPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { type IntlayerConfig, getConfiguration } from '@intlayer/config';\nimport fg from 'fast-glob';\n\nexport const listDictionaries = (\n configuration: IntlayerConfig = getConfiguration()\n) => {\n const files: string[] = fg.sync(\n configuration.content.watchedFilesPatternWithPath,\n {\n ignore: [\n '**/node_modules/**',\n '**/.git/**',\n '**/.github/**',\n '**/.next/**',\n '**/.expo/**',\n '**/.expo-shared/**',\n '**/.vercel/**',\n '**/.cache/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n }\n );\n\n return files;\n};\n"],"mappings":"AAAA,SAA8B,wBAAwB;AACtD,OAAO,QAAQ;AAER,MAAM,mBAAmB,CAC9B,gBAAgC,iBAAiB,MAC9C;AACH,QAAM,QAAkB,GAAG;AAAA,IACzB,cAAc,QAAQ;AAAA,IACtB;AAAA,MACE,QAAQ;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deepTransformNode,
|
|
3
|
+
NodeType
|
|
4
|
+
} from "@intlayer/core";
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
const writeFilePlugin = {
|
|
8
|
+
id: "write-file-plugin",
|
|
9
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.File,
|
|
10
|
+
transform: (node) => {
|
|
11
|
+
const fileContent = node.content;
|
|
12
|
+
const filePath = node.fixedPath;
|
|
13
|
+
if (typeof fileContent !== "string") {
|
|
14
|
+
throw new Error("File content must be a string");
|
|
15
|
+
}
|
|
16
|
+
if (typeof filePath !== "string") {
|
|
17
|
+
throw new Error("File path must be a string");
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const abolsuteFilePath = join(process.cwd(), filePath);
|
|
21
|
+
const fileDirectory = join(process.cwd(), filePath);
|
|
22
|
+
if (!fileDirectory.startsWith(process.cwd())) {
|
|
23
|
+
throw new Error("File directory not found");
|
|
24
|
+
}
|
|
25
|
+
if (!existsSync(fileDirectory)) {
|
|
26
|
+
mkdirSync(fileDirectory, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
writeFileSync(abolsuteFilePath, fileContent);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Error writing file to ${filePath}: ${error}`);
|
|
31
|
+
}
|
|
32
|
+
const transformedFileContent = {
|
|
33
|
+
nodeType: NodeType.File,
|
|
34
|
+
[NodeType.File]: node.file
|
|
35
|
+
};
|
|
36
|
+
return transformedFileContent;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const mardownFilePlugin = {
|
|
40
|
+
id: "markdown-file-plugin",
|
|
41
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Markdown,
|
|
42
|
+
transform: (node, props, deepTransformNode2) => {
|
|
43
|
+
const simplifiedMarkdownNode = {
|
|
44
|
+
nodeType: NodeType.Markdown,
|
|
45
|
+
[NodeType.Markdown]: deepTransformNode2(node.markdown, props)
|
|
46
|
+
};
|
|
47
|
+
return simplifiedMarkdownNode;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const insertionFilePlugin = {
|
|
51
|
+
id: "insertion-file-plugin",
|
|
52
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Insertion,
|
|
53
|
+
transform: (node, props, deepTransformNode2) => {
|
|
54
|
+
const simplifiedInsertionNode = {
|
|
55
|
+
nodeType: NodeType.Insertion,
|
|
56
|
+
[NodeType.Insertion]: deepTransformNode2(node.insertion, props)
|
|
57
|
+
};
|
|
58
|
+
return simplifiedInsertionNode;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const prepareContentDeclaration = async (dictionary) => deepTransformNode(dictionary, {
|
|
62
|
+
dictionaryKey: dictionary.key,
|
|
63
|
+
keyPath: [],
|
|
64
|
+
plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin]
|
|
65
|
+
});
|
|
66
|
+
export {
|
|
67
|
+
prepareContentDeclaration
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=prepareContentDeclaration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/prepareContentDeclaration.ts"],"sourcesContent":["import {\n deepTransformNode,\n type Plugins,\n type Dictionary,\n NodeType,\n type FileContent,\n type FileContentConstructer,\n type MarkdownContent,\n type InsertionContent,\n type MarkdownContentConstructer,\n type InsertionContentConstructer,\n} from '@intlayer/core';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { join } from 'path';\n\n/**\n * Write file plugin\n */\n\nconst writeFilePlugin: Plugins = {\n id: 'write-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent) => {\n const fileContent = node.content;\n const filePath = node.fixedPath;\n\n if (typeof fileContent !== 'string') {\n throw new Error('File content must be a string');\n }\n\n if (typeof filePath !== 'string') {\n throw new Error('File path must be a string');\n }\n\n // Write the file to the file system\n try {\n const abolsuteFilePath = join(process.cwd(), filePath);\n\n // Create the file directory if it doesn't exist\n const fileDirectory = join(process.cwd(), filePath);\n if (!fileDirectory.startsWith(process.cwd())) {\n throw new Error('File directory not found');\n }\n\n if (!existsSync(fileDirectory)) {\n mkdirSync(fileDirectory, { recursive: true });\n }\n\n // Write the file\n writeFileSync(abolsuteFilePath, fileContent);\n } catch (error) {\n throw new Error(`Error writing file to ${filePath}: ${error}`);\n }\n\n const transformedFileContent: FileContentConstructer = {\n nodeType: NodeType.File,\n [NodeType.File]: node.file,\n };\n\n return transformedFileContent;\n },\n};\n\n/**\n * Markdown file plugin\n */\n\nconst mardownFilePlugin: Plugins = {\n id: 'markdown-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const simplifiedMarkdownNode: MarkdownContentConstructer = {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: deepTransformNode(node.markdown, props),\n };\n\n return simplifiedMarkdownNode;\n },\n};\n\n/**\n * Injection file plugin\n */\n\nconst insertionFilePlugin: Plugins = {\n id: 'insertion-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const simplifiedInsertionNode: InsertionContentConstructer = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: deepTransformNode(node.insertion, props),\n };\n\n return simplifiedInsertionNode;\n },\n};\n\nexport const prepareContentDeclaration = async (dictionary: Dictionary) =>\n deepTransformNode(dictionary, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [writeFilePlugin, mardownFilePlugin, insertionFilePlugin],\n });\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EAGA;AAAA,OAOK;AACP,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,YAAY;AAMrB,MAAM,kBAA2B;AAAA,EAC/B,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,SAAsB;AAChC,UAAM,cAAc,KAAK;AACzB,UAAM,WAAW,KAAK;AAEtB,QAAI,OAAO,gBAAgB,UAAU;AACnC,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,QAAI,OAAO,aAAa,UAAU;AAChC,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC9C;AAGA,QAAI;AACF,YAAM,mBAAmB,KAAK,QAAQ,IAAI,GAAG,QAAQ;AAGrD,YAAM,gBAAgB,KAAK,QAAQ,IAAI,GAAG,QAAQ;AAClD,UAAI,CAAC,cAAc,WAAW,QAAQ,IAAI,CAAC,GAAG;AAC5C,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAEA,UAAI,CAAC,WAAW,aAAa,GAAG;AAC9B,kBAAU,eAAe,EAAE,WAAW,KAAK,CAAC;AAAA,MAC9C;AAGA,oBAAc,kBAAkB,WAAW;AAAA,IAC7C,SAAS,OAAO;AACd,YAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,KAAK,EAAE;AAAA,IAC/D;AAEA,UAAM,yBAAiD;AAAA,MACrD,UAAU,SAAS;AAAA,MACnB,CAAC,SAAS,IAAI,GAAG,KAAK;AAAA,IACxB;AAEA,WAAO;AAAA,EACT;AACF;AAMA,MAAM,oBAA6B;AAAA,EACjC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAuB,OAAOA,uBAAsB;AAC9D,UAAM,yBAAqD;AAAA,MACzD,UAAU,SAAS;AAAA,MACnB,CAAC,SAAS,QAAQ,GAAGA,mBAAkB,KAAK,UAAU,KAAK;AAAA,IAC7D;AAEA,WAAO;AAAA,EACT;AACF;AAMA,MAAM,sBAA+B;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAOA,uBAAsB;AAC/D,UAAM,0BAAuD;AAAA,MAC3D,UAAU,SAAS;AAAA,MACnB,CAAC,SAAS,SAAS,GAAGA,mBAAkB,KAAK,WAAW,KAAK;AAAA,IAC/D;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,4BAA4B,OAAO,eAC9C,kBAAkB,YAAY;AAAA,EAC5B,eAAe,WAAW;AAAA,EAC1B,SAAS,CAAC;AAAA,EACV,SAAS,CAAC,iBAAiB,mBAAmB,mBAAmB;AACnE,CAAC;","names":["deepTransformNode"]}
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
appLogger,
|
|
3
3
|
getConfiguration
|
|
4
4
|
} from "@intlayer/config";
|
|
5
|
-
import fg from "fast-glob";
|
|
6
5
|
import { cleanOutputDir } from "./cleanOutputDir.mjs";
|
|
7
6
|
import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
|
|
8
7
|
import { buildDictionary } from "./transpiler/declaration_file_to_dictionary/index.mjs";
|
|
@@ -12,29 +11,13 @@ import {
|
|
|
12
11
|
createModuleAugmentation
|
|
13
12
|
} from "./transpiler/dictionary_to_type/index.mjs";
|
|
14
13
|
import { writeConfiguration } from "./writeConfiguration/index.mjs";
|
|
14
|
+
import { listDictionaries } from "./listDictionariesPath.mjs";
|
|
15
15
|
const prepareIntlayer = async (configuration = getConfiguration()) => {
|
|
16
16
|
cleanOutputDir();
|
|
17
17
|
appLogger("Output directory cleaned", {
|
|
18
18
|
isVerbose: true
|
|
19
19
|
});
|
|
20
|
-
const files =
|
|
21
|
-
configuration.content.watchedFilesPatternWithPath,
|
|
22
|
-
{
|
|
23
|
-
ignore: [
|
|
24
|
-
"**/node_modules/**",
|
|
25
|
-
"**/.git/**",
|
|
26
|
-
"**/.github/**",
|
|
27
|
-
"**/.next/**",
|
|
28
|
-
"**/.expo/**",
|
|
29
|
-
"**/.expo-shared/**",
|
|
30
|
-
"**/.vercel/**",
|
|
31
|
-
"**/.cache/**",
|
|
32
|
-
"**/dist/**",
|
|
33
|
-
"**/build/**",
|
|
34
|
-
"**/.intlayer/**"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
);
|
|
20
|
+
const files = listDictionaries(configuration);
|
|
38
21
|
const dictionaries = await loadDictionaries(files);
|
|
39
22
|
const dictionariesPaths = await buildDictionary(dictionaries);
|
|
40
23
|
createTypes(dictionariesPaths);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport
|
|
1
|
+
{"version":3,"sources":["../../src/prepareIntlayer.ts"],"sourcesContent":["import {\n type IntlayerConfig,\n appLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { cleanOutputDir } from './cleanOutputDir';\nimport { loadDictionaries } from './loadDictionaries/loadDictionaries';\nimport { buildDictionary } from './transpiler/declaration_file_to_dictionary/index';\nimport { createDictionaryEntryPoint } from './transpiler/dictionary_to_main/createDictionaryEntryPoint';\nimport {\n createTypes,\n createModuleAugmentation,\n} from './transpiler/dictionary_to_type/index';\nimport { writeConfiguration } from './writeConfiguration';\nimport { listDictionaries } from './listDictionariesPath';\n\nexport const prepareIntlayer = async (\n configuration: IntlayerConfig = getConfiguration()\n) => {\n cleanOutputDir();\n\n appLogger('Output directory cleaned', {\n isVerbose: true,\n });\n\n const files: string[] = listDictionaries(configuration);\n\n const dictionaries = await loadDictionaries(files);\n\n // Build locale dictionaries\n const dictionariesPaths = await buildDictionary(dictionaries);\n\n createTypes(dictionariesPaths);\n\n createDictionaryEntryPoint();\n\n appLogger('Dictionaries built');\n\n createModuleAugmentation();\n\n appLogger('Module augmentation built', {\n isVerbose: true,\n });\n\n writeConfiguration(configuration);\n\n appLogger('Configuration written', {\n isVerbose: true,\n });\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,wBAAwB;AAE1B,MAAM,kBAAkB,OAC7B,gBAAgC,iBAAiB,MAC9C;AACH,iBAAe;AAEf,YAAU,4BAA4B;AAAA,IACpC,WAAW;AAAA,EACb,CAAC;AAED,QAAM,QAAkB,iBAAiB,aAAa;AAEtD,QAAM,eAAe,MAAM,iBAAiB,KAAK;AAGjD,QAAM,oBAAoB,MAAM,gBAAgB,YAAY;AAE5D,cAAY,iBAAiB;AAE7B,6BAA2B;AAE3B,YAAU,oBAAoB;AAE9B,2BAAyB;AAEzB,YAAU,6BAA6B;AAAA,IACrC,WAAW;AAAA,EACb,CAAC;AAED,qBAAmB,aAAa;AAEhC,YAAU,yBAAyB;AAAA,IACjC,WAAW;AAAA,EACb,CAAC;AACH;","names":[]}
|
package/dist/esm/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.mjs
CHANGED
|
@@ -5,10 +5,8 @@ const { dictionariesDir } = getConfiguration().content;
|
|
|
5
5
|
const writeDictionary = async (dictionaries) => {
|
|
6
6
|
const resultDictionariesPaths = [];
|
|
7
7
|
for await (const dictionaryContent of dictionaries) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
...dictionaryContent
|
|
11
|
-
});
|
|
8
|
+
const isDevelopement = process.env.NODE_ENV === "development";
|
|
9
|
+
const contentString = isDevelopement ? JSON.stringify(dictionaryContent, null, 2) : JSON.stringify(dictionaryContent);
|
|
12
10
|
const key = dictionaryContent.key;
|
|
13
11
|
const outputFileName = `${key}.json`;
|
|
14
12
|
const resultFilePath = resolve(dictionariesDir, outputFileName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const contentString = JSON.stringify(
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/intlayer_dictionary/writeDictionary.ts"],"sourcesContent":["import { writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n\nconst { dictionariesDir } = getConfiguration().content;\n\nexport const writeDictionary = async (dictionaries: Dictionary[]) => {\n const resultDictionariesPaths: string[] = [];\n\n for await (const dictionaryContent of dictionaries) {\n const isDevelopement = process.env.NODE_ENV === 'development';\n const contentString = isDevelopement\n ? JSON.stringify(dictionaryContent, null, 2)\n : JSON.stringify(dictionaryContent);\n\n const key = dictionaryContent.key;\n const outputFileName = `${key}.json`;\n const resultFilePath = resolve(dictionariesDir, outputFileName);\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 return resultDictionariesPaths;\n};\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,wBAAwB;AAGjC,MAAM,EAAE,gBAAgB,IAAI,iBAAiB,EAAE;AAExC,MAAM,kBAAkB,OAAO,iBAA+B;AACnE,QAAM,0BAAoC,CAAC;AAE3C,mBAAiB,qBAAqB,cAAc;AAClD,UAAM,iBAAiB,QAAQ,IAAI,aAAa;AAChD,UAAM,gBAAgB,iBAClB,KAAK,UAAU,mBAAmB,MAAM,CAAC,IACzC,KAAK,UAAU,iBAAiB;AAEpC,UAAM,MAAM,kBAAkB;AAC9B,UAAM,iBAAiB,GAAG,GAAG;AAC7B,UAAM,iBAAiB,QAAQ,iBAAiB,cAAc;AAG9D,UAAM,UAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,cAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,IACxD,CAAC;AAED,4BAAwB,KAAK,cAAc;AAAA,EAC7C;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { basename, extname, relative, resolve } from "path";
|
|
3
3
|
import { getConfiguration } from "@intlayer/config";
|
|
4
|
-
import {
|
|
4
|
+
import { getBuiltDictionariesPath } from "../../getBuiltDictionariesPath.mjs";
|
|
5
5
|
import { getFileHash } from "../../utils.mjs";
|
|
6
6
|
const { content } = getConfiguration();
|
|
7
7
|
const { mainDir } = content;
|
|
@@ -40,7 +40,7 @@ const createDictionaryEntryPoint = () => {
|
|
|
40
40
|
if (!existsSync(mainDir)) {
|
|
41
41
|
mkdirSync(mainDir, { recursive: true });
|
|
42
42
|
}
|
|
43
|
-
const dictionariesPath =
|
|
43
|
+
const dictionariesPath = getBuiltDictionariesPath();
|
|
44
44
|
const cjsContent = generateDictionaryListContent(dictionariesPath, "cjs");
|
|
45
45
|
writeFileSync(resolve(mainDir, "dictionaries.cjs"), cjsContent);
|
|
46
46
|
const esmContent = generateDictionaryListContent(dictionariesPath, "esm");
|
|
@@ -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 { getConfiguration } from '@intlayer/config';\nimport {
|
|
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 { getConfiguration } from '@intlayer/config';\nimport { getBuiltDictionariesPath } from '../../getBuiltDictionariesPath';\nimport { getFileHash } from '../../utils';\n\nconst { content } = getConfiguration();\nconst { mainDir } = content;\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): string => {\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 // Create main directory if it doesn't exist\n if (!existsSync(mainDir)) {\n mkdirSync(mainDir, { recursive: true });\n }\n\n const dictionariesPath: string[] = getBuiltDictionariesPath();\n\n // Create the dictionary list file\n const cjsContent = generateDictionaryListContent(dictionariesPath, 'cjs');\n writeFileSync(resolve(mainDir, 'dictionaries.cjs'), cjsContent);\n\n const esmContent = generateDictionaryListContent(dictionariesPath, 'esm');\n writeFileSync(resolve(mainDir, 'dictionaries.mjs'), esmContent);\n};\n"],"mappings":"AAAA,SAAS,YAAY,WAAW,qBAAqB;AACrD,SAAS,UAAU,SAAS,UAAU,eAAe;AACrD,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAE5B,MAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,MAAM,EAAE,QAAQ,IAAI;AAKpB,MAAM,gCAAgC,CACpC,cACA,SAAwB,UACb;AACX,MAAIA,WAAU;AAEd,QAAM,kBAAkB,aAAa,IAAI,CAAC,oBAAoB;AAAA,IAC5D,cAAc,SAAS,SAAS,cAAc;AAAA,IAC9C,IAAI,SAAS,gBAAgB,QAAQ,cAAc,CAAC;AAAA;AAAA,IACpD,MAAM,IAAI,YAAY,cAAc,CAAC;AAAA;AAAA,EACvC,EAAE;AAGF,kBAAgB,QAAQ,CAAC,eAAe;AACtC,QAAI,WAAW;AACb,MAAAA,YAAW,UAAU,WAAW,IAAI,UAAU,WAAW,YAAY;AAAA;AACvE,QAAI,WAAW;AACb,MAAAA,YAAW,SAAS,WAAW,IAAI,eAAe,WAAW,YAAY;AAAA;AAAA,EAC7E,CAAC;AAED,EAAAA,YAAW;AAGX,QAAM,yBAAiC,gBACpC,IAAI,CAAC,eAAe,MAAM,WAAW,EAAE,MAAM,WAAW,IAAI,EAAE,EAC9D,KAAK,KAAK;AAEb,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAqB,sBAAsB;AAAA;AAAA;AACxD,MAAI,WAAW;AACb,IAAAA,YAAW;AAAA,EAAuB,sBAAsB;AAAA;AAAA;AAE1D,SAAOA;AACT;AAKO,MAAM,6BAA6B,MAAM;AAE9C,MAAI,CAAC,WAAW,OAAO,GAAG;AACxB,cAAU,SAAS,EAAE,WAAW,KAAK,CAAC;AAAA,EACxC;AAEA,QAAM,mBAA6B,yBAAyB;AAG5D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAE9D,QAAM,aAAa,8BAA8B,kBAAkB,KAAK;AACxE,gBAAc,QAAQ,SAAS,kBAAkB,GAAG,UAAU;AAChE;","names":["content"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=dictionaryStatus.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/writeContentDeclaration/index.ts"],"sourcesContent":["export * from './writeContentDeclaration';\nexport * from './dictionaryStatus';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|