@intlayer/cli 9.5.12 → 9.6.0

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 (82) hide show
  1. package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
  2. package/dist/cjs/ci.cjs +1 -1
  3. package/dist/cjs/cli.cjs +51 -12
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/extract.cjs +1 -1
  6. package/dist/cjs/fill/fill.cjs +25 -9
  7. package/dist/cjs/fill/fill.cjs.map +1 -1
  8. package/dist/cjs/getTargetDictionary.cjs +1 -1
  9. package/dist/cjs/index.cjs +15 -1
  10. package/dist/cjs/init.cjs +98 -27
  11. package/dist/cjs/init.cjs.map +1 -1
  12. package/dist/cjs/initChromeExtension.cjs +26 -3
  13. package/dist/cjs/initChromeExtension.cjs.map +1 -1
  14. package/dist/cjs/initInfra.cjs +6 -0
  15. package/dist/cjs/initInfra.cjs.map +1 -1
  16. package/dist/cjs/initMCP.cjs +18 -7
  17. package/dist/cjs/initMCP.cjs.map +1 -1
  18. package/dist/cjs/initSkills.cjs +37 -34
  19. package/dist/cjs/initSkills.cjs.map +1 -1
  20. package/dist/cjs/listContentDeclaration.cjs +1 -1
  21. package/dist/cjs/listProjects.cjs +1 -1
  22. package/dist/cjs/pull.cjs +1 -1
  23. package/dist/cjs/push/push.cjs +1 -1
  24. package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -1
  25. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
  26. package/dist/cjs/translateDoc/translateDoc.cjs +1 -1
  27. package/dist/cjs/upgrade.cjs +1 -1
  28. package/dist/cjs/utils/getParentPackageJSON.cjs +1 -1
  29. package/dist/cjs/utils/isInteractiveTerminal.cjs +12 -0
  30. package/dist/cjs/utils/isInteractiveTerminal.cjs.map +1 -0
  31. package/dist/cjs/utils/parseChoice.cjs +21 -0
  32. package/dist/cjs/utils/parseChoice.cjs.map +1 -0
  33. package/dist/esm/_virtual/_utils_asset.mjs +1 -1
  34. package/dist/esm/ci.mjs +1 -1
  35. package/dist/esm/cli.mjs +51 -12
  36. package/dist/esm/cli.mjs.map +1 -1
  37. package/dist/esm/extract.mjs +1 -1
  38. package/dist/esm/fill/fill.mjs +25 -9
  39. package/dist/esm/fill/fill.mjs.map +1 -1
  40. package/dist/esm/getTargetDictionary.mjs +1 -1
  41. package/dist/esm/index.mjs +5 -4
  42. package/dist/esm/init.mjs +93 -28
  43. package/dist/esm/init.mjs.map +1 -1
  44. package/dist/esm/initChromeExtension.mjs +24 -4
  45. package/dist/esm/initChromeExtension.mjs.map +1 -1
  46. package/dist/esm/initInfra.mjs +6 -0
  47. package/dist/esm/initInfra.mjs.map +1 -1
  48. package/dist/esm/initMCP.mjs +21 -11
  49. package/dist/esm/initMCP.mjs.map +1 -1
  50. package/dist/esm/initSkills.mjs +37 -36
  51. package/dist/esm/initSkills.mjs.map +1 -1
  52. package/dist/esm/listContentDeclaration.mjs +1 -1
  53. package/dist/esm/listProjects.mjs +1 -1
  54. package/dist/esm/pull.mjs +1 -1
  55. package/dist/esm/push/push.mjs +1 -1
  56. package/dist/esm/reviewDoc/reviewDoc.mjs +1 -1
  57. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
  58. package/dist/esm/translateDoc/translateDoc.mjs +1 -1
  59. package/dist/esm/upgrade.mjs +1 -1
  60. package/dist/esm/utils/getParentPackageJSON.mjs +1 -1
  61. package/dist/esm/utils/isInteractiveTerminal.mjs +11 -0
  62. package/dist/esm/utils/isInteractiveTerminal.mjs.map +1 -0
  63. package/dist/esm/utils/parseChoice.mjs +20 -0
  64. package/dist/esm/utils/parseChoice.mjs.map +1 -0
  65. package/dist/types/fill/fill.d.ts +22 -1
  66. package/dist/types/fill/fill.d.ts.map +1 -1
  67. package/dist/types/fill/index.d.ts +2 -2
  68. package/dist/types/index.d.ts +6 -5
  69. package/dist/types/init.d.ts +36 -0
  70. package/dist/types/init.d.ts.map +1 -1
  71. package/dist/types/initChromeExtension.d.ts +19 -1
  72. package/dist/types/initChromeExtension.d.ts.map +1 -1
  73. package/dist/types/initInfra.d.ts.map +1 -1
  74. package/dist/types/initMCP.d.ts +16 -2
  75. package/dist/types/initMCP.d.ts.map +1 -1
  76. package/dist/types/initSkills.d.ts +23 -6
  77. package/dist/types/initSkills.d.ts.map +1 -1
  78. package/dist/types/utils/isInteractiveTerminal.d.ts +9 -0
  79. package/dist/types/utils/isInteractiveTerminal.d.ts.map +1 -0
  80. package/dist/types/utils/parseChoice.d.ts +13 -0
  81. package/dist/types/utils/parseChoice.d.ts.map +1 -0
  82. package/package.json +11 -11
package/dist/esm/init.mjs CHANGED
@@ -1,12 +1,14 @@
1
1
  import { login } from "./auth/login.mjs";
2
2
  import { loadPrompts } from "./loadPrompts.mjs";
3
+ import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
4
+ import { parseChoice } from "./utils/parseChoice.mjs";
3
5
  import { initChromeExtension } from "./initChromeExtension.mjs";
4
6
  import { initInfra } from "./initInfra.mjs";
5
7
  import { initSkills } from "./initSkills.mjs";
6
8
  import { initMCP } from "./initMCP.mjs";
7
- import { join, resolve } from "node:path";
8
9
  import { detectCompatI18nLibraries, hasLintTooling, hasUrlRoutingFramework, initIntlayer, logInitSuccessMessage, setupCmsCredentials } from "@intlayer/engine/cli";
9
10
  import { existsSync, readFileSync } from "node:fs";
11
+ import { join, resolve } from "node:path";
10
12
 
11
13
  //#region src/init.ts
12
14
  const findProjectRoot = (startDir) => {
@@ -17,12 +19,81 @@ const findProjectRoot = (startDir) => {
17
19
  }
18
20
  return startDir;
19
21
  };
22
+ /** Resolves the project root from `--project-root`, else the working directory. */
23
+ const resolveProjectRoot = (projectRoot) => findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
20
24
  /**
21
25
  * Steps shown but not pre-selected. The infrastructure installer touches the
22
26
  * machine (downloads an app, pulls Docker images) and browser extensions open external URLs
23
27
  * rather than modifying the project, so they must be an explicit choice.
24
28
  */
25
29
  const OPT_IN_INIT_STEPS = ["infra", "chromeExtension"];
30
+ /**
31
+ * Steps run by `intlayer init` without `--interactive`: install the packages
32
+ * and set up the framework. Every other step has its own command
33
+ * ({@link INIT_STEP_COMMANDS}), so nothing outside the app code is touched
34
+ * unless asked for.
35
+ */
36
+ const DEFAULT_INIT_STEPS = ["packages", "projectSetup"];
37
+ /**
38
+ * Command running each interactive step on its own, without prompts when every
39
+ * value is passed as a flag. Printed when `--interactive` has no terminal.
40
+ */
41
+ const INIT_STEP_COMMANDS = {
42
+ packages: "intlayer init packages",
43
+ projectSetup: "intlayer init project [--routing <routing>]",
44
+ githubActions: "intlayer init github-actions",
45
+ vscodeExtension: "intlayer init vscode-extension",
46
+ eslint: "intlayer init eslint",
47
+ chromeExtension: "intlayer init extension [--browser <chrome|firefox>]",
48
+ skills: "intlayer init skills [--platform <platform>] [--skills <skills...>]",
49
+ mcp: "intlayer init mcp [--platform <platform>] [--transport <stdio|sse>]",
50
+ lsp: "intlayer init lsp",
51
+ cms: "intlayer init cms",
52
+ infra: "intlayer init infra --mode <desktop|docker|compose>"
53
+ };
54
+ /**
55
+ * Maps setup steps to the {@link initIntlayer} options: every step handled by
56
+ * `initIntlayer` that is not listed is skipped. Explicit `--no-*` flags in
57
+ * `baseOptions` still win over a listed step.
58
+ */
59
+ const getInitOptionsForSteps = (steps, baseOptions) => ({
60
+ ...baseOptions,
61
+ noInstallPackages: baseOptions?.noInstallPackages || !steps.includes("packages"),
62
+ noGitignore: baseOptions?.noGitignore || !steps.includes("projectSetup"),
63
+ noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
64
+ noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("projectSetup"),
65
+ noVscodeExtension: baseOptions?.noVscodeExtension || !steps.includes("vscodeExtension"),
66
+ noLsp: baseOptions?.noLsp || !steps.includes("lsp"),
67
+ noEslint: baseOptions?.noEslint || !steps.includes("eslint"),
68
+ skipFinalMessage: baseOptions?.skipFinalMessage || !steps.includes("projectSetup")
69
+ });
70
+ /**
71
+ * Runs the given {@link initIntlayer} steps only (packages, project setup, CI,
72
+ * VS Code extension, LSP, lint rules). Backs `intlayer init` and its
73
+ * single-step subcommands.
74
+ */
75
+ const initSteps = async (projectRoot, steps, options) => {
76
+ await initIntlayer(resolveProjectRoot(projectRoot), getInitOptionsForSteps(steps, options));
77
+ };
78
+ /**
79
+ * Logs in to the Intlayer CMS through the browser, then stores the access-key
80
+ * credentials in `.env` and enables the editor in the config file.
81
+ */
82
+ const initCms = async (projectRoot) => {
83
+ const root = resolveProjectRoot(projectRoot);
84
+ (await loadPrompts()).log.info("Opening your browser to log in to the Intlayer CMS...");
85
+ await login({
86
+ exitAfter: false,
87
+ onCredentials: (credentials) => setupCmsCredentials(root, credentials)
88
+ });
89
+ };
90
+ /** Explains why `--interactive` cannot run, and what to run instead. */
91
+ const getNoTerminalMessage = () => [
92
+ "`intlayer init --interactive` needs a terminal to answer its prompts (none is attached, e.g. when run by an AI agent or in CI).",
93
+ "Run the steps directly instead:",
94
+ " intlayer init (installs the packages and sets up the framework)",
95
+ ...Object.values(INIT_STEP_COMMANDS).map((command) => ` ${command}`)
96
+ ].join("\n");
26
97
  /** Grouped checkbox entries of the interactive init flow, in display order. */
