@intlayer/cli 9.0.0-canary.0 → 9.0.0-canary.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 (131) hide show
  1. package/dist/cjs/auth/login.cjs +42 -29
  2. package/dist/cjs/auth/login.cjs.map +1 -1
  3. package/dist/cjs/cli.cjs +25 -12
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/index.cjs +1 -1
  6. package/dist/cjs/init.cjs +332 -2
  7. package/dist/cjs/init.cjs.map +1 -1
  8. package/dist/cjs/initBuildOptimization.cjs +81 -0
  9. package/dist/cjs/initBuildOptimization.cjs.map +1 -0
  10. package/dist/cjs/initCompiler.cjs +117 -0
  11. package/dist/cjs/initCompiler.cjs.map +1 -0
  12. package/dist/cjs/initMCP.cjs +22 -19
  13. package/dist/cjs/initMCP.cjs.map +1 -1
  14. package/dist/cjs/initSkills.cjs +21 -18
  15. package/dist/cjs/initSkills.cjs.map +1 -1
  16. package/dist/cjs/reviewDoc/reviewDoc.cjs +38 -11
  17. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  18. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +55 -38
  19. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  20. package/dist/cjs/reviewDoc/reviewDocLog.cjs +48 -0
  21. package/dist/cjs/reviewDoc/reviewDocLog.cjs.map +1 -0
  22. package/dist/cjs/translateDoc/translateFile.cjs +1 -1
  23. package/dist/cjs/utils/formatLineRanges.cjs +44 -0
  24. package/dist/cjs/utils/formatLineRanges.cjs.map +1 -0
  25. package/dist/esm/auth/login.mjs +42 -29
  26. package/dist/esm/auth/login.mjs.map +1 -1
  27. package/dist/esm/cli.mjs +25 -12
  28. package/dist/esm/cli.mjs.map +1 -1
  29. package/dist/esm/index.mjs +1 -1
  30. package/dist/esm/init.mjs +332 -4
  31. package/dist/esm/init.mjs.map +1 -1
  32. package/dist/esm/initBuildOptimization.mjs +78 -0
  33. package/dist/esm/initBuildOptimization.mjs.map +1 -0
  34. package/dist/esm/initCompiler.mjs +114 -0
  35. package/dist/esm/initCompiler.mjs.map +1 -0
  36. package/dist/esm/initMCP.mjs +22 -19
  37. package/dist/esm/initMCP.mjs.map +1 -1
  38. package/dist/esm/initSkills.mjs +21 -18
  39. package/dist/esm/initSkills.mjs.map +1 -1
  40. package/dist/esm/reviewDoc/reviewDoc.mjs +38 -11
  41. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  42. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +55 -38
  43. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  44. package/dist/esm/reviewDoc/reviewDocLog.mjs +46 -0
  45. package/dist/esm/reviewDoc/reviewDocLog.mjs.map +1 -0
  46. package/dist/esm/translateDoc/translateFile.mjs +1 -1
  47. package/dist/esm/utils/formatLineRanges.mjs +42 -0
  48. package/dist/esm/utils/formatLineRanges.mjs.map +1 -0
  49. package/dist/types/auth/login.d.ts +13 -4
  50. package/dist/types/auth/login.d.ts.map +1 -1
  51. package/dist/types/cli.d.ts.map +1 -1
  52. package/dist/types/init.d.ts +1 -1
  53. package/dist/types/init.d.ts.map +1 -1
  54. package/dist/types/initBuildOptimization.d.ts +20 -0
  55. package/dist/types/initBuildOptimization.d.ts.map +1 -0
  56. package/dist/types/initCompiler.d.ts +18 -0
  57. package/dist/types/initCompiler.d.ts.map +1 -0
  58. package/dist/types/initMCP.d.ts +3 -1
  59. package/dist/types/initMCP.d.ts.map +1 -1
  60. package/dist/types/initSkills.d.ts +1 -1
  61. package/dist/types/initSkills.d.ts.map +1 -1
  62. package/dist/types/reviewDoc/reviewDoc.d.ts +8 -1
  63. package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
  64. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +8 -6
  65. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
  66. package/dist/types/reviewDoc/reviewDocLog.d.ts +25 -0
  67. package/dist/types/reviewDoc/reviewDocLog.d.ts.map +1 -0
  68. package/dist/types/utils/formatLineRanges.d.ts +21 -0
  69. package/dist/types/utils/formatLineRanges.d.ts.map +1 -0
  70. package/package.json +14 -14
  71. package/dist/cjs/translation-alignment/alignBlocks.cjs +0 -68
  72. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +0 -1
  73. package/dist/cjs/translation-alignment/computeSimilarity.cjs +0 -26
  74. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +0 -1
  75. package/dist/cjs/translation-alignment/fingerprintBlock.cjs +0 -24
  76. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +0 -1
  77. package/dist/cjs/translation-alignment/index.cjs +0 -22
  78. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +0 -19
  79. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +0 -1
  80. package/dist/cjs/translation-alignment/normalizeBlock.cjs +0 -23
  81. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +0 -1
  82. package/dist/cjs/translation-alignment/pipeline.cjs +0 -38
  83. package/dist/cjs/translation-alignment/pipeline.cjs.map +0 -1
  84. package/dist/cjs/translation-alignment/planActions.cjs +0 -47
  85. package/dist/cjs/translation-alignment/planActions.cjs.map +0 -1
  86. package/dist/cjs/translation-alignment/rebuildDocument.cjs +0 -50
  87. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +0 -1
  88. package/dist/cjs/translation-alignment/segmentDocument.cjs +0 -67
  89. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +0 -1
  90. package/dist/cjs/translation-alignment/types.cjs +0 -0
  91. package/dist/esm/translation-alignment/alignBlocks.mjs +0 -67
  92. package/dist/esm/translation-alignment/alignBlocks.mjs.map +0 -1
  93. package/dist/esm/translation-alignment/computeSimilarity.mjs +0 -23
  94. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +0 -1
  95. package/dist/esm/translation-alignment/fingerprintBlock.mjs +0 -21
  96. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +0 -1
  97. package/dist/esm/translation-alignment/index.mjs +0 -11
  98. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +0 -17
  99. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +0 -1
  100. package/dist/esm/translation-alignment/normalizeBlock.mjs +0 -21
  101. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +0 -1
  102. package/dist/esm/translation-alignment/pipeline.mjs +0 -36
  103. package/dist/esm/translation-alignment/pipeline.mjs.map +0 -1
  104. package/dist/esm/translation-alignment/planActions.mjs +0 -45
  105. package/dist/esm/translation-alignment/planActions.mjs.map +0 -1
  106. package/dist/esm/translation-alignment/rebuildDocument.mjs +0 -47
  107. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +0 -1
  108. package/dist/esm/translation-alignment/segmentDocument.mjs +0 -65
  109. package/dist/esm/translation-alignment/segmentDocument.mjs.map +0 -1
  110. package/dist/esm/translation-alignment/types.mjs +0 -0
  111. package/dist/types/translation-alignment/alignBlocks.d.ts +0 -7
  112. package/dist/types/translation-alignment/alignBlocks.d.ts.map +0 -1
  113. package/dist/types/translation-alignment/computeSimilarity.d.ts +0 -6
  114. package/dist/types/translation-alignment/computeSimilarity.d.ts.map +0 -1
  115. package/dist/types/translation-alignment/fingerprintBlock.d.ts +0 -7
  116. package/dist/types/translation-alignment/fingerprintBlock.d.ts.map +0 -1
  117. package/dist/types/translation-alignment/index.d.ts +0 -11
  118. package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts +0 -7
  119. package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts.map +0 -1
  120. package/dist/types/translation-alignment/normalizeBlock.d.ts +0 -7
  121. package/dist/types/translation-alignment/normalizeBlock.d.ts.map +0 -1
  122. package/dist/types/translation-alignment/pipeline.d.ts +0 -25
  123. package/dist/types/translation-alignment/pipeline.d.ts.map +0 -1
  124. package/dist/types/translation-alignment/planActions.d.ts +0 -7
  125. package/dist/types/translation-alignment/planActions.d.ts.map +0 -1
  126. package/dist/types/translation-alignment/rebuildDocument.d.ts +0 -32
  127. package/dist/types/translation-alignment/rebuildDocument.d.ts.map +0 -1
  128. package/dist/types/translation-alignment/segmentDocument.d.ts +0 -7
  129. package/dist/types/translation-alignment/segmentDocument.d.ts.map +0 -1
  130. package/dist/types/translation-alignment/types.d.ts +0 -49
  131. package/dist/types/translation-alignment/types.d.ts.map +0 -1
