@intlayer/cli 9.0.0-canary.12 → 9.0.0-canary.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/init.cjs CHANGED
@@ -82,6 +82,28 @@ const ROUTING_MODE_OPTIONS = [
82
82
  hint: "/about?locale=fr"
83
83
  }
84
84
  ];
85
+ /**
86
+ * Content organization strategies offered by the interactive init flow.
87
+ * Drives the `compiler.output` template (autogenerated content: compiler /
88
+ * autofill / extract) or the injection of the syncJSON plugin.
89
+ */
90
+ const CONTENT_STRATEGY_OPTIONS = [
91
+ {
92
+ value: "per-component",
93
+ label: "Per component (default)",
94
+ hint: "multilingual .content files co-located with the components"
95
+ },
96
+ {
97
+ value: "centralized",
98
+ label: "Centralized folder",
99
+ hint: "per-locale JSON dictionaries under /locales/{locale}/{key}.content.json"
100
+ },
101
+ {
102
+ value: "json-namespaces",
103
+ label: "JSON namespaces",
104
+ hint: "plain /locales/{locale}/{namespace}.json files synced via @intlayer/sync-json-plugin"
105
+ }
106
+ ];
85
107
  const COMPAT_LIB_OPTIONS = [
86
108
  {
87
109
  value: "i18next",
@@ -284,10 +306,24 @@ const runInteractiveInit = async (root, baseOptions) => {
284
306
  } else if (hasLinguiJson && !hasLinguiPo) hintDependencies["__lingui_json__"] = "*";
285
307
  }
286
308
  }