27
98
  const INIT_STEP_GROUPS = {
28
99
  Codebase: [
@@ -117,11 +188,7 @@ const ROUTING_OPTIONS = [
117
188
  /** Locale routing choices accepted by `--routing`. */
118
189
  const LOCALE_ROUTING_CHOICES = ROUTING_OPTIONS.map((option) => option.value);
119
190
  /** Validates a `--routing` value, throwing on an unknown choice. */
120
- const parseLocaleRoutingChoice = (value) => {
121
- const choice = LOCALE_ROUTING_CHOICES.find((routing) => routing === value);
122
- if (!choice) throw new Error(`Invalid --routing value "${value}". Expected one of: ${LOCALE_ROUTING_CHOICES.join(", ")}.`);
123
- return choice;
124
- };
191
+ const parseLocaleRoutingChoice = (value) => parseChoice(value, LOCALE_ROUTING_CHOICES, "--routing");
125
192
  /** Maps a routing choice to the init options it sets. */
126
193
  const getRoutingInitOptions = (choice) => choice === "none" ? {
127
194
  routingMode: "no-prefix",
@@ -222,41 +289,39 @@ const runInteractiveInit = async (root, baseOptions) => {
222
289
  routingOptions = getRoutingInitOptions(selectedRouting);
223
290
  }
224
291
  const options = {
225
- ...baseOptions,
226
- ...routingOptions,
227
- noInstallPackages: !steps.includes("packages"),
228
- noGitignore: baseOptions?.noGitignore || !steps.includes("projectSetup"),
229
- noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
230
- noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("projectSetup"),
231
- noVscodeExtension: !steps.includes("vscodeExtension"),
232
- noLsp: !steps.includes("lsp"),
233
- noEslint: !steps.includes("eslint"),
292
+ ...getInitOptionsForSteps(steps, {
293
+ ...baseOptions,
294
+ ...routingOptions
295
+ }),
234
296
  skipFinalMessage: true
235
297
  };
236
298
  const { guideUrl } = await initIntlayer(root, options);
237
299
  const skillsPlatform = steps.includes("skills") ? await initSkills(root) : void 0;
238
- if (steps.includes("mcp")) await initMCP(root, skillsPlatform);
300
+ if (steps.includes("mcp")) await initMCP(root, { platform: skillsPlatform });
239
301
  if (steps.includes("infra")) await initInfra();
240
302
  if (steps.includes("chromeExtension")) await initChromeExtension();
241
- if (steps.includes("cms")) {
242
- p.log.info("Opening your browser to log in to the Intlayer CMS...");
243
- await login({
244
- exitAfter: false,
245
- onCredentials: (credentials) => setupCmsCredentials(root, credentials)
246
- });
247
- }
303
+ if (steps.includes("cms")) await initCms(root);
248
304
  p.outro("Intlayer initialization complete");
249
305
  if (guideUrl) logInitSuccessMessage(guideUrl);
250
306
  };
307
+ /**
308
+ * `intlayer init`: installs the packages and sets up the framework, or, with
309
+ * `interactive`, lets the user pick every setup step. `--interactive` needs a
310
+ * terminal; without one it fails and lists the single-step commands instead.
311
+ */
251
312
  const init = async (projectRoot, options, interactive) => {
252
- const root = projectRoot ? findProjectRoot(resolve(projectRoot)) : findProjectRoot(process.cwd());
253
- if (interactive) {
254
- await runInteractiveInit(root, options);
313
+ if (!interactive) {
314
+ await initSteps(projectRoot, DEFAULT_INIT_STEPS, options);
315
+ return;
316
+ }
317
+ if (!isInteractiveTerminal()) {
318
+ (await loadPrompts()).log.error(getNoTerminalMessage());
319
+ process.exitCode = 1;
255
320
  return;
256
321
  }
257
- await initIntlayer(root, options);
322
+ await runInteractiveInit(resolveProjectRoot(projectRoot), options);
258
323
  };
259
324
 
260
325
  //#endregion
261
- export { ESLINT_CONFIG_FILES, INIT_STEP_GROUPS, LOCALE_ROUTING_CHOICES, OPT_IN_INIT_STEPS, findProjectRoot, getInitialInitSteps, getProjectDependencies, getRoutingInitOptions, init, isEslintInstalled, parseLocaleRoutingChoice };
326
+ export { DEFAULT_INIT_STEPS, ESLINT_CONFIG_FILES, INIT_STEP_COMMANDS, INIT_STEP_GROUPS, LOCALE_ROUTING_CHOICES, OPT_IN_INIT_STEPS, findProjectRoot, getInitOptionsForSteps, getInitialInitSteps, getProjectDependencies, getRoutingInitOptions, init, initCms, initSteps, isEslintInstalled, parseLocaleRoutingChoice, resolveProjectRoot };
262
327
  //# sourceMappingURL=init.mjs.map
@@ -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 {\n detectCompatI18nLibraries,\n hasLintTooling,\n hasUrlRoutingFramework,\n type InitOptions,\n initIntlayer,\n logInitSuccessMessage,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/engine/cli';\nimport { login } from './auth/login';\nimport { initChromeExtension } from './initChromeExtension';\nimport { initInfra } from './initInfra';\nimport { initMCP } from './initMCP';\nimport { initSkills } from './initSkills';\nimport { loadPrompts } from './loadPrompts';\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. */\nexport type InitStep =\n | 'packages'\n | 'githubActions'\n | 'projectSetup'\n | 'vscodeExtension'\n | 'lsp'\n | 'eslint'\n | 'skills'\n | 'mcp'\n | 'infra'\n | 'cms'\n | 'chromeExtension';\n\n/** A checkbox entry of the interactive init flow. */\nexport type InitStepOption = {\n value: InitStep;\n label: string;\n hint: string;\n};\n\n/**\n * Steps shown but not pre-selected. The infrastructure installer touches the\n * machine (downloads an app, pulls Docker images) and browser extensions open external URLs\n * rather than modifying the project, so they must be an explicit choice.\n */\nexport const OPT_IN_INIT_STEPS: InitStep[] = ['infra', 'chromeExtension'];\n\n/** Grouped checkbox entries of the interactive init flow, in display order. */\nexport const INIT_STEP_GROUPS: Record<string, InitStepOption[]> = {\n Codebase: [\n {\n value: 'packages',\n label: 'Install & upgrade packages',\n hint: 'install missing Intlayer dependencies and upgrade outdated ones',\n },\n {\n value: 'projectSetup',\n label: 'Project setup',\n hint: 'intlayer config, tsconfig, bundler plugin, middleware/proxy and providers in layout/page',\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 (covers every project in a monorepo)',\n },\n ],\n DevTools: [\n {\n value: 'vscodeExtension',\n label: 'VS Code extension',\n hint: 'recommend the Intlayer extension',\n },\n {\n value: 'eslint',\n label: 'Lint rules (ESLint / oxlint)',\n hint: 'flag hardcoded text and dynamic calls the compiler cannot optimize',\n },\n {\n value: 'chromeExtension',\n label: 'Chrome extension',\n hint: 'for audit, debug and analysis purpose',\n },\n ],\n 'Coding assistant': [\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 value: 'lsp',\n label: 'Editor LSP',\n hint: 'go-to-definition from keys to .content files',\n },\n ],\n CMS: [\n {\n value: 'cms',\n label: 'CMS',\n hint: 'log in through your browser, then store the credentials in your .env',\n },\n {\n value: 'infra',\n label: 'Infrastructure (desktop app / self-hosting)',\n hint: 'install the desktop app, or self-host with Docker (all-in-one or Compose)',\n },\n ],\n};\n\n/**\n * Locale routing choice: a `routing.mode` served through the locale proxy, or\n * `none` to leave routing to the app (`no-prefix` with the proxy disabled).\n */\nexport type LocaleRoutingChoice = RoutingMode | 'none';\n\n/** Locale routing strategies offered by the interactive init flow. */\nconst ROUTING_OPTIONS: Array<{\n value: LocaleRoutingChoice;\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 value: 'none',\n label: 'No locale routing',\n hint: 'no proxy, no locale route segment — handle the locale yourself',\n },\n];\n\n/** Locale routing choices accepted by `--routing`. */\nexport const LOCALE_ROUTING_CHOICES = ROUTING_OPTIONS.map(\n (option) => option.value\n);\n\n/** Validates a `--routing` value, throwing on an unknown choice. */\nexport const parseLocaleRoutingChoice = (\n value: string\n): LocaleRoutingChoice => {\n const choice = LOCALE_ROUTING_CHOICES.find((routing) => routing === value);\n\n if (!choice) {\n throw new Error(\n `Invalid --routing value \"${value}\". Expected one of: ${LOCALE_ROUTING_CHOICES.join(', ')}.`\n );\n }\n\n return choice;\n};\n\n/** Maps a routing choice to the init options it sets. */\nexport const getRoutingInitOptions = (\n choice: LocaleRoutingChoice\n): Pick<InitOptions, 'routingMode' | 'enableProxy'> =>\n choice === 'none'\n ? { routingMode: 'no-prefix', enableProxy: false }\n : { routingMode: choice, enableProxy: true };\n\n/** Known ESLint and oxlint configuration file names. */\nexport const ESLINT_CONFIG_FILES = [\n 'eslint.config.js',\n 'eslint.config.mjs',\n 'eslint.config.cjs',\n 'eslint.config.ts',\n 'eslint.config.mts',\n 'eslint.config.cts',\n '.eslintrc.js',\n '.eslintrc.cjs',\n '.eslintrc.yaml',\n '.eslintrc.yml',\n '.eslintrc.json',\n '.eslintrc',\n '.oxlintrc.json',\n];\n\n/**\n * Checks whether ESLint or a compatible linter (oxlint) is installed or\n * configured in the project.\n */\nexport const isEslintInstalled = (\n dependencies: Record<string, string>,\n root?: string\n): boolean => {\n if (hasLintTooling(dependencies)) return true;\n if (dependencies.eslint || dependencies.oxlint) return true;\n\n if (root) {\n return ESLINT_CONFIG_FILES.some((file) => existsSync(join(root, file)));\n }\n\n return false;\n};\n\n/**\n * Computes the initial setup steps selected by default in the interactive prompt.\n * Steps like infrastructure and browser extension require opt-in, while\n * eslint is preselected only if installed on the project.\n */\nexport const getInitialInitSteps = (\n dependencies: Record<string, string>,\n root?: string\n): InitStep[] => {\n const isEslintPresent = isEslintInstalled(dependencies, root);\n\n return Object.values(INIT_STEP_GROUPS)\n .flat()\n .map((option) => option.value)\n .filter((step) => {\n if (OPT_IN_INIT_STEPS.includes(step)) return false;\n if (step === 'eslint' && !isEslintPresent) return false;\n return true;\n });\n};\n\n/** Reads the merged dependencies of the project at `root`. */\nexport const getProjectDependencies = (\n root: string\n): 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/**\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 const p = await loadPrompts();\n\n p.intro('Initialize Intlayer');\n\n const projectDependencies = getProjectDependencies(root);\n\n const selected = await p.groupMultiselect<InitStep>({\n message: 'Select what you want to set up:',\n options: INIT_STEP_GROUPS,\n initialValues: getInitialInitSteps(projectDependencies, root),\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 // Compat i18n library detection — never asked, always derived from the\n // installed packages. `detectMissingIntlayerPackages` reads the very same\n // dependency map to schedule the compat adapter, the sync plugin and the\n // catalog template, so a project without any of those packages is simply set\n // up on Intlayer alone.\n const detectedCompatLibraries =\n detectCompatI18nLibraries(projectDependencies);\n const hasCompatLib = detectedCompatLibraries.length > 0;\n\n if (hasCompatLib) {\n p.log.info(\n `Detected existing i18n ${detectedCompatLibraries.length > 1 ? 'libraries' : 'library'}: ${detectedCompatLibraries.join(', ')} — the matching Intlayer compat adapter and catalog sync will be set up.`\n );\n }\n\n // Locale routing → `routing.mode` + `routing.enableProxy` in the config, and\n // the route segment the framework scaffolding creates. Only asked for web\n // frontends; projects without URL routing (backend, React Native / Expo) keep\n // only `routing.storage` in a freshly created config. Skipped for compat\n // i18n libraries, which keep their own routing.\n let routingOptions: Pick<InitOptions, 'routingMode' | 'enableProxy'> = {};\n\n if (\n steps.includes('projectSetup') &&\n baseOptions?.routingMode === undefined &&\n !hasCompatLib &&\n hasUrlRoutingFramework(projectDependencies)\n ) {\n const selectedRouting = await p.select<LocaleRoutingChoice>({\n message: 'How should the locale appear in your URLs?',\n options: ROUTING_OPTIONS,\n initialValue: 'prefix-no-default',\n });\n\n if (p.isCancel(selectedRouting)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n routingOptions = getRoutingInitOptions(selectedRouting);\n }\n\n const options: InitOptions = {\n ...baseOptions,\n ...routingOptions,\n noInstallPackages: !steps.includes('packages'),\n // The `.gitignore` entry is tied to project setup.\n noGitignore: baseOptions?.noGitignore || !steps.includes('projectSetup'),\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('projectSetup'),\n noVscodeExtension: !steps.includes('vscodeExtension'),\n noLsp: !steps.includes('lsp'),\n noEslint: !steps.includes('eslint'),\n skipFinalMessage: true,\n };\n\n const { guideUrl } = await initIntlayer(root, options);\n\n // Skills ask for the platform after the skill selection; MCP reuses it.\n const skillsPlatform = steps.includes('skills')\n ? await initSkills(root)\n : undefined;\n\n if (steps.includes('mcp')) {\n await initMCP(root, skillsPlatform);\n }\n\n // Delegated to the hosted install script, which owns its own menu.\n if (steps.includes('infra')) {\n await initInfra();\n }\n\n if (steps.includes('chromeExtension')) {\n await initChromeExtension();\n }\n\n // CMS / visual editor runs last: the browser login persists the access-key\n // credentials to `.env` and enables the editor in the config file. Kept last\n // so the browser flow does not interrupt setup.\n if (steps.includes('cms')) {\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 if (guideUrl) {\n logInitSuccessMessage(guideUrl);\n }\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":";;;;;;;;;;;AAmBA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;CAEjB,OAAO,eAAe,QAAQ,YAAY,IAAI,GAAG;EAC/C,IAAI,WAAW,KAAK,YAAY,cAAc,CAAC,GAC7C,OAAO;EAET,aAAa,QAAQ,YAAY,IAAI;CACvC;CAIA,OAAO;AACT;;;;;;AA4BA,MAAa,oBAAgC,CAAC,SAAS,iBAAiB;;AAGxE,MAAa,mBAAqD;CAChE,UAAU;EACR;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,UAAU;EACR;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,oBAAoB;EAClB;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,KAAK,CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR,GACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR,CACF;AACF;;AASA,MAAM,kBAID;CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;AACF;;AAGA,MAAa,yBAAyB,gBAAgB,KACnD,WAAW,OAAO,KACrB;;AAGA,MAAa,4BACX,UACwB;CACxB,MAAM,SAAS,uBAAuB,MAAM,YAAY,YAAY,KAAK;CAEzE,IAAI,CAAC,QACH,MAAM,IAAI,MACR,4BAA4B,MAAM,sBAAsB,uBAAuB,KAAK,IAAI,EAAE,EAC5F;CAGF,OAAO;AACT;;AAGA,MAAa,yBACX,WAEA,WAAW,SACP;CAAE,aAAa;CAAa,aAAa;AAAM,IAC/C;CAAE,aAAa;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S,KAAK,GAAG;EACzB,EAAE,IAAI,KAAK,uDAAuD;EAGlE,MAAM,MAAM;GACV,WAAW;GACX,gBAAgB,gBAAgB,oBAAoB,MAAM,WAAW;EACvE,CAAC;CACH;CAEA,EAAE,MAAM,kCAAkC;CAE1C,IAAI,UACF,sBAAsB,QAAQ;AAElC;AAEA,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,gBAAgB,QAAQ,WAAW,CAAC,IACpC,gBAAgB,QAAQ,IAAI,CAAC;CAEjC,IAAI,aAAa;EACf,MAAM,mBAAmB,MAAM,OAAO;EACtC;CACF;CAEA,MAAM,aAAa,MAAM,OAAO;AAClC"}
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 {\n detectCompatI18nLibraries,\n hasLintTooling,\n hasUrlRoutingFramework,\n type InitOptions,\n initIntlayer,\n logInitSuccessMessage,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/engine/cli';\nimport { login } from './auth/login';\nimport { initChromeExtension } from './initChromeExtension';\nimport { initInfra } from './initInfra';\nimport { initMCP } from './initMCP';\nimport { initSkills } from './initSkills';\nimport { loadPrompts } from './loadPrompts';\nimport { isInteractiveTerminal } from './utils/isInteractiveTerminal';\nimport { parseChoice } from './utils/parseChoice';\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/** Resolves the project root from `--project-root`, else the working directory. */\nexport const resolveProjectRoot = (projectRoot?: string): string =>\n findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());\n\n/** Individually selectable setup steps exposed by the interactive init flow. */\nexport type InitStep =\n | 'packages'\n | 'githubActions'\n | 'projectSetup'\n | 'vscodeExtension'\n | 'lsp'\n | 'eslint'\n | 'skills'\n | 'mcp'\n | 'infra'\n | 'cms'\n | 'chromeExtension';\n\n/** A checkbox entry of the interactive init flow. */\nexport type InitStepOption = {\n value: InitStep;\n label: string;\n hint: string;\n};\n\n/**\n * Steps shown but not pre-selected. The infrastructure installer touches the\n * machine (downloads an app, pulls Docker images) and browser extensions open external URLs\n * rather than modifying the project, so they must be an explicit choice.\n */\nexport const OPT_IN_INIT_STEPS: InitStep[] = ['infra', 'chromeExtension'];\n\n/**\n * Steps run by `intlayer init` without `--interactive`: install the packages\n * and set up the framework. Every other step has its own command\n * ({@link INIT_STEP_COMMANDS}), so nothing outside the app code is touched\n * unless asked for.\n */\nexport const DEFAULT_INIT_STEPS: InitStep[] = ['packages', 'projectSetup'];\n\n/**\n * Command running each interactive step on its own, without prompts when every\n * value is passed as a flag. Printed when `--interactive` has no terminal.\n */\nexport const INIT_STEP_COMMANDS: Record<InitStep, string> = {\n packages: 'intlayer init packages',\n projectSetup: 'intlayer init project [--routing <routing>]',\n githubActions: 'intlayer init github-actions',\n vscodeExtension: 'intlayer init vscode-extension',\n eslint: 'intlayer init eslint',\n chromeExtension: 'intlayer init extension [--browser <chrome|firefox>]',\n skills: 'intlayer init skills [--platform <platform>] [--skills <skills...>]',\n mcp: 'intlayer init mcp [--platform <platform>] [--transport <stdio|sse>]',\n lsp: 'intlayer init lsp',\n cms: 'intlayer init cms',\n infra: 'intlayer init infra --mode <desktop|docker|compose>',\n};\n\n/**\n * Maps setup steps to the {@link initIntlayer} options: every step handled by\n * `initIntlayer` that is not listed is skipped. Explicit `--no-*` flags in\n * `baseOptions` still win over a listed step.\n */\nexport const getInitOptionsForSteps = (\n steps: InitStep[],\n baseOptions?: InitOptions\n): InitOptions => ({\n ...baseOptions,\n noInstallPackages:\n baseOptions?.noInstallPackages || !steps.includes('packages'),\n // The `.gitignore` entry is tied to project setup.\n noGitignore: baseOptions?.noGitignore || !steps.includes('projectSetup'),\n noGithubActions:\n baseOptions?.noGithubActions || !steps.includes('githubActions'),\n noFrameworkSetup:\n baseOptions?.noFrameworkSetup || !steps.includes('projectSetup'),\n noVscodeExtension:\n baseOptions?.noVscodeExtension || !steps.includes('vscodeExtension'),\n noLsp: baseOptions?.noLsp || !steps.includes('lsp'),\n noEslint: baseOptions?.noEslint || !steps.includes('eslint'),\n // The documentation link only matters once the project itself is set up.\n skipFinalMessage:\n baseOptions?.skipFinalMessage || !steps.includes('projectSetup'),\n});\n\n/**\n * Runs the given {@link initIntlayer} steps only (packages, project setup, CI,\n * VS Code extension, LSP, lint rules). Backs `intlayer init` and its\n * single-step subcommands.\n */\nexport const initSteps = async (\n projectRoot: string | undefined,\n steps: InitStep[],\n options?: InitOptions\n): Promise<void> => {\n await initIntlayer(\n resolveProjectRoot(projectRoot),\n getInitOptionsForSteps(steps, options)\n );\n};\n\n/**\n * Logs in to the Intlayer CMS through the browser, then stores the access-key\n * credentials in `.env` and enables the editor in the config file.\n */\nexport const initCms = async (projectRoot?: string): Promise<void> => {\n const root = resolveProjectRoot(projectRoot);\n const p = await loadPrompts();\n\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/** Explains why `--interactive` cannot run, and what to run instead. */\nconst getNoTerminalMessage = (): string =>\n [\n '`intlayer init --interactive` needs a terminal to answer its prompts (none is attached, e.g. when run by an AI agent or in CI).',\n 'Run the steps directly instead:',\n ' intlayer init (installs the packages and sets up the framework)',\n ...Object.values(INIT_STEP_COMMANDS).map((command) => ` ${command}`),\n ].join('\\n');\n\n/** Grouped checkbox entries of the interactive init flow, in display order. */\nexport const INIT_STEP_GROUPS: Record<string, InitStepOption[]> = {\n Codebase: [\n {\n value: 'packages',\n label: 'Install & upgrade packages',\n hint: 'install missing Intlayer dependencies and upgrade outdated ones',\n },\n {\n value: 'projectSetup',\n label: 'Project setup',\n hint: 'intlayer config, tsconfig, bundler plugin, middleware/proxy and providers in layout/page',\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 (covers every project in a monorepo)',\n },\n ],\n DevTools: [\n {\n value: 'vscodeExtension',\n label: 'VS Code extension',\n hint: 'recommend the Intlayer extension',\n },\n {\n value: 'eslint',\n label: 'Lint rules (ESLint / oxlint)',\n hint: 'flag hardcoded text and dynamic calls the compiler cannot optimize',\n },\n {\n value: 'chromeExtension',\n label: 'Chrome extension',\n hint: 'for audit, debug and analysis purpose',\n },\n ],\n 'Coding assistant': [\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 value: 'lsp',\n label: 'Editor LSP',\n hint: 'go-to-definition from keys to .content files',\n },\n ],\n CMS: [\n {\n value: 'cms',\n label: 'CMS',\n hint: 'log in through your browser, then store the credentials in your .env',\n },\n {\n value: 'infra',\n label: 'Infrastructure (desktop app / self-hosting)',\n hint: 'install the desktop app, or self-host with Docker (all-in-one or Compose)',\n },\n ],\n};\n\n/**\n * Locale routing choice: a `routing.mode` served through the locale proxy, or\n * `none` to leave routing to the app (`no-prefix` with the proxy disabled).\n */\nexport type LocaleRoutingChoice = RoutingMode | 'none';\n\n/** Locale routing strategies offered by the interactive init flow. */\nconst ROUTING_OPTIONS: Array<{\n value: LocaleRoutingChoice;\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 value: 'none',\n label: 'No locale routing',\n hint: 'no proxy, no locale route segment — handle the locale yourself',\n },\n];\n\n/** Locale routing choices accepted by `--routing`. */\nexport const LOCALE_ROUTING_CHOICES = ROUTING_OPTIONS.map(\n (option) => option.value\n);\n\n/** Validates a `--routing` value, throwing on an unknown choice. */\nexport const parseLocaleRoutingChoice = (value: string): LocaleRoutingChoice =>\n parseChoice(value, LOCALE_ROUTING_CHOICES, '--routing');\n\n/** Maps a routing choice to the init options it sets. */\nexport const getRoutingInitOptions = (\n choice: LocaleRoutingChoice\n): Pick<InitOptions, 'routingMode' | 'enableProxy'> =>\n choice === 'none'\n ? { routingMode: 'no-prefix', enableProxy: false }\n : { routingMode: choice, enableProxy: true };\n\n/** Known ESLint and oxlint configuration file names. */\nexport const ESLINT_CONFIG_FILES = [\n 'eslint.config.js',\n 'eslint.config.mjs',\n 'eslint.config.cjs',\n 'eslint.config.ts',\n 'eslint.config.mts',\n 'eslint.config.cts',\n '.eslintrc.js',\n '.eslintrc.cjs',\n '.eslintrc.yaml',\n '.eslintrc.yml',\n '.eslintrc.json',\n '.eslintrc',\n '.oxlintrc.json',\n];\n\n/**\n * Checks whether ESLint or a compatible linter (oxlint) is installed or\n * configured in the project.\n */\nexport const isEslintInstalled = (\n dependencies: Record<string, string>,\n root?: string\n): boolean => {\n if (hasLintTooling(dependencies)) return true;\n if (dependencies.eslint || dependencies.oxlint) return true;\n\n if (root) {\n return ESLINT_CONFIG_FILES.some((file) => existsSync(join(root, file)));\n }\n\n return false;\n};\n\n/**\n * Computes the initial setup steps selected by default in the interactive prompt.\n * Steps like infrastructure and browser extension require opt-in, while\n * eslint is preselected only if installed on the project.\n */\nexport const getInitialInitSteps = (\n dependencies: Record<string, string>,\n root?: string\n): InitStep[] => {\n const isEslintPresent = isEslintInstalled(dependencies, root);\n\n return Object.values(INIT_STEP_GROUPS)\n .flat()\n .map((option) => option.value)\n .filter((step) => {\n if (OPT_IN_INIT_STEPS.includes(step)) return false;\n if (step === 'eslint' && !isEslintPresent) return false;\n return true;\n });\n};\n\n/** Reads the merged dependencies of the project at `root`. */\nexport const getProjectDependencies = (\n root: string\n): 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/**\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 const p = await loadPrompts();\n\n p.intro('Initialize Intlayer');\n\n const projectDependencies = getProjectDependencies(root);\n\n const selected = await p.groupMultiselect<InitStep>({\n message: 'Select what you want to set up:',\n options: INIT_STEP_GROUPS,\n initialValues: getInitialInitSteps(projectDependencies, root),\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 // Compat i18n library detection — never asked, always derived from the\n // installed packages. `detectMissingIntlayerPackages` reads the very same\n // dependency map to schedule the compat adapter, the sync plugin and the\n // catalog template, so a project without any of those packages is simply set\n // up on Intlayer alone.\n const detectedCompatLibraries =\n detectCompatI18nLibraries(projectDependencies);\n const hasCompatLib = detectedCompatLibraries.length > 0;\n\n if (hasCompatLib) {\n p.log.info(\n `Detected existing i18n ${detectedCompatLibraries.length > 1 ? 'libraries' : 'library'}: ${detectedCompatLibraries.join(', ')} — the matching Intlayer compat adapter and catalog sync will be set up.`\n );\n }\n\n // Locale routing → `routing.mode` + `routing.enableProxy` in the config, and\n // the route segment the framework scaffolding creates. Only asked for web\n // frontends; projects without URL routing (backend, React Native / Expo) keep\n // only `routing.storage` in a freshly created config. Skipped for compat\n // i18n libraries, which keep their own routing.\n let routingOptions: Pick<InitOptions, 'routingMode' | 'enableProxy'> = {};\n\n if (\n steps.includes('projectSetup') &&\n baseOptions?.routingMode === undefined &&\n !hasCompatLib &&\n hasUrlRoutingFramework(projectDependencies)\n ) {\n const selectedRouting = await p.select<LocaleRoutingChoice>({\n message: 'How should the locale appear in your URLs?',\n options: ROUTING_OPTIONS,\n initialValue: 'prefix-no-default',\n });\n\n if (p.isCancel(selectedRouting)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n routingOptions = getRoutingInitOptions(selectedRouting);\n }\n\n const options: InitOptions = {\n ...getInitOptionsForSteps(steps, { ...baseOptions, ...routingOptions }),\n skipFinalMessage: true,\n };\n\n const { guideUrl } = await initIntlayer(root, options);\n\n // Skills ask for the platform after the skill selection; MCP reuses it.\n const skillsPlatform = steps.includes('skills')\n ? await initSkills(root)\n : undefined;\n\n if (steps.includes('mcp')) {\n await initMCP(root, { platform: skillsPlatform });\n }\n\n // Delegated to the hosted install script, which owns its own menu.\n if (steps.includes('infra')) {\n await initInfra();\n }\n\n if (steps.includes('chromeExtension')) {\n await initChromeExtension();\n }\n\n // CMS / visual editor runs last: the browser login persists the access-key\n // credentials to `.env` and enables the editor in the config file. Kept last\n // so the browser flow does not interrupt setup.\n if (steps.includes('cms')) {\n await initCms(root);\n }\n\n p.outro('Intlayer initialization complete');\n\n if (guideUrl) {\n logInitSuccessMessage(guideUrl);\n }\n};\n\n/**\n * `intlayer init`: installs the packages and sets up the framework, or, with\n * `interactive`, lets the user pick every setup step. `--interactive` needs a\n * terminal; without one it fails and lists the single-step commands instead.\n */\nexport const init = async (\n projectRoot?: string,\n options?: InitOptions,\n interactive?: boolean\n) => {\n if (!interactive) {\n await initSteps(projectRoot, DEFAULT_INIT_STEPS, options);\n return;\n }\n\n if (!isInteractiveTerminal()) {\n const p = await loadPrompts();\n\n p.log.error(getNoTerminalMessage());\n process.exitCode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;CACpE,MAAM,OAAO,mBAAmB,WAAW;CAG3C,OAFgB,YAAY,EAE3B,CAAC,IAAI,KAAK,uDAAuD;CAGlE,MAAM,MAAM;EACV,WAAW;EACX,gBAAgB,gBAAgB,oBAAoB,MAAM,WAAW;CACvE,CAAC;AACH;;AAGA,MAAM,6BACJ;CACE;CACA;CACA;CACA,GAAG,OAAO,OAAO,kBAAkB,CAAC,CAAC,KAAK,YAAY,KAAK,SAAS;AACtE,CAAC,CAAC,KAAK,IAAI;;AAGb,MAAa,mBAAqD;CAChE,UAAU;EACR;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,UAAU;EACR;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,oBAAoB;EAClB;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;CACF;CACA,KAAK,CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR,GACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR,CACF;AACF;;AASA,MAAM,kBAID;CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;CACA;EACE,OAAO;EACP,OAAO;EACP,MAAM;CACR;AACF;;AAGA,MAAa,yBAAyB,gBAAgB,KACnD,WAAW,OAAO,KACrB;;AAGA,MAAa,4BAA4B,UACvC,YAAY,OAAO,wBAAwB,WAAW;;AAGxD,MAAa,yBACX,WAE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AU,aAAa,oBAAoB,OAAO;EACxD;CACF;CAEA,IAAI,CAAC,sBAAsB,GAAG;EAG5B,OAFgB,YAAY,EAE3B,CAAC,IAAI,MAAM,qBAAqB,CAAC;EAClC,QAAQ,WAAW;EACnB;CACF;CAEA,MAAM,mBAAmB,mBAAmB,WAAW,GAAG,OAAO;AACnE"}
@@ -1,5 +1,7 @@
1
1
  import { openBrowser } from "./utils/openBrowser.mjs";
2
2
  import { loadPrompts } from "./loadPrompts.mjs";
3
+ import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
4
+ import { parseChoice } from "./utils/parseChoice.mjs";
3
5
 
4
6
  //#region src/initChromeExtension.ts
5
7
  const CHROME_EXTENSION_URL = "https://chromewebstore.google.com/detail/intlayer_i18n_scanner/pmlehcgmjmfimmjnembihbakhnheiabc";
@@ -13,20 +15,38 @@ const BROWSER_EXTENSION_OPTIONS = [{
13
15
  label: "Mozilla Firefox",
14
16
  hint: MOZILLA_EXTENSION_URL
15
17
  }];
16
- const initChromeExtension = async () => {
18
+ /** Browsers accepted by `intlayer init extension --browser`. */
19
+ const EXTENSION_BROWSERS = ["chrome", "firefox"];
20
+ /** Store page of the Intlayer extension, per browser. */
21
+ const EXTENSION_URL_BY_BROWSER = {
22
+ chrome: CHROME_EXTENSION_URL,
23
+ firefox: MOZILLA_EXTENSION_URL
24
+ };
25
+ /** Validates the `--browser` values, ignoring case. */
26
+ const parseExtensionBrowsers = (values) => values.flatMap((value) => value.split(",")).filter((value) => value.trim() !== "").map((value) => parseChoice(value, EXTENSION_BROWSERS, "--browser"));
27
+ /**
28
+ * Opens the store page of the Intlayer browser extension. The browsers are
29
+ * prompted for unless given; without a terminal (AI agents, CI) the store
30
+ * links are only printed, since the install needs a person anyway.
31
+ */
32
+ const initChromeExtension = async (options = {}) => {
17
33
  const p = await loadPrompts();
18
- const selectedUrls = await p.multiselect({
34
+ if (!options.browsers && !isInteractiveTerminal()) {
35
+ p.log.info(`Install the Intlayer browser extension:\n${BROWSER_EXTENSION_OPTIONS.map(({ label, value }) => ` ${label}: ${value}`).join("\n")}`);
36
+ return;
37
+ }
38
+ const selectedUrls = options.browsers ? options.browsers.map((browser) => EXTENSION_URL_BY_BROWSER[browser]) : await p.multiselect({
19
39
  message: "Select browser extension(s) to install:",
20
40
  options: BROWSER_EXTENSION_OPTIONS,
21
41
  required: false
22
42
  });
23
43
  if (p.isCancel(selectedUrls)) return;
24
- if (Array.isArray(selectedUrls) && selectedUrls.length > 0) for (const url of selectedUrls) {
44
+ for (const url of selectedUrls) {
25
45
  p.log.info(`Opening ${url} in your browser...`);
26
46
  openBrowser(url);
27
47
  }
28
48
  };
29
49
 
30
50
  //#endregion
31
- export { BROWSER_EXTENSION_OPTIONS, CHROME_EXTENSION_URL, MOZILLA_EXTENSION_URL, initChromeExtension };
51
+ export { BROWSER_EXTENSION_OPTIONS, CHROME_EXTENSION_URL, EXTENSION_BROWSERS, EXTENSION_URL_BY_BROWSER, MOZILLA_EXTENSION_URL, initChromeExtension, parseExtensionBrowsers };
32
52
  //# sourceMappingURL=initChromeExtension.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initChromeExtension.mjs","names":[],"sources":["../../src/initChromeExtension.ts"],"sourcesContent":["import { loadPrompts } from './loadPrompts';\nimport { openBrowser } from './utils/openBrowser';\n\nexport const CHROME_EXTENSION_URL =\n 'https://chromewebstore.google.com/detail/intlayer_i18n_scanner/pmlehcgmjmfimmjnembihbakhnheiabc';\n\nexport const MOZILLA_EXTENSION_URL =\n 'https://addons.mozilla.org/en-US/firefox/addon/intlayer-i18n-scanner/';\n\nexport const BROWSER_EXTENSION_OPTIONS = [\n {\n value: CHROME_EXTENSION_URL,\n label: 'Chrome',\n hint: CHROME_EXTENSION_URL,\n },\n {\n value: MOZILLA_EXTENSION_URL,\n label: 'Mozilla Firefox',\n hint: MOZILLA_EXTENSION_URL,\n },\n];\n\nexport const initChromeExtension = async () => {\n const p = await loadPrompts();\n\n const selectedUrls = await p.multiselect({\n message: 'Select browser extension(s) to install:',\n options: BROWSER_EXTENSION_OPTIONS,\n required: false,\n });\n\n if (p.isCancel(selectedUrls)) {\n return;\n }\n\n if (Array.isArray(selectedUrls) && selectedUrls.length > 0) {\n for (const url of selectedUrls) {\n p.log.info(`Opening ${url} in your browser...`);\n openBrowser(url);\n }\n }\n};\n"],"mappings":";;;;AAGA,MAAa,uBACX;AAEF,MAAa,wBACX;AAEF,MAAa,4BAA4B,CACvC;CACE,OAAO;CACP,OAAO;CACP,MAAM;AACR,GACA;CACE,OAAO;CACP,OAAO;CACP,MAAM;AACR,CACF;AAEA,MAAa,sBAAsB,YAAY;CAC7C,MAAM,IAAI,MAAM,YAAY;CAE5B,MAAM,eAAe,MAAM,EAAE,YAAY;EACvC,SAAS;EACT,SAAS;EACT,UAAU;CACZ,CAAC;CAED,IAAI,EAAE,SAAS,YAAY,GACzB;CAGF,IAAI,MAAM,QAAQ,YAAY,KAAK,aAAa,SAAS,GACvD,KAAK,MAAM,OAAO,cAAc;EAC9B,EAAE,IAAI,KAAK,WAAW,IAAI,oBAAoB;EAC9C,YAAY,GAAG;CACjB;AAEJ"}
1
+ {"version":3,"file":"initChromeExtension.mjs","names":[],"sources":["../../src/initChromeExtension.ts"],"sourcesContent":["import { loadPrompts } from './loadPrompts';\nimport { isInteractiveTerminal } from './utils/isInteractiveTerminal';\nimport { openBrowser } from './utils/openBrowser';\nimport { parseChoice } from './utils/parseChoice';\n\nexport const CHROME_EXTENSION_URL =\n 'https://chromewebstore.google.com/detail/intlayer_i18n_scanner/pmlehcgmjmfimmjnembihbakhnheiabc';\n\nexport const MOZILLA_EXTENSION_URL =\n 'https://addons.mozilla.org/en-US/firefox/addon/intlayer-i18n-scanner/';\n\nexport const BROWSER_EXTENSION_OPTIONS = [\n {\n value: CHROME_EXTENSION_URL,\n label: 'Chrome',\n hint: CHROME_EXTENSION_URL,\n },\n {\n value: MOZILLA_EXTENSION_URL,\n label: 'Mozilla Firefox',\n hint: MOZILLA_EXTENSION_URL,\n },\n];\n\n/** Browsers the Intlayer extension is published for. */\nexport type ExtensionBrowser = 'chrome' | 'firefox';\n\n/** Browsers accepted by `intlayer init extension --browser`. */\nexport const EXTENSION_BROWSERS: ExtensionBrowser[] = ['chrome', 'firefox'];\n\n/** Store page of the Intlayer extension, per browser. */\nexport const EXTENSION_URL_BY_BROWSER: Record<ExtensionBrowser, string> = {\n chrome: CHROME_EXTENSION_URL,\n firefox: MOZILLA_EXTENSION_URL,\n};\n\n/** Validates the `--browser` values, ignoring case. */\nexport const parseExtensionBrowsers = (values: string[]): ExtensionBrowser[] =>\n values\n .flatMap((value) => value.split(','))\n .filter((value) => value.trim() !== '')\n .map((value) => parseChoice(value, EXTENSION_BROWSERS, '--browser'));\n\n/** Options of {@link initChromeExtension}. */\nexport type InitChromeExtensionOptions = {\n /** Browsers to open the store page for, skipping the prompt. */\n browsers?: ExtensionBrowser[];\n};\n\n/**\n * Opens the store page of the Intlayer browser extension. The browsers are\n * prompted for unless given; without a terminal (AI agents, CI) the store\n * links are only printed, since the install needs a person anyway.\n */\nexport const initChromeExtension = async (\n options: InitChromeExtensionOptions = {}\n) => {\n const p = await loadPrompts();\n\n if (!options.browsers && !isInteractiveTerminal()) {\n p.log.info(\n `Install the Intlayer browser extension:\\n${BROWSER_EXTENSION_OPTIONS.map(\n ({ label, value }) => ` ${label}: ${value}`\n ).join('\\n')}`\n );\n return;\n }\n\n const selectedUrls = options.browsers\n ? options.browsers.map((browser) => EXTENSION_URL_BY_BROWSER[browser])\n : await p.multiselect({\n message: 'Select browser extension(s) to install:',\n options: BROWSER_EXTENSION_OPTIONS,\n required: false,\n });\n\n if (p.isCancel(selectedUrls)) {\n return;\n }\n\n for (const url of selectedUrls) {\n p.log.info(`Opening ${url} in your browser...`);\n openBrowser(url);\n }\n};\n"],"mappings":";;;;;;AAKA,MAAa,uBACX;AAEF,MAAa,wBACX;AAEF,MAAa,4BAA4B,CACvC;CACE,OAAO;CACP,OAAO;CACP,MAAM;AACR,GACA;CACE,OAAO;CACP,OAAO;CACP,MAAM;AACR,CACF;;AAMA,MAAa,qBAAyC,CAAC,UAAU,SAAS;;AAG1E,MAAa,2BAA6D;CACxE,QAAQ;CACR,SAAS;AACX;;AAGA,MAAa,0BAA0B,WACrC,OACG,SAAS,UAAU,MAAM,MAAM,GAAG,CAAC,CAAC,CACpC,QAAQ,UAAU,MAAM,KAAK,MAAM,EAAE,CAAC,CACtC,KAAK,UAAU,YAAY,OAAO,oBAAoB,WAAW,CAAC;;;;;;AAavE,MAAa,sBAAsB,OACjC,UAAsC,CAAC,MACpC;CACH,MAAM,IAAI,MAAM,YAAY;CAE5B,IAAI,CAAC,QAAQ,YAAY,CAAC,sBAAsB,GAAG;EACjD,EAAE,IAAI,KACJ,4CAA4C,0BAA0B,KACnE,EAAE,OAAO,YAAY,KAAK,MAAM,IAAI,OACvC,CAAC,CAAC,KAAK,IAAI,GACb;EACA;CACF;CAEA,MAAM,eAAe,QAAQ,WACzB,QAAQ,SAAS,KAAK,YAAY,yBAAyB,QAAQ,IACnE,MAAM,EAAE,YAAY;EAClB,SAAS;EACT,SAAS;EACT,UAAU;CACZ,CAAC;CAEL,IAAI,EAAE,SAAS,YAAY,GACzB;CAGF,KAAK,MAAM,OAAO,cAAc;EAC9B,EAAE,IAAI,KAAK,WAAW,IAAI,oBAAoB;EAC9C,YAAY,GAAG;CACjB;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { loadPrompts } from "./loadPrompts.mjs";
2
+ import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
2
3
  import { join } from "node:path";
3
4
  import { spawn } from "node:child_process";
4
5
  import { tmpdir } from "node:os";
@@ -64,6 +65,11 @@ const runInstaller = (command, args) => new Promise((resolve, reject) => {
64
65
  */
65
66
  const initInfra = async (options = {}) => {
66
67
  const p = await loadPrompts();
68
+ if (!options.mode && !isInteractiveTerminal()) {
69
+ p.log.error(`No terminal to show the setup menu. Pass the mode explicitly: intlayer init infra --mode <${INFRA_MODES.join(" | ")}>`);
70
+ process.exitCode = 1;
71
+ return;
72
+ }
67
73
  const runner = getInstallerRunner();
68
74
  const scriptUrl = options.scriptUrl ?? runner.url;
69
75
  const spinner = p.spinner();
@@ -1 +1 @@
1
- {"version":3,"file":"initInfra.mjs","names":[],"sources":["../../src/initInfra.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { mkdtemp, rm, writeFile } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { loadPrompts } from './loadPrompts';\n\n/** Setup modes understood by the hosted installer. */\nexport const INFRA_MODES = ['desktop', 'docker', 'compose'] as const;\n\nexport type InfraMode = (typeof INFRA_MODES)[number];\n\n/**\n * The hosted installers are the single source of truth for the infrastructure\n * setup flow (desktop app, all-in-one container, Compose stack). The CLI runs\n * them rather than re-implementing the same steps in JavaScript.\n */\nexport const INSTALL_SCRIPT_URL = 'https://intlayer.org/install.sh';\nexport const INSTALL_SCRIPT_URL_WINDOWS = 'https://intlayer.org/install.ps1';\n\nexport type InitInfraOptions = {\n /** Skip the interactive menu and run this mode directly. */\n mode?: InfraMode;\n /** Installer URL override (forks, staging). Defaults to the platform's script. */\n scriptUrl?: string;\n};\n\n/** How to fetch and execute the installer on the current platform. */\ntype InstallerRunner = {\n url: string;\n fileName: string;\n /** Builds the command and arguments that execute the downloaded script. */\n command: (scriptPath: string, mode?: InfraMode) => [string, string[]];\n};\n\nconst POSIX_RUNNER: InstallerRunner = {\n url: INSTALL_SCRIPT_URL,\n fileName: 'install.sh',\n command: (scriptPath, mode) => [\n 'sh',\n [scriptPath, ...(mode ? ['--mode', mode] : [])],\n ],\n};\n\nconst WINDOWS_RUNNER: InstallerRunner = {\n url: INSTALL_SCRIPT_URL_WINDOWS,\n fileName: 'install.ps1',\n command: (scriptPath, mode) => [\n 'powershell',\n [\n '-NoProfile',\n '-ExecutionPolicy',\n 'Bypass',\n '-File',\n scriptPath,\n ...(mode ? ['-Mode', mode] : []),\n ],\n ],\n};\n\nconst getInstallerRunner = (): InstallerRunner =>\n process.platform === 'win32' ? WINDOWS_RUNNER : POSIX_RUNNER;\n\n/**\n * Validates a user-provided mode against {@link INFRA_MODES}.\n *\n * @throws When the value is not a known mode.\n */\nexport const parseInfraMode = (value: string): InfraMode => {\n if ((INFRA_MODES as readonly string[]).includes(value)) {\n return value as InfraMode;\n }\n\n throw new Error(\n `Unknown infra mode \"${value}\". Expected one of: ${INFRA_MODES.join(', ')}`\n );\n};\n\n/**\n * Runs the installer with the terminal attached, so its own prompts and\n * progress bars reach the user unchanged.\n *\n * @returns The script's exit code.\n */\nconst runInstaller = (command: string, args: string[]): Promise<number> =>\n new Promise((resolve, reject) => {\n const child = spawn(command, args, { stdio: 'inherit' });\n\n child.on('error', reject);\n child.on('close', (code) => resolve(code ?? 1));\n });\n\n/**\n * Downloads the hosted installer and runs it: desktop app, all-in-one Docker\n * container or Docker Compose stack, chosen interactively unless `mode` is set.\n *\n * Exposed as `intlayer init infra` and as a step of `intlayer init --interactive`.\n */\nexport const initInfra = async (\n options: InitInfraOptions = {}\n): Promise<void> => {\n const p = await loadPrompts();\n const runner = getInstallerRunner();\n const scriptUrl = options.scriptUrl ?? runner.url;\n\n const spinner = p.spinner();\n spinner.start(`Fetching ${scriptUrl}`);\n\n let script: string;\n\n try {\n const response = await fetch(scriptUrl);\n\n if (!response.ok) {\n throw new Error(`${response.status} ${response.statusText}`);\n }\n\n script = await response.text();\n } catch (error) {\n spinner.stop('Could not download the installer');\n p.log.error(\n `${(error as Error).message}\\nRun it directly: ${\n process.platform === 'win32'\n ? `irm ${scriptUrl} | iex`\n : `curl -fsSL ${scriptUrl} | sh`\n }`\n );\n process.exitCode = 1;\n return;\n }\n\n spinner.stop('Installer downloaded');\n\n const directory = await mkdtemp(join(tmpdir(), 'intlayer-install-'));\n const scriptPath = join(directory, runner.fileName);\n\n try {\n await writeFile(scriptPath, script, { mode: 0o700 });\n\n const [command, args] = runner.command(scriptPath, options.mode);\n const exitCode = await runInstaller(command, args);\n\n if (exitCode !== 0) {\n process.exitCode = exitCode;\n }\n } finally {\n await rm(directory, { recursive: true, force: true });\n }\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,cAAc;CAAC;CAAW;CAAU;AAAS;;;;;;AAS1D,MAAa,qBAAqB;AAClC,MAAa,6BAA6B;AAiB1C,MAAM,eAAgC;CACpC,KAAK;CACL,UAAU;CACV,UAAU,YAAY,SAAS,CAC7B,MACA,CAAC,YAAY,GAAI,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,CAAE,CAChD;AACF;AAEA,MAAM,iBAAkC;CACtC,KAAK;CACL,UAAU;CACV,UAAU,YAAY,SAAS,CAC7B,cACA;EACE;EACA;EACA;EACA;EACA;EACA,GAAI,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;CAChC,CACF;AACF;AAEA,MAAM,2BACJ,QAAQ,aAAa,UAAU,iBAAiB;;;;;;AAOlD,MAAa,kBAAkB,UAA6B;CAC1D,IAAK,YAAkC,SAAS,KAAK,GACnD,OAAO;CAGT,MAAM,IAAI,MACR,uBAAuB,MAAM,sBAAsB,YAAY,KAAK,IAAI,GAC1E;AACF;;;;;;;AAQA,MAAM,gBAAgB,SAAiB,SACrC,IAAI,SAAS,SAAS,WAAW;CAC/B,MAAM,QAAQ,MAAM,SAAS,MAAM,EAAE,OAAO,UAAU,CAAC;CAEvD,MAAM,GAAG,SAAS,MAAM;CACxB,MAAM,GAAG,UAAU,SAAS,QAAQ,QAAQ,CAAC,CAAC;AAChD,CAAC;;;;;;;AAQH,MAAa,YAAY,OACvB,UAA4B,CAAC,MACX;CAClB,MAAM,IAAI,MAAM,YAAY;CAC5B,MAAM,SAAS,mBAAmB;CAClC,MAAM,YAAY,QAAQ,aAAa,OAAO;CAE9C,MAAM,UAAU,EAAE,QAAQ;CAC1B,QAAQ,MAAM,YAAY,WAAW;CAErC,IAAI;CAEJ,IAAI;EACF,MAAM,WAAW,MAAM,MAAM,SAAS;EAEtC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,GAAG,SAAS,OAAO,GAAG,SAAS,YAAY;EAG7D,SAAS,MAAM,SAAS,KAAK;CAC/B,SAAS,OAAO;EACd,QAAQ,KAAK,kCAAkC;EAC/C,EAAE,IAAI,MACJ,GAAI,MAAgB,QAAQ,qBAC1B,QAAQ,aAAa,UACjB,OAAO,UAAU,UACjB,cAAc,UAAU,QAEhC;EACA,QAAQ,WAAW;EACnB;CACF;CAEA,QAAQ,KAAK,sBAAsB;CAEnC,MAAM,YAAY,MAAM,QAAQ,KAAK,OAAO,GAAG,mBAAmB,CAAC;CACnE,MAAM,aAAa,KAAK,WAAW,OAAO,QAAQ;CAElD,IAAI;EACF,MAAM,UAAU,YAAY,QAAQ,EAAE,MAAM,IAAM,CAAC;EAEnD,MAAM,CAAC,SAAS,QAAQ,OAAO,QAAQ,YAAY,QAAQ,IAAI;EAC/D,MAAM,WAAW,MAAM,aAAa,SAAS,IAAI;EAEjD,IAAI,aAAa,GACf,QAAQ,WAAW;CAEvB,UAAU;EACR,MAAM,GAAG,WAAW;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CACtD;AACF"}
1
+ {"version":3,"file":"initInfra.mjs","names":[],"sources":["../../src/initInfra.ts"],"sourcesContent":["import { spawn } from 'node:child_process';\nimport { mkdtemp, rm, writeFile } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { loadPrompts } from './loadPrompts';\nimport { isInteractiveTerminal } from './utils/isInteractiveTerminal';\n\n/** Setup modes understood by the hosted installer. */\nexport const INFRA_MODES = ['desktop', 'docker', 'compose'] as const;\n\nexport type InfraMode = (typeof INFRA_MODES)[number];\n\n/**\n * The hosted installers are the single source of truth for the infrastructure\n * setup flow (desktop app, all-in-one container, Compose stack). The CLI runs\n * them rather than re-implementing the same steps in JavaScript.\n */\nexport const INSTALL_SCRIPT_URL = 'https://intlayer.org/install.sh';\nexport const INSTALL_SCRIPT_URL_WINDOWS = 'https://intlayer.org/install.ps1';\n\nexport type InitInfraOptions = {\n /** Skip the interactive menu and run this mode directly. */\n mode?: InfraMode;\n /** Installer URL override (forks, staging). Defaults to the platform's script. */\n scriptUrl?: string;\n};\n\n/** How to fetch and execute the installer on the current platform. */\ntype InstallerRunner = {\n url: string;\n fileName: string;\n /** Builds the command and arguments that execute the downloaded script. */\n command: (scriptPath: string, mode?: InfraMode) => [string, string[]];\n};\n\nconst POSIX_RUNNER: InstallerRunner = {\n url: INSTALL_SCRIPT_URL,\n fileName: 'install.sh',\n command: (scriptPath, mode) => [\n 'sh',\n [scriptPath, ...(mode ? ['--mode', mode] : [])],\n ],\n};\n\nconst WINDOWS_RUNNER: InstallerRunner = {\n url: INSTALL_SCRIPT_URL_WINDOWS,\n fileName: 'install.ps1',\n command: (scriptPath, mode) => [\n 'powershell',\n [\n '-NoProfile',\n '-ExecutionPolicy',\n 'Bypass',\n '-File',\n scriptPath,\n ...(mode ? ['-Mode', mode] : []),\n ],\n ],\n};\n\nconst getInstallerRunner = (): InstallerRunner =>\n process.platform === 'win32' ? WINDOWS_RUNNER : POSIX_RUNNER;\n\n/**\n * Validates a user-provided mode against {@link INFRA_MODES}.\n *\n * @throws When the value is not a known mode.\n */\nexport const parseInfraMode = (value: string): InfraMode => {\n if ((INFRA_MODES as readonly string[]).includes(value)) {\n return value as InfraMode;\n }\n\n throw new Error(\n `Unknown infra mode \"${value}\". Expected one of: ${INFRA_MODES.join(', ')}`\n );\n};\n\n/**\n * Runs the installer with the terminal attached, so its own prompts and\n * progress bars reach the user unchanged.\n *\n * @returns The script's exit code.\n */\nconst runInstaller = (command: string, args: string[]): Promise<number> =>\n new Promise((resolve, reject) => {\n const child = spawn(command, args, { stdio: 'inherit' });\n\n child.on('error', reject);\n child.on('close', (code) => resolve(code ?? 1));\n });\n\n/**\n * Downloads the hosted installer and runs it: desktop app, all-in-one Docker\n * container or Docker Compose stack, chosen interactively unless `mode` is set.\n *\n * Exposed as `intlayer init infra` and as a step of `intlayer init --interactive`.\n */\nexport const initInfra = async (\n options: InitInfraOptions = {}\n): Promise<void> => {\n const p = await loadPrompts();\n\n // The installer's menu reads from the terminal: without one it cannot be\n // answered, so the mode has to be passed explicitly.\n if (!options.mode && !isInteractiveTerminal()) {\n p.log.error(\n `No terminal to show the setup menu. Pass the mode explicitly: intlayer init infra --mode <${INFRA_MODES.join(' | ')}>`\n );\n process.exitCode = 1;\n return;\n }\n\n const runner = getInstallerRunner();\n const scriptUrl = options.scriptUrl ?? runner.url;\n\n const spinner = p.spinner();\n spinner.start(`Fetching ${scriptUrl}`);\n\n let script: string;\n\n try {\n const response = await fetch(scriptUrl);\n\n if (!response.ok) {\n throw new Error(`${response.status} ${response.statusText}`);\n }\n\n script = await response.text();\n } catch (error) {\n spinner.stop('Could not download the installer');\n p.log.error(\n `${(error as Error).message}\\nRun it directly: ${\n process.platform === 'win32'\n ? `irm ${scriptUrl} | iex`\n : `curl -fsSL ${scriptUrl} | sh`\n }`\n );\n process.exitCode = 1;\n return;\n }\n\n spinner.stop('Installer downloaded');\n\n const directory = await mkdtemp(join(tmpdir(), 'intlayer-install-'));\n const scriptPath = join(directory, runner.fileName);\n\n try {\n await writeFile(scriptPath, script, { mode: 0o700 });\n\n const [command, args] = runner.command(scriptPath, options.mode);\n const exitCode = await runInstaller(command, args);\n\n if (exitCode !== 0) {\n process.exitCode = exitCode;\n }\n } finally {\n await rm(directory, { recursive: true, force: true });\n }\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,cAAc;CAAC;CAAW;CAAU;AAAS;;;;;;AAS1D,MAAa,qBAAqB;AAClC,MAAa,6BAA6B;AAiB1C,MAAM,eAAgC;CACpC,KAAK;CACL,UAAU;CACV,UAAU,YAAY,SAAS,CAC7B,MACA,CAAC,YAAY,GAAI,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,CAAE,CAChD;AACF;AAEA,MAAM,iBAAkC;CACtC,KAAK;CACL,UAAU;CACV,UAAU,YAAY,SAAS,CAC7B,cACA;EACE;E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,QAAQ,KAAK,sBAAsB;CAEnC,MAAM,YAAY,MAAM,QAAQ,KAAK,OAAO,GAAG,mBAAmB,CAAC;CACnE,MAAM,aAAa,KAAK,WAAW,OAAO,QAAQ;CAElD,IAAI;EACF,MAAM,UAAU,YAAY,QAAQ,EAAE,MAAM,IAAM,CAAC;EAEnD,MAAM,CAAC,SAAS,QAAQ,OAAO,QAAQ,YAAY,QAAQ,IAAI;EAC/D,MAAM,WAAW,MAAM,aAAa,SAAS,IAAI;EAEjD,IAAI,aAAa,GACf,QAAQ,WAAW;CAEvB,UAAU;EACR,MAAM,GAAG,WAAW;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CACtD;AACF"}
@@ -1,20 +1,29 @@
1
1
  import { loadPrompts } from "./loadPrompts.mjs";
2
- import { promptPlatform } from "./initSkills.mjs";
3
- import { findProjectRoot } from "./init.mjs";
4
- import { resolve } from "node:path";
5
- import { installMCP } from "@intlayer/engine/cli";
2
+ import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
3
+ import { parseChoice } from "./utils/parseChoice.mjs";
4
+ import { promptPlatform, resolvePlatformWithoutPrompt } from "./initSkills.mjs";
5
+ import { resolveProjectRoot } from "./init.mjs";
6
+ import { MCP_TRANSPORTS, installMCP } from "@intlayer/engine/cli";
6
7
 
7
8
  //#region src/initMCP.ts
8
- const initMCP = async (projectRoot, preselectedPlatform) => {
9
+ /** Validates a `--transport` value, ignoring case. */
10
+ const parseMCPTransport = (value) => parseChoice(value, MCP_TRANSPORTS, "--transport");
11
+ /**
12
+ * Configures the Intlayer MCP server for an AI platform. Without a terminal
13
+ * (AI agents, CI), nothing is prompted: the platform defaults to the detected
14
+ * one and the transport to `stdio`.
15
+ */
16
+ const initMCP = async (projectRoot, options = {}) => {
9
17
  const p = await loadPrompts();
10
- const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
18
+ const root = resolveProjectRoot(projectRoot);
19
+ const isInteractive = isInteractiveTerminal();
11
20
  p.intro("Initializing Intlayer MCP Server");
12
- const platform = preselectedPlatform ?? await promptPlatform();
21
+ const platform = isInteractive ? options.platform ?? await promptPlatform(root) : await resolvePlatformWithoutPrompt(root, options.platform, "intlayer init mcp");
13
22
  if (!platform) {
14
23
  p.cancel("Operation cancelled. No platform selected.");
15
24
  return;
16
25
  }
17
- const transport = await p.select({
26
+ const transport = options.transport ?? (isInteractive ? await p.select({
18
27
  message: "Which transport method do you want to use?",
19
28
  options: [{
20
29
  value: "stdio",
@@ -25,8 +34,8 @@ const initMCP = async (projectRoot, preselectedPlatform) => {
25
34
  label: "Remote server (SSE)",
26
35
  hint: "Hosted by Intlayer. Documentation only."
27
36
  }]
28
- });
29
- if (p.isCancel(transport) || !transport) {
37
+ }) : "stdio");
38
+ if (p.isCancel(transport)) {
30
39
  p.cancel("Operation cancelled.");
31
40
  return;
32
41
  }
@@ -39,10 +48,11 @@ const initMCP = async (projectRoot, preselectedPlatform) => {
39
48
  } catch (error) {
40
49
  s.stop("Failed to configure MCP Server");
41
50
  p.log.error(error instanceof Error ? error.message : String(error));
51
+ process.exitCode = 1;
42
52
  }
43
53
  p.outro("Intlayer MCP Server initialization complete");
44
54
  };
45
55
 
46
56
  //#endregion
47
- export { initMCP };
57
+ export { initMCP, parseMCPTransport };
48
58
  //# sourceMappingURL=initMCP.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"initMCP.mjs","names":[],"sources":["../../src/initMCP.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport {\n installMCP,\n type MCPTransport,\n type Platform,\n} from '@intlayer/engine/cli';\nimport { findProjectRoot } from './init';\nimport { promptPlatform } from './initSkills';\nimport { loadPrompts } from './loadPrompts';\n\nexport const initMCP = async (\n projectRoot?: string,\n preselectedPlatform?: Platform\n) => {\n const p = await loadPrompts();\n\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n p.intro('Initializing Intlayer MCP Server');\n\n const platform = preselectedPlatform ?? (await promptPlatform());\n\n if (!platform) {\n p.cancel('Operation cancelled. No platform selected.');\n return;\n }\n\n const transport = (await p.select({\n message: 'Which transport method do you want to use?',\n options: [\n {\n value: 'stdio',\n label: 'Local server (stdio)',\n hint: 'Recommended. Integrates all features including CLI tools.',\n },\n {\n value: 'sse',\n label: 'Remote server (SSE)',\n hint: 'Hosted by Intlayer. Documentation only.',\n },\n ],\n })) as MCPTransport;\n\n if (p.isCancel(transport) || !transport) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const s = p.spinner();\n s.start('Configuring MCP Server...');\n\n try {\n const result = await installMCP(root, platform, transport);\n\n s.stop('MCP Server configured successfully');\n\n p.note(result, 'Success');\n } catch (error) {\n s.stop('Failed to configure MCP Server');\n p.log.error(error instanceof Error ? error.message : String(error));\n }\n\n p.outro('Intlayer MCP Server initialization complete');\n};\n"],"mappings":";;;;;;;AAUA,MAAa,UAAU,OACrB,aACA,wBACG;CACH,MAAM,IAAI,MAAM,YAAY;CAE5B,MAAM,OAAO,gBACX,cAAc,QAAQ,WAAW,IAAI,QAAQ,IAAI,CACnD;CAEA,EAAE,MAAM,kCAAkC;CAE1C,MAAM,WAAW,uBAAwB,MAAM,eAAe;CAE9D,IAAI,CAAC,UAAU;EACb,EAAE,OAAO,4CAA4C;EACrD;CACF;CAEA,MAAM,YAAa,MAAM,EAAE,OAAO;EAChC,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR,GACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR,CACF;CACF,CAAC;CAED,IAAI,EAAE,SAAS,SAAS,KAAK,CAAC,WAAW;EACvC,EAAE,OAAO,sBAAsB;EAC/B;CACF;CAEA,MAAM,IAAI,EAAE,QAAQ;CACpB,EAAE,MAAM,2BAA2B;CAEnC,IAAI;EACF,MAAM,SAAS,MAAM,WAAW,MAAM,UAAU,SAAS;EAEzD,EAAE,KAAK,oCAAoC;EAE3C,EAAE,KAAK,QAAQ,SAAS;CAC1B,SAAS,OAAO;EACd,EAAE,KAAK,gCAAgC;EACvC,EAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE;CAEA,EAAE,MAAM,6CAA6C;AACvD"}
1
+ {"version":3,"file":"initMCP.mjs","names":[],"sources":["../../src/initMCP.ts"],"sourcesContent":["import {\n installMCP,\n MCP_TRANSPORTS,\n type MCPTransport,\n type Platform,\n} from '@intlayer/engine/cli';\nimport { resolveProjectRoot } from './init';\nimport { promptPlatform, resolvePlatformWithoutPrompt } from './initSkills';\nimport { loadPrompts } from './loadPrompts';\nimport { isInteractiveTerminal } from './utils/isInteractiveTerminal';\nimport { parseChoice } from './utils/parseChoice';\n\n/** Options of {@link initMCP}; anything omitted is prompted for. */\nexport type InitMCPOptions = {\n /** AI platform to configure the MCP server for. */\n platform?: Platform;\n /** MCP transport. Defaults to `stdio` without a terminal. */\n transport?: MCPTransport;\n};\n\n/** Validates a `--transport` value, ignoring case. */\nexport const parseMCPTransport = (value: string): MCPTransport =>\n parseChoice(value, MCP_TRANSPORTS, '--transport');\n\n/**\n * Configures the Intlayer MCP server for an AI platform. Without a terminal\n * (AI agents, CI), nothing is prompted: the platform defaults to the detected\n * one and the transport to `stdio`.\n */\nexport const initMCP = async (\n projectRoot?: string,\n options: InitMCPOptions = {}\n) => {\n const p = await loadPrompts();\n\n const root = resolveProjectRoot(projectRoot);\n const isInteractive = isInteractiveTerminal();\n\n p.intro('Initializing Intlayer MCP Server');\n\n const platform = isInteractive\n ? (options.platform ?? (await promptPlatform(root)))\n : await resolvePlatformWithoutPrompt(\n root,\n options.platform,\n 'intlayer init mcp'\n );\n\n if (!platform) {\n p.cancel('Operation cancelled. No platform selected.');\n return;\n }\n\n const transport =\n options.transport ??\n (isInteractive\n ? await p.select<MCPTransport>({\n message: 'Which transport method do you want to use?',\n options: [\n {\n value: 'stdio',\n label: 'Local server (stdio)',\n hint: 'Recommended. Integrates all features including CLI tools.',\n },\n {\n value: 'sse',\n label: 'Remote server (SSE)',\n hint: 'Hosted by Intlayer. Documentation only.',\n },\n ],\n })\n : 'stdio');\n\n if (p.isCancel(transport)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const s = p.spinner();\n s.start('Configuring MCP Server...');\n\n try {\n const result = await installMCP(root, platform, transport);\n\n s.stop('MCP Server configured successfully');\n\n p.note(result, 'Success');\n } catch (error) {\n s.stop('Failed to configure MCP Server');\n p.log.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n }\n\n p.outro('Intlayer MCP Server initialization complete');\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,qBAAqB,UAChC,YAAY,OAAO,gBAAgB,aAAa;;;;;;AAOlD,MAAa,UAAU,OACrB,aACA,UAA0B,CAAC,MACxB;CACH,MAAM,IAAI,MAAM,YAAY;CAE5B,MAAM,OAAO,mBAAmB,WAAW;CAC3C,MAAM,gBAAgB,sBAAsB;CAE5C,EAAE,MAAM,kCAAkC;CAE1C,MAAM,WAAW,gBACZ,QAAQ,YAAa,MAAM,eAAe,IAAI,IAC/C,MAAM,6BACJ,MACA,QAAQ,UACR,mBACF;CAEJ,IAAI,CAAC,UAAU;EACb,EAAE,OAAO,4CAA4C;EACrD;CACF;CAEA,MAAM,YACJ,QAAQ,cACP,gBACG,MAAM,EAAE,OAAqB;EAC3B,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR,GACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR,CACF;CACF,CAAC,IACD;CAEN,IAAI,EAAE,SAAS,SAAS,GAAG;EACzB,EAAE,OAAO,sBAAsB;EAC/B;CACF;CAEA,MAAM,IAAI,EAAE,QAAQ;CACpB,EAAE,MAAM,2BAA2B;CAEnC,IAAI;EACF,MAAM,SAAS,MAAM,WAAW,MAAM,UAAU,SAAS;EAEzD,EAAE,KAAK,oCAAoC;EAE3C,EAAE,KAAK,QAAQ,SAAS;CAC1B,SAAS,OAAO;EACd,EAAE,KAAK,gCAAgC;EACvC,EAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;EAClE,QAAQ,WAAW;CACrB;CAEA,EAAE,MAAM,6CAA6C;AACvD"}
@@ -1,40 +1,22 @@
1
1
  import { loadPrompts } from "./loadPrompts.mjs";
2
- import { findProjectRoot } from "./init.mjs";
3
- import { join, resolve } from "node:path";
4
- import { PLATFORMS, PLATFORMS_METADATA, SKILLS, SKILLS_METADATA, getInitialSkills, installSkills } from "@intlayer/engine/cli";
5
- import { existsSync, readFileSync } from "node:fs";
2
+ import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
3
+ import { parseChoice } from "./utils/parseChoice.mjs";
4
+ import { getProjectDependencies, resolveProjectRoot } from "./init.mjs";
5
+ import { PLATFORMS, PLATFORMS_METADATA, SKILLS, SKILLS_METADATA, detectPlatform, getInitialSkills, installSkills } from "@intlayer/engine/cli";
6
6
  import enquirer from "enquirer";
7
7
 
8
8
  //#region src/initSkills.ts
9
- const PLATFORM_CHECKS = PLATFORMS.filter((platform) => PLATFORMS_METADATA[platform]?.check).map((platform) => ({
10
- check: PLATFORMS_METADATA[platform]?.check ?? (() => false),
11
- platform
12
- }));
13
9
  const PLATFORM_OPTIONS = PLATFORMS.map((platform) => ({
14
10
  value: platform,
15
11
  label: PLATFORMS_METADATA[platform]?.label ?? "",
16
12
  hint: `(${PLATFORMS_METADATA[platform]?.dir})`
17
13
  }));
18
- const getDetectedPlatform = () => PLATFORM_CHECKS.find(({ check }) => check())?.platform;
19
- const getDependencies = (root) => {
20
- try {
21
- const packageJsonPath = join(root, "package.json");
22
- if (!existsSync(packageJsonPath)) return {};
23
- const { dependencies = {}, devDependencies = {} } = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
24
- return {
25
- ...dependencies,
26
- ...devDependencies
27
- };
28
- } catch {
29
- return {};
30
- }
31
- };
32
14
  /**
33
15
  * Asks which AI platform the user is using, preselecting the detected one.
34
16
  * Resolves to `undefined` when the prompt is cancelled.
35
17
  */
36
- const promptPlatform = async () => {
37
- const detectedPlatform = getDetectedPlatform();
18
+ const promptPlatform = async (projectRoot) => {
19
+ const detectedPlatform = detectPlatform(projectRoot);
38
20
  try {
39
21
  return (await enquirer.prompt({
40
22
  type: "autocomplete",
@@ -52,32 +34,50 @@ const promptPlatform = async () => {
52
34
  return;
53
35
  }
54
36
  };
37
+ /** Validates a `--platform` value, ignoring case. */
38
+ const parsePlatform = (value) => parseChoice(value, PLATFORMS, "--platform");
39
+ /** Validates the `--skills` values, ignoring case. */
40
+ const parseSkills = (values) => values.flatMap((value) => value.split(",")).filter((value) => value.trim() !== "").map((value) => parseChoice(value, SKILLS, "--skills"));
41
+ /**
42
+ * Resolves the platform without prompting: the given one, else the detected
43
+ * one. Logs how to pass it and sets a failing exit code when neither exists.
44
+ */
45
+ const resolvePlatformWithoutPrompt = async (projectRoot, platform, command) => {
46
+ const resolvedPlatform = platform ?? detectPlatform(projectRoot);
47
+ if (!resolvedPlatform) {
48
+ (await loadPrompts()).log.error(`No AI platform detected. Pass it explicitly: ${command} --platform <platform>\nPlatforms: ${PLATFORMS.join(", ")}`);
49
+ process.exitCode = 1;
50
+ }
51
+ return resolvedPlatform;
52
+ };
55
53
  /**
56
54
  * Installs the Intlayer documentation skills. The skills are picked first, then
57
- * the platform (unless preselected). Resolves to the platform used, so a
58
- * following step (e.g. MCP) can reuse it without asking again.
55
+ * the platform. Without a terminal (AI agents, CI), nothing is prompted: the
56
+ * skills default to the project stack and the platform to the detected one.
57
+ * Resolves to the platform used, so a following step (e.g. MCP) can reuse it
58
+ * without asking again.
59
59
  */
60
- const initSkills = async (projectRoot, preselectedPlatform) => {
60
+ const initSkills = async (projectRoot, options = {}) => {
61
61
  const p = await loadPrompts();
62
- const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
62
+ const root = resolveProjectRoot(projectRoot);
63
+ const isInteractive = isInteractiveTerminal();
63
64
  p.intro("Initializing Intlayer skills");
64
- const dependencies = getDependencies(root);
65
- const initialValues = getInitialSkills(dependencies);
66
- const selectedSkills = await p.multiselect({
65
+ const initialSkills = getInitialSkills(getProjectDependencies(root));
66
+ const selectedSkills = options.skills ?? (isInteractive ? await p.multiselect({
67
67
  message: "Select the documentation skills to provide to your AI:",
68
- initialValues,
68
+ initialValues: initialSkills,
69
69
  options: SKILLS.map((skill) => ({
70
70
  value: skill,
71
71
  label: skill,
72
72
  hint: SKILLS_METADATA[skill]
73
73
  })),
74
74
  required: false
75
- });
76
- if (p.isCancel(selectedSkills) || !selectedSkills || selectedSkills.length === 0) {
75
+ }) : initialSkills);
76
+ if (p.isCancel(selectedSkills) || selectedSkills.length === 0) {
77
77
  p.cancel("Operation cancelled. No skills selected.");
78
78
  return;
79
79
  }
80
- const platform = preselectedPlatform ?? await promptPlatform();
80
+ const platform = isInteractive ? options.platform ?? await promptPlatform(root) : await resolvePlatformWithoutPrompt(root, options.platform, "intlayer init skills");
81
81
  if (!platform) {
82
82
  p.cancel("Operation cancelled. No platform selected.");
83
83
  return;
@@ -91,11 +91,12 @@ const initSkills = async (projectRoot, preselectedPlatform) => {
91
91
  } catch (error) {
92
92
  s.stop("Failed to install skills");
93
93
  p.log.error(error instanceof Error ? error.message : String(error));
94
+ process.exitCode = 1;
94
95
  }
95
96
  p.outro("Intlayer skills initialization complete");
96
97
  return platform;
97
98
  };
98
99
 
99
100
  //#endregion
100
- export { PLATFORM_OPTIONS, getDetectedPlatform, initSkills, promptPlatform };
101
+ export { PLATFORM_OPTIONS, initSkills, parsePlatform, parseSkills, promptPlatform, resolvePlatformWithoutPrompt };
101
102
  //# sourceMappingURL=initSkills.mjs.map