@intlayer/chokidar 7.5.8 → 7.5.10

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.
Files changed (54) hide show
  1. package/README.md +9 -2
  2. package/dist/assets/initConfig/templates/cjs.txt +5 -12
  3. package/dist/assets/initConfig/templates/mjs.txt +5 -12
  4. package/dist/assets/initConfig/templates/ts.txt +5 -11
  5. package/dist/cjs/init/index.cjs +18 -71
  6. package/dist/cjs/init/index.cjs.map +1 -1
  7. package/dist/cjs/init/utils/fileSystem.cjs +30 -0
  8. package/dist/cjs/init/utils/fileSystem.cjs.map +1 -0
  9. package/dist/cjs/init/utils/index.cjs +9 -0
  10. package/dist/cjs/init/utils/jsonParser.cjs +42 -0
  11. package/dist/cjs/init/utils/jsonParser.cjs.map +1 -0
  12. package/dist/cjs/init/utils/tsConfig.cjs +18 -0
  13. package/dist/cjs/init/utils/tsConfig.cjs.map +1 -0
  14. package/dist/cjs/initConfig/index.cjs +8 -12
  15. package/dist/cjs/initConfig/index.cjs.map +1 -1
  16. package/dist/cjs/watcher.cjs +1 -1
  17. package/dist/cjs/watcher.cjs.map +1 -1
  18. package/dist/esm/init/index.mjs +18 -71
  19. package/dist/esm/init/index.mjs.map +1 -1
  20. package/dist/esm/init/utils/fileSystem.mjs +27 -0
  21. package/dist/esm/init/utils/fileSystem.mjs.map +1 -0
  22. package/dist/esm/init/utils/index.mjs +5 -0
  23. package/dist/esm/init/utils/jsonParser.mjs +41 -0
  24. package/dist/esm/init/utils/jsonParser.mjs.map +1 -0
  25. package/dist/esm/init/utils/tsConfig.mjs +17 -0
  26. package/dist/esm/init/utils/tsConfig.mjs.map +1 -0
  27. package/dist/esm/initConfig/index.mjs +11 -14
  28. package/dist/esm/initConfig/index.mjs.map +1 -1
  29. package/dist/esm/watcher.mjs +1 -1
  30. package/dist/esm/watcher.mjs.map +1 -1
  31. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
  32. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
  33. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
  34. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
  35. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
  36. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
  37. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -1
  38. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
  39. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -1
  40. package/dist/types/formatDictionary.d.ts +15 -15
  41. package/dist/types/init/index.d.ts +1 -1
  42. package/dist/types/init/index.d.ts.map +1 -1
  43. package/dist/types/init/utils/fileSystem.d.ts +16 -0
  44. package/dist/types/init/utils/fileSystem.d.ts.map +1 -0
  45. package/dist/types/init/utils/index.d.ts +4 -0
  46. package/dist/types/init/utils/jsonParser.d.ts +8 -0
  47. package/dist/types/init/utils/jsonParser.d.ts.map +1 -0
  48. package/dist/types/init/utils/tsConfig.d.ts +8 -0
  49. package/dist/types/init/utils/tsConfig.d.ts.map +1 -0
  50. package/dist/types/initConfig/index.d.ts +2 -2
  51. package/dist/types/initConfig/index.d.ts.map +1 -1
  52. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
  53. package/package.json +10 -10
  54. package/dist/assets/initConfig/templates/js.txt +0 -18
package/README.md CHANGED
@@ -5,8 +5,11 @@
5
5
  </p>
6
6
 
7
7
  <h1 align="center">
8
- <strong> Intlayer : an Open-source, per-component i18n toolkit with AI-powered translation & CMS.</strong>
8
+ <strong>Per-component i18n</strong>
9
9
  </h1>
10
+ <h2 align="center">
11
+ <strong>AI-powered translation. Visual Editor. Multilingual CMS.</strong>
12
+ </h2>
10
13
 
11
14
  <br />
12
15
 
@@ -24,6 +27,8 @@
24
27
  <a href="https://github.com/aymericzip/intlayer/blob/main/LICENSE" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/license/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="license"/></a>
25
28
  <a href="https://github.com/aymericzip/intlayer/commits/main" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/github/last-commit/aymericzip/intlayer?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="last commit"/>
26
29
  </a>
30
+ <a href="https://www.bountyhub.dev/en/bounty/view/a2f24259-80ae-4a19-82e7-288718fba449/adapt-markdown-parser-in-a-custom-packages" target="_blank" rel="noopener noreferrer nofollow"><img src="https://img.shields.io/badge/Bounties-on%20BountyHub-yellow?style=for-the-badge&labelColor=000000&color=FFFFFF&logoColor=000000&cacheSeconds=86400" alt="Bounties on BountyHub"/>
31
+ </a>
27
32
  </p>