309
+ let contentStrategy;
310
+ if (!hasCompatLib && !hintDependencies) {
311
+ const selectedContentStrategy = await _clack_prompts.select({
312
+ message: "How do you want to organize your translated content?",
313
+ options: CONTENT_STRATEGY_OPTIONS,
314
+ initialValue: "per-component"
315
+ });
316
+ if (_clack_prompts.isCancel(selectedContentStrategy)) {
317
+ _clack_prompts.cancel("Operation cancelled.");
318
+ return;
319
+ }
320
+ contentStrategy = selectedContentStrategy;
321
+ }
287
322
  await (0, _intlayer_engine_cli.initIntlayer)(root, {
288
323
  ...baseOptions,
289
324
  routingMode,
290
325
  hintDependencies,
326
+ contentStrategy,
291
327
  noInstallPackages: !steps.includes("packages"),
292
328
  noGitignore: baseOptions?.noGitignore,
293
329
  noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
@@ -1 +1 @@
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/engine/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;EACP,MAAM;EACN,UAAU,CAAC,iBAAiB;EAC7B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,aAAa;EACzB;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;EACP,MAAM;EACN,UAAU,CAAC,cAAc;EAC1B;CACF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QAAMQ,yBAAM;GACV,WAAW;GACX,gBAAgB,8DAAoC,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,8CAAmB,MAAM,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 ContentStrategy,\n type InitOptions,\n initIntlayer,\n PLATFORMS,\n type Platform,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/engine/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 * Content organization strategies offered by the interactive init flow.\n * Drives the `compiler.output` template (autogenerated content: compiler /\n * autofill / extract) or the injection of the syncJSON plugin.\n */\nconst CONTENT_STRATEGY_OPTIONS: Array<{\n value: ContentStrategy;\n label: string;\n hint: string;\n}> = [\n {\n value: 'per-component',\n label: 'Per component (default)',\n hint: 'multilingual .content files co-located with the components',\n },\n {\n value: 'centralized',\n label: 'Centralized folder',\n hint: 'per-locale JSON dictionaries under /locales/{locale}/{key}.content.json',\n },\n {\n value: 'json-namespaces',\n label: 'JSON namespaces',\n hint: 'plain /locales/{locale}/{namespace}.json files synced via @intlayer/sync-json-plugin',\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 // Content organization strategy → drives `compiler.output` (autogenerated\n // content) or the syncJSON plugin injection. A compat library already\n // dictates the catalog layout (its JSON/PO files are synced as-is), so the\n // question is only asked when none is in play.\n let contentStrategy: ContentStrategy | undefined;\n\n if (!hasCompatLib && !hintDependencies) {\n const selectedContentStrategy = await p.select<ContentStrategy>({\n message: 'How do you want to organize your translated content?',\n options: CONTENT_STRATEGY_OPTIONS,\n initialValue: 'per-component',\n });\n\n if (p.isCancel(selectedContentStrategy)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n contentStrategy = selectedContentStrategy;\n }\n\n const options: InitOptions = {\n ...baseOptions,\n routingMode,\n hintDependencies,\n contentStrategy,\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":";;;;;;;;;;;;;;;;AAuBA,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;;;;;;AAOD,MAAM,2BAID;CACH;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;EACP,MAAM;EACN,UAAU,CAAC,iBAAiB;EAC7B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,aAAa;EACzB;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;EACP,MAAM;EACN,UAAU,CAAC,cAAc;EAC1B;CACF;;AAGD,MAAM,0BAA0B,SAAyC;AACvE,KAAI;EACF,MAAM,sCAAuB,MAAM,eAAe;AAClD,MAAI,y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AAc;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,8DAAoC,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,8CAAmB,MAAM,QAAQ"}
package/dist/esm/init.mjs CHANGED
@@ -78,6 +78,28 @@ const ROUTING_MODE_OPTIONS = [
78
78
  hint: "/about?locale=fr"
79
79
  }
80
80
  ];
81
+ /**
82
+ * Content organization strategies offered by the interactive init flow.
83
+ * Drives the `compiler.output` template (autogenerated content: compiler /
84
+ * autofill / extract) or the injection of the syncJSON plugin.
85
+ */
86
+ const CONTENT_STRATEGY_OPTIONS = [
87
+ {
88
+ value: "per-component",
89
+ label: "Per component (default)",
90
+ hint: "multilingual .content files co-located with the components"
91
+ },
92
+ {
93
+ value: "centralized",
94
+ label: "Centralized folder",
95
+ hint: "per-locale JSON dictionaries under /locales/{locale}/{key}.content.json"
96
+ },
97
+ {
98
+ value: "json-namespaces",
99
+ label: "JSON namespaces",
100
+ hint: "plain /locales/{locale}/{namespace}.json files synced via @intlayer/sync-json-plugin"
101
+ }
102
+ ];
81
103
  const COMPAT_LIB_OPTIONS = [
82
104
  {
83
105
  value: "i18next",
@@ -280,10 +302,24 @@ const runInteractiveInit = async (root, baseOptions) => {
280
302
  } else if (hasLinguiJson && !hasLinguiPo) hintDependencies["__lingui_json__"] = "*";
281
303
  }
282
304
  }
305
+ let contentStrategy;
306
+ if (!hasCompatLib && !hintDependencies) {
307
+ const selectedContentStrategy = await p.select({
308
+ message: "How do you want to organize your translated content?",
309
+ options: CONTENT_STRATEGY_OPTIONS,
310
+ initialValue: "per-component"
311
+ });
312
+ if (p.isCancel(selectedContentStrategy)) {
313
+ p.cancel("Operation cancelled.");
314
+ return;
315
+ }
316
+ contentStrategy = selectedContentStrategy;
317
+ }
283
318
  await initIntlayer(root, {
284
319
  ...baseOptions,
285
320
  routingMode,
286
321
  hintDependencies,
322
+ contentStrategy,
287
323
  noInstallPackages: !steps.includes("packages"),
288
324
  noGitignore: baseOptions?.noGitignore,
289
325
  noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
@@ -1 +1 @@
1
- {"version":3,"file":"init.mjs","names":[],"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/engine/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,eAAe,QAAQ,YAAY,KAAK,EAAE;AAC/C,MAAI,WAAW,KAAK,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,eAAa,QAAQ,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;EACP,MAAM;EACN,UAAU,CAAC,iBAAiB;EAC7B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;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BAAsB,KAAK;CAMnC,MAAM,iBAAiB,MAAM,EAAE,QAAQ;EACrC,SACE;EACF,cAAc;EACf,CAAC;AAEF,KAAI,EAAE,SAAS,eAAe,EAAE;AAC9B,IAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,gBAAgB;AAClB,IAAE,IAAI,KAAK,wDAAwD;AAGnE,QAAM,MAAM;GACV,WAAW;GACX,gBAAgB,gBAAgB,oBAAoB,MAAM,YAAY;GACvE,CAAC;;AAGJ,GAAE,MAAM,mCAAmC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,gBAAgB,QAAQ,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,OAAM,aAAa,MAAM,QAAQ"}
1
+ {"version":3,"file":"init.mjs","names":[],"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 ContentStrategy,\n type InitOptions,\n initIntlayer,\n PLATFORMS,\n type Platform,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/engine/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 * Content organization strategies offered by the interactive init flow.\n * Drives the `compiler.output` template (autogenerated content: compiler /\n * autofill / extract) or the injection of the syncJSON plugin.\n */\nconst CONTENT_STRATEGY_OPTIONS: Array<{\n value: ContentStrategy;\n label: string;\n hint: string;\n}> = [\n {\n value: 'per-component',\n label: 'Per component (default)',\n hint: 'multilingual .content files co-located with the components',\n },\n {\n value: 'centralized',\n label: 'Centralized folder',\n hint: 'per-locale JSON dictionaries under /locales/{locale}/{key}.content.json',\n },\n {\n value: 'json-namespaces',\n label: 'JSON namespaces',\n hint: 'plain /locales/{locale}/{namespace}.json files synced via @intlayer/sync-json-plugin',\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 // Content organization strategy → drives `compiler.output` (autogenerated\n // content) or the syncJSON plugin injection. A compat library already\n // dictates the catalog layout (its JSON/PO files are synced as-is), so the\n // question is only asked when none is in play.\n let contentStrategy: ContentStrategy | undefined;\n\n if (!hasCompatLib && !hintDependencies) {\n const selectedContentStrategy = await p.select<ContentStrategy>({\n message: 'How do you want to organize your translated content?',\n options: CONTENT_STRATEGY_OPTIONS,\n initialValue: 'per-component',\n });\n\n if (p.isCancel(selectedContentStrategy)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n contentStrategy = selectedContentStrategy;\n }\n\n const options: InitOptions = {\n ...baseOptions,\n routingMode,\n hintDependencies,\n contentStrategy,\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":";;;;;;;;;;;;AAuBA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;AAEjB,QAAO,eAAe,QAAQ,YAAY,KAAK,EAAE;AAC/C,MAAI,WAAW,KAAK,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,eAAa,QAAQ,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;;;;;;AAOD,MAAM,2BAID;CACH;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;EACP,MAAM;EACN,UAAU,CAAC,iBAAiB;EAC7B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,aAAa;EACzB;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAAC,eAAe;EAC3B;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACN,UAAU,CAA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,SAAS,WAAW,CAC5B,OAAM,aAAa,KAAK;AAG1B,KAAI,MAAM,SAAS,oBAAoB,CACrC,OAAM,sBAAsB,KAAK;CAMnC,MAAM,iBAAiB,MAAM,EAAE,QAAQ;EACrC,SACE;EACF,cAAc;EACf,CAAC;AAEF,KAAI,EAAE,SAAS,eAAe,EAAE;AAC9B,IAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,gBAAgB;AAClB,IAAE,IAAI,KAAK,wDAAwD;AAGnE,QAAM,MAAM;GACV,WAAW;GACX,gBAAgB,gBAAgB,oBAAoB,MAAM,YAAY;GACvE,CAAC;;AAGJ,GAAE,MAAM,mCAAmC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,gBAAgB,QAAQ,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,OAAM,aAAa,MAAM,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","names":[],"sources":["../../src/init.ts"],"mappings":";;;cAsBa,eAAA,GAAmB,QAAA;AAAA,cA0enB,IAAA,GACX,WAAA,WACA,OAAA,GAAU,WAAA,EACV,WAAA,eAAqB,OAAA"}
1
+ {"version":3,"file":"init.d.ts","names":[],"sources":["../../src/init.ts"],"mappings":";;;cAuBa,eAAA,GAAmB,QAAA;AAAA,cA2hBnB,IAAA,GACX,WAAA,WACA,OAAA,GAAU,WAAA,EACV,WAAA,eAAqB,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/cli",
3
- "version": "9.0.0-canary.12",
3
+ "version": "9.0.0-canary.13",
4
4
  "private": false,
5
5
  "description": "Provides uniform command-line interface scripts for Intlayer, used in packages like intlayer-cli and intlayer.",
6
6
  "keywords": [
@@ -67,22 +67,22 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@clack/prompts": "0.11.0",
70
- "@intlayer/api": "9.0.0-canary.12",
71
- "@intlayer/babel": "9.0.0-canary.12",
72
- "@intlayer/config": "9.0.0-canary.12",
73
- "@intlayer/core": "9.0.0-canary.12",
74
- "@intlayer/dictionaries-entry": "9.0.0-canary.12",
75
- "@intlayer/engine": "9.0.0-canary.12",
76
- "@intlayer/remote-dictionaries-entry": "9.0.0-canary.12",
77
- "@intlayer/types": "9.0.0-canary.12",
78
- "@intlayer/unmerged-dictionaries-entry": "9.0.0-canary.12",
79
- "commander": "14.0.3",
70
+ "@intlayer/api": "9.0.0-canary.13",
71
+ "@intlayer/babel": "9.0.0-canary.13",
72
+ "@intlayer/config": "9.0.0-canary.13",
73
+ "@intlayer/core": "9.0.0-canary.13",
74
+ "@intlayer/dictionaries-entry": "9.0.0-canary.13",
75
+ "@intlayer/engine": "9.0.0-canary.13",
76
+ "@intlayer/remote-dictionaries-entry": "9.0.0-canary.13",
77
+ "@intlayer/types": "9.0.0-canary.13",
78
+ "@intlayer/unmerged-dictionaries-entry": "9.0.0-canary.13",
79
+ "commander": "15.0.0",
80
80
  "enquirer": "2.4.1",
81
81
  "eventsource": "4.1.0",
82
82
  "fast-glob": "3.3.3"
83
83
  },
84
84
  "devDependencies": {
85
- "@intlayer/ai": "9.0.0-canary.12",
85
+ "@intlayer/ai": "9.0.0-canary.13",
86
86
  "@types/node": "25.9.4",
87
87
  "@utils/ts-config": "1.0.4",
88
88
  "@utils/ts-config-types": "1.0.4",
@@ -93,7 +93,7 @@
93
93
  "vitest": "4.1.9"
94
94
  },
95
95
  "peerDependencies": {
96
- "@intlayer/ai": "9.0.0-canary.12"
96
+ "@intlayer/ai": "9.0.0-canary.13"
97
97
  },
98
98
  "peerDependenciesMeta": {
99
99
  "@intlayer/ai": {