@intlayer/chokidar 7.5.8 → 7.5.9
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/assets/initConfig/templates/cjs.txt +5 -12
- package/dist/assets/initConfig/templates/mjs.txt +5 -12
- package/dist/assets/initConfig/templates/ts.txt +5 -11
- package/dist/cjs/init/index.cjs +18 -71
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/utils/fileSystem.cjs +30 -0
- package/dist/cjs/init/utils/fileSystem.cjs.map +1 -0
- package/dist/cjs/init/utils/index.cjs +9 -0
- package/dist/cjs/init/utils/jsonParser.cjs +42 -0
- package/dist/cjs/init/utils/jsonParser.cjs.map +1 -0
- package/dist/cjs/init/utils/tsConfig.cjs +18 -0
- package/dist/cjs/init/utils/tsConfig.cjs.map +1 -0
- package/dist/cjs/initConfig/index.cjs +8 -12
- package/dist/cjs/initConfig/index.cjs.map +1 -1
- package/dist/esm/init/index.mjs +18 -71
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/utils/fileSystem.mjs +27 -0
- package/dist/esm/init/utils/fileSystem.mjs.map +1 -0
- package/dist/esm/init/utils/index.mjs +5 -0
- package/dist/esm/init/utils/jsonParser.mjs +41 -0
- package/dist/esm/init/utils/jsonParser.mjs.map +1 -0
- package/dist/esm/init/utils/tsConfig.mjs +17 -0
- package/dist/esm/init/utils/tsConfig.mjs.map +1 -0
- package/dist/esm/initConfig/index.mjs +11 -14
- package/dist/esm/initConfig/index.mjs.map +1 -1
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -1
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
- package/dist/types/formatDictionary.d.ts +15 -15
- package/dist/types/init/index.d.ts +1 -1
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/init/utils/fileSystem.d.ts +16 -0
- package/dist/types/init/utils/fileSystem.d.ts.map +1 -0
- package/dist/types/init/utils/index.d.ts +4 -0
- package/dist/types/init/utils/jsonParser.d.ts +8 -0
- package/dist/types/init/utils/jsonParser.d.ts.map +1 -0
- package/dist/types/init/utils/tsConfig.d.ts +8 -0
- package/dist/types/init/utils/tsConfig.d.ts.map +1 -0
- package/dist/types/initConfig/index.d.ts +2 -2
- package/dist/types/initConfig/index.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/utils/chunkJSON.d.ts.map +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
const { Locales } = require('intlayer');
|
|
2
2
|
|
|
3
3
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
defaultLocale: Locales.ENGLISH,
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
return config;
|
|
4
|
+
const config = {
|
|
5
|
+
internationalization: {
|
|
6
|
+
locales: [Locales.ENGLISH],
|
|
7
|
+
defaultLocale: Locales.ENGLISH,
|
|
8
|
+
},
|
|
14
9
|
};
|
|
15
10
|
|
|
16
|
-
const config = getIntlayerConfig();
|
|
17
|
-
|
|
18
11
|
module.exports = config;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { Locales } from 'intlayer';
|
|
2
2
|
|
|
3
3
|
/** @type {import('intlayer').IntlayerConfig} */
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
defaultLocale: Locales.ENGLISH,
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
return config;
|
|
4
|
+
const config = {
|
|
5
|
+
internationalization: {
|
|
6
|
+
locales: [Locales.ENGLISH],
|
|
7
|
+
defaultLocale: Locales.ENGLISH,
|
|
8
|
+
},
|
|
14
9
|
};
|
|
15
10
|
|
|
16
|
-
const config = getIntlayerConfig();
|
|
17
|
-
|
|
18
11
|
export default config;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { type IntlayerConfig, Locales } from 'intlayer';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
return config;
|
|
3
|
+
const config: IntlayerConfig = {
|
|
4
|
+
internationalization: {
|
|
5
|
+
locales: [Locales.ENGLISH],
|
|
6
|
+
defaultLocale: Locales.ENGLISH,
|
|
7
|
+
},
|
|
12
8
|
};
|
|
13
9
|
|
|
14
|
-
const config = getIntlayerConfig();
|
|
15
|
-
|
|
16
10
|
export default config;
|
package/dist/cjs/init/index.cjs
CHANGED
|
@@ -1,87 +1,34 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_initConfig_index = require('../initConfig/index.cjs');
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const require_init_utils_fileSystem = require('./utils/fileSystem.cjs');
|
|
4
|
+
const require_init_utils_jsonParser = require('./utils/jsonParser.cjs');
|
|
5
|
+
const require_init_utils_tsConfig = require('./utils/tsConfig.cjs');
|
|
5
6
|
let _intlayer_config = require("@intlayer/config");
|
|
6
7
|
|
|
7
8
|
//#region src/init/index.ts
|
|
8
9
|
/**
|
|
9
|
-
* UTILITIES
|
|
10
|
-
*/
|
|
11
|
-
const rootDir = process.cwd();
|
|
12
|
-
const exists = async (filePath) => {
|
|
13
|
-
try {
|
|
14
|
-
await (0, node_fs_promises.access)((0, node_path.join)(rootDir, filePath));
|
|
15
|
-
return true;
|
|
16
|
-
} catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const readFileFromRoot = async (filePath) => await (0, node_fs_promises.readFile)((0, node_path.join)(rootDir, filePath), "utf8");
|
|
21
|
-
const writeFileToRoot = async (filePath, content) => await (0, node_fs_promises.writeFile)((0, node_path.join)(rootDir, filePath), content, "utf8");
|
|
22
|
-
const parseJSONWithComments = (jsonString) => {
|
|
23
|
-
try {
|
|
24
|
-
return JSON.parse(jsonString);
|
|
25
|
-
} catch {}
|
|
26
|
-
const cleanedLines = jsonString.split("\n").map((line) => {
|
|
27
|
-
let inString = false;
|
|
28
|
-
let result = "";
|
|
29
|
-
for (let i = 0; i < line.length; i++) {
|
|
30
|
-
const char = line[i];
|
|
31
|
-
const nextChar = line[i + 1];
|
|
32
|
-
if (char === "\"" && (i === 0 || line[i - 1] !== "\\")) {
|
|
33
|
-
inString = !inString;
|
|
34
|
-
result += char;
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (inString) {
|
|
38
|
-
result += char;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (char === "/" && nextChar === "/") break;
|
|
42
|
-
if (char === "/" && nextChar === "*") {
|
|
43
|
-
const endIndex = line.indexOf("*/", i + 2);
|
|
44
|
-
if (endIndex !== -1) {
|
|
45
|
-
i = endIndex + 1;
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
result += char;
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
});
|
|
53
|
-
return JSON.parse(cleanedLines.join("\n"));
|
|
54
|
-
};
|
|
55
|
-
const findTsConfigFiles = async () => {
|
|
56
|
-
try {
|
|
57
|
-
return (await (0, node_fs_promises.readdir)(rootDir)).filter((file) => file === "tsconfig.json" || /^tsconfig\..+\.json$/.test(file));
|
|
58
|
-
} catch {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
10
|
* MAIN LOGIC
|
|
64
11
|
*/
|
|
65
|
-
const initIntlayer = async () => {
|
|
12
|
+
const initIntlayer = async (rootDir) => {
|
|
66
13
|
(0, _intlayer_config.logger)((0, _intlayer_config.colorize)("Checking Intlayer configuration...", _intlayer_config.ANSIColors.CYAN));
|
|
67
|
-
if (!await exists("package.json")) {
|
|
14
|
+
if (!await require_init_utils_fileSystem.exists(rootDir, "package.json")) {
|
|
68
15
|
(0, _intlayer_config.logger)(`${_intlayer_config.x} No ${(0, _intlayer_config.colorizePath)("package.json")} found. Please run this script from the project root.`, { level: "error" });
|
|
69
16
|
process.exit(1);
|
|
70
17
|
}
|
|
71
18
|
const gitignorePath = ".gitignore";
|
|
72
|
-
if (await exists(gitignorePath)) {
|
|
73
|
-
const gitignoreContent = await readFileFromRoot(gitignorePath);
|
|
19
|
+
if (await require_init_utils_fileSystem.exists(rootDir, gitignorePath)) {
|
|
20
|
+
const gitignoreContent = await require_init_utils_fileSystem.readFileFromRoot(rootDir, gitignorePath);
|
|
74
21
|
if (!gitignoreContent.includes("intlayer")) {
|
|
75
|
-
await writeFileToRoot(gitignorePath, `${gitignoreContent}\n
|
|
22
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, gitignorePath, `${gitignoreContent}\n# Intlayer\n.intlayer\n`);
|
|
76
23
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} Added ${(0, _intlayer_config.colorizePath)(".intlayer")} to ${(0, _intlayer_config.colorizePath)(gitignorePath)}`);
|
|
77
24
|
} else (0, _intlayer_config.logger)(`${_intlayer_config.v} ${(0, _intlayer_config.colorizePath)(gitignorePath)} already includes .intlayer`);
|
|
78
25
|
}
|
|
79
|
-
const tsConfigFiles = await findTsConfigFiles();
|
|
26
|
+
const tsConfigFiles = await require_init_utils_tsConfig.findTsConfigFiles(rootDir);
|
|
80
27
|
let hasTsConfig = false;
|
|
81
|
-
for (const fileName of tsConfigFiles) if (await exists(fileName)) {
|
|
28
|
+
for (const fileName of tsConfigFiles) if (await require_init_utils_fileSystem.exists(rootDir, fileName)) {
|
|
82
29
|
hasTsConfig = true;
|
|
83
30
|
try {
|
|
84
|
-
const config = parseJSONWithComments(await readFileFromRoot(fileName));
|
|
31
|
+
const config = require_init_utils_jsonParser.parseJSONWithComments(await require_init_utils_fileSystem.readFileFromRoot(rootDir, fileName));
|
|
85
32
|
const typeDefinition = ".intlayer/**/*.ts";
|
|
86
33
|
let updated = false;
|
|
87
34
|
if (!config.include) {} else if (Array.isArray(config.include) && !config.include.some((patten) => patten.includes(".intlayer"))) {
|
|
@@ -89,7 +36,7 @@ const initIntlayer = async () => {
|
|
|
89
36
|
updated = true;
|
|
90
37
|
} else if (config.include.includes(typeDefinition)) (0, _intlayer_config.logger)(`${_intlayer_config.v} ${(0, _intlayer_config.colorizePath)(fileName)} already includes intlayer types`);
|
|
91
38
|
if (updated) {
|
|
92
|
-
await writeFileToRoot(fileName, JSON.stringify(config, null, 2));
|
|
39
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, fileName, JSON.stringify(config, null, 2));
|
|
93
40
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} Updated ${(0, _intlayer_config.colorizePath)(fileName)} to include intlayer types`);
|
|
94
41
|
}
|
|
95
42
|
} catch {
|
|
@@ -101,11 +48,11 @@ const initIntlayer = async () => {
|
|
|
101
48
|
"vite.config.ts",
|
|
102
49
|
"vite.config.js",
|
|
103
50
|
"vite.config.mjs"
|
|
104
|
-
]) if (await exists(file)) {
|
|
105
|
-
let content = await readFileFromRoot(file);
|
|
51
|
+
]) if (await require_init_utils_fileSystem.exists(rootDir, file)) {
|
|
52
|
+
let content = await require_init_utils_fileSystem.readFileFromRoot(rootDir, file);
|
|
106
53
|
if (!content.includes("vite-intlayer")) {
|
|
107
54
|
content = `import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\n${content}`;
|
|
108
|
-
await writeFileToRoot(file, content);
|
|
55
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, file, content);
|
|
109
56
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} Injected import into ${(0, _intlayer_config.colorizePath)(file)}`);
|
|
110
57
|
}
|
|
111
58
|
break;
|
|
@@ -114,11 +61,11 @@ const initIntlayer = async () => {
|
|
|
114
61
|
"next.config.js",
|
|
115
62
|
"next.config.mjs",
|
|
116
63
|
"next.config.ts"
|
|
117
|
-
]) if (await exists(file)) {
|
|
118
|
-
let content = await readFileFromRoot(file);
|
|
64
|
+
]) if (await require_init_utils_fileSystem.exists(rootDir, file)) {
|
|
65
|
+
let content = await require_init_utils_fileSystem.readFileFromRoot(rootDir, file);
|
|
119
66
|
if (!content.includes("next-intlayer")) {
|
|
120
67
|
content = `import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\n${content}`;
|
|
121
|
-
await writeFileToRoot(file, content);
|
|
68
|
+
await require_init_utils_fileSystem.writeFileToRoot(rootDir, file, content);
|
|
122
69
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} Injected import into ${(0, _intlayer_config.colorizePath)(file)}`);
|
|
123
70
|
}
|
|
124
71
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["ANSIColors","x","v","initConfig"],"sources":["../../../src/init/index.ts"],"sourcesContent":["import { access, readdir, readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\n\n/**\n * UTILITIES\n */\nconst rootDir = process.cwd();\n\n// Helper to check if a file exists\nconst exists = async (filePath: string) => {\n try {\n await access(join(rootDir, filePath));\n return true;\n } catch {\n return false;\n }\n};\n\n// Helper to read a file\nconst readFileFromRoot = async (filePath: string) =>\n await readFile(join(rootDir, filePath), 'utf8');\n\n// Helper to write a file\nconst writeFileToRoot = async (filePath: string, content: string) =>\n await writeFile(join(rootDir, filePath), content, 'utf8');\n\n// Helper to parse JSON that may contain comments (tsconfig allows comments)\nconst parseJSONWithComments = (jsonString: string) => {\n // First, try parsing as-is (most tsconfig files don't have comments)\n try {\n return JSON.parse(jsonString);\n } catch {\n // If that fails, try stripping comments\n // Note: This simple approach removes comments line by line to avoid\n // matching glob patterns like /* and */ that appear in paths\n }\n\n // Process line by line to safely remove comments\n const lines = jsonString.split('\\n');\n const cleanedLines = lines.map((line) => {\n // Track if we're inside a string\n let inString = false;\n let result = '';\n\n for (let i = 0; i < line.length; i++) {\n const char = line[i];\n const nextChar = line[i + 1];\n\n // Handle string boundaries (accounting for escaped quotes)\n if (char === '\"' && (i === 0 || line[i - 1] !== '\\\\')) {\n inString = !inString;\n result += char;\n continue;\n }\n\n // If we're inside a string, keep the character\n if (inString) {\n result += char;\n continue;\n }\n\n // Check for single-line comment outside of strings\n if (char === '/' && nextChar === '/') {\n // Rest of line is a comment, stop here\n break;\n }\n\n // Check for multi-line comment start (/* ... */)\n // For simplicity, we only handle single-line /* */ comments here\n if (char === '/' && nextChar === '*') {\n const endIndex = line.indexOf('*/', i + 2);\n if (endIndex !== -1) {\n // Skip the comment\n i = endIndex + 1;\n continue;\n }\n }\n\n result += char;\n }\n\n return result;\n });\n\n return JSON.parse(cleanedLines.join('\\n'));\n};\n\n// Helper to find all tsconfig files (tsconfig.json, tsconfig.*.json)\nconst findTsConfigFiles = async (): Promise<string[]> => {\n try {\n const files = await readdir(rootDir);\n\n return files.filter(\n (file) => file === 'tsconfig.json' || /^tsconfig\\..+\\.json$/.test(file)\n );\n } catch {\n return [];\n }\n};\n\n/**\n * MAIN LOGIC\n */\n\nexport const initIntlayer = async () => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // Check for package.json to ensure we are in a project root\n if (!(await exists('package.json'))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n // Check .gitignore\n const gitignorePath = '.gitignore';\n if (await exists(gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // Check TSConfigs\n // Find all tsconfig files (tsconfig.json, tsconfig.*.json)\n const tsConfigFiles = await findTsConfigFiles();\n\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n // Check if include array exists - if not, skip (likely a solution-style tsconfig with references)\n let updated = false;\n if (!config.include) {\n // Skip tsconfig files without include array (e.g. solution-style configs with references)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((patten: string) =>\n patten.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n // We write back using standard JSON stringify (comments will be lost, sadly)\n // If preserving comments is critical, a more complex parser/printer is needed.\n await writeFileToRoot(fileName, JSON.stringify(config, null, 2));\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // Initialize Intlayer configuration file\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // Check Vite Config\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n\n for (const file of viteConfigs) {\n if (await exists(file)) {\n let content = await readFileFromRoot(file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n // Prepend the import\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one vite config\n }\n }\n\n // Check Next Config\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n\n for (const file of nextConfigs) {\n if (await exists(file)) {\n let content = await readFileFromRoot(file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\";\n\n // Prepend the import\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one next config\n }\n }\n\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAM,UAAU,QAAQ,KAAK;AAG7B,MAAM,SAAS,OAAO,aAAqB;AACzC,KAAI;AACF,yDAAkB,SAAS,SAAS,CAAC;AACrC,SAAO;SACD;AACN,SAAO;;;AAKX,MAAM,mBAAmB,OAAO,aAC9B,yDA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AM,QAAQ;AACpC,gCAAO,GAAGD,mBAAE,2DAAqC,KAAK,GAAG;;AAE3D;;AAOJ,MAAK,MAAM,QAFS;EAAC;EAAkB;EAAmB;EAAiB,CAGzE,KAAI,MAAM,OAAO,KAAK,EAAE;EACtB,IAAI,UAAU,MAAM,iBAAiB,KAAK;AAE1C,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAKtC,aAAU,iGAAkB;AAC5B,SAAM,gBAAgB,MAAM,QAAQ;AACpC,gCAAO,GAAGA,mBAAE,2DAAqC,KAAK,GAAG;;AAE3D;;AAIJ,8BAAO,GAAGA,mBAAE,kCAAY,iCAAiCF,4BAAW,MAAM,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ANSIColors","exists","x","readFileFromRoot","writeFileToRoot","v","findTsConfigFiles","parseJSONWithComments","initConfig"],"sources":["../../../src/init/index.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\nimport {\n exists,\n findTsConfigFiles,\n parseJSONWithComments,\n readFileFromRoot,\n writeFileToRoot,\n} from './utils';\n\n/**\n * MAIN LOGIC\n */\n\nexport const initIntlayer = async (rootDir: string) => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // Check for package.json to ensure we are in a project root\n if (!(await exists(rootDir, 'package.json'))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n // Check .gitignore\n const gitignorePath = '.gitignore';\n if (await exists(rootDir, gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(rootDir, gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // Check TSConfigs\n // Find all tsconfig files (tsconfig.json, tsconfig.*.json)\n const tsConfigFiles = await findTsConfigFiles(rootDir);\n\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(rootDir, fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(rootDir, fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n // Check if include array exists - if not, skip (likely a solution-style tsconfig with references)\n let updated = false;\n if (!config.include) {\n // Skip tsconfig files without include array (e.g. solution-style configs with references)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((patten: string) =>\n patten.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n // We write back using standard JSON stringify (comments will be lost, sadly)\n // If preserving comments is critical, a more complex parser/printer is needed.\n await writeFileToRoot(\n rootDir,\n fileName,\n JSON.stringify(config, null, 2)\n );\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // Initialize Intlayer configuration file\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // Check Vite Config\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n\n for (const file of viteConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n // Prepend the import\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one vite config\n }\n }\n\n // Check Next Config\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n\n for (const file of nextConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\";\n\n // Prepend the import\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one next config\n }\n }\n\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n};\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,YAAoB;AACrD,6DAAgB,sCAAsCA,4BAAW,KAAK,CAAC;AAGvE,KAAI,CAAE,MAAMC,qCAAO,SAAS,eAAe,EAAG;AAC5C,+BACE,GAAGC,mBAAE,yCAAmB,eAAe,CAAC,wDACxC,EAAE,OAAO,SAAS,CACnB;AACD,UAAQ,KAAK,EAAE;;CAIjB,MAAM,gBAAgB;AACtB,KAAI,MAAMD,qCAAO,SAAS,cAAc,EAAE;EACxC,MAAM,mBAAmB,MAAME,+CAAiB,SAAS,cAAc;AAEvE,MAAI,CAAC,iBAAiB,SAAS,WAAW,EAAE;AAE1C,SAAMC,8CAAgB,SAAS,eADZ,GAAG,iBAAiB,2BACkB;AACzD,gCACE,GAAGC,mBAAE,4CAAsB,YAAY,CAAC,yCAAmB,cAAc,GAC1E;QAED,8BAAO,GAAGA,mBAAE,sCAAgB,cAAc,CAAC,6BAA6B;;CAM5E,MAAM,gBAAgB,MAAMC,8CAAkB,QAAQ;CAEtD,IAAI,cAAc;AAElB,MAAK,MAAM,YAAY,cACrB,KAAI,MAAML,qCAAO,SAAS,SAAS,EAAE;AACnC,gBAAc;AACd,MAAI;GAEF,MAAM,SAASM,oDADK,M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qC,KAAK,GAAG;;AAE3D;;AAIJ,8BAAO,GAAGA,mBAAE,kCAAY,iCAAiCL,4BAAW,MAAM,GAAG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
|
|
5
|
+
//#region src/init/utils/fileSystem.ts
|
|
6
|
+
/**
|
|
7
|
+
* Helper to check if a file exists
|
|
8
|
+
*/
|
|
9
|
+
const exists = async (rootDir, filePath) => {
|
|
10
|
+
try {
|
|
11
|
+
await (0, node_fs_promises.access)((0, node_path.join)(rootDir, filePath));
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Helper to read a file
|
|
19
|
+
*/
|
|
20
|
+
const readFileFromRoot = async (rootDir, filePath) => await (0, node_fs_promises.readFile)((0, node_path.join)(rootDir, filePath), "utf8");
|
|
21
|
+
/**
|
|
22
|
+
* Helper to write a file
|
|
23
|
+
*/
|
|
24
|
+
const writeFileToRoot = async (rootDir, filePath, content) => await (0, node_fs_promises.writeFile)((0, node_path.join)(rootDir, filePath), content, "utf8");
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.exists = exists;
|
|
28
|
+
exports.readFileFromRoot = readFileFromRoot;
|
|
29
|
+
exports.writeFileToRoot = writeFileToRoot;
|
|
30
|
+
//# sourceMappingURL=fileSystem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystem.cjs","names":[],"sources":["../../../../src/init/utils/fileSystem.ts"],"sourcesContent":["import { access, readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\n/**\n * Helper to check if a file exists\n */\nexport const exists = async (rootDir: string, filePath: string) => {\n try {\n await access(join(rootDir, filePath));\n return true;\n } catch {\n return false;\n }\n};\n\n/**\n * Helper to read a file\n */\nexport const readFileFromRoot = async (rootDir: string, filePath: string) =>\n await readFile(join(rootDir, filePath), 'utf8');\n\n/**\n * Helper to write a file\n */\nexport const writeFileToRoot = async (\n rootDir: string,\n filePath: string,\n content: string\n) => await writeFile(join(rootDir, filePath), content, 'utf8');\n"],"mappings":";;;;;;;;AAMA,MAAa,SAAS,OAAO,SAAiB,aAAqB;AACjE,KAAI;AACF,yDAAkB,SAAS,SAAS,CAAC;AACrC,SAAO;SACD;AACN,SAAO;;;;;;AAOX,MAAa,mBAAmB,OAAO,SAAiB,aACtD,yDAAoB,SAAS,SAAS,EAAE,OAAO;;;;AAKjD,MAAa,kBAAkB,OAC7B,SACA,UACA,YACG,0DAAqB,SAAS,SAAS,EAAE,SAAS,OAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const require_init_utils_fileSystem = require('./fileSystem.cjs');
|
|
2
|
+
const require_init_utils_jsonParser = require('./jsonParser.cjs');
|
|
3
|
+
const require_init_utils_tsConfig = require('./tsConfig.cjs');
|
|
4
|
+
|
|
5
|
+
exports.exists = require_init_utils_fileSystem.exists;
|
|
6
|
+
exports.findTsConfigFiles = require_init_utils_tsConfig.findTsConfigFiles;
|
|
7
|
+
exports.parseJSONWithComments = require_init_utils_jsonParser.parseJSONWithComments;
|
|
8
|
+
exports.readFileFromRoot = require_init_utils_fileSystem.readFileFromRoot;
|
|
9
|
+
exports.writeFileToRoot = require_init_utils_fileSystem.writeFileToRoot;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/init/utils/jsonParser.ts
|
|
3
|
+
/**
|
|
4
|
+
* Helper to parse JSON that may contain comments (tsconfig allows comments)
|
|
5
|
+
*/
|
|
6
|
+
const parseJSONWithComments = (jsonString) => {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(jsonString);
|
|
9
|
+
} catch {}
|
|
10
|
+
const cleanedLines = jsonString.split("\n").map((line) => {
|
|
11
|
+
let inString = false;
|
|
12
|
+
let result = "";
|
|
13
|
+
for (let i = 0; i < line.length; i++) {
|
|
14
|
+
const char = line[i];
|
|
15
|
+
const nextChar = line[i + 1];
|
|
16
|
+
if (char === "\"" && (i === 0 || line[i - 1] !== "\\")) {
|
|
17
|
+
inString = !inString;
|
|
18
|
+
result += char;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (inString) {
|
|
22
|
+
result += char;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (char === "/" && nextChar === "/") break;
|
|
26
|
+
if (char === "/" && nextChar === "*") {
|
|
27
|
+
const endIndex = line.indexOf("*/", i + 2);
|
|
28
|
+
if (endIndex !== -1) {
|
|
29
|
+
i = endIndex + 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
result += char;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
});
|
|
37
|
+
return JSON.parse(cleanedLines.join("\n"));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.parseJSONWithComments = parseJSONWithComments;
|
|
42
|
+
//# sourceMappingURL=jsonParser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonParser.cjs","names":[],"sources":["../../../../src/init/utils/jsonParser.ts"],"sourcesContent":["/**\n * Helper to parse JSON that may contain comments (tsconfig allows comments)\n */\nexport const parseJSONWithComments = (jsonString: string) => {\n // First, try parsing as-is (most tsconfig files don't have comments)\n try {\n return JSON.parse(jsonString);\n } catch {\n // If that fails, try stripping comments\n // Note: This simple approach removes comments line by line to avoid\n // matching glob patterns like /* and */ that appear in paths\n }\n\n // Process line by line to safely remove comments\n const lines = jsonString.split('\\n');\n const cleanedLines = lines.map((line) => {\n // Track if we're inside a string\n let inString = false;\n let result = '';\n\n for (let i = 0; i < line.length; i++) {\n const char = line[i];\n const nextChar = line[i + 1];\n\n // Handle string boundaries (accounting for escaped quotes)\n if (char === '\"' && (i === 0 || line[i - 1] !== '\\\\')) {\n inString = !inString;\n result += char;\n continue;\n }\n\n // If we're inside a string, keep the character\n if (inString) {\n result += char;\n continue;\n }\n\n // Check for single-line comment outside of strings\n if (char === '/' && nextChar === '/') {\n // Rest of line is a comment, stop here\n break;\n }\n\n // Check for multi-line comment start (/* ... */)\n // For simplicity, we only handle single-line /* */ comments here\n if (char === '/' && nextChar === '*') {\n const endIndex = line.indexOf('*/', i + 2);\n if (endIndex !== -1) {\n // Skip the comment\n i = endIndex + 1;\n continue;\n }\n }\n\n result += char;\n }\n\n return result;\n });\n\n return JSON.parse(cleanedLines.join('\\n'));\n};\n"],"mappings":";;;;;AAGA,MAAa,yBAAyB,eAAuB;AAE3D,KAAI;AACF,SAAO,KAAK,MAAM,WAAW;SACvB;CAQR,MAAM,eADQ,WAAW,MAAM,KAAK,CACT,KAAK,SAAS;EAEvC,IAAI,WAAW;EACf,IAAI,SAAS;AAEb,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,OAAO,KAAK;GAClB,MAAM,WAAW,KAAK,IAAI;AAG1B,OAAI,SAAS,SAAQ,MAAM,KAAK,KAAK,IAAI,OAAO,OAAO;AACrD,eAAW,CAAC;AACZ,cAAU;AACV;;AAIF,OAAI,UAAU;AACZ,cAAU;AACV;;AAIF,OAAI,SAAS,OAAO,aAAa,IAE/B;AAKF,OAAI,SAAS,OAAO,aAAa,KAAK;IACpC,MAAM,WAAW,KAAK,QAAQ,MAAM,IAAI,EAAE;AAC1C,QAAI,aAAa,IAAI;AAEnB,SAAI,WAAW;AACf;;;AAIJ,aAAU;;AAGZ,SAAO;GACP;AAEF,QAAO,KAAK,MAAM,aAAa,KAAK,KAAK,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
|
|
4
|
+
//#region src/init/utils/tsConfig.ts
|
|
5
|
+
/**
|
|
6
|
+
* Helper to find all tsconfig files (tsconfig.json, tsconfig.*.json)
|
|
7
|
+
*/
|
|
8
|
+
const findTsConfigFiles = async (rootDir) => {
|
|
9
|
+
try {
|
|
10
|
+
return (await (0, node_fs_promises.readdir)(rootDir)).filter((file) => file === "tsconfig.json" || /^tsconfig\..+\.json$/.test(file));
|
|
11
|
+
} catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.findTsConfigFiles = findTsConfigFiles;
|
|
18
|
+
//# sourceMappingURL=tsConfig.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsConfig.cjs","names":[],"sources":["../../../../src/init/utils/tsConfig.ts"],"sourcesContent":["import { readdir } from 'node:fs/promises';\n\n/**\n * Helper to find all tsconfig files (tsconfig.json, tsconfig.*.json)\n */\nexport const findTsConfigFiles = async (rootDir: string): Promise<string[]> => {\n try {\n const files = await readdir(rootDir);\n\n return files.filter(\n (file) => file === 'tsconfig.json' || /^tsconfig\\..+\\.json$/.test(file)\n );\n } catch {\n return [];\n }\n};\n"],"mappings":";;;;;;;AAKA,MAAa,oBAAoB,OAAO,YAAuC;AAC7E,KAAI;AAGF,UAFc,oCAAc,QAAQ,EAEvB,QACV,SAAS,SAAS,mBAAmB,uBAAuB,KAAK,KAAK,CACxE;SACK;AACN,SAAO,EAAE"}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require__utils_asset = require('../_virtual/_utils_asset.cjs');
|
|
2
3
|
let node_fs_promises = require("node:fs/promises");
|
|
3
4
|
let node_path = require("node:path");
|
|
4
5
|
let _intlayer_config = require("@intlayer/config");
|
|
5
|
-
let node_url = require("node:url");
|
|
6
6
|
|
|
7
7
|
//#region src/initConfig/index.ts
|
|
8
8
|
/**
|
|
9
9
|
* UTILITIES
|
|
10
10
|
*/
|
|
11
11
|
const rootDir = process.cwd();
|
|
12
|
-
const isESModule = typeof require("url").pathToFileURL(__filename).href === "string";
|
|
13
|
-
const currentFileDir = isESModule ? (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href)) : __dirname;
|
|
14
12
|
const writeFileToRoot = async (filePath, content) => await (0, node_fs_promises.writeFile)((0, node_path.join)(rootDir, filePath), content, "utf8");
|
|
15
|
-
const readTemplate = async (templatePath) => await (0, node_fs_promises.readFile)((0, node_path.join)(currentFileDir, "templates", templatePath), "utf8");
|
|
16
13
|
const getTemplatePath = (format) => {
|
|
17
14
|
switch (format) {
|
|
18
|
-
case "ts": return "ts.txt";
|
|
19
|
-
case "cjs": return "cjs.txt";
|
|
20
|
-
case "mjs": return "mjs.txt";
|
|
21
|
-
case "js": return "
|
|
22
|
-
case "json": return "json.txt";
|
|
23
|
-
default: return "ts.txt";
|
|
15
|
+
case "ts": return "./templates/ts.txt";
|
|
16
|
+
case "cjs": return "./templates/cjs.txt";
|
|
17
|
+
case "mjs": return "./templates/mjs.txt";
|
|
18
|
+
case "js": return "./templates/mjs.txt";
|
|
19
|
+
case "json": return "./templates/json.txt";
|
|
20
|
+
default: return "./templates/ts.txt";
|
|
24
21
|
}
|
|
25
22
|
};
|
|
26
23
|
/**
|
|
@@ -32,11 +29,10 @@ const initConfig = async (format, baseDir) => {
|
|
|
32
29
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} ${(0, _intlayer_config.colorizePath)((0, node_path.relative)(baseDir, configurationFilePath))} already exists`);
|
|
33
30
|
return;
|
|
34
31
|
}
|
|
35
|
-
await writeFileToRoot(format,
|
|
32
|
+
await writeFileToRoot(format, require__utils_asset.readAsset(getTemplatePath(format.split(".").pop())));
|
|
36
33
|
(0, _intlayer_config.logger)(`Created ${format}`);
|
|
37
34
|
};
|
|
38
35
|
|
|
39
36
|
//#endregion
|
|
40
37
|
exports.initConfig = initConfig;
|
|
41
|
-
exports.isESModule = isESModule;
|
|
42
38
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["v"],"sources":["../../../src/initConfig/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["v","readAsset"],"sources":["../../../src/initConfig/index.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport {\n colorizePath,\n type configurationFilesCandidates,\n logger,\n searchConfigurationFile,\n v,\n} from '@intlayer/config';\n\n/**\n * UTILITIES\n */\nconst rootDir = process.cwd();\n\n// Helper to write a file\nconst writeFileToRoot = async (filePath: string, content: string) =>\n await writeFile(join(rootDir, filePath), content, 'utf8');\n\ntype ConfigFormat = 'ts' | 'cjs' | 'mjs' | 'js' | 'json';\n\nconst getTemplatePath = (format: ConfigFormat) => {\n switch (format) {\n case 'ts':\n return './templates/ts.txt';\n case 'cjs':\n return './templates/cjs.txt';\n case 'mjs':\n return './templates/mjs.txt';\n case 'js':\n return './templates/mjs.txt';\n case 'json':\n return './templates/json.txt';\n default:\n return './templates/ts.txt';\n }\n};\n\n/**\n * Initialize the Intlayer configuration file\n */\nexport const initConfig = async (\n format: (typeof configurationFilesCandidates)[number],\n baseDir: string\n) => {\n // Search for configuration file\n const { configurationFilePath } = searchConfigurationFile(baseDir);\n\n // return if the configuration file is found\n if (configurationFilePath) {\n const relativePath = relative(baseDir, configurationFilePath);\n logger(`${v} ${colorizePath(relativePath)} already exists`);\n return;\n }\n\n // Extract the format from the filename (e.g. 'intlayer.config.ts' -> 'ts')\n const extension = format.split('.').pop() as ConfigFormat;\n\n const templatePath = getTemplatePath(extension);\n const configContent = readAsset(templatePath);\n\n await writeFileToRoot(format, configContent);\n logger(`Created ${format}`);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,UAAU,QAAQ,KAAK;AAG7B,MAAM,kBAAkB,OAAO,UAAkB,YAC/C,0DAAqB,SAAS,SAAS,EAAE,SAAS,OAAO;AAI3D,MAAM,mBAAmB,WAAyB;AAChD,SAAQ,QAAR;EACE,KAAK,KACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,KACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;;;;AAOb,MAAa,aAAa,OACxB,QACA,YACG;CAEH,MAAM,EAAE,wEAAkD,QAAQ;AAGlE,KAAI,uBAAuB;AAEzB,+BAAO,GAAGA,mBAAE,8DADkB,SAAS,sBAAsB,CACpB,CAAC,iBAAiB;AAC3D;;AASF,OAAM,gBAAgB,QAFAC,+BADD,gBAFH,OAAO,MAAM,IAAI,CAAC,KAAK,CAEM,CACF,CAED;AAC5C,8BAAO,WAAW,SAAS"}
|
package/dist/esm/init/index.mjs
CHANGED
|
@@ -1,86 +1,33 @@
|
|
|
1
1
|
import { initConfig } from "../initConfig/index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { exists, readFileFromRoot, writeFileToRoot } from "./utils/fileSystem.mjs";
|
|
3
|
+
import { parseJSONWithComments } from "./utils/jsonParser.mjs";
|
|
4
|
+
import { findTsConfigFiles } from "./utils/tsConfig.mjs";
|
|
4
5
|
import { ANSIColors, colorize, colorizePath, logger, v, x } from "@intlayer/config";
|
|
5
6
|
|
|
6
7
|
//#region src/init/index.ts
|
|
7
8
|
/**
|
|
8
|
-
* UTILITIES
|
|
9
|
-
*/
|
|
10
|
-
const rootDir = process.cwd();
|
|
11
|
-
const exists = async (filePath) => {
|
|
12
|
-
try {
|
|
13
|
-
await access(join(rootDir, filePath));
|
|
14
|
-
return true;
|
|
15
|
-
} catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const readFileFromRoot = async (filePath) => await readFile(join(rootDir, filePath), "utf8");
|
|
20
|
-
const writeFileToRoot = async (filePath, content) => await writeFile(join(rootDir, filePath), content, "utf8");
|
|
21
|
-
const parseJSONWithComments = (jsonString) => {
|
|
22
|
-
try {
|
|
23
|
-
return JSON.parse(jsonString);
|
|
24
|
-
} catch {}
|
|
25
|
-
const cleanedLines = jsonString.split("\n").map((line) => {
|
|
26
|
-
let inString = false;
|
|
27
|
-
let result = "";
|
|
28
|
-
for (let i = 0; i < line.length; i++) {
|
|
29
|
-
const char = line[i];
|
|
30
|
-
const nextChar = line[i + 1];
|
|
31
|
-
if (char === "\"" && (i === 0 || line[i - 1] !== "\\")) {
|
|
32
|
-
inString = !inString;
|
|
33
|
-
result += char;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (inString) {
|
|
37
|
-
result += char;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (char === "/" && nextChar === "/") break;
|
|
41
|
-
if (char === "/" && nextChar === "*") {
|
|
42
|
-
const endIndex = line.indexOf("*/", i + 2);
|
|
43
|
-
if (endIndex !== -1) {
|
|
44
|
-
i = endIndex + 1;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
result += char;
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
});
|
|
52
|
-
return JSON.parse(cleanedLines.join("\n"));
|
|
53
|
-
};
|
|
54
|
-
const findTsConfigFiles = async () => {
|
|
55
|
-
try {
|
|
56
|
-
return (await readdir(rootDir)).filter((file) => file === "tsconfig.json" || /^tsconfig\..+\.json$/.test(file));
|
|
57
|
-
} catch {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
9
|
* MAIN LOGIC
|
|
63
10
|
*/
|
|
64
|
-
const initIntlayer = async () => {
|
|
11
|
+
const initIntlayer = async (rootDir) => {
|
|
65
12
|
logger(colorize("Checking Intlayer configuration...", ANSIColors.CYAN));
|
|
66
|
-
if (!await exists("package.json")) {
|
|
13
|
+
if (!await exists(rootDir, "package.json")) {
|
|
67
14
|
logger(`${x} No ${colorizePath("package.json")} found. Please run this script from the project root.`, { level: "error" });
|
|
68
15
|
process.exit(1);
|
|
69
16
|
}
|
|
70
17
|
const gitignorePath = ".gitignore";
|
|
71
|
-
if (await exists(gitignorePath)) {
|
|
72
|
-
const gitignoreContent = await readFileFromRoot(gitignorePath);
|
|
18
|
+
if (await exists(rootDir, gitignorePath)) {
|
|
19
|
+
const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);
|
|
73
20
|
if (!gitignoreContent.includes("intlayer")) {
|
|
74
|
-
await writeFileToRoot(gitignorePath, `${gitignoreContent}\n
|
|
21
|
+
await writeFileToRoot(rootDir, gitignorePath, `${gitignoreContent}\n# Intlayer\n.intlayer\n`);
|
|
75
22
|
logger(`${v} Added ${colorizePath(".intlayer")} to ${colorizePath(gitignorePath)}`);
|
|
76
23
|
} else logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);
|
|
77
24
|
}
|
|
78
|
-
const tsConfigFiles = await findTsConfigFiles();
|
|
25
|
+
const tsConfigFiles = await findTsConfigFiles(rootDir);
|
|
79
26
|
let hasTsConfig = false;
|
|
80
|
-
for (const fileName of tsConfigFiles) if (await exists(fileName)) {
|
|
27
|
+
for (const fileName of tsConfigFiles) if (await exists(rootDir, fileName)) {
|
|
81
28
|
hasTsConfig = true;
|
|
82
29
|
try {
|
|
83
|
-
const config = parseJSONWithComments(await readFileFromRoot(fileName));
|
|
30
|
+
const config = parseJSONWithComments(await readFileFromRoot(rootDir, fileName));
|
|
84
31
|
const typeDefinition = ".intlayer/**/*.ts";
|
|
85
32
|
let updated = false;
|
|
86
33
|
if (!config.include) {} else if (Array.isArray(config.include) && !config.include.some((patten) => patten.includes(".intlayer"))) {
|
|
@@ -88,7 +35,7 @@ const initIntlayer = async () => {
|
|
|
88
35
|
updated = true;
|
|
89
36
|
} else if (config.include.includes(typeDefinition)) logger(`${v} ${colorizePath(fileName)} already includes intlayer types`);
|
|
90
37
|
if (updated) {
|
|
91
|
-
await writeFileToRoot(fileName, JSON.stringify(config, null, 2));
|
|
38
|
+
await writeFileToRoot(rootDir, fileName, JSON.stringify(config, null, 2));
|
|
92
39
|
logger(`${v} Updated ${colorizePath(fileName)} to include intlayer types`);
|
|
93
40
|
}
|
|
94
41
|
} catch {
|
|
@@ -100,11 +47,11 @@ const initIntlayer = async () => {
|
|
|
100
47
|
"vite.config.ts",
|
|
101
48
|
"vite.config.js",
|
|
102
49
|
"vite.config.mjs"
|
|
103
|
-
]) if (await exists(file)) {
|
|
104
|
-
let content = await readFileFromRoot(file);
|
|
50
|
+
]) if (await exists(rootDir, file)) {
|
|
51
|
+
let content = await readFileFromRoot(rootDir, file);
|
|
105
52
|
if (!content.includes("vite-intlayer")) {
|
|
106
53
|
content = `import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\n${content}`;
|
|
107
|
-
await writeFileToRoot(file, content);
|
|
54
|
+
await writeFileToRoot(rootDir, file, content);
|
|
108
55
|
logger(`${v} Injected import into ${colorizePath(file)}`);
|
|
109
56
|
}
|
|
110
57
|
break;
|
|
@@ -113,11 +60,11 @@ const initIntlayer = async () => {
|
|
|
113
60
|
"next.config.js",
|
|
114
61
|
"next.config.mjs",
|
|
115
62
|
"next.config.ts"
|
|
116
|
-
]) if (await exists(file)) {
|
|
117
|
-
let content = await readFileFromRoot(file);
|
|
63
|
+
]) if (await exists(rootDir, file)) {
|
|
64
|
+
let content = await readFileFromRoot(rootDir, file);
|
|
118
65
|
if (!content.includes("next-intlayer")) {
|
|
119
66
|
content = `import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\n${content}`;
|
|
120
|
-
await writeFileToRoot(file, content);
|
|
67
|
+
await writeFileToRoot(rootDir, file, content);
|
|
121
68
|
logger(`${v} Injected import into ${colorizePath(file)}`);
|
|
122
69
|
}
|
|
123
70
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/init/index.ts"],"sourcesContent":["import { access, readdir, readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\n\n/**\n * UTILITIES\n */\nconst rootDir = process.cwd();\n\n// Helper to check if a file exists\nconst exists = async (filePath: string) => {\n try {\n await access(join(rootDir, filePath));\n return true;\n } catch {\n return false;\n }\n};\n\n// Helper to read a file\nconst readFileFromRoot = async (filePath: string) =>\n await readFile(join(rootDir, filePath), 'utf8');\n\n// Helper to write a file\nconst writeFileToRoot = async (filePath: string, content: string) =>\n await writeFile(join(rootDir, filePath), content, 'utf8');\n\n// Helper to parse JSON that may contain comments (tsconfig allows comments)\nconst parseJSONWithComments = (jsonString: string) => {\n // First, try parsing as-is (most tsconfig files don't have comments)\n try {\n return JSON.parse(jsonString);\n } catch {\n // If that fails, try stripping comments\n // Note: This simple approach removes comments line by line to avoid\n // matching glob patterns like /* and */ that appear in paths\n }\n\n // Process line by line to safely remove comments\n const lines = jsonString.split('\\n');\n const cleanedLines = lines.map((line) => {\n // Track if we're inside a string\n let inString = false;\n let result = '';\n\n for (let i = 0; i < line.length; i++) {\n const char = line[i];\n const nextChar = line[i + 1];\n\n // Handle string boundaries (accounting for escaped quotes)\n if (char === '\"' && (i === 0 || line[i - 1] !== '\\\\')) {\n inString = !inString;\n result += char;\n continue;\n }\n\n // If we're inside a string, keep the character\n if (inString) {\n result += char;\n continue;\n }\n\n // Check for single-line comment outside of strings\n if (char === '/' && nextChar === '/') {\n // Rest of line is a comment, stop here\n break;\n }\n\n // Check for multi-line comment start (/* ... */)\n // For simplicity, we only handle single-line /* */ comments here\n if (char === '/' && nextChar === '*') {\n const endIndex = line.indexOf('*/', i + 2);\n if (endIndex !== -1) {\n // Skip the comment\n i = endIndex + 1;\n continue;\n }\n }\n\n result += char;\n }\n\n return result;\n });\n\n return JSON.parse(cleanedLines.join('\\n'));\n};\n\n// Helper to find all tsconfig files (tsconfig.json, tsconfig.*.json)\nconst findTsConfigFiles = async (): Promise<string[]> => {\n try {\n const files = await readdir(rootDir);\n\n return files.filter(\n (file) => file === 'tsconfig.json' || /^tsconfig\\..+\\.json$/.test(file)\n );\n } catch {\n return [];\n }\n};\n\n/**\n * MAIN LOGIC\n */\n\nexport const initIntlayer = async () => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // Check for package.json to ensure we are in a project root\n if (!(await exists('package.json'))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n // Check .gitignore\n const gitignorePath = '.gitignore';\n if (await exists(gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // Check TSConfigs\n // Find all tsconfig files (tsconfig.json, tsconfig.*.json)\n const tsConfigFiles = await findTsConfigFiles();\n\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n // Check if include array exists - if not, skip (likely a solution-style tsconfig with references)\n let updated = false;\n if (!config.include) {\n // Skip tsconfig files without include array (e.g. solution-style configs with references)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((patten: string) =>\n patten.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n // We write back using standard JSON stringify (comments will be lost, sadly)\n // If preserving comments is critical, a more complex parser/printer is needed.\n await writeFileToRoot(fileName, JSON.stringify(config, null, 2));\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // Initialize Intlayer configuration file\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // Check Vite Config\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n\n for (const file of viteConfigs) {\n if (await exists(file)) {\n let content = await readFileFromRoot(file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n // Prepend the import\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one vite config\n }\n }\n\n // Check Next Config\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n\n for (const file of nextConfigs) {\n if (await exists(file)) {\n let content = await readFileFromRoot(file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\";\n\n // Prepend the import\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one next config\n }\n }\n\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n};\n"],"mappings":";;;;;;;;;AAeA,MAAM,UAAU,QAAQ,KAAK;AAG7B,MAAM,SAAS,OAAO,aAAqB;AACzC,KAAI;AACF,QAAM,OAAO,KAAK,SAAS,SAAS,CAAC;AACrC,SAAO;SACD;AACN,SAAO;;;AAKX,MAAM,mBAAmB,OAAO,aAC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AKtC,aAAU,wFAAkB;AAC5B,SAAM,gBAAgB,MAAM,QAAQ;AACpC,UAAO,GAAG,EAAE,wBAAwB,aAAa,KAAK,GAAG;;AAE3D;;AAOJ,MAAK,MAAM,QAFS;EAAC;EAAkB;EAAmB;EAAiB,CAGzE,KAAI,MAAM,OAAO,KAAK,EAAE;EACtB,IAAI,UAAU,MAAM,iBAAiB,KAAK;AAE1C,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAKtC,aAAU,iGAAkB;AAC5B,SAAM,gBAAgB,MAAM,QAAQ;AACpC,UAAO,GAAG,EAAE,wBAAwB,aAAa,KAAK,GAAG;;AAE3D;;AAIJ,QAAO,GAAG,EAAE,GAAG,SAAS,iCAAiC,WAAW,MAAM,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/init/index.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n colorizePath,\n logger,\n v,\n x,\n} from '@intlayer/config';\nimport { initConfig } from '../initConfig';\nimport {\n exists,\n findTsConfigFiles,\n parseJSONWithComments,\n readFileFromRoot,\n writeFileToRoot,\n} from './utils';\n\n/**\n * MAIN LOGIC\n */\n\nexport const initIntlayer = async (rootDir: string) => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // Check for package.json to ensure we are in a project root\n if (!(await exists(rootDir, 'package.json'))) {\n logger(\n `${x} No ${colorizePath('package.json')} found. Please run this script from the project root.`,\n { level: 'error' }\n );\n process.exit(1);\n }\n\n // Check .gitignore\n const gitignorePath = '.gitignore';\n if (await exists(rootDir, gitignorePath)) {\n const gitignoreContent = await readFileFromRoot(rootDir, gitignorePath);\n\n if (!gitignoreContent.includes('intlayer')) {\n const newContent = `${gitignoreContent}\\n# Intlayer\\n.intlayer\\n`;\n await writeFileToRoot(rootDir, gitignorePath, newContent);\n logger(\n `${v} Added ${colorizePath('.intlayer')} to ${colorizePath(gitignorePath)}`\n );\n } else {\n logger(`${v} ${colorizePath(gitignorePath)} already includes .intlayer`);\n }\n }\n\n // Check TSConfigs\n // Find all tsconfig files (tsconfig.json, tsconfig.*.json)\n const tsConfigFiles = await findTsConfigFiles(rootDir);\n\n let hasTsConfig = false;\n\n for (const fileName of tsConfigFiles) {\n if (await exists(rootDir, fileName)) {\n hasTsConfig = true;\n try {\n const fileContent = await readFileFromRoot(rootDir, fileName);\n const config = parseJSONWithComments(fileContent);\n const typeDefinition = '.intlayer/**/*.ts';\n\n // Check if include array exists - if not, skip (likely a solution-style tsconfig with references)\n let updated = false;\n if (!config.include) {\n // Skip tsconfig files without include array (e.g. solution-style configs with references)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((patten: string) =>\n patten.includes('.intlayer')\n )\n ) {\n config.include.push(typeDefinition);\n updated = true;\n } else if (config.include.includes(typeDefinition)) {\n logger(\n `${v} ${colorizePath(fileName)} already includes intlayer types`\n );\n }\n\n if (updated) {\n // We write back using standard JSON stringify (comments will be lost, sadly)\n // If preserving comments is critical, a more complex parser/printer is needed.\n await writeFileToRoot(\n rootDir,\n fileName,\n JSON.stringify(config, null, 2)\n );\n logger(\n `${v} Updated ${colorizePath(fileName)} to include intlayer types`\n );\n }\n } catch {\n logger(\n `${x} Could not parse or update ${colorizePath(fileName)}. You may need to add ${colorizePath('.intlayer/types/**/*.ts')} manually.`,\n { level: 'warn' }\n );\n }\n }\n }\n\n // Initialize Intlayer configuration file\n const format = hasTsConfig ? 'intlayer.config.ts' : 'intlayer.config.mjs';\n await initConfig(format, rootDir);\n\n // Check Vite Config\n const viteConfigs = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs'];\n\n for (const file of viteConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('vite-intlayer')) {\n const viteImport =\n \"import { intlayer } from 'vite-intlayer'; // Add the plugin to the Vite plugin list\";\n\n // Prepend the import\n content = `${viteImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one vite config\n }\n }\n\n // Check Next Config\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\n\n for (const file of nextConfigs) {\n if (await exists(rootDir, file)) {\n let content = await readFileFromRoot(rootDir, file);\n\n if (!content.includes('next-intlayer')) {\n const nextImport =\n \"import { withIntlayer } from 'next-intlayer'; // Add the plugin to the Next.js configuration\";\n\n // Prepend the import\n content = `${nextImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break; // Stop after finding one next config\n }\n }\n\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAa,eAAe,OAAO,YAAoB;AACrD,QAAO,SAAS,sCAAsC,WAAW,KAAK,CAAC;AAGvE,KAAI,CAAE,MAAM,OAAO,SAAS,eAAe,EAAG;AAC5C,SACE,GAAG,EAAE,MAAM,aAAa,eAAe,CAAC,wDACxC,EAAE,OAAO,SAAS,CACnB;AACD,UAAQ,KAAK,EAAE;;CAIjB,MAAM,gBAAgB;AACtB,KAAI,MAAM,OAAO,SAAS,cAAc,EAAE;EACxC,MAAM,mBAAmB,MAAM,iBAAiB,SAAS,cAAc;AAEvE,MAAI,CAAC,iBAAiB,SAAS,WAAW,EAAE;AAE1C,SAAM,gBAAgB,SAAS,eADZ,GAAG,iBAAiB,2BACkB;AACzD,UACE,GAAG,EAAE,SAAS,aAAa,YAAY,CAAC,MAAM,aAAa,cAAc,GAC1E;QAED,QAAO,GAAG,EAAE,GAAG,aAAa,cAAc,CAAC,6BAA6B;;CAM5E,MAAM,gBAAgB,MAAM,kBAAkB,QAAQ;CAEtD,IAAI,cAAc;AAElB,MAAK,MAAM,YAAY,cACrB,KAAI,MAAM,OAAO,SAAS,SAAS,EAAE;AACnC,gBAAc;AACd,MAAI;GAEF,MAAM,SAAS,sBADK,MAAM,iBAAiB,SAAS,SAAS,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