package/dist/cjs/init.cjs CHANGED
@@ -1,8 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_auth_login = require('./auth/login.cjs');
4
+ const require_initBuildOptimization = require('./initBuildOptimization.cjs');
5
+ const require_initCompiler = require('./initCompiler.cjs');
6
+ const require_initSkills = require('./initSkills.cjs');
7
+ const require_initMCP = require('./initMCP.cjs');
3
8
  let node_fs = require("node:fs");
4
9
  let node_path = require("node:path");
5
10
  let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
11
+ let enquirer = require("enquirer");
12
+ enquirer = require_runtime.__toESM(enquirer);
13
+ let _clack_prompts = require("@clack/prompts");
14
+ _clack_prompts = require_runtime.__toESM(_clack_prompts);
6
15
 
7
16
  //#region src/init.ts
8
17
  const findProjectRoot = (startDir) => {
@@ -13,8 +22,329 @@ const findProjectRoot = (startDir) => {
13
22
  }
14
23
  return startDir;
15
24
  };
16
- const init = async (projectRoot, options) => {
17
- await (0, _intlayer_chokidar_cli.initIntlayer)(projectRoot ? findProjectRoot((0, node_path.resolve)(projectRoot)) : findProjectRoot(process.cwd()), options);
25
+ const BASE_INIT_STEP_OPTIONS = [
26
+ {
27
+ value: "packages",
28
+ label: "Install & upgrade packages",
29
+ hint: "install missing Intlayer dependencies and upgrade outdated ones"
30
+ },
31
+ {
32
+ value: "githubActions",
33
+ label: "CI/CD (GitHub Actions)",
34
+ hint: "scaffold the fill and test workflows that run on every pull request"
35
+ },
36
+ {
37
+ value: "frameworkSetup",
38
+ label: "Framework setup",
39
+ hint: "middleware/proxy and providers in layout/page"
40
+ },
41
+ {
42
+ value: "vscodeExtension",
43
+ label: "VS Code extension",
44
+ hint: "recommend the Intlayer extension"
45
+ },
46
+ {
47
+ value: "lsp",
48
+ label: "Editor LSP",
49
+ hint: "go-to-definition from keys to .content files"
50
+ },
51
+ {
52
+ value: "skills",
53
+ label: "AI skills",
54
+ hint: "install the Intlayer documentation as agent skills"
55
+ },
56
+ {
57
+ value: "mcp",
58
+ label: "MCP server",
59
+ hint: "configure the Intlayer MCP server"
60
+ }
61
+ ];
62
+ /** Locale routing strategies offered by the interactive init flow. */
63
+ const ROUTING_MODE_OPTIONS = [
64
+ {
65
+ value: "prefix-no-default",
66
+ label: "Prefix all except the default locale",
67
+ hint: "/about, /fr/about (default)"
68
+ },
69
+ {
70
+ value: "prefix-all",
71
+ label: "Prefix all locales",
72
+ hint: "/en/about, /fr/about"
73
+ },
74
+ {
75
+ value: "no-prefix",
76
+ label: "No locale in the URL",
77
+ hint: "/about"
78
+ },
79
+ {
80
+ value: "search-params",
81
+ label: "Use a search parameter",
82
+ hint: "/about?locale=fr"
83
+ }
84
+ ];
85
+ const COMPAT_LIB_OPTIONS = [
86
+ {
87
+ value: "i18next",
88
+ label: "i18next / react-i18next",
89
+ hint: "i18next JSON format — installs @intlayer/i18next + @intlayer/sync-json-plugin",
90
+ packages: ["i18next", "react-i18next"]
91
+ },
92
+ {
93
+ value: "next-intl",
94
+ label: "next-intl / use-intl",
95
+ hint: "ICU format, Next.js — installs @intlayer/next-intl + @intlayer/sync-json-plugin",
96
+ packages: ["next-intl"]
97
+ },
98
+ {
99
+ value: "vue-i18n",
100
+ label: "vue-i18n",
101
+ hint: "Vue i18n JSON format — installs @intlayer/vue-i18n + @intlayer/sync-json-plugin",
102
+ packages: ["vue-i18n"]
103
+ },
104
+ {
105
+ value: "nuxtjs-i18n",
106
+ label: "@nuxtjs/i18n",
107
+ hint: "Nuxt i18n module — installs @intlayer/nuxtjs-i18n + @intlayer/sync-json-plugin",
108
+ packages: ["@nuxtjs/i18n"]
109
+ },
110
+ {
111
+ value: "next-i18next",
112
+ label: "next-i18next",
113
+ hint: "i18next JSON format, Next.js — installs @intlayer/next-i18next + @intlayer/sync-json-plugin",
114
+ packages: ["next-i18next"]
115
+ },
116
+ {
117
+ value: "next-translate",
118
+ label: "next-translate",
119
+ hint: "i18next flat-namespace JSON, Next.js — installs @intlayer/next-translate + @intlayer/sync-json-plugin",
120
+ packages: ["next-translate"]
121
+ },
122
+ {
123
+ value: "react-intl",
124
+ label: "react-intl",
125
+ hint: "ICU format — installs @intlayer/react-intl + @intlayer/sync-json-plugin",
126
+ packages: ["react-intl"]
127
+ },
128
+ {
129
+ value: "lingui-po",
130
+ label: "Lingui (.po catalogs)",
131
+ hint: "gettext PO — Lingui's default, installs @intlayer/lingui + @intlayer/sync-po-plugin",
132
+ packages: ["@lingui/core"]
133
+ },
134
+ {
135
+ value: "lingui-json",
136
+ label: "Lingui (.json catalogs)",
137
+ hint: "JSON catalogs — installs @intlayer/lingui + @intlayer/sync-json-plugin",
138
+ packages: ["@lingui/core"]
139
+ },
140
+ {
141
+ value: "svelte-i18n",
142
+ label: "svelte-i18n",
143
+ hint: "Flat i18next JSON — installs @intlayer/svelte-i18n + @intlayer/sync-json-plugin",
144
+ packages: ["svelte-i18n"]
145
+ }
146
+ ];
147
+ /** Reads the merged dependencies of the project at `root`. */
148
+ const getProjectDependencies = (root) => {
149
+ try {
150
+ const packageJsonPath = (0, node_path.join)(root, "package.json");
151
+ if (!(0, node_fs.existsSync)(packageJsonPath)) return {};
152
+ const { dependencies = {}, devDependencies = {} } = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf-8"));
153
+ return {
154
+ ...dependencies,
155
+ ...devDependencies
156
+ };
157
+ } catch {
158
+ return {};
159
+ }
160
+ };
161
+ /** Returns true when the project at `root` depends on Next.js. */
162
+ const isNextJsProject = (root) => Boolean(getProjectDependencies(root).next);
163
+ /** Returns true when the project at `root` depends on Vite. */
164
+ const isViteProject = (root) => Boolean(getProjectDependencies(root).vite);
165
+ /**
166
+ * Returns true when the project uses a URL-based router for which a locale
167
+ * routing strategy is meaningful: Next.js, React Router, or TanStack Router.
168
+ * Apps without URL routing (e.g. React Native / Expo) are excluded, since
169
+ * `routing.mode` has no effect there.
170
+ */
171
+ const hasUrlRouting = (root) => {
172
+ const deps = getProjectDependencies(root);
173
+ if (deps["react-native"] || deps.expo) return false;
174
+ return Boolean(deps.next || deps["react-router"] || deps["react-router-dom"] || deps["@tanstack/react-router"] || deps["@tanstack/react-start"]);
175
+ };
176
+ /**
177
+ * Runs `init` in interactive mode: prompts the user with a checkbox of setup
178
+ * steps, then forwards the selection to {@link initIntlayer} (packages, GitHub
179
+ * Actions, VS Code extension, LSP) and runs the dedicated skills/MCP installers
180
+ * for the steps that own their own prompts. The `.gitignore` entry is not
181
+ * offered as a checkbox — it is always added (unless `--no-gitignore` is set).
182
+ */
183
+ const runInteractiveInit = async (root, baseOptions) => {
184
+ _clack_prompts.intro("Initialize Intlayer");
185
+ const stepOptions = [...BASE_INIT_STEP_OPTIONS];
186
+ const nextJsProject = isNextJsProject(root);
187
+ if (nextJsProject || isViteProject(root)) stepOptions.push({
188
+ value: "compiler",
189
+ label: "Compiler",
190
+ hint: nextJsProject ? "add the Babel compiler config to extract inline content (Next.js)" : "auto-extract inline content at build time (already plugged in on Vite)"
191
+ });
192
+ if (nextJsProject) stepOptions.push({
193
+ value: "buildOptimization",
194
+ label: "Bundle optimization",
195
+ hint: "choose @intlayer/babel or @intlayer/swc for tree-shaking and minification (Next.js only)"
196
+ });
197
+ const selected = await _clack_prompts.multiselect({
198
+ message: "Select what you want to set up:",
199
+ options: stepOptions,
200
+ initialValues: BASE_INIT_STEP_OPTIONS.map((option) => option.value),
201
+ required: false
202
+ });
203
+ if (_clack_prompts.isCancel(selected)) {
204
+ _clack_prompts.cancel("Operation cancelled.");
205
+ return;
206
+ }
207
+ const steps = selected;
208
+ let routingMode;
209
+ if (hasUrlRouting(root)) {
210
+ const selectedRoutingMode = await _clack_prompts.select({
211
+ message: "Which locale routing strategy do you want?",
212
+ options: ROUTING_MODE_OPTIONS,
213
+ initialValue: "prefix-no-default"
214
+ });
215
+ if (_clack_prompts.isCancel(selectedRoutingMode)) {
216
+ _clack_prompts.cancel("Operation cancelled.");
217
+ return;
218
+ }
219
+ routingMode = selectedRoutingMode;
220
+ }
221
+ const knownCompatPackages = [
222
+ "i18next",
223
+ "react-i18next",
224
+ "next-intl",
225
+ "use-intl",
226
+ "vue-i18n",
227
+ "@nuxtjs/i18n",
228
+ "next-i18next",
229
+ "next-translate",
230
+ "react-intl",
231
+ "@lingui/core",
232
+ "@lingui/react",
233
+ "svelte-i18n",
234
+ "@ngneat/transloco",
235
+ "@ngx-translate/core",
236
+ "node-polyglot",
237
+ "i18n-js"
238
+ ];
239
+ const existingDeps = getProjectDependencies(root);
240
+ const hasCompatLib = knownCompatPackages.some((pkg) => Boolean(existingDeps[pkg]));
241
+ let hintDependencies;
242
+ if (!hasCompatLib) {
243
+ const selectedCompatLibs = await _clack_prompts.multiselect({
244
+ message: "Are you using any existing i18n library? (Select all that apply, or press Enter to skip)",
245
+ options: COMPAT_LIB_OPTIONS.map((opt) => ({
246
+ value: opt.value,
247
+ label: opt.label,
248
+ hint: opt.hint
249
+ })),
250
+ required: false
251
+ });
252
+ if (_clack_prompts.isCancel(selectedCompatLibs)) {
253
+ _clack_prompts.cancel("Operation cancelled.");
254
+ return;
255
+ }
256
+ const selectedLibs = selectedCompatLibs;
257
+ if (selectedLibs.length > 0) {
258
+ hintDependencies = {};
259
+ for (const value of selectedLibs) {
260
+ const option = COMPAT_LIB_OPTIONS.find((o) => o.value === value);
261
+ if (option?.packages) for (const pkg of option.packages) hintDependencies[pkg] = "*";
262
+ }
263
+ const hasLinguiPo = selectedLibs.includes("lingui-po");
264
+ const hasLinguiJson = selectedLibs.includes("lingui-json");
265
+ if (hasLinguiPo && hasLinguiJson) {
266
+ const linguiFormat = await _clack_prompts.select({
267
+ message: "Which catalog format does Lingui use in your project?",
268
+ options: [{
269
+ value: "po",
270
+ label: ".po files (gettext)",
271
+ hint: "Lingui's default — installs @intlayer/sync-po-plugin"
272
+ }, {
273
+ value: "json",
274
+ label: ".json files",
275
+ hint: "JSON catalogs — installs @intlayer/sync-json-plugin"
276
+ }],
277
+ initialValue: "po"
278
+ });
279
+ if (_clack_prompts.isCancel(linguiFormat)) {
280
+ _clack_prompts.cancel("Operation cancelled.");
281
+ return;
282
+ }
283
+ if (linguiFormat === "json") hintDependencies["__lingui_json__"] = "*";
284
+ } else if (hasLinguiJson && !hasLinguiPo) hintDependencies["__lingui_json__"] = "*";
285
+ }
286
+ }
287
+ await (0, _intlayer_chokidar_cli.initIntlayer)(root, {
288
+ ...baseOptions,
289
+ routingMode,
290
+ hintDependencies,
291
+ noInstallPackages: !steps.includes("packages"),
292
+ noGitignore: baseOptions?.noGitignore,
293
+ noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
294
+ noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("frameworkSetup"),
295
+ noVscodeExtension: !steps.includes("vscodeExtension"),
296
+ noLsp: !steps.includes("lsp")
297
+ });
298
+ const needsPlatform = steps.includes("skills") || steps.includes("mcp");
299
+ let sharedPlatform;
300
+ if (needsPlatform) {
301
+ const detectedPlatform = require_initSkills.getDetectedPlatform();
302
+ try {
303
+ sharedPlatform = (await enquirer.default.prompt({
304
+ type: "autocomplete",
305
+ name: "platforms",
306
+ message: "Which platform are you using? (Type to search)",
307
+ multiple: false,
308
+ initial: detectedPlatform ? _intlayer_chokidar_cli.PLATFORMS.indexOf(detectedPlatform) : void 0,
309
+ choices: require_initSkills.PLATFORM_OPTIONS.map((opt) => ({
310
+ name: opt.value,
311
+ message: opt.label,
312
+ hint: opt.hint
313
+ }))
314
+ })).platforms;
315
+ } catch {
316
+ _clack_prompts.cancel("Operation cancelled.");
317
+ return;
318
+ }
319
+ }
320
+ if (steps.includes("skills")) await require_initSkills.initSkills(root, sharedPlatform);
321
+ if (steps.includes("mcp")) await require_initMCP.initMCP(root, sharedPlatform);
322
+ if (steps.includes("compiler")) await require_initCompiler.initCompiler(root);
323
+ if (steps.includes("buildOptimization")) await require_initBuildOptimization.initBuildOptimization(root);
324
+ const shouldSetUpCms = await _clack_prompts.confirm({
325
+ message: "Set up the Intlayer CMS now? (opens your browser to log in, then stores the credentials in your .env)",
326
+ initialValue: false
327
+ });
328
+ if (_clack_prompts.isCancel(shouldSetUpCms)) {
329
+ _clack_prompts.cancel("Operation cancelled.");
330
+ return;
331
+ }
332
+ if (shouldSetUpCms) {
333
+ _clack_prompts.log.info("Opening your browser to log in to the Intlayer CMS...");
334
+ await require_auth_login.login({
335
+ exitAfter: false,
336
+ onCredentials: (credentials) => (0, _intlayer_chokidar_cli.setupCmsCredentials)(root, credentials)
337
+ });
338
+ }
339
+ _clack_prompts.outro("Intlayer initialization complete");
340
+ };
341
+ const init = async (projectRoot, options, interactive) => {
342
+ const root = projectRoot ? findProjectRoot((0, node_path.resolve)(projectRoot)) : findProjectRoot(process.cwd());
343
+ if (interactive) {
344
+ await runInteractiveInit(root, options);
345
+ return;
346
+ }
347
+ await (0, _intlayer_chokidar_cli.initIntlayer)(root, options);
18
348
  };
19
349
 
20
350
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"init.cjs","names":[],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { type InitOptions, initIntlayer } from '@intlayer/chokidar/cli';\n\nexport const findProjectRoot = (startDir: string) => {\n let currentDir = startDir;\n\n while (currentDir !== resolve(currentDir, '..')) {\n if (existsSync(join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = resolve(currentDir, '..');\n }\n\n // If no package.json is found, return the start directory.\n // The initIntlayer function will handle the missing package.json error.\n return startDir;\n};\n\nexport const init = async (projectRoot?: string, options?: InitOptions) => {\n const root = projectRoot\n ? findProjectRoot(resolve(projectRoot))\n : findProjectRoot(process.cwd());\n\n await initIntlayer(root, options);\n};\n"],"mappings":";;;;;;;AAIA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;AAEjB,QAAO,sCAAuB,YAAY,KAAK,EAAE;AAC/C,kDAAoB,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,sCAAqB,YAAY,KAAK;;AAKxC,QAAO;;AAGT,MAAa,OAAO,OAAO,aAAsB,YAA0B;AAKzE,gDAJa,cACT,uCAAwB,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC,EAET,QAAQ"}
1
+ {"version":3,"file":"init.cjs","names":["p","getDetectedPlatform","PLATFORMS","PLATFORM_OPTIONS","initSkills","initMCP","initCompiler","initBuildOptimization","login"],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n type InitOptions,\n initIntlayer,\n PLATFORMS,\n type Platform,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { login } from './auth/login';\nimport { initBuildOptimization } from './initBuildOptimization';\nimport { initCompiler } from './initCompiler';\nimport { initMCP } from './initMCP';\nimport {\n getDetectedPlatform,\n initSkills,\n PLATFORM_OPTIONS,\n} from './initSkills';\n\nexport const findProjectRoot = (startDir: string) => {\n let currentDir = startDir;\n\n while (currentDir !== resolve(currentDir, '..')) {\n if (existsSync(join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = resolve(currentDir, '..');\n }\n\n // If no package.json is found, return the start directory.\n // The initIntlayer function will handle the missing package.json error.\n return startDir;\n};\n\n/** Individually selectable setup steps exposed by the interactive init flow. */\ntype InitStep =\n | 'packages'\n | 'githubActions'\n | 'frameworkSetup'\n | 'vscodeExtension'\n | 'lsp'\n | 'skills'\n | 'mcp'\n | 'compiler'\n | 'buildOptimization';\n\nconst BASE_INIT_STEP_OPTIONS: Array<{\n value: InitStep;\n label: string;\n hint: string;\n}> = [\n {\n value: 'packages',\n label: 'Install & upgrade packages',\n hint: 'install missing Intlayer dependencies and upgrade outdated ones',\n },\n {\n value: 'githubActions',\n label: 'CI/CD (GitHub Actions)',\n hint: 'scaffold the fill and test workflows that run on every pull request',\n },\n {\n value: 'frameworkSetup',\n label: 'Framework setup',\n hint: 'middleware/proxy and providers in layout/page',\n },\n {\n value: 'vscodeExtension',\n label: 'VS Code extension',\n hint: 'recommend the Intlayer extension',\n },\n {\n value: 'lsp',\n label: 'Editor LSP',\n hint: 'go-to-definition from keys to .content files',\n },\n {\n value: 'skills',\n label: 'AI skills',\n hint: 'install the Intlayer documentation as agent skills',\n },\n {\n value: 'mcp',\n label: 'MCP server',\n hint: 'configure the Intlayer MCP server',\n },\n];\n\n/** Locale routing strategies offered by the interactive init flow. */\nconst ROUTING_MODE_OPTIONS: Array<{\n value: RoutingMode;\n label: string;\n hint: string;\n}> = [\n {\n value: 'prefix-no-default',\n label: 'Prefix all except the default locale',\n hint: '/about, /fr/about (default)',\n },\n {\n value: 'prefix-all',\n label: 'Prefix all locales',\n hint: '/en/about, /fr/about',\n },\n {\n value: 'no-prefix',\n label: 'No locale in the URL',\n hint: '/about',\n },\n {\n value: 'search-params',\n label: 'Use a search parameter',\n hint: '/about?locale=fr',\n },\n];\n\n/**\n * Compat i18n library options surfaced in the interactive init prompt.\n * The `packages` field lists the package names to inject as hint-deps so\n * `detectMissingIntlayerPackages` detects the right sync plugin even before\n * those libraries are installed.\n */\ntype CompatLibOption = {\n value: string;\n label: string;\n hint: string;\n /**\n * Package names to inject as hint-dependencies (fake \"installed\" so that\n * the detection logic schedules the correct sync plugin and compat adapter).\n */\n packages?: string[];\n};\n\nconst COMPAT_LIB_OPTIONS: CompatLibOption[] = [\n {\n value: 'i18next',\n label: 'i18next / react-i18next',\n hint: 'i18next JSON format — installs @intlayer/i18next + @intlayer/sync-json-plugin',\n packages: ['i18next', 'react-i18next'],\n },\n {\n value: 'next-intl',\n label: 'next-intl / use-intl',\n hint: 'ICU format, Next.js — installs @intlayer/next-intl + @intlayer/sync-json-plugin',\n packages: ['next-intl'],\n },\n {\n value: 'vue-i18n',\n label: 'vue-i18n',\n hint: 'Vue i18n JSON format — installs @intlayer/vue-i18n + @intlayer/sync-json-plugin',\n packages: ['vue-i18n'],\n },\n {\n value: 'nuxtjs-i18n',\n label: '@nuxtjs/i18n',\n hint: 'Nuxt i18n module — installs @intlayer/nuxtjs-i18n + @intlayer/sync-json-plugin',\n packages: ['@nuxtjs/i18n'],\n },\n {\n value: 'next-i18next',\n label: 'next-i18next',\n hint: 'i18next JSON format, Next.js — installs @intlayer/next-i18next + @intlayer/sync-json-plugin',\n packages: ['next-i18next'],\n },\n {\n value: 'next-translate',\n label: 'next-translate',\n hint: 'i18next flat-namespace JSON, Next.js — installs @intlayer/next-translate + @intlayer/sync-json-plugin',\n packages: ['next-translate'],\n },\n {\n value: 'react-intl',\n label: 'react-intl',\n hint: 'ICU format — installs @intlayer/react-intl + @intlayer/sync-json-plugin',\n packages: ['react-intl'],\n },\n {\n value: 'lingui-po',\n label: 'Lingui (.po catalogs)',\n hint: \"gettext PO — Lingui's default, installs @intlayer/lingui + @intlayer/sync-po-plugin\",\n packages: ['@lingui/core'],\n },\n {\n value: 'lingui-json',\n label: 'Lingui (.json catalogs)',\n hint: 'JSON catalogs — installs @intlayer/lingui + @intlayer/sync-json-plugin',\n packages: ['@lingui/core'],\n },\n {\n value: 'svelte-i18n',\n label: 'svelte-i18n',\n hint: 'Flat i18next JSON — installs @intlayer/svelte-i18n + @intlayer/sync-json-plugin',\n packages: ['svelte-i18n'],\n },\n];\n\n/** Reads the merged dependencies of the project at `root`. */\nconst getProjectDependencies = (root: string): Record<string, string> => {\n try {\n const packageJsonPath = join(root, 'package.json');\n if (!existsSync(packageJsonPath)) return {};\n const { dependencies = {}, devDependencies = {} } = JSON.parse(\n readFileSync(packageJsonPath, 'utf-8')\n );\n return { ...dependencies, ...devDependencies };\n } catch {\n return {};\n }\n};\n\n/** Returns true when the project at `root` depends on Next.js. */\nconst isNextJsProject = (root: string): boolean =>\n Boolean(getProjectDependencies(root).next);\n\n/** Returns true when the project at `root` depends on Vite. */\nconst isViteProject = (root: string): boolean =>\n Boolean(getProjectDependencies(root).vite);\n\n/**\n * Returns true when the project uses a URL-based router for which a locale\n * routing strategy is meaningful: Next.js, React Router, or TanStack Router.\n * Apps without URL routing (e.g. React Native / Expo) are excluded, since\n * `routing.mode` has no effect there.\n */\nconst hasUrlRouting = (root: string): boolean => {\n const deps = getProjectDependencies(root);\n\n // React Native / Expo apps have no URL routing — never ask for a strategy.\n if (deps['react-native'] || deps.expo) return false;\n\n return Boolean(\n deps.next ||\n deps['react-router'] ||\n deps['react-router-dom'] ||\n deps['@tanstack/react-router'] ||\n deps['@tanstack/react-start']\n );\n};\n\n/**\n * Runs `init` in interactive mode: prompts the user with a checkbox of setup\n * steps, then forwards the selection to {@link initIntlayer} (packages, GitHub\n * Actions, VS Code extension, LSP) and runs the dedicated skills/MCP installers\n * for the steps that own their own prompts. The `.gitignore` entry is not\n * offered as a checkbox — it is always added (unless `--no-gitignore` is set).\n */\nconst runInteractiveInit = async (\n root: string,\n baseOptions?: InitOptions\n): Promise<void> => {\n p.intro('Initialize Intlayer');\n\n const stepOptions = [...BASE_INIT_STEP_OPTIONS];\n\n const nextJsProject = isNextJsProject(root);\n\n // The compiler is plugged in directly on Vite; on Next.js it needs a Babel\n // config. Only offer the step when one of those frameworks is detected.\n if (nextJsProject || isViteProject(root)) {\n stepOptions.push({\n value: 'compiler',\n label: 'Compiler',\n hint: nextJsProject\n ? 'add the Babel compiler config to extract inline content (Next.js)'\n : 'auto-extract inline content at build time (already plugged in on Vite)',\n });\n }\n\n if (nextJsProject) {\n stepOptions.push({\n value: 'buildOptimization',\n label: 'Bundle optimization',\n hint: 'choose @intlayer/babel or @intlayer/swc for tree-shaking and minification (Next.js only)',\n });\n }\n\n const selected = await p.multiselect<InitStep>({\n message: 'Select what you want to set up:',\n options: stepOptions,\n initialValues: BASE_INIT_STEP_OPTIONS.map((option) => option.value),\n required: false,\n });\n\n if (p.isCancel(selected)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const steps = selected as InitStep[];\n\n // Locale routing strategy → written to `routing.mode` in the config file.\n // Only relevant for URL-based routers (Next.js, React Router, TanStack);\n // skipped for apps without URL routing such as React Native / Expo.\n let routingMode: RoutingMode | undefined;\n\n if (hasUrlRouting(root)) {\n const selectedRoutingMode = await p.select<RoutingMode>({\n message: 'Which locale routing strategy do you want?',\n options: ROUTING_MODE_OPTIONS,\n initialValue: 'prefix-no-default',\n });\n\n if (p.isCancel(selectedRoutingMode)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n routingMode = selectedRoutingMode;\n }\n\n // Compat i18n library detection / selection.\n // When a compat library is already present in package.json the detection\n // in detectMissingIntlayerPackages handles everything automatically. We\n // only show the prompt when none of the known compat libs is detected so\n // we don't ask redundant questions.\n const knownCompatPackages = [\n 'i18next',\n 'react-i18next',\n 'next-intl',\n 'use-intl',\n 'vue-i18n',\n '@nuxtjs/i18n',\n 'next-i18next',\n 'next-translate',\n 'react-intl',\n '@lingui/core',\n '@lingui/react',\n 'svelte-i18n',\n '@ngneat/transloco',\n '@ngx-translate/core',\n 'node-polyglot',\n 'i18n-js',\n ];\n\n const existingDeps = getProjectDependencies(root);\n const hasCompatLib = knownCompatPackages.some((pkg) =>\n Boolean(existingDeps[pkg])\n );\n\n let hintDependencies: Record<string, string> | undefined;\n\n if (!hasCompatLib) {\n const selectedCompatLibs = await p.multiselect<string>({\n message:\n 'Are you using any existing i18n library? (Select all that apply, or press Enter to skip)',\n options: COMPAT_LIB_OPTIONS.map((opt) => ({\n value: opt.value,\n label: opt.label,\n hint: opt.hint,\n })),\n required: false,\n });\n\n if (p.isCancel(selectedCompatLibs)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const selectedLibs = selectedCompatLibs as string[];\n\n if (selectedLibs.length > 0) {\n hintDependencies = {};\n\n for (const value of selectedLibs) {\n const option = COMPAT_LIB_OPTIONS.find((o) => o.value === value);\n if (option?.packages) {\n for (const pkg of option.packages) {\n hintDependencies[pkg] = '*';\n }\n }\n }\n\n // Lingui-specific: determine the catalog format so the right sync plugin\n // is chosen. If both lingui variants are selected, ask for clarification.\n const hasLinguiPo = selectedLibs.includes('lingui-po');\n const hasLinguiJson = selectedLibs.includes('lingui-json');\n\n if (hasLinguiPo && hasLinguiJson) {\n // Both selected — ask for clarification\n const linguiFormat = await p.select<'po' | 'json'>({\n message: 'Which catalog format does Lingui use in your project?',\n options: [\n {\n value: 'po' as const,\n label: '.po files (gettext)',\n hint: \"Lingui's default — installs @intlayer/sync-po-plugin\",\n },\n {\n value: 'json' as const,\n label: '.json files',\n hint: 'JSON catalogs — installs @intlayer/sync-json-plugin',\n },\n ],\n initialValue: 'po' as const,\n });\n\n if (p.isCancel(linguiFormat)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n // Signal JSON format to detectMissingIntlayerPackages via a sentinel\n // hint dep (the lingui detection only needs @lingui/core; the format\n // is conveyed through linguiCatalogFormat option from the filesystem\n // scan). For JSON we override by injecting a flag the init/index.ts\n // can read back from hintDependencies.\n if (linguiFormat === 'json') {\n hintDependencies['__lingui_json__'] = '*';\n }\n } else if (hasLinguiJson && !hasLinguiPo) {\n hintDependencies['__lingui_json__'] = '*';\n }\n // hasLinguiPo alone: @lingui/core hint is enough; PO is the default\n }\n }\n\n const options: InitOptions = {\n ...baseOptions,\n routingMode,\n hintDependencies,\n noInstallPackages: !steps.includes('packages'),\n // The `.gitignore` entry is never offered as a checkbox: in interactive\n // mode we always add `.intlayer` to `.gitignore`, only honoring an explicit\n // `--no-gitignore` flag from the command line.\n noGitignore: baseOptions?.noGitignore,\n // Respect explicit `--no-*` flags from the command line even when the\n // corresponding step is selected in the checkbox.\n noGithubActions:\n baseOptions?.noGithubActions || !steps.includes('githubActions'),\n noFrameworkSetup:\n baseOptions?.noFrameworkSetup || !steps.includes('frameworkSetup'),\n noVscodeExtension: !steps.includes('vscodeExtension'),\n noLsp: !steps.includes('lsp'),\n };\n\n await initIntlayer(root, options);\n\n const needsPlatform = steps.includes('skills') || steps.includes('mcp');\n\n let sharedPlatform: Platform | undefined;\n\n if (needsPlatform) {\n const detectedPlatform = getDetectedPlatform();\n\n try {\n const response = await enquirer.prompt<{ platforms: Platform }>({\n type: 'autocomplete',\n name: 'platforms',\n message: 'Which platform are you using? (Type to search)',\n multiple: false,\n initial: detectedPlatform\n ? PLATFORMS.indexOf(detectedPlatform)\n : undefined,\n choices: PLATFORM_OPTIONS.map((opt) => ({\n name: opt.value,\n message: opt.label,\n hint: opt.hint,\n })),\n });\n sharedPlatform = response.platforms;\n } catch {\n p.cancel('Operation cancelled.');\n return;\n }\n }\n\n if (steps.includes('skills')) {\n await initSkills(root, sharedPlatform);\n }\n\n if (steps.includes('mcp')) {\n await initMCP(root, sharedPlatform);\n }\n\n if (steps.includes('compiler')) {\n await initCompiler(root);\n }\n\n if (steps.includes('buildOptimization')) {\n await initBuildOptimization(root);\n }\n\n // CMS / visual editor is the last step: an opt-in browser login that\n // persists the access-key credentials to `.env` and enables the editor in the\n // config file. Asked last so the browser flow does not interrupt setup.\n const shouldSetUpCms = await p.confirm({\n message:\n 'Set up the Intlayer CMS now? (opens your browser to log in, then stores the credentials in your .env)',\n initialValue: false,\n });\n\n if (p.isCancel(shouldSetUpCms)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n if (shouldSetUpCms) {\n p.log.info('Opening your browser to log in to the Intlayer CMS...');\n // `exitAfter: false` keeps the process alive so the flow can finish; the\n // credentials are persisted to `.env` and the editor enabled in the config.\n await login({\n exitAfter: false,\n onCredentials: (credentials) => setupCmsCredentials(root, credentials),\n });\n }\n\n p.outro('Intlayer initialization complete');\n};\n\nexport const init = async (\n projectRoot?: string,\n options?: InitOptions,\n interactive?: boolean\n) => {\n const root = projectRoot\n ? findProjectRoot(resolve(projectRoot))\n : findProjectRoot(process.cwd());\n\n if (interactive) {\n await runInteractiveInit(root, options);\n return;\n }\n\n await initIntlayer(root, options);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;AAEjB,QAAO,sCAAuB,YAAY,KAAK,EAAE;AAC/C,kDAAoB,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,sCAAqB,YAAY,KAAK;;AAKxC,QAAO;;AAeT,MAAM,yBAID;CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACF;;AAGD,MAAM,uBAID;CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACF;AAmBD,MAAM,qBAAwC;CAC5C;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,WAAW,gBAAgB;EACvC;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,YAAY;EACxB;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,WAAW;EACvB;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,eAAe;EAC3B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,eAAe;EAC3B;CACD;EACE,OAAO;EACP,OAAO;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AAM,SAAS,WAAW,CAC5B,OAAMC,kCAAa,KAAK;AAG1B,KAAI,MAAM,SAAS,oBAAoB,CACrC,OAAMC,oDAAsB,KAAK;CAMnC,MAAM,iBAAiB,MAAMP,eAAE,QAAQ;EACrC,SACE;EACF,cAAc;EACf,CAAC;AAEF,KAAIA,eAAE,SAAS,eAAe,EAAE;AAC9B,iBAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,gBAAgB;AAClB,iBAAE,IAAI,KAAK,wDAAwD;AAGnE,QAAMQ,yBAAM;GACV,WAAW;GACX,gBAAgB,gEAAoC,MAAM,YAAY;GACvE,CAAC;;AAGJ,gBAAE,MAAM,mCAAmC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,uCAAwB,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,gDAAmB,MAAM,QAAQ"}
@@ -0,0 +1,81 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_init = require('./init.cjs');
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
7
+ let _clack_prompts = require("@clack/prompts");
8
+ _clack_prompts = require_runtime.__toESM(_clack_prompts);
9
+
10
+ //#region src/initBuildOptimization.ts
11
+ /** Babel config filenames Next.js picks up, ordered by preference. */
12
+ const BABEL_CONFIG_CANDIDATES = [
13
+ "babel.config.js",
14
+ "babel.config.cjs",
15
+ "babel.config.mjs",
16
+ "babel.config.ts"
17
+ ];
18
+ /**
19
+ * Interactive prompt to select a build optimization plugin for Next.js and
20
+ * scaffold the required files. The two options are independent — pick one:
21
+ *
22
+ * - `@intlayer/babel` — runs the full compiler pipeline (extract, purge, minify,
23
+ * optimize) through Babel. Installs `@intlayer/babel` and creates a
24
+ * `babel.config.js`.
25
+ * - `@intlayer/swc` — lightweight SWC plugin that rewrites `useIntlayer` imports.
26
+ * Installs only the dependency; `withIntlayer` wires it in automatically, so
27
+ * no config file is required.
28
+ *
29
+ * @param projectRoot - Optional project root; defaults to the current directory.
30
+ */
31
+ const initBuildOptimization = async (projectRoot) => {
32
+ const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
33
+ _clack_prompts.intro("Configuring Next.js build optimization");
34
+ const plugin = await _clack_prompts.select({
35
+ message: "Which build optimization plugin do you want to use?",
36
+ options: [{
37
+ value: "babel",
38
+ label: "@intlayer/babel",
39
+ hint: "Full pipeline — extract, purge, minify and optimize via Babel; creates babel.config.js"
40
+ }, {
41
+ value: "swc",
42
+ label: "@intlayer/swc",
43
+ hint: "Lightweight — SWC plugin that rewrites useIntlayer imports; wired automatically by withIntlayer"
44
+ }]
45
+ });
46
+ if (_clack_prompts.isCancel(plugin) || !plugin) {
47
+ _clack_prompts.cancel("Operation cancelled.");
48
+ return;
49
+ }
50
+ const packageManager = (0, _intlayer_chokidar_cli.detectPackageManager)(root);
51
+ const packageToInstall = plugin === "babel" ? "@intlayer/babel" : "@intlayer/swc";
52
+ const spinner = _clack_prompts.spinner();
53
+ spinner.start("Installing packages...");
54
+ try {
55
+ (0, _intlayer_chokidar_cli.installPackages)(root, [packageToInstall], packageManager, true);
56
+ spinner.stop(`Installed: ${packageToInstall}`);
57
+ } catch {
58
+ spinner.stop("Package installation failed");
59
+ _clack_prompts.log.warn(`Please install manually: ${packageToInstall} (dev dependency)`);
60
+ }
61
+ if (plugin === "swc") {
62
+ _clack_prompts.outro("Build optimization configuration complete");
63
+ return;
64
+ }
65
+ const existingBabelConfig = BABEL_CONFIG_CANDIDATES.find((file) => (0, node_fs.existsSync)((0, node_path.join)(root, file)));
66
+ if (existingBabelConfig) {
67
+ _clack_prompts.log.warn(`${existingBabelConfig} already exists — add the Intlayer plugins manually.`);
68
+ _clack_prompts.note(_intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "Plugins to add to your babel config");
69
+ } else try {
70
+ (0, node_fs.writeFileSync)((0, node_path.join)(root, "babel.config.js"), _intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, { encoding: "utf-8" });
71
+ _clack_prompts.log.success("Created babel.config.js with the Intlayer compiler plugins (extract, purge, minify, optimize)");
72
+ } catch {
73
+ _clack_prompts.log.warn("Could not create babel.config.js — please create it manually.");
74
+ _clack_prompts.note(_intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "babel.config.js");
75
+ }
76
+ _clack_prompts.outro("Build optimization configuration complete");
77
+ };
78
+
79
+ //#endregion
80
+ exports.initBuildOptimization = initBuildOptimization;
81
+ //# sourceMappingURL=initBuildOptimization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initBuildOptimization.cjs","names":["findProjectRoot","p","NEXT_INTLAYER_BABEL_CONFIG_CONTENT"],"sources":["../../src/initBuildOptimization.ts"],"sourcesContent":["import { existsSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n detectPackageManager,\n installPackages,\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n} from '@intlayer/chokidar/cli';\nimport { findProjectRoot } from './init';\n\n/** Intlayer build optimization plugin choices for Next.js. */\nexport type BuildOptimizationPlugin = 'babel' | 'swc';\n\n/** Babel config filenames Next.js picks up, ordered by preference. */\nconst BABEL_CONFIG_CANDIDATES = [\n 'babel.config.js',\n 'babel.config.cjs',\n 'babel.config.mjs',\n 'babel.config.ts',\n];\n\n/**\n * Interactive prompt to select a build optimization plugin for Next.js and\n * scaffold the required files. The two options are independent — pick one:\n *\n * - `@intlayer/babel` — runs the full compiler pipeline (extract, purge, minify,\n * optimize) through Babel. Installs `@intlayer/babel` and creates a\n * `babel.config.js`.\n * - `@intlayer/swc` — lightweight SWC plugin that rewrites `useIntlayer` imports.\n * Installs only the dependency; `withIntlayer` wires it in automatically, so\n * no config file is required.\n *\n * @param projectRoot - Optional project root; defaults to the current directory.\n */\nexport const initBuildOptimization = async (\n projectRoot?: string\n): Promise<void> => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n p.intro('Configuring Next.js build optimization');\n\n const plugin = (await p.select({\n message: 'Which build optimization plugin do you want to use?',\n options: [\n {\n value: 'babel',\n label: '@intlayer/babel',\n hint: 'Full pipeline — extract, purge, minify and optimize via Babel; creates babel.config.js',\n },\n {\n value: 'swc',\n label: '@intlayer/swc',\n hint: 'Lightweight — SWC plugin that rewrites useIntlayer imports; wired automatically by withIntlayer',\n },\n ],\n })) as BuildOptimizationPlugin;\n\n if (p.isCancel(plugin) || !plugin) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const packageManager = detectPackageManager(root);\n const packageToInstall =\n plugin === 'babel' ? '@intlayer/babel' : '@intlayer/swc';\n\n const spinner = p.spinner();\n spinner.start('Installing packages...');\n\n try {\n installPackages(root, [packageToInstall], packageManager, true);\n spinner.stop(`Installed: ${packageToInstall}`);\n } catch {\n spinner.stop('Package installation failed');\n p.log.warn(`Please install manually: ${packageToInstall} (dev dependency)`);\n }\n\n // SWC needs no extra setup — withIntlayer injects the plugin at build time.\n if (plugin === 'swc') {\n p.outro('Build optimization configuration complete');\n return;\n }\n\n // BABEL — scaffold babel.config.js with the full compiler pipeline.\n const existingBabelConfig = BABEL_CONFIG_CANDIDATES.find((file) =>\n existsSync(join(root, file))\n );\n\n if (existingBabelConfig) {\n p.log.warn(\n `${existingBabelConfig} already exists — add the Intlayer plugins manually.`\n );\n p.note(\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n 'Plugins to add to your babel config'\n );\n } else {\n try {\n writeFileSync(\n join(root, 'babel.config.js'),\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n { encoding: 'utf-8' }\n );\n p.log.success(\n 'Created babel.config.js with the Intlayer compiler plugins (extract, purge, minify, optimize)'\n );\n } catch {\n p.log.warn(\n 'Could not create babel.config.js — please create it manually.'\n );\n p.note(NEXT_INTLAYER_BABEL_CONFIG_CONTENT, 'babel.config.js');\n }\n }\n\n p.outro('Build optimization configuration complete');\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;AAeD,MAAa,wBAAwB,OACnC,gBACkB;CAClB,MAAM,OAAOA,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AACD,gBAAE,MAAM,yCAAyC;CAEjD,MAAM,SAAU,MAAMC,eAAE,OAAO;EAC7B,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,EACD;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,CACF;EACF,CAAC;AAEF,KAAIA,eAAE,SAAS,OAAO,IAAI,CAAC,QAAQ;AACjC,iBAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,kEAAsC,KAAK;CACjD,MAAM,mBACJ,WAAW,UAAU,oBAAoB;CAE3C,MAAM,UAAUA,eAAE,SAAS;AAC3B,SAAQ,MAAM,yBAAyB;AAEvC,KAAI;AACF,8CAAgB,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,KAAK;AAC/D,UAAQ,KAAK,cAAc,mBAAmB;SACxC;AACN,UAAQ,KAAK,8BAA8B;AAC3C,iBAAE,IAAI,KAAK,4BAA4B,iBAAiB,mBAAmB;;AAI7E,KAAI,WAAW,OAAO;AACpB,iBAAE,MAAM,4CAA4C;AACpD;;CAIF,MAAM,sBAAsB,wBAAwB,MAAM,qDACxC,MAAM,KAAK,CAAC,CAC7B;AAED,KAAI,qBAAqB;AACvB,iBAAE,IAAI,KACJ,GAAG,oBAAoB,sDACxB;AACD,iBAAE,KACAC,2DACA,sCACD;OAED,KAAI;AACF,iDACO,MAAM,kBAAkB,EAC7BA,2DACA,EAAE,UAAU,SAAS,CACtB;AACD,iBAAE,IAAI,QACJ,gGACD;SACK;AACN,iBAAE,IAAI,KACJ,gEACD;AACD,iBAAE,KAAKA,2DAAoC,kBAAkB;;AAIjE,gBAAE,MAAM,4CAA4C"}
@@ -0,0 +1,117 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_init = require('./init.cjs');
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
7
+ let _clack_prompts = require("@clack/prompts");
8
+ _clack_prompts = require_runtime.__toESM(_clack_prompts);
9
+
10
+ //#region src/initCompiler.ts
11
+ /**
12
+ * babel.config.js that runs the Intlayer compiler passes for Next.js.
13
+ *
14
+ * Mirrors the Next.js (Babel) tab of `docs/docs/en/compiler.md`: the extract
15
+ * plugin pulls inline content into dictionaries and the optimize plugin
16
+ * rewrites `useIntlayer` into direct dictionary imports. On Vite the same work
17
+ * is handled by the `intlayer()` plugin (which bundles the compiler in v9), so
18
+ * no Babel config is needed.
19
+ */
20
+ const BABEL_COMPILER_CONFIG_CONTENT = `const {
21
+ intlayerExtractBabelPlugin,
22
+ intlayerOptimizeBabelPlugin,
23
+ getExtractPluginOptions,
24
+ getOptimizePluginOptions,
25
+ } = require("@intlayer/babel");
26
+
27
+ module.exports = {
28
+ presets: ["next/babel"],
29
+ plugins: [
30
+ // Extract content from components into dictionaries
31
+ [intlayerExtractBabelPlugin, getExtractPluginOptions()],
32
+ // Optimize imports by replacing useIntlayer with direct dictionary imports
33
+ [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],
34
+ ],
35
+ };
36
+ `;
37
+ /**
38
+ * Reads the project dependencies and detects which framework the compiler
39
+ * should target. Next.js is checked before Vite because a Next.js project may
40
+ * transitively depend on Vite tooling.
41
+ */
42
+ const detectCompilerFramework = (root) => {
43
+ try {
44
+ const packageJsonPath = (0, node_path.join)(root, "package.json");
45
+ if (!(0, node_fs.existsSync)(packageJsonPath)) return "unknown";
46
+ const { dependencies = {}, devDependencies = {} } = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf-8"));
47
+ const allDependencies = {
48
+ ...dependencies,
49
+ ...devDependencies
50
+ };
51
+ if (allDependencies.next) return "nextjs";
52
+ if (allDependencies.vite) return "vite";
53
+ return "unknown";
54
+ } catch {
55
+ return "unknown";
56
+ }
57
+ };
58
+ /**
59
+ * Scaffolds the Intlayer compiler for the current project during interactive
60
+ * init.
61
+ *
62
+ * - **Vite** — nothing to do: since v9 the compiler is built into the
63
+ * `intlayer()` plugin in `vite.config.ts`, so this only confirms the setup
64
+ * to the user.
65
+ * - **Next.js** — installs `@intlayer/babel` and writes a `babel.config.js`
66
+ * that runs the extract + optimize compiler passes.
67
+ *
68
+ * In non-interactive init this function is never called, so the compiler setup
69
+ * is left untouched.
70
+ */
71
+ const initCompiler = async (projectRoot) => {
72
+ const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
73
+ const framework = detectCompilerFramework(root);
74
+ if (framework === "vite") {
75
+ _clack_prompts.log.info("Vite detected — the compiler is built into `intlayer()` in your vite.config. Nothing to configure.");
76
+ return;
77
+ }
78
+ if (framework !== "nextjs") {
79
+ _clack_prompts.log.warn("No supported framework detected for the compiler — skipping. See the compiler docs for manual setup.");
80
+ return;
81
+ }
82
+ _clack_prompts.intro("Configuring the Intlayer compiler for Next.js");
83
+ const packageManager = (0, _intlayer_chokidar_cli.detectPackageManager)(root);
84
+ const devPackagesToInstall = ["@intlayer/babel"];
85
+ const spinner = _clack_prompts.spinner();
86
+ spinner.start("Installing packages...");
87
+ try {
88
+ (0, _intlayer_chokidar_cli.installPackages)(root, devPackagesToInstall, packageManager, true);
89
+ spinner.stop(`Installed: ${devPackagesToInstall.join(", ")}`);
90
+ } catch {
91
+ spinner.stop("Package installation failed");
92
+ _clack_prompts.log.warn(`Please install manually: ${devPackagesToInstall.join(" ")} (dev dependency)`);
93
+ }
94
+ const existingBabelConfig = [
95
+ "babel.config.js",
96
+ "babel.config.cjs",
97
+ "babel.config.mjs",
98
+ "babel.config.ts",
99
+ ".babelrc",
100
+ ".babelrc.js"
101
+ ].find((file) => (0, node_fs.existsSync)((0, node_path.join)(root, file)));
102
+ if (existingBabelConfig) {
103
+ _clack_prompts.log.warn(`${existingBabelConfig} already exists — add the Intlayer compiler plugins manually.`);
104
+ _clack_prompts.note(BABEL_COMPILER_CONFIG_CONTENT, "Plugins to add to your babel config");
105
+ } else try {
106
+ (0, node_fs.writeFileSync)((0, node_path.join)(root, "babel.config.js"), BABEL_COMPILER_CONFIG_CONTENT, { encoding: "utf-8" });
107
+ _clack_prompts.log.success("Created babel.config.js with the Intlayer compiler extract and optimize plugins");
108
+ } catch {
109
+ _clack_prompts.log.warn("Could not create babel.config.js — please create it manually.");
110
+ _clack_prompts.note(BABEL_COMPILER_CONFIG_CONTENT, "babel.config.js");
111
+ }
112
+ _clack_prompts.outro("Compiler configuration complete");
113
+ };
114
+
115
+ //#endregion
116
+ exports.initCompiler = initCompiler;
117
+ //# sourceMappingURL=initCompiler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initCompiler.cjs","names":["findProjectRoot","p"],"sources":["../../src/initCompiler.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { detectPackageManager, installPackages } from '@intlayer/chokidar/cli';\nimport { findProjectRoot } from './init';\n\n/** Framework the Intlayer compiler can be wired into during init. */\ntype CompilerFramework = 'vite' | 'nextjs' | 'unknown';\n\n/**\n * babel.config.js that runs the Intlayer compiler passes for Next.js.\n *\n * Mirrors the Next.js (Babel) tab of `docs/docs/en/compiler.md`: the extract\n * plugin pulls inline content into dictionaries and the optimize plugin\n * rewrites `useIntlayer` into direct dictionary imports. On Vite the same work\n * is handled by the `intlayer()` plugin (which bundles the compiler in v9), so\n * no Babel config is needed.\n */\nconst BABEL_COMPILER_CONFIG_CONTENT = `const {\n intlayerExtractBabelPlugin,\n intlayerOptimizeBabelPlugin,\n getExtractPluginOptions,\n getOptimizePluginOptions,\n} = require(\"@intlayer/babel\");\n\nmodule.exports = {\n presets: [\"next/babel\"],\n plugins: [\n // Extract content from components into dictionaries\n [intlayerExtractBabelPlugin, getExtractPluginOptions()],\n // Optimize imports by replacing useIntlayer with direct dictionary imports\n [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],\n ],\n};\n`;\n\n/**\n * Reads the project dependencies and detects which framework the compiler\n * should target. Next.js is checked before Vite because a Next.js project may\n * transitively depend on Vite tooling.\n */\nconst detectCompilerFramework = (root: string): CompilerFramework => {\n try {\n const packageJsonPath = join(root, 'package.json');\n if (!existsSync(packageJsonPath)) return 'unknown';\n\n const { dependencies = {}, devDependencies = {} } = JSON.parse(\n readFileSync(packageJsonPath, 'utf-8')\n );\n const allDependencies = { ...dependencies, ...devDependencies };\n\n if (allDependencies.next) return 'nextjs';\n if (allDependencies.vite) return 'vite';\n\n return 'unknown';\n } catch {\n return 'unknown';\n }\n};\n\n/**\n * Scaffolds the Intlayer compiler for the current project during interactive\n * init.\n *\n * - **Vite** — nothing to do: since v9 the compiler is built into the\n * `intlayer()` plugin in `vite.config.ts`, so this only confirms the setup\n * to the user.\n * - **Next.js** — installs `@intlayer/babel` and writes a `babel.config.js`\n * that runs the extract + optimize compiler passes.\n *\n * In non-interactive init this function is never called, so the compiler setup\n * is left untouched.\n */\nexport const initCompiler = async (projectRoot?: string): Promise<void> => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n const framework = detectCompilerFramework(root);\n\n if (framework === 'vite') {\n // Since v9 the compiler is bundled inside intlayer() — nothing to scaffold.\n p.log.info(\n 'Vite detected — the compiler is built into `intlayer()` in your vite.config. Nothing to configure.'\n );\n return;\n }\n\n if (framework !== 'nextjs') {\n p.log.warn(\n 'No supported framework detected for the compiler — skipping. See the compiler docs for manual setup.'\n );\n return;\n }\n\n p.intro('Configuring the Intlayer compiler for Next.js');\n\n const packageManager = detectPackageManager(root);\n const devPackagesToInstall = ['@intlayer/babel'];\n\n const spinner = p.spinner();\n spinner.start('Installing packages...');\n\n try {\n installPackages(root, devPackagesToInstall, packageManager, true);\n spinner.stop(`Installed: ${devPackagesToInstall.join(', ')}`);\n } catch {\n spinner.stop('Package installation failed');\n p.log.warn(\n `Please install manually: ${devPackagesToInstall.join(' ')} (dev dependency)`\n );\n }\n\n const babelConfigCandidates = [\n 'babel.config.js',\n 'babel.config.cjs',\n 'babel.config.mjs',\n 'babel.config.ts',\n '.babelrc',\n '.babelrc.js',\n ];\n\n const existingBabelConfig = babelConfigCandidates.find((file) =>\n existsSync(join(root, file))\n );\n\n if (existingBabelConfig) {\n p.log.warn(\n `${existingBabelConfig} already exists — add the Intlayer compiler plugins manually.`\n );\n p.note(\n BABEL_COMPILER_CONFIG_CONTENT,\n 'Plugins to add to your babel config'\n );\n } else {\n try {\n writeFileSync(\n join(root, 'babel.config.js'),\n BABEL_COMPILER_CONFIG_CONTENT,\n { encoding: 'utf-8' }\n );\n p.log.success(\n 'Created babel.config.js with the Intlayer compiler extract and optimize plugins'\n );\n } catch {\n p.log.warn(\n 'Could not create babel.config.js — please create it manually.'\n );\n p.note(BABEL_COMPILER_CONFIG_CONTENT, 'babel.config.js');\n }\n }\n\n p.outro('Compiler configuration complete');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;AAuBtC,MAAM,2BAA2B,SAAoC;AACnE,KAAI;EACF,MAAM,sCAAuB,MAAM,eAAe;AAClD,MAAI,yBAAY,gBAAgB,CAAE,QAAO;EAEzC,MAAM,EAAE,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,KAAK,gCAC1C,iBAAiB,QAAQ,CACvC;EACD,MAAM,kBAAkB;GAAE,GAAG;GAAc,GAAG;GAAiB;AAE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