28
33
 
29
34
  ![Watch the video](https://github.com/aymericzip/intlayer/blob/main/docs/assets/demo_video.gif)
@@ -46,7 +51,7 @@ With **per-locale content files**, **TypeScript autocompletion**, **tree-shakabl
46
51
  | Feature | Description |
47
52
  | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
48
53
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/frameworks.png?raw=true" alt="Feature" width="700"> | **Cross-Frameworks Support**<br><br>Intlayer is compatible with all major frameworks and libraries, including Next.js, React, Vite, Vue.js, Nuxt, Preact, Express, and more. |
49
- | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.png?raw=true" alt="Feature" width="700"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](https://intlayer.org/doc/concept/content) |
54
+ | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/javascript_content_management.jpg?raw=true" alt="Feature" width="700"> | **JavaScript-Powered Content Management**<br><br>Harness the flexibility of JavaScript to define and manage your content efficiently. <br><br> - [Content declaration](https://intlayer.org/doc/concept/content) |
50
55
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/per_locale_content_declaration_file.png?raw=true" alt="Feature" width="700"> | **Per-Locale Content Declaration File**<br><br>Speed up your development by declaring your content once, before auto generation.<br><br> - [Per-Locale Content Declaration File](https://intlayer.org/doc/concept/per-locale-file) |
51
56
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/autocompletion.png?raw=true" alt="Feature" width="700"> | **Type-Safe Environment**<br><br>Leverage TypeScript to ensure your content definitions and code are error-free, while also benefiting from IDE autocompletion.<br><br> - [TypeScript configuration](https://intlayer.org/doc/environment/vite-and-react#configure-typescript) |
52
57
  | <img src="https://github.com/aymericzip/intlayer/blob/main/docs/assets/config_file.png?raw=true" alt="Feature" width="700"> | **Simplified Setup**<br><br>Get up and running quickly with minimal configuration. Adjust settings for internationalization, routing, AI, build, and content handling with ease. <br><br> - [Explore Next.js integration](https://intlayer.org/doc/environment/nextjs) |
@@ -268,6 +273,8 @@ You can also follow us on :
268
273
 
269
274
  For more detailed guidelines on contributing to this project, please refer to the [`CONTRIBUTING.md`](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md) file. It contains essential information on our development process, commit message conventions, and release procedures. Your contributions are valuable to us, and we appreciate your efforts in making this project better!
270
275
 
276
+ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https://gitlab.com/ay.pineau/intlayer), or [Bitbucket](https://bitbucket.org/intlayer/intlayer/).
277
+
271
278
  ### Thank You for the Support
272
279
 
273
280
  If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
@@ -1,18 +1,11 @@
1
1
  const { Locales } = require('intlayer');
2
2
 
3
3
  /** @type {import('intlayer').IntlayerConfig} */
4
- const getIntlayerConfig = () => {
5
- /** @type {import('intlayer').IntlayerConfig} */
6
- const config = {
7
- internationalization: {
8
- locales: [Locales.ENGLISH],
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 getIntlayerConfig = () => {
5
- /** @type {import('intlayer').IntlayerConfig} */
6
- const config = {
7
- internationalization: {
8
- locales: [Locales.ENGLISH],
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 getIntlayerConfig = (): IntlayerConfig => {
4
- const config: IntlayerConfig = {
5
- internationalization: {
6
- locales: [Locales.ENGLISH],
7
- defaultLocale: Locales.ENGLISH,
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;
@@ -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
- let node_fs_promises = require("node:fs/promises");
4
- let node_path = require("node:path");
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\n# Intlayer\n.intlayer\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,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CAGzE,KAAI,MAAM,OAAO,KAAK,EAAE;EACtB,IAAI,UAAU,MAAM,iBAAiB,KAAK;AAE1C,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAKtC,aAAU,wFAAkB;AAC5B,SAAM,gBAAgB,MAAM,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,gBAAg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AiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAKtC,aAAU,iGAAkB;AAC5B,SAAMC,8CAAgB,SAAS,MAAM,QAAQ;AAC7C,gCAAO,GAAGC,mBAAE,2DAAqC,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 "js.txt";
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, await readTemplate(getTemplatePath(format.split(".").pop())));
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 { readFile, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\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();\nexport const isESModule = typeof import.meta.url === 'string';\n\nconst currentFileDir = isESModule\n ? dirname(fileURLToPath(import.meta.url))\n : __dirname;\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 read a template file\nconst readTemplate = async (templatePath: string) =>\n await readFile(join(currentFileDir, 'templates', templatePath), 'utf8');\n\ntype ConfigFormat = 'ts' | 'cjs' | 'mjs' | 'js' | 'json';\n\nconst getTemplatePath = (format: ConfigFormat) => {\n switch (format) {\n case 'ts':\n return 'ts.txt';\n case 'cjs':\n return 'cjs.txt';\n case 'mjs':\n return 'mjs.txt';\n case 'js':\n return 'js.txt';\n case 'json':\n return 'json.txt';\n default:\n return '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 = await readTemplate(templatePath);\n\n await writeFileToRoot(format, configContent);\n logger(`Created ${format}`);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,UAAU,QAAQ,KAAK;AAC7B,MAAa,aAAa,yDAA2B;AAErD,MAAM,iBAAiB,8GACmB,CAAC,GACvC;AAGJ,MAAM,kBAAkB,OAAO,UAAkB,YAC/C,0DAAqB,SAAS,SAAS,EAAE,SAAS,OAAO;AAG3D,MAAM,eAAe,OAAO,iBAC1B,yDAAoB,gBAAgB,aAAa,aAAa,EAAE,OAAO;AAIzE,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,QAFA,MAAM,aADP,gBAFH,OAAO,MAAM,IAAI,CAAC,KAAK,CAEM,CACO,CAEV;AAC5C,8BAAO,WAAW,SAAS"}
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"}
@@ -11,7 +11,7 @@ let _intlayer_config = require("@intlayer/config");
11
11
  let chokidar = require("chokidar");
12
12
 
13
13
  //#region src/watcher.ts
14
- /** @ts-ignore remove error Module '"chokidar"' has no exported member 'ChokidarOptions'. */
14
+ /** @ts-ignore remove error Module '"chokidar"' has no exported member 'ChokidarOptions' */
15
15
  const pendingUnlinks = /* @__PURE__ */ new Map();
16
16
  const watch = (options) => {
17
17
  const configuration = options?.configuration ?? (0, _intlayer_config.getConfiguration)(options?.configOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.cjs","names":["configuration: IntlayerConfig","matchedOldPath: string | undefined","handleContentDeclarationFileMoved","writeContentDeclaration","handleAdditionalContentDeclarationFile","handleContentDeclarationFileChange","handleUnlinkedContentDeclarationFile","prepareIntlayer"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions'. */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleContentDeclarationFileMoved } from './handleContentDeclarationFileMoved';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\n// Map to track files that were recently unlinked: oldPath -> { timer, timestamp }\nconst pendingUnlinks = new Map<\n string,\n { timer: NodeJS.Timeout; oldPath: string }\n>();\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration: IntlayerConfig =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n let isMove = false;\n\n // 1. Check if this Add corresponds to a pending Unlink (Move/Rename detection)\n // Heuristic:\n // - Priority A: Exact basename match (Moved to different folder)\n // - Priority B: Single entry in pendingUnlinks (Renamed file)\n let matchedOldPath: string | undefined;\n\n // Search for basename match\n for (const [oldPath] of pendingUnlinks) {\n if (basename(oldPath) === fileName) {\n matchedOldPath = oldPath;\n break;\n }\n }\n\n // If no basename match, but exactly one file was recently unlinked, assume it's a rename\n if (!matchedOldPath && pendingUnlinks.size === 1) {\n matchedOldPath = pendingUnlinks.keys().next().value;\n }\n\n if (matchedOldPath) {\n // It is a move! Cancel the unlink handler\n const pending = pendingUnlinks.get(matchedOldPath);\n if (pending) {\n clearTimeout(pending.timer);\n pendingUnlinks.delete(matchedOldPath);\n }\n\n isMove = true;\n appLogger(`File moved from ${matchedOldPath} to ${filePath}`);\n\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n }\n\n // 2. If it's NOT a move, perform standard \"New File\" logic\n if (!isMove) {\n const fileContent = await readFile(filePath, 'utf-8');\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(\n new RegExp(`(${extensionPattern})$`),\n ''\n );\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n }\n\n // 3. Always ensure the file is processed (both for moves and adds)\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n // Delay unlink processing to see if an 'add' event occurs (indicating a move)\n const timer = setTimeout(async () => {\n // If timer fires, the file was genuinely removed\n pendingUnlinks.delete(filePath);\n await handleUnlinkedContentDeclarationFile(filePath, configuration);\n }, 200); // 200ms window to catch the 'add' event\n\n pendingUnlinks.set(filePath, { timer, oldPath: filePath });\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 { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAM,iCAAiB,IAAI,KAGxB;AASH,MAAa,SAAS,YAA2B;CAC/C,MAAMA,gBACJ,SAAS,wDAAkC,SAAS,cAAc;CACpE,MAAM,+CAAyB,cAAc;CAE7C,MAAM,EACJ,OAAO,aACP,6BACA,mBACE,cAAc;AAElB,4BAAqB,6BAA6B;EAChD,YAAY;EACZ,eAAe;EACf,kBAAkB;GAChB,oBAAoB;GACpB,cAAc;GACf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gB,cAAc;GACpC;;AAGN,MAAa,wBAAwB,OAAO,YAA2B;CACrE,MAAM,EAAE,aAAa,GAAG,SAAS,WAAW,EAAE;CAC9C,MAAM,gBACJ,SAAS,wDAAkC,SAAS,cAAc;AAEpE,KAAI,CAAC,YACH,OAAMA,wCAAgB,eAAe,EAAE,UAAU,MAAM,CAAC;AAG1D,KAAI,cAAc,QAAQ,SAAS,SAAS,YAAY;AAGtD,qCAF+B,cAAc,CAEnC,yCAAyC;AACnD,QAAM;GAAE,GAAG;GAAM;GAAe,CAAC"}
1
+ {"version":3,"file":"watcher.cjs","names":["configuration: IntlayerConfig","matchedOldPath: string | undefined","handleContentDeclarationFileMoved","writeContentDeclaration","handleAdditionalContentDeclarationFile","handleContentDeclarationFileChange","handleUnlinkedContentDeclarationFile","prepareIntlayer"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleContentDeclarationFileMoved } from './handleContentDeclarationFileMoved';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\n// Map to track files that were recently unlinked: oldPath -> { timer, timestamp }\nconst pendingUnlinks = new Map<\n string,\n { timer: NodeJS.Timeout; oldPath: string }\n>();\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration: IntlayerConfig =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n let isMove = false;\n\n // Check if this Add corresponds to a pending Unlink (Move/Rename detection)\n // Heuristic:\n // - Priority A: Exact basename match (Moved to different folder)\n // - Priority B: Single entry in pendingUnlinks (Renamed file)\n let matchedOldPath: string | undefined;\n\n // Search for basename match\n for (const [oldPath] of pendingUnlinks) {\n if (basename(oldPath) === fileName) {\n matchedOldPath = oldPath;\n break;\n }\n }\n\n // If no basename match, but exactly one file was recently unlinked, assume it's a rename\n if (!matchedOldPath && pendingUnlinks.size === 1) {\n matchedOldPath = pendingUnlinks.keys().next().value;\n }\n\n if (matchedOldPath) {\n // It is a move! Cancel the unlink handler\n const pending = pendingUnlinks.get(matchedOldPath);\n if (pending) {\n clearTimeout(pending.timer);\n pendingUnlinks.delete(matchedOldPath);\n }\n\n isMove = true;\n appLogger(`File moved from ${matchedOldPath} to ${filePath}`);\n\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n }\n\n // If it's NOT a move, perform standard \"New File\" logic\n if (!isMove) {\n const fileContent = await readFile(filePath, 'utf-8');\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(\n new RegExp(`(${extensionPattern})$`),\n ''\n );\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n }\n\n // Always ensure the file is processed (both for moves and adds)\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n // Delay unlink processing to see if an 'add' event occurs (indicating a move)\n const timer = setTimeout(async () => {\n // If timer fires, the file was genuinely removed\n pendingUnlinks.delete(filePath);\n await handleUnlinkedContentDeclarationFile(filePath, configuration);\n }, 200); // 200ms window to catch the 'add' event\n\n pendingUnlinks.set(filePath, { timer, oldPath: filePath });\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 { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAM,iCAAiB,IAAI,KAGxB;AASH,MAAa,SAAS,YAA2B;CAC/C,MAAMA,gBACJ,SAAS,wDAAkC,SAAS,cAAc;CACpE,MAAM,+CAAyB,cAAc;CAE7C,MAAM,EACJ,OAAO,aACP,6BACA,mBACE,cAAc;AAElB,4BAAqB,6BAA6B;EAChD,YAAY;EACZ,eAAe;EACf,kBAAkB;GAChB,oBAAoB;GACpB,cAAc;GACf;EACD,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,GAAG;EACJ,CAAC,CACC,GAAG,OAAO,OAAO,aAAa;EAC7B,MAAM,mCAAoB,SAAS;EACnC,IAAI,SAAS;EAMb,IAAIC;AAGJ,OAAK,MAAM,CAAC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