@intlayer/chokidar 7.5.9 → 7.5.11
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/README.md +9 -2
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/init/index.cjs +101 -2
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/listDictionariesPath.cjs +16 -1
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +47 -0
- package/dist/cjs/listProjects.cjs.map +1 -0
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +4 -13
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/watcher.cjs +1 -1
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/init/index.mjs +101 -2
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs +16 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +44 -0
- package/dist/esm/listProjects.mjs.map +1 -0
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +4 -13
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/watcher.mjs +1 -1
- package/dist/esm/watcher.mjs.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/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -1
- package/dist/types/formatDictionary.d.ts +15 -15
- package/dist/types/index.d.ts +2 -1
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/listProjects.d.ts +26 -0
- package/dist/types/listProjects.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/package.json +10 -10
- 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>
|
|
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
|

|
|
@@ -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.
|
|
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-).
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ const require_handleUnlinkedContentDeclarationFile = require('./handleUnlinkedCo
|
|
|
26
26
|
const require_getContentDeclarationFileTemplate_getContentDeclarationFileTemplate = require('./getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs');
|
|
27
27
|
const require_init_index = require('./init/index.cjs');
|
|
28
28
|
const require_listGitFiles = require('./listGitFiles.cjs');
|
|
29
|
+
const require_listProjects = require('./listProjects.cjs');
|
|
29
30
|
const require_utils_sortAlphabetically = require('./utils/sortAlphabetically.cjs');
|
|
30
31
|
const require_loadDictionaries_loadRemoteDictionaries = require('./loadDictionaries/loadRemoteDictionaries.cjs');
|
|
31
32
|
const require_loadDictionaries_loadDictionaries = require('./loadDictionaries/loadDictionaries.cjs');
|
|
@@ -97,6 +98,7 @@ exports.listDictionaries = require_listDictionariesPath.listDictionaries;
|
|
|
97
98
|
exports.listDictionariesWithStats = require_listDictionariesPath.listDictionariesWithStats;
|
|
98
99
|
exports.listGitFiles = require_listGitFiles.listGitFiles;
|
|
99
100
|
exports.listGitLines = require_listGitFiles.listGitLines;
|
|
101
|
+
exports.listProjects = require_listProjects.listProjects;
|
|
100
102
|
exports.loadContentDeclarations = require_loadDictionaries_loadContentDeclaration.loadContentDeclarations;
|
|
101
103
|
exports.loadDictionaries = require_loadDictionaries_loadDictionaries.loadDictionaries;
|
|
102
104
|
exports.loadLocalDictionaries = require_loadDictionaries_loadLocalDictionaries.loadLocalDictionaries;
|
package/dist/cjs/init/index.cjs
CHANGED
|
@@ -7,14 +7,108 @@ let _intlayer_config = require("@intlayer/config");
|
|
|
7
7
|
|
|
8
8
|
//#region src/init/index.ts
|
|
9
9
|
/**
|
|
10
|
+
* Documentation URL Constants
|
|
11
|
+
*/
|
|
12
|
+
const DocumentationRouter = {
|
|
13
|
+
NextJS: "https://intlayer.org/doc/environment/nextjs.md",
|
|
14
|
+
NextJS_15: "https://intlayer.org/doc/environment/nextjs/15.md",
|
|
15
|
+
NextJS_14: "https://intlayer.org/doc/environment/nextjs/14.md",
|
|
16
|
+
CRA: "https://intlayer.org/doc/environment/create-react-app.md",
|
|
17
|
+
Astro: "https://intlayer.org/doc/environment/astro.md",
|
|
18
|
+
ViteAndReact: "https://intlayer.org/doc/environment/vite-and-react.md",
|
|
19
|
+
ViteAndReact_ReactRouterV7: "https://intlayer.org/doc/environment/vite-and-react/react-router-v7.md",
|
|
20
|
+
ViteAndReact_ReactRouterV7_FSRoutes: "https://intlayer.org/doc/environment/vite-and-react/react-router-v7-fs-routes.md",
|
|
21
|
+
ViteAndVue: "https://intlayer.org/doc/environment/vite-and-vue.md",
|
|
22
|
+
ViteAndSolid: "https://intlayer.org/doc/environment/vite-and-solid.md",
|
|
23
|
+
ViteAndSvelte: "https://intlayer.org/doc/environment/vite-and-svelte.md",
|
|
24
|
+
ViteAndPreact: "https://intlayer.org/doc/environment/vite-and-preact.md",
|
|
25
|
+
TanStackRouter: "https://intlayer.org/doc/environment/tanstack.md",
|
|
26
|
+
NuxtAndVue: "https://intlayer.org/doc/environment/nuxt-and-vue.md",
|
|
27
|
+
Angular: "https://intlayer.org/doc/environment/angular.md",
|
|
28
|
+
SvelteKit: "https://intlayer.org/doc/environment/sveltekit.md",
|
|
29
|
+
ReactNativeAndExpo: "https://intlayer.org/doc/environment/react-native-and-expo.md",
|
|
30
|
+
Lynx: "https://intlayer.org/doc/environment/lynx-and-react.md",
|
|
31
|
+
Express: "https://intlayer.org/doc/environment/express.md",
|
|
32
|
+
NestJS: "https://intlayer.org/doc/environment/nestjs.md",
|
|
33
|
+
Fastify: "https://intlayer.org/doc/environment/fastify.md",
|
|
34
|
+
Default: "https://intlayer.org/doc/get-started",
|
|
35
|
+
NextIntl: "https://intlayer.org/blog/intlayer-with-next-intl.md",
|
|
36
|
+
ReactI18Next: "https://intlayer.org/blog/intlayer-with-react-i18next.md",
|
|
37
|
+
ReactIntl: "https://intlayer.org/blog/intlayer-with-react-intl.md",
|
|
38
|
+
NextI18Next: "https://intlayer.org/blog/intlayer-with-next-i18next.md",
|
|
39
|
+
VueI18n: "https://intlayer.org/blog/intlayer-with-vue-i18n.md"
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Helper: Detects the environment and returns the doc URL
|
|
43
|
+
*/
|
|
44
|
+
const getDocumentationUrl = (packageJson) => {
|
|
45
|
+
const deps = {
|
|
46
|
+
...packageJson.dependencies,
|
|
47
|
+
...packageJson.devDependencies
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Helper to check if a version string matches a specific major version
|
|
51
|
+
* Matches: "15", "^15.0.0", "~15.2", "15.0.0-beta"
|
|
52
|
+
*/
|
|
53
|
+
const isVersion = (versionString, major) => {
|
|
54
|
+
if (!versionString || typeof versionString !== "string") return false;
|
|
55
|
+
return (/* @__PURE__ */ new RegExp(`^[\\^~]?${major}(?:\\.|$)`)).test(versionString);
|
|
56
|
+
};
|
|
57
|
+
if (deps["@lynx-js/react"] || deps["@lynx-js/core"]) return DocumentationRouter.Lynx;
|
|
58
|
+
if (deps["react-native"] || deps["expo"]) return DocumentationRouter.ReactNativeAndExpo;
|
|
59
|
+
if (deps["next"]) {
|
|
60
|
+
const version = deps["next"];
|
|
61
|
+
if (isVersion(version, 14)) return DocumentationRouter.NextJS_14;
|
|
62
|
+
if (isVersion(version, 15)) return DocumentationRouter.NextJS_15;
|
|
63
|
+
return DocumentationRouter.NextJS;
|
|
64
|
+
}
|
|
65
|
+
if (deps["nuxt"]) return DocumentationRouter.NuxtAndVue;
|
|
66
|
+
if (deps["astro"]) return DocumentationRouter.Astro;
|
|
67
|
+
if (deps["@sveltejs/kit"]) return DocumentationRouter.SvelteKit;
|
|
68
|
+
if (deps["@tanstack/react-router"]) return DocumentationRouter.TanStackRouter;
|
|
69
|
+
const reactRouterVersion = deps["react-router"];
|
|
70
|
+
if (reactRouterVersion && typeof reactRouterVersion === "string") {
|
|
71
|
+
if (deps["@react-router/fs-routes"]) return DocumentationRouter.ViteAndReact_ReactRouterV7_FSRoutes;
|
|
72
|
+
if (isVersion(reactRouterVersion, 7)) return DocumentationRouter.ViteAndReact_ReactRouterV7;
|
|
73
|
+
}
|
|
74
|
+
if (deps["vite"]) {
|
|
75
|
+
if (deps["vue"]) return DocumentationRouter.ViteAndVue;
|
|
76
|
+
if (deps["solid-js"]) return DocumentationRouter.ViteAndSolid;
|
|
77
|
+
if (deps["svelte"]) return DocumentationRouter.ViteAndSvelte;
|
|
78
|
+
if (deps["preact"]) return DocumentationRouter.ViteAndPreact;
|
|
79
|
+
return DocumentationRouter.ViteAndReact;
|
|
80
|
+
}
|
|
81
|
+
if (deps["react-scripts"]) return DocumentationRouter.CRA;
|
|
82
|
+
if (deps["@angular/core"]) return DocumentationRouter.Angular;
|
|
83
|
+
if (deps["@nestjs/core"]) return DocumentationRouter.NestJS;
|
|
84
|
+
if (deps["express"]) return DocumentationRouter.Express;
|
|
85
|
+
if (deps["fastify"]) return DocumentationRouter.Fastify;
|
|
86
|
+
if (deps["next-intl"]) return DocumentationRouter.NextIntl;
|
|
87
|
+
if (deps["react-i18next"] || deps["i18next"]) return DocumentationRouter.ReactI18Next;
|
|
88
|
+
if (deps["react-intl"]) return DocumentationRouter.ReactIntl;
|
|
89
|
+
if (deps["next-i18next"]) return DocumentationRouter.NextI18Next;
|
|
90
|
+
if (deps["vue-i18n"]) return DocumentationRouter.VueI18n;
|
|
91
|
+
return DocumentationRouter.Default;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
10
94
|
* MAIN LOGIC
|
|
11
95
|
*/
|
|
12
96
|
const initIntlayer = async (rootDir) => {
|
|
13
97
|
(0, _intlayer_config.logger)((0, _intlayer_config.colorize)("Checking Intlayer configuration...", _intlayer_config.ANSIColors.CYAN));
|
|
14
|
-
|
|
98
|
+
const packageJsonPath = "package.json";
|
|
99
|
+
if (!await require_init_utils_fileSystem.exists(rootDir, packageJsonPath)) {
|
|
15
100
|
(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" });
|
|
16
101
|
process.exit(1);
|
|
17
102
|
}
|
|
103
|
+
const packageJsonContent = await require_init_utils_fileSystem.readFileFromRoot(rootDir, packageJsonPath);
|
|
104
|
+
let packageJson;
|
|
105
|
+
try {
|
|
106
|
+
packageJson = JSON.parse(packageJsonContent);
|
|
107
|
+
} catch {
|
|
108
|
+
(0, _intlayer_config.logger)(`${_intlayer_config.x} Could not parse ${(0, _intlayer_config.colorizePath)("package.json")}.`, { level: "error" });
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
const guideUrl = getDocumentationUrl(packageJson);
|
|
18
112
|
const gitignorePath = ".gitignore";
|
|
19
113
|
if (await require_init_utils_fileSystem.exists(rootDir, gitignorePath)) {
|
|
20
114
|
const gitignoreContent = await require_init_utils_fileSystem.readFileFromRoot(rootDir, gitignorePath);
|
|
@@ -31,7 +125,7 @@ const initIntlayer = async (rootDir) => {
|
|
|
31
125
|
const config = require_init_utils_jsonParser.parseJSONWithComments(await require_init_utils_fileSystem.readFileFromRoot(rootDir, fileName));
|
|
32
126
|
const typeDefinition = ".intlayer/**/*.ts";
|
|
33
127
|
let updated = false;
|
|
34
|
-
if (!config.include) {} else if (Array.isArray(config.include) && !config.include.some((
|
|
128
|
+
if (!config.include) {} else if (Array.isArray(config.include) && !config.include.some((pattern) => pattern.includes(".intlayer"))) {
|
|
35
129
|
config.include.push(typeDefinition);
|
|
36
130
|
updated = true;
|
|
37
131
|
} else if (config.include.includes(typeDefinition)) (0, _intlayer_config.logger)(`${_intlayer_config.v} ${(0, _intlayer_config.colorizePath)(fileName)} already includes intlayer types`);
|
|
@@ -71,6 +165,11 @@ const initIntlayer = async (rootDir) => {
|
|
|
71
165
|
break;
|
|
72
166
|
}
|
|
73
167
|
(0, _intlayer_config.logger)(`${_intlayer_config.v} ${(0, _intlayer_config.colorize)("Intlayer init setup complete.", _intlayer_config.ANSIColors.GREEN)}`);
|
|
168
|
+
(0, _intlayer_config.logger)([
|
|
169
|
+
(0, _intlayer_config.colorize)("Next →", _intlayer_config.ANSIColors.MAGENTA),
|
|
170
|
+
(0, _intlayer_config.colorize)(`Follow the instructions in the documentation to complete the setup:`, _intlayer_config.ANSIColors.GREY_LIGHT),
|
|
171
|
+
(0, _intlayer_config.colorizePath)(guideUrl)
|
|
172
|
+
]);
|
|
74
173
|
};
|
|
75
174
|
|
|
76
175
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
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,sCAA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0BAA0B,CAAC,aACzH,EAAE,OAAO,QAAQ,CAClB;;;AAOP,OAAMM,oCADS,cAAc,uBAAuB,uBAC3B,QAAQ;AAKjC,MAAK,MAAM,QAFS;EAAC;EAAkB;EAAkB;EAAkB,CAGzE,KAAI,MAAMP,qCAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAME,+CAAiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAKtC,aAAU,wFAAkB;AAC5B,SAAMC,8CAAgB,SAAS,MAAM,QAAQ;AAC7C,gCAAO,GAAGC,mBAAE,2DAAqC,KAAK,GAAG;;AAE3D;;AAOJ,MAAK,MAAM,QAFS;EAAC;EAAkB;EAAmB;EAAiB,CAGzE,KAAI,MAAMJ,qCAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAME,+CAAiB,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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["ANSIColors","exists","x","readFileFromRoot","packageJson: Record<string, any>","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 * Documentation URL Constants\n */\nconst DocumentationRouter = {\n NextJS: 'https://intlayer.org/doc/environment/nextjs.md',\n NextJS_15: 'https://intlayer.org/doc/environment/nextjs/15.md',\n NextJS_14: 'https://intlayer.org/doc/environment/nextjs/14.md',\n CRA: 'https://intlayer.org/doc/environment/create-react-app.md',\n Astro: 'https://intlayer.org/doc/environment/astro.md',\n ViteAndReact: 'https://intlayer.org/doc/environment/vite-and-react.md',\n ViteAndReact_ReactRouterV7:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7.md',\n ViteAndReact_ReactRouterV7_FSRoutes:\n 'https://intlayer.org/doc/environment/vite-and-react/react-router-v7-fs-routes.md',\n ViteAndVue: 'https://intlayer.org/doc/environment/vite-and-vue.md',\n ViteAndSolid: 'https://intlayer.org/doc/environment/vite-and-solid.md',\n ViteAndSvelte: 'https://intlayer.org/doc/environment/vite-and-svelte.md',\n ViteAndPreact: 'https://intlayer.org/doc/environment/vite-and-preact.md',\n TanStackRouter: 'https://intlayer.org/doc/environment/tanstack.md',\n NuxtAndVue: 'https://intlayer.org/doc/environment/nuxt-and-vue.md',\n Angular: 'https://intlayer.org/doc/environment/angular.md',\n SvelteKit: 'https://intlayer.org/doc/environment/sveltekit.md',\n ReactNativeAndExpo:\n 'https://intlayer.org/doc/environment/react-native-and-expo.md',\n Lynx: 'https://intlayer.org/doc/environment/lynx-and-react.md',\n Express: 'https://intlayer.org/doc/environment/express.md',\n NestJS: 'https://intlayer.org/doc/environment/nestjs.md',\n Fastify: 'https://intlayer.org/doc/environment/fastify.md',\n Default: 'https://intlayer.org/doc/get-started',\n\n // Check for competitors libs\n NextIntl: 'https://intlayer.org/blog/intlayer-with-next-intl.md',\n ReactI18Next: 'https://intlayer.org/blog/intlayer-with-react-i18next.md',\n ReactIntl: 'https://intlayer.org/blog/intlayer-with-react-intl.md',\n NextI18Next: 'https://intlayer.org/blog/intlayer-with-next-i18next.md',\n VueI18n: 'https://intlayer.org/blog/intlayer-with-vue-i18n.md',\n};\n\n/**\n * Helper: Detects the environment and returns the doc URL\n */\nconst getDocumentationUrl = (packageJson: any): string => {\n const deps = {\n ...packageJson.dependencies,\n ...packageJson.devDependencies,\n };\n\n /**\n * Helper to check if a version string matches a specific major version\n * Matches: \"15\", \"^15.0.0\", \"~15.2\", \"15.0.0-beta\"\n */\n const isVersion = (versionString: string, major: number): boolean => {\n if (!versionString || typeof versionString !== 'string') return false;\n const regex = new RegExp(`^[\\\\^~]?${major}(?:\\\\.|$)`);\n return regex.test(versionString);\n };\n\n // Mobile / Cross-platform\n if (deps['@lynx-js/react'] || deps['@lynx-js/core']) {\n return DocumentationRouter.Lynx;\n }\n if (deps['react-native'] || deps['expo']) {\n return DocumentationRouter.ReactNativeAndExpo;\n }\n\n // Meta-frameworks (Next, Nuxt, Astro, SvelteKit)\n if (deps['next']) {\n const version = deps['next'];\n\n if (isVersion(version, 14)) {\n return DocumentationRouter.NextJS_14;\n }\n\n if (isVersion(version, 15)) {\n return DocumentationRouter.NextJS_15;\n }\n\n return DocumentationRouter.NextJS;\n }\n\n if (deps['nuxt']) return DocumentationRouter.NuxtAndVue;\n if (deps['astro']) return DocumentationRouter.Astro;\n if (deps['@sveltejs/kit']) return DocumentationRouter.SvelteKit;\n\n // Routers (TanStack & React Router v7)\n if (deps['@tanstack/react-router']) {\n return DocumentationRouter.TanStackRouter;\n }\n\n // Check for React Router v7\n const reactRouterVersion = deps['react-router'];\n if (reactRouterVersion && typeof reactRouterVersion === 'string') {\n // Distinguish between standard v7 and v7 with FS routes\n if (deps['@react-router/fs-routes']) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7_FSRoutes;\n }\n\n // Use Regex to ensure it is v7\n if (isVersion(reactRouterVersion, 7)) {\n return DocumentationRouter.ViteAndReact_ReactRouterV7;\n }\n }\n\n // Vite Ecosystem (General)\n if (deps['vite']) {\n if (deps['vue']) return DocumentationRouter.ViteAndVue;\n if (deps['solid-js']) return DocumentationRouter.ViteAndSolid;\n if (deps['svelte']) return DocumentationRouter.ViteAndSvelte;\n if (deps['preact']) return DocumentationRouter.ViteAndPreact;\n\n // Default to React if Vite is present but specific other frameworks aren't found\n return DocumentationRouter.ViteAndReact;\n }\n\n // Other Web Frameworks\n if (deps['react-scripts']) return DocumentationRouter.CRA;\n if (deps['@angular/core']) return DocumentationRouter.Angular;\n\n // Backend\n if (deps['@nestjs/core']) return DocumentationRouter.NestJS;\n if (deps['express']) return DocumentationRouter.Express;\n if (deps['fastify']) return DocumentationRouter.Fastify;\n\n // Competitor Libs (Migration Guides)\n // We check these last as specific environment setup is usually higher priority,\n // but if no specific framework logic matched (or as a fallback), we guide to migration.\n if (deps['next-intl']) return DocumentationRouter.NextIntl;\n if (deps['react-i18next'] || deps['i18next'])\n return DocumentationRouter.ReactI18Next;\n if (deps['react-intl']) return DocumentationRouter.ReactIntl;\n if (deps['next-i18next']) return DocumentationRouter.NextI18Next;\n if (deps['vue-i18n']) return DocumentationRouter.VueI18n;\n\n return DocumentationRouter.Default;\n};\n\n/**\n * MAIN LOGIC\n */\nexport const initIntlayer = async (rootDir: string) => {\n logger(colorize('Checking Intlayer configuration...', ANSIColors.CYAN));\n\n // READ PACKAGE.JSON\n const packageJsonPath = 'package.json';\n if (!(await exists(rootDir, packageJsonPath))) {\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 const packageJsonContent = await readFileFromRoot(rootDir, packageJsonPath);\n let packageJson: Record<string, any>;\n try {\n packageJson = JSON.parse(packageJsonContent);\n } catch {\n logger(`${x} Could not parse ${colorizePath('package.json')}.`, {\n level: 'error',\n });\n process.exit(1);\n }\n\n // Determine the correct documentation URL based on dependencies\n const guideUrl = getDocumentationUrl(packageJson);\n\n // 2. 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 const tsConfigFiles = await findTsConfigFiles(rootDir);\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 let updated = false;\n\n if (!config.include) {\n // Skip if no include array (solution-style)\n } else if (\n Array.isArray(config.include) &&\n !(config.include as string[]).some((pattern: string) =>\n pattern.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 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 CONFIG 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 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 content = `${viteImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // CHECK NEXT CONFIG\n const nextConfigs = ['next.config.js', 'next.config.mjs', 'next.config.ts'];\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 content = `${nextImport}\\n${content}`;\n await writeFileToRoot(rootDir, file, content);\n logger(`${v} Injected import into ${colorizePath(file)}`);\n }\n break;\n }\n }\n\n // FINAL SUCCESS MESSAGE\n logger(`${v} ${colorize('Intlayer init setup complete.', ANSIColors.GREEN)}`);\n logger([\n colorize('Next →', ANSIColors.MAGENTA),\n colorize(\n `Follow the instructions in the documentation to complete the setup:`,\n ANSIColors.GREY_LIGHT\n ),\n colorizePath(guideUrl),\n ]);\n};\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,sBAAsB;CAC1B,QAAQ;CACR,WAAW;CACX,WAAW;CACX,KAAK;CACL,OAAO;CACP,cAAc;CACd,4BACE;CACF,qCACE;CACF,YAAY;CACZ,cAAc;CACd,eAAe;CACf,eAAe;CACf,gBAAgB;CAChB,YAAY;CACZ,SAAS;CACT,WAAW;CACX,oBACE;CACF,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CAGT,UAAU;CACV,cAAc;CACd,WAAW;CACX,aAAa;CACb,SAAS;CACV;;;;AAKD,MAAM,uBAAuB,gBAA6B;CACxD,MAAM,OAAO;EACX,GAAG,YAAY;EACf,GAAG,YAAY;EAChB;;;;;CAMD,MAAM,aAAa,eAAuB,UAA2B;AACnE,MAAI,CAAC,iBAAiB,OAAO,kBAAkB,SAAU,QAAO;AAEhE,0BADc,IAAI,OAAO,WAAW,MAAM,WAAW,EACxC,KAAK,cAAc;;AAIlC,KAAI,KAAK,qBAAqB,KAAK,iBACjC,QAAO,oBAAoB;AAE7B,KAAI,KAAK,mBAAmB,KAAK,QAC/B,QAAO,oBAAoB;AAI7B,KAAI,KAAK,SAAS;EAChB,MAAM,UAAU,KAAK;AAErB,MAAI,UAAU,SAAS,GAAG,CACxB,QA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AAK,UAAU,QAAQ,MAAM,EAAE,CAChC;AACD,iCACE,GAAGC,mBAAE,8CAAwB,SAAS,CAAC,4BACxC;;UAEG;AACN,gCACE,GAAGJ,mBAAE,gEAA0C,SAAS,CAAC,2DAAqC,0BAA0B,CAAC,aACzH,EAAE,OAAO,QAAQ,CAClB;;;AAOP,OAAMO,oCADS,cAAc,uBAAuB,uBAC3B,QAAQ;AAIjC,MAAK,MAAM,QADS;EAAC;EAAkB;EAAkB;EAAkB,CAEzE,KAAI,MAAMR,qCAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAME,+CAAiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAItC,aAAU,wFAAkB;AAC5B,SAAME,8CAAgB,SAAS,MAAM,QAAQ;AAC7C,gCAAO,GAAGC,mBAAE,2DAAqC,KAAK,GAAG;;AAE3D;;AAMJ,MAAK,MAAM,QADS;EAAC;EAAkB;EAAmB;EAAiB,CAEzE,KAAI,MAAML,qCAAO,SAAS,KAAK,EAAE;EAC/B,IAAI,UAAU,MAAME,+CAAiB,SAAS,KAAK;AAEnD,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAE;AAItC,aAAU,iGAAkB;AAC5B,SAAME,8CAAgB,SAAS,MAAM,QAAQ;AAC7C,gCAAO,GAAGC,mBAAE,2DAAqC,KAAK,GAAG;;AAE3D;;AAKJ,8BAAO,GAAGA,mBAAE,kCAAY,iCAAiCN,4BAAW,MAAM,GAAG;AAC7E,8BAAO;iCACI,UAAUA,4BAAW,QAAQ;iCAEpC,uEACAA,4BAAW,WACZ;qCACY,SAAS;EACvB,CAAC"}
|
|
@@ -10,7 +10,22 @@ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
|
|
|
10
10
|
* @returns An array of dictionary paths
|
|
11
11
|
*/
|
|
12
12
|
const listDictionaries = async (configuration) => {
|
|
13
|
-
|
|
13
|
+
const { watchedFilesPatternWithPath, excludedPath } = configuration.content;
|
|
14
|
+
const filePromises = watchedFilesPatternWithPath.map(async (pattern) => {
|
|
15
|
+
const magicIndex = pattern.search(/[*?{}(]/);
|
|
16
|
+
const basePattern = magicIndex > -1 ? pattern.slice(0, magicIndex) : pattern;
|
|
17
|
+
return (0, fast_glob.default)(pattern, {
|
|
18
|
+
ignore: excludedPath.filter((excludePattern) => {
|
|
19
|
+
const cleanName = excludePattern.replace(/\*\*/g, "").replace(/\//g, "");
|
|
20
|
+
if (cleanName && basePattern.includes(`/${cleanName}/`)) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}),
|
|
23
|
+
absolute: true,
|
|
24
|
+
dot: true
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
const filesArrays = await Promise.all(filePromises);
|
|
28
|
+
return Array.from(new Set(filesArrays.flat()));
|
|
14
29
|
};
|
|
15
30
|
const listDictionariesWithStats = async (configuration) => {
|
|
16
31
|
const files = await listDictionaries(configuration);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listDictionariesPath.cjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const
|
|
1
|
+
{"version":3,"file":"listDictionariesPath.cjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const { watchedFilesPatternWithPath, excludedPath } = configuration.content;\n\n const filePromises = watchedFilesPatternWithPath.map(async (pattern) => {\n // Identify the static part of the path (before any wildcards like *)\n // e.g. \"/Users/.../design-system/dist/esm/**/*.content.ts\" -> \"/Users/.../design-system/dist/esm/\"\n const magicIndex = pattern.search(/[*?{}(]/);\n const basePattern =\n magicIndex > -1 ? pattern.slice(0, magicIndex) : pattern;\n\n // Filter the global ignored list for this specific pattern\n const applicableIgnore = excludedPath.filter((excludePattern) => {\n // Heuristic: Extract the key directory name from the glob\n // e.g. \"**/dist/**\" -> \"dist\", \"**/node_modules/**\" -> \"node_modules\"\n const cleanName = excludePattern.replace(/\\*\\*/g, '').replace(/\\//g, '');\n\n // If the explicit base path contains the excluded directory (e.g. \".../dist/...\"),\n // we assume you explicitly want it, so we REMOVE it from the ignore list.\n // We check for `/${cleanName}/` to ensure we match whole folder names.\n if (cleanName && basePattern.includes(`/${cleanName}/`)) {\n return false; // Drop this exclude rule\n }\n\n return true; // Keep this exclude rule\n });\n\n // Run fast-glob with the customized ignore list\n return fg(pattern, {\n ignore: applicableIgnore,\n absolute: true,\n dot: true,\n });\n });\n\n const filesArrays = await Promise.all(filePromises);\n\n // Flatten and deduplicate\n const uniqueFiles = Array.from(new Set(filesArrays.flat()));\n\n return uniqueFiles;\n};\n\nexport const listDictionariesWithStats = async (\n configuration: IntlayerConfig\n) => {\n const files = await listDictionaries(configuration);\n\n return Promise.all(\n files.map(async (file) => ({ path: file, stats: await stat(file) }))\n );\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAa,mBAAmB,OAC9B,kBACsB;CACtB,MAAM,EAAE,6BAA6B,iBAAiB,cAAc;CAEpE,MAAM,eAAe,4BAA4B,IAAI,OAAO,YAAY;EAGtE,MAAM,aAAa,QAAQ,OAAO,UAAU;EAC5C,MAAM,cACJ,aAAa,KAAK,QAAQ,MAAM,GAAG,WAAW,GAAG;AAmBnD,gCAAU,SAAS;GACjB,QAjBuB,aAAa,QAAQ,mBAAmB;IAG/D,MAAM,YAAY,eAAe,QAAQ,SAAS,GAAG,CAAC,QAAQ,OAAO,GAAG;AAKxE,QAAI,aAAa,YAAY,SAAS,IAAI,UAAU,GAAG,CACrD,QAAO;AAGT,WAAO;KACP;GAKA,UAAU;GACV,KAAK;GACN,CAAC;GACF;CAEF,MAAM,cAAc,MAAM,QAAQ,IAAI,aAAa;AAKnD,QAFoB,MAAM,KAAK,IAAI,IAAI,YAAY,MAAM,CAAC,CAAC;;AAK7D,MAAa,4BAA4B,OACvC,kBACG;CACH,MAAM,QAAQ,MAAM,iBAAiB,cAAc;AAEnD,QAAO,QAAQ,IACb,MAAM,IAAI,OAAO,UAAU;EAAE,MAAM;EAAM,OAAO,iCAAW,KAAK;EAAE,EAAE,CACrE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
let fast_glob = require("fast-glob");
|
|
4
|
+
fast_glob = require_rolldown_runtime.__toESM(fast_glob);
|
|
5
|
+
let _intlayer_config = require("@intlayer/config");
|
|
6
|
+
let simple_git = require("simple-git");
|
|
7
|
+
simple_git = require_rolldown_runtime.__toESM(simple_git);
|
|
8
|
+
|
|
9
|
+
//#region src/listProjects.ts
|
|
10
|
+
/**
|
|
11
|
+
* Get the git root directory
|
|
12
|
+
*/
|
|
13
|
+
const getGitRootDir = async (cwd) => {
|
|
14
|
+
try {
|
|
15
|
+
return (await (cwd ? (0, simple_git.default)(cwd) : (0, simple_git.default)()).revparse(["--show-toplevel"])).trim();
|
|
16
|
+
} catch (_error) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* List all Intlayer projects by searching for configuration files
|
|
22
|
+
*
|
|
23
|
+
* @param options - Options for listing projects
|
|
24
|
+
* @returns Array of absolute paths to project directories containing Intlayer config
|
|
25
|
+
*/
|
|
26
|
+
const listProjects = async (options) => {
|
|
27
|
+
let searchDir = options?.baseDir ?? process.cwd();
|
|
28
|
+
if (options?.gitRoot) {
|
|
29
|
+
const gitRootDir = await getGitRootDir(searchDir);
|
|
30
|
+
if (gitRootDir) searchDir = gitRootDir;
|
|
31
|
+
}
|
|
32
|
+
const configFiles = await (0, fast_glob.default)(_intlayer_config.configurationFilesCandidates.map((fileName) => `**/${fileName}`), {
|
|
33
|
+
cwd: searchDir,
|
|
34
|
+
absolute: true,
|
|
35
|
+
ignore: ["**/node_modules/**", "**/.git/**"],
|
|
36
|
+
dot: true
|
|
37
|
+
});
|
|
38
|
+
const projectDirs = [...new Set(configFiles.map((file) => (0, node_path.dirname)(file)))];
|
|
39
|
+
return {
|
|
40
|
+
searchDir,
|
|
41
|
+
projectsPath: projectDirs.sort()
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.listProjects = listProjects;
|
|
47
|
+
//# sourceMappingURL=listProjects.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listProjects.cjs","names":["configurationFilesCandidates"],"sources":["../../src/listProjects.ts"],"sourcesContent":["import { dirname } from 'node:path';\nimport { configurationFilesCandidates } from '@intlayer/config';\nimport fg from 'fast-glob';\nimport simpleGit from 'simple-git';\n\nexport type ListProjectsOptions = {\n /**\n * Base directory to search from\n * @default process.cwd()\n */\n baseDir?: string;\n /**\n * If true, search from the git root directory instead of baseDir\n * @default false\n */\n gitRoot?: boolean;\n};\n\n/**\n * Get the git root directory\n */\nconst getGitRootDir = async (cwd?: string): Promise<string | null> => {\n try {\n const git = cwd ? simpleGit(cwd) : simpleGit();\n const rootDir = await git.revparse(['--show-toplevel']);\n return rootDir.trim();\n } catch (_error) {\n return null;\n }\n};\n\n/**\n * List all Intlayer projects by searching for configuration files\n *\n * @param options - Options for listing projects\n * @returns Array of absolute paths to project directories containing Intlayer config\n */\nexport const listProjects = async (\n options?: ListProjectsOptions\n): Promise<{ searchDir: string; projectsPath: string[] }> => {\n let searchDir = options?.baseDir ?? process.cwd();\n\n // If gitRoot option is enabled, try to get the git root directory\n if (options?.gitRoot) {\n const gitRootDir = await getGitRootDir(searchDir);\n if (gitRootDir) {\n searchDir = gitRootDir;\n }\n }\n\n // Build glob patterns for all config file candidates\n const configPatterns = configurationFilesCandidates.map(\n (fileName) => `**/${fileName}`\n );\n\n // Search for all config files\n const configFiles = await fg(configPatterns, {\n cwd: searchDir,\n absolute: true,\n ignore: ['**/node_modules/**', '**/.git/**'],\n dot: true, // Include dot files like .intlayerrc\n });\n\n // Extract unique directory paths from config files\n const projectDirs = [...new Set(configFiles.map((file) => dirname(file)))];\n\n // Sort alphabetically for consistent output\n return { searchDir, projectsPath: projectDirs.sort() };\n};\n"],"mappings":";;;;;;;;;;;;AAqBA,MAAM,gBAAgB,OAAO,QAAyC;AACpE,KAAI;AAGF,UADgB,OADJ,8BAAgB,IAAI,4BAAc,EACpB,SAAS,CAAC,kBAAkB,CAAC,EACxC,MAAM;UACd,QAAQ;AACf,SAAO;;;;;;;;;AAUX,MAAa,eAAe,OAC1B,YAC2D;CAC3D,IAAI,YAAY,SAAS,WAAW,QAAQ,KAAK;AAGjD,KAAI,SAAS,SAAS;EACpB,MAAM,aAAa,MAAM,cAAc,UAAU;AACjD,MAAI,WACF,aAAY;;CAUhB,MAAM,cAAc,6BALGA,8CAA6B,KACjD,aAAa,MAAM,WACrB,EAG4C;EAC3C,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,sBAAsB,aAAa;EAC5C,KAAK;EACN,CAAC;CAGF,MAAM,cAAc,CAAC,GAAG,IAAI,IAAI,YAAY,KAAK,gCAAiB,KAAK,CAAC,CAAC,CAAC;AAG1E,QAAO;EAAE;EAAW,cAAc,YAAY,MAAM;EAAE"}
|
|
@@ -78,26 +78,17 @@ const loadDictionaries = async (contentDeclarationsPaths, configuration) => {
|
|
|
78
78
|
const { plugins } = configuration;
|
|
79
79
|
const loadDictionariesStartTime = Date.now();
|
|
80
80
|
(0, _intlayer_config_client.getAppLogger)(configuration)("Dictionaries:", { isVerbose: true });
|
|
81
|
-
const
|
|
82
|
-
logger.setPluginTotal(pluginsWithLoadDictionaries.length);
|
|
83
|
-
const completedPluginIndices = /* @__PURE__ */ new Set();
|
|
84
|
-
const updatePluginProgress = () => {
|
|
85
|
-
logger.setPluginDone(completedPluginIndices.size);
|
|
86
|
-
};
|
|
87
|
-
const loadPluginDictionariesPromise = pluginsWithLoadDictionaries.map(async (plugin, index) => {
|
|
81
|
+
const loadPluginDictionariesPromise = (plugins ?? []).filter((plugin) => plugin.loadDictionaries).map(async (plugin, index) => {
|
|
88
82
|
try {
|
|
89
|
-
|
|
90
|
-
completedPluginIndices.add(index);
|
|
91
|
-
updatePluginProgress();
|
|
92
|
-
return res ?? [];
|
|
83
|
+
return await plugin.loadDictionaries?.({ configuration }) ?? [];
|
|
93
84
|
} catch (error) {
|
|
94
85
|
logger.setPluginError(error);
|
|
95
|
-
completedPluginIndices.add(index);
|
|
96
|
-
updatePluginProgress();
|
|
97
86
|
return [];
|
|
98
87
|
}
|
|
99
88
|
});
|
|
100
89
|
const pluginDictionaries = await Promise.all(loadPluginDictionariesPromise).then((dictionaries) => dictionaries.flat()).then((dictionaries) => require_filterInvalidDictionaries.filterInvalidDictionaries(dictionaries, configuration)).then((dictionaries) => require_formatDictionary.formatDictionaries(dictionaries));
|
|
90
|
+
logger.setPluginTotal(pluginDictionaries.length);
|
|
91
|
+
logger.setPluginDone(pluginDictionaries.length);
|
|
101
92
|
const pluginDictionariesTime = Date.now();
|
|
102
93
|
const localDictionaries = await require_loadDictionaries_loadContentDeclaration.loadContentDeclarations(Array.isArray(contentDeclarationsPaths) ? contentDeclarationsPaths : [contentDeclarationsPaths], configuration, setLoadDictionariesStatus).then((dictionaries) => require_filterInvalidDictionaries.filterInvalidDictionaries(dictionaries, configuration)).then((dictionaries) => require_formatDictionary.formatDictionaries(dictionaries));
|
|
103
94
|
const localDictionariesTime = Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadDictionaries.cjs","names":["loadDictionariesStatus: DictionariesStatus[]","DictionariesLogger","updated: DictionariesStatus[]","ANSIColors","labels: string[]","pluginDictionaries: Dictionary[]","filterInvalidDictionaries","formatDictionaries","localDictionaries: Dictionary[]","loadContentDeclarations","remoteDictionaries: Dictionary[]","loadRemoteDictionaries"],"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["import {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n getAppLogger,\n} from '@intlayer/config/client';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { formatDictionaries } from '../formatDictionary';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadRemoteDictionaries } from './loadRemoteDictionaries';\nimport { DictionariesLogger } from './log';\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n type: 'local' | 'remote';\n status:\n | 'pending' // Key found but not fetched yet\n | 'fetching' // If dictionary fetch is in progress\n | 'fetched' // If dictionary fetch succeeded\n | 'error' // If dictionary fetch failed\n | 'imported' // If dictionary already fetched and still up to date\n | 'found' // If dictionary key is found but promise is not resolved yet (ex: fetching distant content)\n | 'building' // If dictionary is being built\n | 'built'; // If dictionary is built;\n error?: string;\n};\n\nlet loadDictionariesStatus: DictionariesStatus[] = [];\nconst logger = new DictionariesLogger();\n\nconst setLoadDictionariesStatus = (statuses: DictionariesStatus[]) => {\n const updated: DictionariesStatus[] = [...loadDictionariesStatus];\n\n for (const incoming of statuses) {\n const index = updated.findIndex(\n (s) =>\n s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type\n );\n if (index >= 0) {\n updated[index] = incoming;\n } else {\n updated.push(incoming);\n }\n }\n\n loadDictionariesStatus = updated;\n logger.update(statuses);\n\n return updated;\n};\n\ntype StatusRecord = {\n local?: DictionariesStatus['status'];\n remote?: DictionariesStatus['status'];\n};\n\nconst iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n};\n\nconst colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n};\n\nconst printSummary = (configuration: IntlayerConfig) => {\n if (configuration.log.mode !== 'verbose') return;\n\n const appLogger = getAppLogger(configuration);\n\n // Aggregate by dictionary key\n const byKey = new Map<string, StatusRecord>();\n for (const status of loadDictionariesStatus) {\n const rec = byKey.get(status.dictionaryKey) ?? {};\n if (status.type === 'local') rec.local = status.status;\n if (status.type === 'remote') rec.remote = status.status;\n byKey.set(status.dictionaryKey, rec);\n }\n\n const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));\n\n // Compute the max visible length of the local label to align distant labels\n let maxLocalLabelLen = 0;\n for (const key of keys) {\n const rec = byKey.get(key)!;\n if (rec.local) {\n const visibleLocal = `[local: ${iconFor(rec.local)} ${rec.local}]`;\n if (visibleLocal.length > maxLocalLabelLen) {\n maxLocalLabelLen = visibleLocal.length;\n }\n }\n }\n\n for (const key of keys) {\n const rec = byKey.get(key)!;\n const labels: string[] = [];\n\n if (rec.local) {\n const inner = colorize(\n `${iconFor(rec.local)} ${rec.local}`,\n colorFor(rec.local)\n );\n const coloredLocal =\n `${ANSIColors.GREY}[` +\n colorize('local: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`;\n\n // Pad to align distant label across rows\n const visibleLocal = `[local: ${iconFor(rec.local)} ${rec.local}]`;\n const pad = Math.max(0, maxLocalLabelLen - visibleLocal.length);\n labels.push(coloredLocal + ' '.repeat(pad));\n } else {\n // If no local label, insert spaces to keep distant aligned\n labels.push(' '.repeat(maxLocalLabelLen));\n }\n\n if (rec.remote) {\n const inner = colorize(\n `${iconFor(rec.remote)} ${rec.remote}`,\n colorFor(rec.remote)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('distant: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n appLogger(\n ` - ${colon(colorizeKey(key), { colSize: keys })} ${labels.join(' ')}`\n );\n }\n};\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration: IntlayerConfig\n): Promise<{\n localDictionaries: Dictionary[];\n remoteDictionaries: Dictionary[];\n pluginDictionaries: Dictionary[];\n time: {\n localDictionaries: number;\n remoteDictionaries: number;\n pluginDictionaries: number;\n };\n}> => {\n const { plugins } = configuration;\n const loadDictionariesStartTime = Date.now();\n const appLogger = getAppLogger(configuration);\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n // Load additional dictionaries via plugins (e.g., ICU JSON ingestion)\n const pluginsWithLoadDictionaries = (plugins ?? []).filter(\n (plugin) => plugin.loadDictionaries\n );\n\n logger.setPluginTotal(pluginsWithLoadDictionaries.length);\n\n const completedPluginIndices = new Set<number>();\n const updatePluginProgress = () => {\n logger.setPluginDone(completedPluginIndices.size);\n };\n\n const loadPluginDictionariesPromise = pluginsWithLoadDictionaries.map(\n async (plugin, index) => {\n try {\n const res = await plugin.loadDictionaries?.({\n configuration,\n });\n completedPluginIndices.add(index);\n updatePluginProgress();\n return (res as Dictionary[] | undefined) ?? [];\n } catch (error) {\n logger.setPluginError(error as Error);\n completedPluginIndices.add(index);\n updatePluginProgress();\n return [];\n }\n }\n );\n\n const pluginDictionaries: Dictionary[] = await Promise.all(\n loadPluginDictionariesPromise as Promise<Dictionary[]>[]\n )\n .then((dictionaries) => dictionaries.flat())\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n\n const pluginDictionariesTime = Date.now();\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n configuration,\n setLoadDictionariesStatus\n )\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n\n const localDictionariesTime = Date.now();\n\n const localDictionariesStatus = localDictionaries.map(\n (dictionary) =>\n ({\n dictionaryKey: dictionary.key,\n type: 'local',\n status: 'built',\n }) as const\n );\n\n setLoadDictionariesStatus(localDictionariesStatus);\n\n const hasRemoteDictionaries = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n\n if (hasRemoteDictionaries) {\n // We expect to fetch remote dictionaries soon; suppress a transient local-only render\n logger.setExpectRemote(true);\n }\n\n let remoteDictionaries: Dictionary[] = [];\n\n if (hasRemoteDictionaries) {\n remoteDictionaries = await loadRemoteDictionaries(\n configuration,\n setLoadDictionariesStatus,\n {\n onStartRemoteCheck: () => logger.startRemoteCheck(),\n onStopRemoteCheck: () => logger.stopRemoteCheck(),\n onError: (e) => logger.setRemoteError(e),\n }\n )\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n }\n\n const remoteDictionariesTime = Date.now();\n\n // Stop spinner and show final progress line(s)\n logger.finish();\n\n printSummary(configuration);\n\n return {\n localDictionaries,\n remoteDictionaries,\n pluginDictionaries,\n time: {\n localDictionaries: localDictionariesTime - pluginDictionariesTime,\n remoteDictionaries: remoteDictionariesTime - localDictionariesTime,\n pluginDictionaries: pluginDictionariesTime - loadDictionariesStartTime,\n },\n };\n};\n"],"mappings":";;;;;;;;;AA6BA,IAAIA,yBAA+C,EAAE;AACrD,MAAM,SAAS,IAAIC,iDAAoB;AAEvC,MAAM,6BAA6B,aAAmC;CACpE,MAAMC,UAAgC,CAAC,GAAG,uBAAuB;AAEjE,MAAK,MAAM,YAAY,UAAU;EAC/B,MAAM,QAAQ,QAAQ,WACnB,MACC,EAAE,kBAAkB,SAAS,iBAAiB,EAAE,SAAS,SAAS,KACrE;AACD,MAAI,SAAS,EACX,SAAQ,SAAS;MAEjB,SAAQ,KAAK,SA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BAAuB,IAAI,MAAM;AACjC,yBAAsB;AACtB,UAAO,EAAE;;GAGd;CAED,MAAME,qBAAmC,MAAM,QAAQ,IACrD,8BACD,CACE,MAAM,iBAAiB,aAAa,MAAM,CAAC,CAC3C,MAAM,iBACLC,4DAA0B,cAAc,cAAc,CACvD,CACA,MAAM,iBAAiBC,4CAAmB,aAAa,CAAC;CAE3D,MAAM,yBAAyB,KAAK,KAAK;CAMzC,MAAMC,oBAAkC,MAAMC,wEAJhC,MAAM,QAAQ,yBAAyB,GACjD,2BACA,CAAC,yBAAyB,EAI5B,eACA,0BACD,CACE,MAAM,iBACLH,4DAA0B,cAAc,cAAc,CACvD,CACA,MAAM,iBAAiBC,4CAAmB,aAAa,CAAC;CAE3D,MAAM,wBAAwB,KAAK,KAAK;AAWxC,2BATgC,kBAAkB,KAC/C,gBACE;EACC,eAAe,WAAW;EAC1B,MAAM;EACN,QAAQ;EACT,EACJ,CAEiD;CAElD,MAAM,wBAAwB,QAC5B,cAAc,OAAO,YAAY,cAAc,OAAO,aACvD;AAED,KAAI,sBAEF,QAAO,gBAAgB,KAAK;CAG9B,IAAIG,qBAAmC,EAAE;AAEzC,KAAI,sBACF,sBAAqB,MAAMC,uEACzB,eACA,2BACA;EACE,0BAA0B,OAAO,kBAAkB;EACnD,yBAAyB,OAAO,iBAAiB;EACjD,UAAU,MAAM,OAAO,eAAe,EAAE;EACzC,CACF,CACE,MAAM,iBACLL,4DAA0B,cAAc,cAAc,CACvD,CACA,MAAM,iBAAiBC,4CAAmB,aAAa,CAAC;CAG7D,MAAM,yBAAyB,KAAK,KAAK;AAGzC,QAAO,QAAQ;AAEf,cAAa,cAAc;AAE3B,QAAO;EACL;EACA;EACA;EACA,MAAM;GACJ,mBAAmB,wBAAwB;GAC3C,oBAAoB,yBAAyB;GAC7C,oBAAoB,yBAAyB;GAC9C;EACF"}
|
|
1
|
+
{"version":3,"file":"loadDictionaries.cjs","names":["loadDictionariesStatus: DictionariesStatus[]","DictionariesLogger","updated: DictionariesStatus[]","ANSIColors","labels: string[]","pluginDictionaries: Dictionary[]","filterInvalidDictionaries","formatDictionaries","localDictionaries: Dictionary[]","loadContentDeclarations","remoteDictionaries: Dictionary[]","loadRemoteDictionaries"],"sources":["../../../src/loadDictionaries/loadDictionaries.ts"],"sourcesContent":["import {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n getAppLogger,\n} from '@intlayer/config/client';\nimport type { Dictionary, IntlayerConfig } from '@intlayer/types';\nimport { filterInvalidDictionaries } from '../filterInvalidDictionaries';\nimport { formatDictionaries } from '../formatDictionary';\nimport { loadContentDeclarations } from './loadContentDeclaration';\nimport { loadRemoteDictionaries } from './loadRemoteDictionaries';\nimport { DictionariesLogger } from './log';\n\nexport type DictionariesStatus = {\n dictionaryKey: string;\n type: 'local' | 'remote';\n status:\n | 'pending' // Key found but not fetched yet\n | 'fetching' // If dictionary fetch is in progress\n | 'fetched' // If dictionary fetch succeeded\n | 'error' // If dictionary fetch failed\n | 'imported' // If dictionary already fetched and still up to date\n | 'found' // If dictionary key is found but promise is not resolved yet (ex: fetching distant content)\n | 'building' // If dictionary is being built\n | 'built'; // If dictionary is built;\n error?: string;\n};\n\nlet loadDictionariesStatus: DictionariesStatus[] = [];\nconst logger = new DictionariesLogger();\n\nconst setLoadDictionariesStatus = (statuses: DictionariesStatus[]) => {\n const updated: DictionariesStatus[] = [...loadDictionariesStatus];\n\n for (const incoming of statuses) {\n const index = updated.findIndex(\n (s) =>\n s.dictionaryKey === incoming.dictionaryKey && s.type === incoming.type\n );\n if (index >= 0) {\n updated[index] = incoming;\n } else {\n updated.push(incoming);\n }\n }\n\n loadDictionariesStatus = updated;\n logger.update(statuses);\n\n return updated;\n};\n\ntype StatusRecord = {\n local?: DictionariesStatus['status'];\n remote?: DictionariesStatus['status'];\n};\n\nconst iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n};\n\nconst colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'built':\n case 'imported':\n case 'fetched':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n};\n\nconst printSummary = (configuration: IntlayerConfig) => {\n if (configuration.log.mode !== 'verbose') return;\n\n const appLogger = getAppLogger(configuration);\n\n // Aggregate by dictionary key\n const byKey = new Map<string, StatusRecord>();\n for (const status of loadDictionariesStatus) {\n const rec = byKey.get(status.dictionaryKey) ?? {};\n if (status.type === 'local') rec.local = status.status;\n if (status.type === 'remote') rec.remote = status.status;\n byKey.set(status.dictionaryKey, rec);\n }\n\n const keys = Array.from(byKey.keys()).sort((a, b) => a.localeCompare(b));\n\n // Compute the max visible length of the local label to align distant labels\n let maxLocalLabelLen = 0;\n for (const key of keys) {\n const rec = byKey.get(key)!;\n if (rec.local) {\n const visibleLocal = `[local: ${iconFor(rec.local)} ${rec.local}]`;\n if (visibleLocal.length > maxLocalLabelLen) {\n maxLocalLabelLen = visibleLocal.length;\n }\n }\n }\n\n for (const key of keys) {\n const rec = byKey.get(key)!;\n const labels: string[] = [];\n\n if (rec.local) {\n const inner = colorize(\n `${iconFor(rec.local)} ${rec.local}`,\n colorFor(rec.local)\n );\n const coloredLocal =\n `${ANSIColors.GREY}[` +\n colorize('local: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`;\n\n // Pad to align distant label across rows\n const visibleLocal = `[local: ${iconFor(rec.local)} ${rec.local}]`;\n const pad = Math.max(0, maxLocalLabelLen - visibleLocal.length);\n labels.push(coloredLocal + ' '.repeat(pad));\n } else {\n // If no local label, insert spaces to keep distant aligned\n labels.push(' '.repeat(maxLocalLabelLen));\n }\n\n if (rec.remote) {\n const inner = colorize(\n `${iconFor(rec.remote)} ${rec.remote}`,\n colorFor(rec.remote)\n );\n labels.push(\n `${ANSIColors.GREY}[` +\n colorize('distant: ', ANSIColors.GREY) +\n inner +\n `${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n appLogger(\n ` - ${colon(colorizeKey(key), { colSize: keys })} ${labels.join(' ')}`\n );\n }\n};\n\nexport const loadDictionaries = async (\n contentDeclarationsPaths: string[] | string,\n configuration: IntlayerConfig\n): Promise<{\n localDictionaries: Dictionary[];\n remoteDictionaries: Dictionary[];\n pluginDictionaries: Dictionary[];\n time: {\n localDictionaries: number;\n remoteDictionaries: number;\n pluginDictionaries: number;\n };\n}> => {\n const { plugins } = configuration;\n const loadDictionariesStartTime = Date.now();\n const appLogger = getAppLogger(configuration);\n\n appLogger('Dictionaries:', { isVerbose: true });\n\n // Load additional dictionaries via plugins (e.g., ICU JSON ingestion)\n const pluginsWithLoadDictionaries = (plugins ?? []).filter(\n (plugin) => plugin.loadDictionaries\n );\n\n const loadPluginDictionariesPromise = pluginsWithLoadDictionaries.map(\n async (plugin, index) => {\n try {\n const res = await plugin.loadDictionaries?.({\n configuration,\n });\n\n return (res as Dictionary[] | undefined) ?? [];\n } catch (error) {\n logger.setPluginError(error as Error);\n\n return [];\n }\n }\n );\n\n const pluginDictionaries: Dictionary[] = await Promise.all(\n loadPluginDictionariesPromise as Promise<Dictionary[]>[]\n )\n .then((dictionaries) => dictionaries.flat())\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n\n logger.setPluginTotal(pluginDictionaries.length);\n logger.setPluginDone(pluginDictionaries.length);\n\n const pluginDictionariesTime = Date.now();\n\n const files = Array.isArray(contentDeclarationsPaths)\n ? contentDeclarationsPaths\n : [contentDeclarationsPaths];\n\n const localDictionaries: Dictionary[] = await loadContentDeclarations(\n files,\n configuration,\n setLoadDictionariesStatus\n )\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n\n const localDictionariesTime = Date.now();\n\n const localDictionariesStatus = localDictionaries.map(\n (dictionary) =>\n ({\n dictionaryKey: dictionary.key,\n type: 'local',\n status: 'built',\n }) as const\n );\n\n setLoadDictionariesStatus(localDictionariesStatus);\n\n const hasRemoteDictionaries = Boolean(\n configuration.editor.clientId && configuration.editor.clientSecret\n );\n\n if (hasRemoteDictionaries) {\n // We expect to fetch remote dictionaries soon; suppress a transient local-only render\n logger.setExpectRemote(true);\n }\n\n let remoteDictionaries: Dictionary[] = [];\n\n if (hasRemoteDictionaries) {\n remoteDictionaries = await loadRemoteDictionaries(\n configuration,\n setLoadDictionariesStatus,\n {\n onStartRemoteCheck: () => logger.startRemoteCheck(),\n onStopRemoteCheck: () => logger.stopRemoteCheck(),\n onError: (e) => logger.setRemoteError(e),\n }\n )\n .then((dictionaries) =>\n filterInvalidDictionaries(dictionaries, configuration)\n )\n .then((dictionaries) => formatDictionaries(dictionaries));\n }\n\n const remoteDictionariesTime = Date.now();\n\n // Stop spinner and show final progress line(s)\n logger.finish();\n\n printSummary(configuration);\n\n return {\n localDictionaries,\n remoteDictionaries,\n pluginDictionaries,\n time: {\n localDictionaries: localDictionariesTime - pluginDictionariesTime,\n remoteDictionaries: remoteDictionariesTime - localDictionariesTime,\n pluginDictionaries: pluginDictionariesTime - loadDictionariesStartTime,\n },\n };\n};\n"],"mappings":";;;;;;;;;AA6BA,IAAIA,yBAA+C,EAAE;AACrD,MAAM,SAAS,IAAIC,iDAAoB;AAEvC,MAAM,6BAA6B,aAAmC;CACpE,MAAMC,UAAgC,CAAC,GAAG,uBAAuB;AAEjE,MAAK,MAAM,YAAY,UAAU;EAC/B,MAAM,QAAQ,QAAQ,WACnB,MACC,EAAE,kBAAkB,SAAS,iBAAiB,EAAE,SAAS,SAAS,KACrE;AACD,MAAI,SAAS,EACX,SAAQ,SAAS;MAEjB,SAAQ,KAAK,SAAS;;AAI1B,0BAAyB;AACzB,QAAO,OAAO,SAAS;AAEvB,QAAO;;AAQT,MAAM,WAAW,WAAyC;AACxD,SAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KA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,QAAQ,yBAAyB,GACjD,2BACA,CAAC,yBAAyB,EAI5B,eACA,0BACD,CACE,MAAM,iBACLH,4DAA0B,cAAc,cAAc,CACvD,CACA,MAAM,iBAAiBC,4CAAmB,aAAa,CAAC;CAE3D,MAAM,wBAAwB,KAAK,KAAK;AAWxC,2BATgC,kBAAkB,KAC/C,gBACE;EACC,eAAe,WAAW;EAC1B,MAAM;EACN,QAAQ;EACT,EACJ,CAEiD;CAElD,MAAM,wBAAwB,QAC5B,cAAc,OAAO,YAAY,cAAc,OAAO,aACvD;AAED,KAAI,sBAEF,QAAO,gBAAgB,KAAK;CAG9B,IAAIG,qBAAmC,EAAE;AAEzC,KAAI,sBACF,sBAAqB,MAAMC,uEACzB,eACA,2BACA;EACE,0BAA0B,OAAO,kBAAkB;EACnD,yBAAyB,OAAO,iBAAiB;EACjD,UAAU,MAAM,OAAO,eAAe,EAAE;EACzC,CACF,CACE,MAAM,iBACLL,4DAA0B,cAAc,cAAc,CACvD,CACA,MAAM,iBAAiBC,4CAAmB,aAAa,CAAC;CAG7D,MAAM,yBAAyB,KAAK,KAAK;AAGzC,QAAO,QAAQ;AAEf,cAAa,cAAc;AAE3B,QAAO;EACL;EACA;EACA;EACA,MAAM;GACJ,mBAAmB,wBAAwB;GAC3C,oBAAoB,yBAAyB;GAC7C,oBAAoB,yBAAyB;GAC9C;EACF"}
|
package/dist/cjs/watcher.cjs
CHANGED
|
@@ -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);
|
package/dist/cjs/watcher.cjs.map
CHANGED
|
@@ -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'
|
|
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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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"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import { handleUnlinkedContentDeclarationFile } from "./handleUnlinkedContentDec
|
|
|
26
26
|
import { getContentDeclarationFileTemplate } from "./getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs";
|
|
27
27
|
import { initIntlayer } from "./init/index.mjs";
|
|
28
28
|
import { listGitFiles, listGitLines } from "./listGitFiles.mjs";
|
|
29
|
+
import { listProjects } from "./listProjects.mjs";
|
|
29
30
|
import { sortAlphabetically } from "./utils/sortAlphabetically.mjs";
|
|
30
31
|
import { loadRemoteDictionaries } from "./loadDictionaries/loadRemoteDictionaries.mjs";
|
|
31
32
|
import { loadDictionaries } from "./loadDictionaries/loadDictionaries.mjs";
|
|
@@ -51,4 +52,4 @@ import { runParallel } from "./utils/runParallel/index.mjs";
|
|
|
51
52
|
import { verifyIdenticObjectFormat } from "./utils/verifyIdenticObjectFormat.mjs";
|
|
52
53
|
import { buildAndWatchIntlayer, watch } from "./watcher.mjs";
|
|
53
54
|
|
|
54
|
-
export { ATTRIBUTES_TO_EXTRACT, assembleJSON, buildAndWatchIntlayer, buildDictionary, buildFilesList, chunkJSON, cleanOutputDir, createDictionaryEntryPoint, createModuleAugmentation, createTypes, detectExportedComponentName, detectFormatCommand, extractDictionaryKey, extractIntlayer, fetchDistantDictionaries, formatDictionaries, formatDictionariesOutput, formatDictionary, formatDictionaryOutput, formatLocale, formatPath, generateDictionaryListContent, generateKey, getBuiltDictionariesPath, getBuiltDynamicDictionariesPath, getBuiltFetchDictionariesPath, getBuiltRemoteDictionariesPath, getBuiltUnmergedDictionariesPath, getChunk, getComponentTransformPattern, getComponentTransformPatternSync, getContentDeclarationFileTemplate, getExtensionFromFormat, getFileHash, getFormatFromExtension, getGlobalLimiter, getTaskLimiter, handleAdditionalContentDeclarationFile, handleContentDeclarationFileChange, handleUnlinkedContentDeclarationFile, initIntlayer, isInvalidDictionary, listDictionaries, listDictionariesWithStats, listGitFiles, listGitLines, loadContentDeclarations, loadDictionaries, loadLocalDictionaries, loadRemoteDictionaries, pLimit, parallelize, parallelizeGlobal, prepareIntlayer, reconstructFromSingleChunk, reduceDictionaryContent, reduceObjectFormat, resolveObjectPromises, runOnce, runParallel, shouldExtract, sortAlphabetically, splitTextByLines, transformFiles, transformJSFile, verifyIdenticObjectFormat, watch, writeContentDeclaration, writeJSFile };
|
|
55
|
+
export { ATTRIBUTES_TO_EXTRACT, assembleJSON, buildAndWatchIntlayer, buildDictionary, buildFilesList, chunkJSON, cleanOutputDir, createDictionaryEntryPoint, createModuleAugmentation, createTypes, detectExportedComponentName, detectFormatCommand, extractDictionaryKey, extractIntlayer, fetchDistantDictionaries, formatDictionaries, formatDictionariesOutput, formatDictionary, formatDictionaryOutput, formatLocale, formatPath, generateDictionaryListContent, generateKey, getBuiltDictionariesPath, getBuiltDynamicDictionariesPath, getBuiltFetchDictionariesPath, getBuiltRemoteDictionariesPath, getBuiltUnmergedDictionariesPath, getChunk, getComponentTransformPattern, getComponentTransformPatternSync, getContentDeclarationFileTemplate, getExtensionFromFormat, getFileHash, getFormatFromExtension, getGlobalLimiter, getTaskLimiter, handleAdditionalContentDeclarationFile, handleContentDeclarationFileChange, handleUnlinkedContentDeclarationFile, initIntlayer, isInvalidDictionary, listDictionaries, listDictionariesWithStats, listGitFiles, listGitLines, listProjects, loadContentDeclarations, loadDictionaries, loadLocalDictionaries, loadRemoteDictionaries, pLimit, parallelize, parallelizeGlobal, prepareIntlayer, reconstructFromSingleChunk, reduceDictionaryContent, reduceObjectFormat, resolveObjectPromises, runOnce, runParallel, shouldExtract, sortAlphabetically, splitTextByLines, transformFiles, transformJSFile, verifyIdenticObjectFormat, watch, writeContentDeclaration, writeJSFile };
|