@intlayer/cli 9.0.0-canary.4 → 9.0.0-canary.6

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 (45) hide show
  1. package/dist/cjs/auth/login.cjs +42 -29
  2. package/dist/cjs/auth/login.cjs.map +1 -1
  3. package/dist/cjs/cli.cjs +3 -1
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/init.cjs +129 -7
  6. package/dist/cjs/init.cjs.map +1 -1
  7. package/dist/cjs/initBuildOptimization.cjs +81 -0
  8. package/dist/cjs/initBuildOptimization.cjs.map +1 -0
  9. package/dist/cjs/initCompiler.cjs +116 -0
  10. package/dist/cjs/initCompiler.cjs.map +1 -0
  11. package/dist/cjs/initMCP.cjs +21 -18
  12. package/dist/cjs/initMCP.cjs.map +1 -1
  13. package/dist/cjs/initSkills.cjs +21 -18
  14. package/dist/cjs/initSkills.cjs.map +1 -1
  15. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
  16. package/dist/cjs/translateDoc/translateFile.cjs +1 -1
  17. package/dist/esm/auth/login.mjs +42 -29
  18. package/dist/esm/auth/login.mjs.map +1 -1
  19. package/dist/esm/cli.mjs +3 -1
  20. package/dist/esm/cli.mjs.map +1 -1
  21. package/dist/esm/init.mjs +131 -10
  22. package/dist/esm/init.mjs.map +1 -1
  23. package/dist/esm/initBuildOptimization.mjs +78 -0
  24. package/dist/esm/initBuildOptimization.mjs.map +1 -0
  25. package/dist/esm/initCompiler.mjs +113 -0
  26. package/dist/esm/initCompiler.mjs.map +1 -0
  27. package/dist/esm/initMCP.mjs +21 -18
  28. package/dist/esm/initMCP.mjs.map +1 -1
  29. package/dist/esm/initSkills.mjs +21 -18
  30. package/dist/esm/initSkills.mjs.map +1 -1
  31. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
  32. package/dist/esm/translateDoc/translateFile.mjs +1 -1
  33. package/dist/types/auth/login.d.ts +13 -4
  34. package/dist/types/auth/login.d.ts.map +1 -1
  35. package/dist/types/cli.d.ts.map +1 -1
  36. package/dist/types/init.d.ts.map +1 -1
  37. package/dist/types/initBuildOptimization.d.ts +20 -0
  38. package/dist/types/initBuildOptimization.d.ts.map +1 -0
  39. package/dist/types/initCompiler.d.ts +18 -0
  40. package/dist/types/initCompiler.d.ts.map +1 -0
  41. package/dist/types/initMCP.d.ts +3 -1
  42. package/dist/types/initMCP.d.ts.map +1 -1
  43. package/dist/types/initSkills.d.ts +1 -1
  44. package/dist/types/initSkills.d.ts.map +1 -1
  45. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"init.cjs","names":["p","initSkills","initMCP"],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { type InitOptions, initIntlayer } from '@intlayer/chokidar/cli';\nimport { initMCP } from './initMCP';\nimport { initSkills } 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 | 'gitignore'\n | 'githubActions'\n | 'frameworkSetup'\n | 'vscodeExtension'\n | 'lsp'\n | 'skills'\n | 'mcp';\n\nconst 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: 'gitignore',\n label: '.gitignore entry',\n hint: 'add .intlayer to .gitignore',\n },\n {\n value: 'githubActions',\n label: 'GitHub Actions',\n hint: 'scaffold the fill and test workflows',\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/**\n * Runs `init` in interactive mode: prompts the user with a checkbox of setup\n * steps, then forwards the selection to {@link initIntlayer} (packages,\n * .gitignore, GitHub Actions, VS Code extension, LSP) and runs the dedicated\n * skills/MCP installers for the steps that own their own prompts.\n */\nconst runInteractiveInit = async (\n root: string,\n baseOptions?: InitOptions\n): Promise<void> => {\n p.intro('Initialize Intlayer');\n\n const selected = await p.multiselect<InitStep>({\n message: 'Select what you want to set up:',\n options: INIT_STEP_OPTIONS,\n initialValues: 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 const options: InitOptions = {\n ...baseOptions,\n noInstallPackages: !steps.includes('packages'),\n // Respect explicit `--no-*` flags from the command line even when the\n // corresponding step is selected in the checkbox.\n noGitignore: baseOptions?.noGitignore || !steps.includes('gitignore'),\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 if (steps.includes('skills')) {\n await initSkills(root);\n }\n\n if (steps.includes('mcp')) {\n await initMCP(root);\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":";;;;;;;;;;;AAOA,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;;AAcT,MAAM,oBAID;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;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACF;;;;;;;AAQD,MAAM,qBAAqB,OACzB,MACA,gBACkB;AAClB,gBAAE,MAAM,sBAAsB;CAE9B,MAAM,WAAW,MAAMA,eAAE,YAAsB;EAC7C,SAAS;EACT,SAAS;EACT,eAAe,kBAAkB,KAAK,WAAW,OAAO,MAAM;EAC9D,UAAU;EACX,CAAC;AAEF,KAAIA,eAAE,SAAS,SAAS,EAAE;AACxB,iBAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,QAAQ;AAgBd,gDAAmB,MAAM;EAbvB,GAAG;EACH,mBAAmB,CAAC,MAAM,SAAS,WAAW;EAG9C,aAAa,aAAa,eAAe,CAAC,MAAM,SAAS,YAAY;EACrE,iBACE,aAAa,mBAAmB,CAAC,MAAM,SAAS,gBAAgB;EAClE,kBACE,aAAa,oBAAoB,CAAC,MAAM,SAAS,iBAAiB;EACpE,mBAAmB,CAAC,MAAM,SAAS,kBAAkB;EACrD,OAAO,CAAC,MAAM,SAAS,MAAM;EAGC,CAAC;AAEjC,KAAI,MAAM,SAAS,SAAS,CAC1B,OAAMC,8BAAW,KAAK;AAGxB,KAAI,MAAM,SAAS,MAAM,CACvB,OAAMC,wBAAQ,KAAK;AAGrB,gBAAE,MAAM,mCAAmC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,uCAAwB,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,gDAAmB,MAAM,QAAQ"}
1
+ {"version":3,"file":"init.cjs","names":["p","getDetectedPlatform","PLATFORMS","PLATFORM_OPTIONS","initSkills","initMCP","initCompiler","initBuildOptimization","login"],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n type InitOptions,\n initIntlayer,\n PLATFORMS,\n type Platform,\n type RoutingMode,\n setupCmsCredentials,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { login } from './auth/login';\nimport { initBuildOptimization } from './initBuildOptimization';\nimport { initCompiler } from './initCompiler';\nimport { initMCP } from './initMCP';\nimport {\n getDetectedPlatform,\n initSkills,\n PLATFORM_OPTIONS,\n} from './initSkills';\n\nexport const findProjectRoot = (startDir: string) => {\n let currentDir = startDir;\n\n while (currentDir !== resolve(currentDir, '..')) {\n if (existsSync(join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = resolve(currentDir, '..');\n }\n\n // If no package.json is found, return the start directory.\n // The initIntlayer function will handle the missing package.json error.\n return startDir;\n};\n\n/** Individually selectable setup steps exposed by the interactive init flow. */\ntype InitStep =\n | 'packages'\n | 'gitignore'\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: 'gitignore',\n label: '.gitignore entry',\n hint: 'add .intlayer to .gitignore',\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/** 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,\n * .gitignore, GitHub Actions, VS Code extension, LSP) and runs the dedicated\n * skills/MCP installers for the steps that own their own prompts.\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 const options: InitOptions = {\n ...baseOptions,\n routingMode,\n noInstallPackages: !steps.includes('packages'),\n // Respect explicit `--no-*` flags from the command line even when the\n // corresponding step is selected in the checkbox.\n noGitignore: baseOptions?.noGitignore || !steps.includes('gitignore'),\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;;AAgBT,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;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACF;;AAGD,MAAM,uBAID;CACH;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP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CACrC,OAAMC,oDAAsB,KAAK;CAMnC,MAAM,iBAAiB,MAAMP,eAAE,QAAQ;EACrC,SACE;EACF,cAAc;EACf,CAAC;AAEF,KAAIA,eAAE,SAAS,eAAe,EAAE;AAC9B,iBAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,gBAAgB;AAClB,iBAAE,IAAI,KAAK,wDAAwD;AAGnE,QAAMQ,yBAAM;GACV,WAAW;GACX,gBAAgB,gEAAoC,MAAM,YAAY;GACvE,CAAC;;AAGJ,gBAAE,MAAM,mCAAmC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,uCAAwB,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,gDAAmB,MAAM,QAAQ"}
@@ -0,0 +1,81 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_init = require('./init.cjs');
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
7
+ let _clack_prompts = require("@clack/prompts");
8
+ _clack_prompts = require_runtime.__toESM(_clack_prompts);
9
+
10
+ //#region src/initBuildOptimization.ts
11
+ /** Babel config filenames Next.js picks up, ordered by preference. */
12
+ const BABEL_CONFIG_CANDIDATES = [
13
+ "babel.config.js",
14
+ "babel.config.cjs",
15
+ "babel.config.mjs",
16
+ "babel.config.ts"
17
+ ];
18
+ /**
19
+ * Interactive prompt to select a build optimization plugin for Next.js and
20
+ * scaffold the required files. The two options are independent — pick one:
21
+ *
22
+ * - `@intlayer/babel` — runs the full compiler pipeline (extract, purge, minify,
23
+ * optimize) through Babel. Installs `@intlayer/babel` and creates a
24
+ * `babel.config.js`.
25
+ * - `@intlayer/swc` — lightweight SWC plugin that rewrites `useIntlayer` imports.
26
+ * Installs only the dependency; `withIntlayer` wires it in automatically, so
27
+ * no config file is required.
28
+ *
29
+ * @param projectRoot - Optional project root; defaults to the current directory.
30
+ */
31
+ const initBuildOptimization = async (projectRoot) => {
32
+ const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
33
+ _clack_prompts.intro("Configuring Next.js build optimization");
34
+ const plugin = await _clack_prompts.select({
35
+ message: "Which build optimization plugin do you want to use?",
36
+ options: [{
37
+ value: "babel",
38
+ label: "@intlayer/babel",
39
+ hint: "Full pipeline — extract, purge, minify and optimize via Babel; creates babel.config.js"
40
+ }, {
41
+ value: "swc",
42
+ label: "@intlayer/swc",
43
+ hint: "Lightweight — SWC plugin that rewrites useIntlayer imports; wired automatically by withIntlayer"
44
+ }]
45
+ });
46
+ if (_clack_prompts.isCancel(plugin) || !plugin) {
47
+ _clack_prompts.cancel("Operation cancelled.");
48
+ return;
49
+ }
50
+ const packageManager = (0, _intlayer_chokidar_cli.detectPackageManager)(root);
51
+ const packageToInstall = plugin === "babel" ? "@intlayer/babel" : "@intlayer/swc";
52
+ const spinner = _clack_prompts.spinner();
53
+ spinner.start("Installing packages...");
54
+ try {
55
+ (0, _intlayer_chokidar_cli.installPackages)(root, [packageToInstall], packageManager, true);
56
+ spinner.stop(`Installed: ${packageToInstall}`);
57
+ } catch {
58
+ spinner.stop("Package installation failed");
59
+ _clack_prompts.log.warn(`Please install manually: ${packageToInstall} (dev dependency)`);
60
+ }
61
+ if (plugin === "swc") {
62
+ _clack_prompts.outro("Build optimization configuration complete");
63
+ return;
64
+ }
65
+ const existingBabelConfig = BABEL_CONFIG_CANDIDATES.find((file) => (0, node_fs.existsSync)((0, node_path.join)(root, file)));
66
+ if (existingBabelConfig) {
67
+ _clack_prompts.log.warn(`${existingBabelConfig} already exists — add the Intlayer plugins manually.`);
68
+ _clack_prompts.note(_intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "Plugins to add to your babel config");
69
+ } else try {
70
+ (0, node_fs.writeFileSync)((0, node_path.join)(root, "babel.config.js"), _intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, { encoding: "utf-8" });
71
+ _clack_prompts.log.success("Created babel.config.js with the Intlayer compiler plugins (extract, purge, minify, optimize)");
72
+ } catch {
73
+ _clack_prompts.log.warn("Could not create babel.config.js — please create it manually.");
74
+ _clack_prompts.note(_intlayer_chokidar_cli.NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "babel.config.js");
75
+ }
76
+ _clack_prompts.outro("Build optimization configuration complete");
77
+ };
78
+
79
+ //#endregion
80
+ exports.initBuildOptimization = initBuildOptimization;
81
+ //# sourceMappingURL=initBuildOptimization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initBuildOptimization.cjs","names":["findProjectRoot","p","NEXT_INTLAYER_BABEL_CONFIG_CONTENT"],"sources":["../../src/initBuildOptimization.ts"],"sourcesContent":["import { existsSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n detectPackageManager,\n installPackages,\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n} from '@intlayer/chokidar/cli';\nimport { findProjectRoot } from './init';\n\n/** Intlayer build optimization plugin choices for Next.js. */\nexport type BuildOptimizationPlugin = 'babel' | 'swc';\n\n/** Babel config filenames Next.js picks up, ordered by preference. */\nconst BABEL_CONFIG_CANDIDATES = [\n 'babel.config.js',\n 'babel.config.cjs',\n 'babel.config.mjs',\n 'babel.config.ts',\n];\n\n/**\n * Interactive prompt to select a build optimization plugin for Next.js and\n * scaffold the required files. The two options are independent — pick one:\n *\n * - `@intlayer/babel` — runs the full compiler pipeline (extract, purge, minify,\n * optimize) through Babel. Installs `@intlayer/babel` and creates a\n * `babel.config.js`.\n * - `@intlayer/swc` — lightweight SWC plugin that rewrites `useIntlayer` imports.\n * Installs only the dependency; `withIntlayer` wires it in automatically, so\n * no config file is required.\n *\n * @param projectRoot - Optional project root; defaults to the current directory.\n */\nexport const initBuildOptimization = async (\n projectRoot?: string\n): Promise<void> => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n p.intro('Configuring Next.js build optimization');\n\n const plugin = (await p.select({\n message: 'Which build optimization plugin do you want to use?',\n options: [\n {\n value: 'babel',\n label: '@intlayer/babel',\n hint: 'Full pipeline — extract, purge, minify and optimize via Babel; creates babel.config.js',\n },\n {\n value: 'swc',\n label: '@intlayer/swc',\n hint: 'Lightweight — SWC plugin that rewrites useIntlayer imports; wired automatically by withIntlayer',\n },\n ],\n })) as BuildOptimizationPlugin;\n\n if (p.isCancel(plugin) || !plugin) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const packageManager = detectPackageManager(root);\n const packageToInstall =\n plugin === 'babel' ? '@intlayer/babel' : '@intlayer/swc';\n\n const spinner = p.spinner();\n spinner.start('Installing packages...');\n\n try {\n installPackages(root, [packageToInstall], packageManager, true);\n spinner.stop(`Installed: ${packageToInstall}`);\n } catch {\n spinner.stop('Package installation failed');\n p.log.warn(`Please install manually: ${packageToInstall} (dev dependency)`);\n }\n\n // SWC needs no extra setup — withIntlayer injects the plugin at build time.\n if (plugin === 'swc') {\n p.outro('Build optimization configuration complete');\n return;\n }\n\n // BABEL — scaffold babel.config.js with the full compiler pipeline.\n const existingBabelConfig = BABEL_CONFIG_CANDIDATES.find((file) =>\n existsSync(join(root, file))\n );\n\n if (existingBabelConfig) {\n p.log.warn(\n `${existingBabelConfig} already exists — add the Intlayer plugins manually.`\n );\n p.note(\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n 'Plugins to add to your babel config'\n );\n } else {\n try {\n writeFileSync(\n join(root, 'babel.config.js'),\n NEXT_INTLAYER_BABEL_CONFIG_CONTENT,\n { encoding: 'utf-8' }\n );\n p.log.success(\n 'Created babel.config.js with the Intlayer compiler plugins (extract, purge, minify, optimize)'\n );\n } catch {\n p.log.warn(\n 'Could not create babel.config.js — please create it manually.'\n );\n p.note(NEXT_INTLAYER_BABEL_CONFIG_CONTENT, 'babel.config.js');\n }\n }\n\n p.outro('Build optimization configuration complete');\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,0BAA0B;CAC9B;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;AAeD,MAAa,wBAAwB,OACnC,gBACkB;CAClB,MAAM,OAAOA,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AACD,gBAAE,MAAM,yCAAyC;CAEjD,MAAM,SAAU,MAAMC,eAAE,OAAO;EAC7B,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,EACD;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,CACF;EACF,CAAC;AAEF,KAAIA,eAAE,SAAS,OAAO,IAAI,CAAC,QAAQ;AACjC,iBAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,kEAAsC,KAAK;CACjD,MAAM,mBACJ,WAAW,UAAU,oBAAoB;CAE3C,MAAM,UAAUA,eAAE,SAAS;AAC3B,SAAQ,MAAM,yBAAyB;AAEvC,KAAI;AACF,8CAAgB,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,KAAK;AAC/D,UAAQ,KAAK,cAAc,mBAAmB;SACxC;AACN,UAAQ,KAAK,8BAA8B;AAC3C,iBAAE,IAAI,KAAK,4BAA4B,iBAAiB,mBAAmB;;AAI7E,KAAI,WAAW,OAAO;AACpB,iBAAE,MAAM,4CAA4C;AACpD;;CAIF,MAAM,sBAAsB,wBAAwB,MAAM,qDACxC,MAAM,KAAK,CAAC,CAC7B;AAED,KAAI,qBAAqB;AACvB,iBAAE,IAAI,KACJ,GAAG,oBAAoB,sDACxB;AACD,iBAAE,KACAC,2DACA,sCACD;OAED,KAAI;AACF,iDACO,MAAM,kBAAkB,EAC7BA,2DACA,EAAE,UAAU,SAAS,CACtB;AACD,iBAAE,IAAI,QACJ,gGACD;SACK;AACN,iBAAE,IAAI,KACJ,gEACD;AACD,iBAAE,KAAKA,2DAAoC,kBAAkB;;AAIjE,gBAAE,MAAM,4CAA4C"}
@@ -0,0 +1,116 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_init = require('./init.cjs');
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
7
+ let _clack_prompts = require("@clack/prompts");
8
+ _clack_prompts = require_runtime.__toESM(_clack_prompts);
9
+
10
+ //#region src/initCompiler.ts
11
+ /**
12
+ * babel.config.js that runs the Intlayer compiler passes for Next.js.
13
+ *
14
+ * Mirrors the Next.js (Babel) tab of `docs/docs/en/compiler.md`: the extract
15
+ * plugin pulls inline content into dictionaries and the optimize plugin
16
+ * rewrites `useIntlayer` into direct dictionary imports. On Vite the same work
17
+ * is handled by the `intlayerCompiler()` plugin, so no Babel config is needed.
18
+ */
19
+ const BABEL_COMPILER_CONFIG_CONTENT = `const {
20
+ intlayerExtractBabelPlugin,
21
+ intlayerOptimizeBabelPlugin,
22
+ getExtractPluginOptions,
23
+ getOptimizePluginOptions,
24
+ } = require("@intlayer/babel");
25
+
26
+ module.exports = {
27
+ presets: ["next/babel"],
28
+ plugins: [
29
+ // Extract content from components into dictionaries
30
+ [intlayerExtractBabelPlugin, getExtractPluginOptions()],
31
+ // Optimize imports by replacing useIntlayer with direct dictionary imports
32
+ [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],
33
+ ],
34
+ };
35
+ `;
36
+ /**
37
+ * Reads the project dependencies and detects which framework the compiler
38
+ * should target. Next.js is checked before Vite because a Next.js project may
39
+ * transitively depend on Vite tooling.
40
+ */
41
+ const detectCompilerFramework = (root) => {
42
+ try {
43
+ const packageJsonPath = (0, node_path.join)(root, "package.json");
44
+ if (!(0, node_fs.existsSync)(packageJsonPath)) return "unknown";
45
+ const { dependencies = {}, devDependencies = {} } = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf-8"));
46
+ const allDependencies = {
47
+ ...dependencies,
48
+ ...devDependencies
49
+ };
50
+ if (allDependencies.next) return "nextjs";
51
+ if (allDependencies.vite) return "vite";
52
+ return "unknown";
53
+ } catch {
54
+ return "unknown";
55
+ }
56
+ };
57
+ /**
58
+ * Scaffolds the Intlayer compiler for the current project during interactive
59
+ * init.
60
+ *
61
+ * - **Vite** — nothing to do: the compiler is plugged in directly through the
62
+ * `intlayerCompiler()` plugin in `vite.config.ts`, so this only confirms the
63
+ * setup to the user.
64
+ * - **Next.js** — installs `@intlayer/babel` and writes a `babel.config.js`
65
+ * that runs the extract + optimize compiler passes.
66
+ *
67
+ * In non-interactive init this function is never called, so the compiler setup
68
+ * is left untouched.
69
+ */
70
+ const initCompiler = async (projectRoot) => {
71
+ const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
72
+ const framework = detectCompilerFramework(root);
73
+ if (framework === "vite") {
74
+ _clack_prompts.log.info("Vite detected — the compiler is plugged in directly through `intlayerCompiler()` in your vite.config. Nothing to configure.");
75
+ return;
76
+ }
77
+ if (framework !== "nextjs") {
78
+ _clack_prompts.log.warn("No supported framework detected for the compiler — skipping. See the compiler docs for manual setup.");
79
+ return;
80
+ }
81
+ _clack_prompts.intro("Configuring the Intlayer compiler for Next.js");
82
+ const packageManager = (0, _intlayer_chokidar_cli.detectPackageManager)(root);
83
+ const devPackagesToInstall = ["@intlayer/babel"];
84
+ const spinner = _clack_prompts.spinner();
85
+ spinner.start("Installing packages...");
86
+ try {
87
+ (0, _intlayer_chokidar_cli.installPackages)(root, devPackagesToInstall, packageManager, true);
88
+ spinner.stop(`Installed: ${devPackagesToInstall.join(", ")}`);
89
+ } catch {
90
+ spinner.stop("Package installation failed");
91
+ _clack_prompts.log.warn(`Please install manually: ${devPackagesToInstall.join(" ")} (dev dependency)`);
92
+ }
93
+ const existingBabelConfig = [
94
+ "babel.config.js",
95
+ "babel.config.cjs",
96
+ "babel.config.mjs",
97
+ "babel.config.ts",
98
+ ".babelrc",
99
+ ".babelrc.js"
100
+ ].find((file) => (0, node_fs.existsSync)((0, node_path.join)(root, file)));
101
+ if (existingBabelConfig) {
102
+ _clack_prompts.log.warn(`${existingBabelConfig} already exists — add the Intlayer compiler plugins manually.`);
103
+ _clack_prompts.note(BABEL_COMPILER_CONFIG_CONTENT, "Plugins to add to your babel config");
104
+ } else try {
105
+ (0, node_fs.writeFileSync)((0, node_path.join)(root, "babel.config.js"), BABEL_COMPILER_CONFIG_CONTENT, { encoding: "utf-8" });
106
+ _clack_prompts.log.success("Created babel.config.js with the Intlayer compiler extract and optimize plugins");
107
+ } catch {
108
+ _clack_prompts.log.warn("Could not create babel.config.js — please create it manually.");
109
+ _clack_prompts.note(BABEL_COMPILER_CONFIG_CONTENT, "babel.config.js");
110
+ }
111
+ _clack_prompts.outro("Compiler configuration complete");
112
+ };
113
+
114
+ //#endregion
115
+ exports.initCompiler = initCompiler;
116
+ //# sourceMappingURL=initCompiler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initCompiler.cjs","names":["findProjectRoot","p"],"sources":["../../src/initCompiler.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport { detectPackageManager, installPackages } from '@intlayer/chokidar/cli';\nimport { findProjectRoot } from './init';\n\n/** Framework the Intlayer compiler can be wired into during init. */\ntype CompilerFramework = 'vite' | 'nextjs' | 'unknown';\n\n/**\n * babel.config.js that runs the Intlayer compiler passes for Next.js.\n *\n * Mirrors the Next.js (Babel) tab of `docs/docs/en/compiler.md`: the extract\n * plugin pulls inline content into dictionaries and the optimize plugin\n * rewrites `useIntlayer` into direct dictionary imports. On Vite the same work\n * is handled by the `intlayerCompiler()` plugin, so no Babel config is needed.\n */\nconst BABEL_COMPILER_CONFIG_CONTENT = `const {\n intlayerExtractBabelPlugin,\n intlayerOptimizeBabelPlugin,\n getExtractPluginOptions,\n getOptimizePluginOptions,\n} = require(\"@intlayer/babel\");\n\nmodule.exports = {\n presets: [\"next/babel\"],\n plugins: [\n // Extract content from components into dictionaries\n [intlayerExtractBabelPlugin, getExtractPluginOptions()],\n // Optimize imports by replacing useIntlayer with direct dictionary imports\n [intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],\n ],\n};\n`;\n\n/**\n * Reads the project dependencies and detects which framework the compiler\n * should target. Next.js is checked before Vite because a Next.js project may\n * transitively depend on Vite tooling.\n */\nconst detectCompilerFramework = (root: string): CompilerFramework => {\n try {\n const packageJsonPath = join(root, 'package.json');\n if (!existsSync(packageJsonPath)) return 'unknown';\n\n const { dependencies = {}, devDependencies = {} } = JSON.parse(\n readFileSync(packageJsonPath, 'utf-8')\n );\n const allDependencies = { ...dependencies, ...devDependencies };\n\n if (allDependencies.next) return 'nextjs';\n if (allDependencies.vite) return 'vite';\n\n return 'unknown';\n } catch {\n return 'unknown';\n }\n};\n\n/**\n * Scaffolds the Intlayer compiler for the current project during interactive\n * init.\n *\n * - **Vite** — nothing to do: the compiler is plugged in directly through the\n * `intlayerCompiler()` plugin in `vite.config.ts`, so this only confirms the\n * setup to the user.\n * - **Next.js** — installs `@intlayer/babel` and writes a `babel.config.js`\n * that runs the extract + optimize compiler passes.\n *\n * In non-interactive init this function is never called, so the compiler setup\n * is left untouched.\n */\nexport const initCompiler = async (projectRoot?: string): Promise<void> => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n const framework = detectCompilerFramework(root);\n\n if (framework === 'vite') {\n // The Vite plugin plugs the compiler in directly — nothing to scaffold.\n p.log.info(\n 'Vite detected — the compiler is plugged in directly through `intlayerCompiler()` in your vite.config. Nothing to configure.'\n );\n return;\n }\n\n if (framework !== 'nextjs') {\n p.log.warn(\n 'No supported framework detected for the compiler — skipping. See the compiler docs for manual setup.'\n );\n return;\n }\n\n p.intro('Configuring the Intlayer compiler for Next.js');\n\n const packageManager = detectPackageManager(root);\n const devPackagesToInstall = ['@intlayer/babel'];\n\n const spinner = p.spinner();\n spinner.start('Installing packages...');\n\n try {\n installPackages(root, devPackagesToInstall, packageManager, true);\n spinner.stop(`Installed: ${devPackagesToInstall.join(', ')}`);\n } catch {\n spinner.stop('Package installation failed');\n p.log.warn(\n `Please install manually: ${devPackagesToInstall.join(' ')} (dev dependency)`\n );\n }\n\n const babelConfigCandidates = [\n 'babel.config.js',\n 'babel.config.cjs',\n 'babel.config.mjs',\n 'babel.config.ts',\n '.babelrc',\n '.babelrc.js',\n ];\n\n const existingBabelConfig = babelConfigCandidates.find((file) =>\n existsSync(join(root, file))\n );\n\n if (existingBabelConfig) {\n p.log.warn(\n `${existingBabelConfig} already exists — add the Intlayer compiler plugins manually.`\n );\n p.note(\n BABEL_COMPILER_CONFIG_CONTENT,\n 'Plugins to add to your babel config'\n );\n } else {\n try {\n writeFileSync(\n join(root, 'babel.config.js'),\n BABEL_COMPILER_CONFIG_CONTENT,\n { encoding: 'utf-8' }\n );\n p.log.success(\n 'Created babel.config.js with the Intlayer compiler extract and optimize plugins'\n );\n } catch {\n p.log.warn(\n 'Could not create babel.config.js — please create it manually.'\n );\n p.note(BABEL_COMPILER_CONFIG_CONTENT, 'babel.config.js');\n }\n }\n\n p.outro('Compiler configuration complete');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;AAuBtC,MAAM,2BAA2B,SAAoC;AACnE,KAAI;EACF,MAAM,sCAAuB,MAAM,eAAe;AAClD,MAAI,yBAAY,gBAAgB,CAAE,QAAO;EAEzC,MAAM,EAAE,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,KAAK,gCAC1C,iBAAiB,QAAQ,CACvC;EACD,MAAM,kBAAkB;GAAE,GAAG;GAAc,GAAG;GAAiB;AAE/D,MAAI,gBAAgB,KAAM,QAAO;AACjC,MAAI,gBAAgB,KAAM,QAAO;AAEjC,SAAO;SACD;AACN,SAAO;;;;;;;;;;;;;;;;AAiBX,MAAa,eAAe,OAAO,gBAAwC;CACzE,MAAM,OAAOA,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;CAED,MAAM,YAAY,wBAAwB,KAAK;AAE/C,KAAI,cAAc,QAAQ;AAExB,iBAAE,IAAI,KACJ,8HACD;AACD;;AAGF,KAAI,cAAc,UAAU;AAC1B,iBAAE,IAAI,KACJ,uGACD;AACD;;AAGF,gBAAE,MAAM,gDAAgD;CAExD,MAAM,kEAAsC,KAAK;CACjD,MAAM,uBAAuB,CAAC,kBAAkB;CAEhD,MAAM,UAAUC,eAAE,SAAS;AAC3B,SAAQ,MAAM,yBAAyB;AAEvC,KAAI;AACF,8CAAgB,MAAM,sBAAsB,gBAAgB,KAAK;AACjE,UAAQ,KAAK,cAAc,qBAAqB,KAAK,KAAK,GAAG;SACvD;AACN,UAAQ,KAAK,8BAA8B;AAC3C,iBAAE,IAAI,KACJ,4BAA4B,qBAAqB,KAAK,IAAI,CAAC,mBAC5D;;CAYH,MAAM,sBAAsB;EAR1B;EACA;EACA;EACA;EACA;EACA;EAG+C,CAAC,MAAM,qDACtC,MAAM,KAAK,CAAC,CAC7B;AAED,KAAI,qBAAqB;AACvB,iBAAE,IAAI,KACJ,GAAG,oBAAoB,+DACxB;AACD,iBAAE,KACA,+BACA,sCACD;OAED,KAAI;AACF,iDACO,MAAM,kBAAkB,EAC7B,+BACA,EAAE,UAAU,SAAS,CACtB;AACD,iBAAE,IAAI,QACJ,kFACD;SACK;AACN,iBAAE,IAAI,KACJ,gEACD;AACD,iBAAE,KAAK,+BAA+B,kBAAkB;;AAI5D,gBAAE,MAAM,kCAAkC"}
@@ -10,27 +10,30 @@ let _clack_prompts = require("@clack/prompts");
10
10
  _clack_prompts = require_runtime.__toESM(_clack_prompts);
11
11
 
12
12
  //#region src/initMCP.ts
13
- const initMCP = async (projectRoot) => {
13
+ const initMCP = async (projectRoot, preselectedPlatform) => {
14
14
  const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
15
15
  _clack_prompts.intro("Initializing Intlayer MCP Server");
16
- const detectedPlatform = require_initSkills.getDetectedPlatform();
17
16
  let platform;
18
- try {
19
- platform = (await enquirer.default.prompt({
20
- type: "autocomplete",
21
- name: "platforms",
22
- message: "Which platform are you using? (Type to search)",
23
- multiple: false,
24
- initial: detectedPlatform ? _intlayer_chokidar_cli.PLATFORMS.indexOf(detectedPlatform) : void 0,
25
- choices: require_initSkills.PLATFORM_OPTIONS.map((opt) => ({
26
- name: opt.value,
27
- message: opt.label,
28
- hint: opt.hint
29
- }))
30
- })).platforms;
31
- } catch {
32
- _clack_prompts.cancel("Operation cancelled.");
33
- return;
17
+ if (preselectedPlatform) platform = preselectedPlatform;
18
+ else {
19
+ const detectedPlatform = require_initSkills.getDetectedPlatform();
20
+ try {
21
+ platform = (await enquirer.default.prompt({
22
+ type: "autocomplete",
23
+ name: "platforms",
24
+ message: "Which platform are you using? (Type to search)",
25
+ multiple: false,
26
+ initial: detectedPlatform ? _intlayer_chokidar_cli.PLATFORMS.indexOf(detectedPlatform) : void 0,
27
+ choices: require_initSkills.PLATFORM_OPTIONS.map((opt) => ({
28
+ name: opt.value,
29
+ message: opt.label,
30
+ hint: opt.hint
31
+ }))
32
+ })).platforms;
33
+ } catch {
34
+ _clack_prompts.cancel("Operation cancelled.");
35
+ return;
36
+ }
34
37
  }
35
38
  if (!platform) {
36
39
  _clack_prompts.cancel("Operation cancelled. No platform selected.");
@@ -1 +1 @@
1
- {"version":3,"file":"initMCP.cjs","names":["findProjectRoot","getDetectedPlatform","PLATFORMS","PLATFORM_OPTIONS","p"],"sources":["../../src/initMCP.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n installMCP,\n type MCPTransport,\n PLATFORMS,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { findProjectRoot } from './init';\nimport { getDetectedPlatform, PLATFORM_OPTIONS } from './initSkills';\n\nexport const initMCP = async (projectRoot?: string) => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n p.intro('Initializing Intlayer MCP Server');\n\n const detectedPlatform = getDetectedPlatform();\n\n let platform: any;\n try {\n const response = await enquirer.prompt<{ platforms: any }>({\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 platform = response.platforms;\n } catch {\n p.cancel('Operation cancelled.');\n return;\n }\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":";;;;;;;;;;;;AAWA,MAAa,UAAU,OAAO,gBAAyB;CACrD,MAAM,OAAOA,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AAED,gBAAE,MAAM,mCAAmC;CAE3C,MAAM,mBAAmBC,wCAAqB;CAE9C,IAAI;AACJ,KAAI;AAeF,cAAW,MAdY,iBAAS,OAA2B;GACzD,MAAM;GACN,MAAM;GACN,SAAS;GACT,UAAU;GACV,SAAS,mBACLC,iCAAU,QAAQ,iBAAiB,GACnC;GACJ,SAASC,oCAAiB,KAAK,SAAS;IACtC,MAAM,IAAI;IACV,SAAS,IAAI;IACb,MAAM,IAAI;IACX,EAAE;GACJ,CAAC,EACkB;SACd;AACN,iBAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,CAAC,UAAU;AACb,iBAAE,OAAO,6CAA6C;AACtD;;CAGF,MAAM,YAAa,MAAMC,eAAE,OAAO;EAChC,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,EACD;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,CACF;EACF,CAAC;AAEF,KAAIA,eAAE,SAAS,UAAU,IAAI,CAAC,WAAW;AACvC,iBAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,IAAIA,eAAE,SAAS;AACrB,GAAE,MAAM,4BAA4B;AAEpC,KAAI;EACF,MAAM,SAAS,6CAAiB,MAAM,UAAU,UAAU;AAE1D,IAAE,KAAK,qCAAqC;AAE5C,iBAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,iCAAiC;AACxC,iBAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,gBAAE,MAAM,8CAA8C"}
1
+ {"version":3,"file":"initMCP.cjs","names":["findProjectRoot","getDetectedPlatform","PLATFORMS","PLATFORM_OPTIONS","p"],"sources":["../../src/initMCP.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n installMCP,\n type MCPTransport,\n PLATFORMS,\n type Platform,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { findProjectRoot } from './init';\nimport { getDetectedPlatform, PLATFORM_OPTIONS } from './initSkills';\n\nexport const initMCP = async (\n projectRoot?: string,\n preselectedPlatform?: Platform\n) => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n p.intro('Initializing Intlayer MCP Server');\n\n let platform: Platform;\n\n if (preselectedPlatform) {\n platform = preselectedPlatform;\n } else {\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 platform = response.platforms;\n } catch {\n p.cancel('Operation cancelled.');\n return;\n }\n }\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":";;;;;;;;;;;;AAYA,MAAa,UAAU,OACrB,aACA,wBACG;CACH,MAAM,OAAOA,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AAED,gBAAE,MAAM,mCAAmC;CAE3C,IAAI;AAEJ,KAAI,oBACF,YAAW;MACN;EACL,MAAM,mBAAmBC,wCAAqB;AAE9C,MAAI;AAeF,eAAW,MAdY,iBAAS,OAAgC;IAC9D,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,SAAS,mBACLC,iCAAU,QAAQ,iBAAiB,GACnC;IACJ,SAASC,oCAAiB,KAAK,SAAS;KACtC,MAAM,IAAI;KACV,SAAS,IAAI;KACb,MAAM,IAAI;KACX,EAAE;IACJ,CAAC,EACkB;UACd;AACN,kBAAE,OAAO,uBAAuB;AAChC;;;AAIJ,KAAI,CAAC,UAAU;AACb,iBAAE,OAAO,6CAA6C;AACtD;;CAGF,MAAM,YAAa,MAAMC,eAAE,OAAO;EAChC,SAAS;EACT,SAAS,CACP;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,EACD;GACE,OAAO;GACP,OAAO;GACP,MAAM;GACP,CACF;EACF,CAAC;AAEF,KAAIA,eAAE,SAAS,UAAU,IAAI,CAAC,WAAW;AACvC,iBAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,IAAIA,eAAE,SAAS;AACrB,GAAE,MAAM,4BAA4B;AAEpC,KAAI;EACF,MAAM,SAAS,6CAAiB,MAAM,UAAU,UAAU;AAE1D,IAAE,KAAK,qCAAqC;AAE5C,iBAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,iCAAiC;AACxC,iBAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,gBAAE,MAAM,8CAA8C"}
@@ -33,27 +33,30 @@ const getDependencies = (root) => {
33
33
  return {};
34
34
  }
35
35
  };
36
- const initSkills = async (projectRoot) => {
36
+ const initSkills = async (projectRoot, preselectedPlatform) => {
37
37
  const root = require_init.findProjectRoot(projectRoot ? (0, node_path.resolve)(projectRoot) : process.cwd());
38
38
  _clack_prompts.intro("Initializing Intlayer skills");
39
- const detectedPlatform = getDetectedPlatform();
40
39
  let platform;
41
- try {
42
- platform = (await enquirer.default.prompt({
43
- type: "autocomplete",
44
- name: "platforms",
45
- message: "Which platforms are you using? (Type to search)",
46
- multiple: false,
47
- initial: detectedPlatform ? _intlayer_chokidar_cli.PLATFORMS.indexOf(detectedPlatform) : void 0,
48
- choices: PLATFORM_OPTIONS.map((opt) => ({
49
- name: opt.value,
50
- message: opt.label,
51
- hint: opt.hint
52
- }))
53
- })).platforms;
54
- } catch {
55
- _clack_prompts.cancel("Operation cancelled.");
56
- return;
40
+ if (preselectedPlatform) platform = preselectedPlatform;
41
+ else {
42
+ const detectedPlatform = getDetectedPlatform();
43
+ try {
44
+ platform = (await enquirer.default.prompt({
45
+ type: "autocomplete",
46
+ name: "platforms",
47
+ message: "Which platforms are you using? (Type to search)",
48
+ multiple: false,
49
+ initial: detectedPlatform ? _intlayer_chokidar_cli.PLATFORMS.indexOf(detectedPlatform) : void 0,
50
+ choices: PLATFORM_OPTIONS.map((opt) => ({
51
+ name: opt.value,
52
+ message: opt.label,
53
+ hint: opt.hint
54
+ }))
55
+ })).platforms;
56
+ } catch {
57
+ _clack_prompts.cancel("Operation cancelled.");
58
+ return;
59
+ }
57
60
  }
58
61
  if (!platform) {
59
62
  _clack_prompts.log.warn("No platform selected. Nothing to install.");
@@ -1 +1 @@
1
- {"version":3,"file":"initSkills.cjs","names":["PLATFORMS","PLATFORMS_METADATA","findProjectRoot","p","SKILLS","SKILLS_METADATA"],"sources":["../../src/initSkills.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n getInitialSkills,\n installSkills,\n PLATFORMS,\n PLATFORMS_METADATA,\n type Platform,\n SKILLS,\n SKILLS_METADATA,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { findProjectRoot } from './init';\n\nconst PLATFORM_CHECKS: Array<{ check: () => boolean; platform: Platform }> =\n PLATFORMS.filter((platform) => PLATFORMS_METADATA[platform]?.check).map(\n (platform) => ({\n check: PLATFORMS_METADATA[platform]?.check ?? (() => false),\n platform,\n })\n );\n\nexport const PLATFORM_OPTIONS: Array<{\n value: Platform;\n label: string;\n hint: string;\n}> = PLATFORMS.map((platform) => ({\n value: platform,\n label: PLATFORMS_METADATA[platform]?.label ?? '',\n hint: `(${PLATFORMS_METADATA[platform]?.dir})`,\n}));\n\nexport const getDetectedPlatform = (): Platform | undefined =>\n PLATFORM_CHECKS.find(({ check }) => check())?.platform;\n\nconst getDependencies = (root: string): Record<string, string> => {\n try {\n const packageJsonPath = join(root, 'package.json');\n if (!existsSync(packageJsonPath)) return {};\n\n const { dependencies = {}, devDependencies = {} } = JSON.parse(\n readFileSync(packageJsonPath, 'utf-8')\n );\n return { ...dependencies, ...devDependencies };\n } catch {\n return {};\n }\n};\n\nexport const initSkills = async (projectRoot?: string) => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n p.intro('Initializing Intlayer skills');\n\n const detectedPlatform = getDetectedPlatform();\n\n let platform: Platform;\n try {\n const response = await enquirer.prompt<{ platforms: Platform }>({\n type: 'autocomplete',\n name: 'platforms',\n message: 'Which platforms 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 platform = response.platforms;\n } catch {\n p.cancel('Operation cancelled.');\n return;\n }\n\n if (!platform) {\n p.log.warn('No platform selected. Nothing to install.');\n return;\n }\n\n const dependencies = getDependencies(root);\n const initialValues = getInitialSkills(dependencies);\n\n const selectedSkills = await p.multiselect({\n message: 'Select the documentation skills to provide to your AI:',\n initialValues,\n options: SKILLS.map((skill) => ({\n value: skill,\n label: skill,\n hint: SKILLS_METADATA[skill],\n })),\n required: false,\n });\n\n if (\n p.isCancel(selectedSkills) ||\n !selectedSkills ||\n (selectedSkills as string[]).length === 0\n ) {\n p.cancel('Operation cancelled. No skills selected.');\n return;\n }\n\n const s = p.spinner();\n s.start('Installing skills...');\n\n try {\n const result = await installSkills(root, platform, selectedSkills);\n\n s.stop('Skills installed successfully');\n\n p.note(result, 'Success');\n } catch (error) {\n s.stop('Failed to install skills');\n p.log.error(error instanceof Error ? error.message : String(error));\n }\n\n p.outro('Intlayer skills initialization complete');\n};\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,kBACJA,iCAAU,QAAQ,aAAaC,0CAAmB,WAAW,MAAM,CAAC,KACjE,cAAc;CACb,OAAOA,0CAAmB,WAAW,gBAAgB;CACrD;CACD,EACF;AAEH,MAAa,mBAIRD,iCAAU,KAAK,cAAc;CAChC,OAAO;CACP,OAAOC,0CAAmB,WAAW,SAAS;CAC9C,MAAM,IAAIA,0CAAmB,WAAW,IAAI;CAC7C,EAAE;AAEH,MAAa,4BACX,gBAAgB,MAAM,EAAE,YAAY,OAAO,CAAC,EAAE;AAEhD,MAAM,mBAAmB,SAAyC;AAChE,KAAI;EACF,MAAM,sCAAuB,MAAM,eAAe;AAClD,MAAI,yBAAY,gBAAgB,CAAE,QAAO,EAAE;EAE3C,MAAM,EAAE,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,KAAK,gCAC1C,iBAAiB,QAAQ,CACvC;AACD,SAAO;GAAE,GAAG;GAAc,GAAG;GAAiB;SACxC;AACN,SAAO,EAAE;;;AAIb,MAAa,aAAa,OAAO,gBAAyB;CACxD,MAAM,OAAOC,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AAED,gBAAE,MAAM,+BAA+B;CAEvC,MAAM,mBAAmB,qBAAqB;CAE9C,IAAI;AACJ,KAAI;AAeF,cAAW,MAdY,iBAAS,OAAgC;GAC9D,MAAM;GACN,MAAM;GACN,SAAS;GACT,UAAU;GACV,SAAS,mBACLF,iCAAU,QAAQ,iBAAiB,GACnC;GACJ,SAAS,iBAAiB,KAAK,SAAS;IACtC,MAAM,IAAI;IACV,SAAS,IAAI;IACb,MAAM,IAAI;IACX,EAAE;GACJ,CAAC,EACkB;SACd;AACN,iBAAE,OAAO,uBAAuB;AAChC;;AAGF,KAAI,CAAC,UAAU;AACb,iBAAE,IAAI,KAAK,4CAA4C;AACvD;;CAIF,MAAM,6DADe,gBAAgB,KACc,CAAC;CAEpD,MAAM,iBAAiB,MAAMG,eAAE,YAAY;EACzC,SAAS;EACT;EACA,SAASC,8BAAO,KAAK,WAAW;GAC9B,OAAO;GACP,OAAO;GACP,MAAMC,uCAAgB;GACvB,EAAE;EACH,UAAU;EACX,CAAC;AAEF,KACEF,eAAE,SAAS,eAAe,IAC1B,CAAC,kBACA,eAA4B,WAAW,GACxC;AACA,iBAAE,OAAO,2CAA2C;AACpD;;CAGF,MAAM,IAAIA,eAAE,SAAS;AACrB,GAAE,MAAM,uBAAuB;AAE/B,KAAI;EACF,MAAM,SAAS,gDAAoB,MAAM,UAAU,eAAe;AAElE,IAAE,KAAK,gCAAgC;AAEvC,iBAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,2BAA2B;AAClC,iBAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,gBAAE,MAAM,0CAA0C"}
1
+ {"version":3,"file":"initSkills.cjs","names":["PLATFORMS","PLATFORMS_METADATA","findProjectRoot","p","SKILLS","SKILLS_METADATA"],"sources":["../../src/initSkills.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n getInitialSkills,\n installSkills,\n PLATFORMS,\n PLATFORMS_METADATA,\n type Platform,\n SKILLS,\n SKILLS_METADATA,\n} from '@intlayer/chokidar/cli';\nimport enquirer from 'enquirer';\nimport { findProjectRoot } from './init';\n\nconst PLATFORM_CHECKS: Array<{ check: () => boolean; platform: Platform }> =\n PLATFORMS.filter((platform) => PLATFORMS_METADATA[platform]?.check).map(\n (platform) => ({\n check: PLATFORMS_METADATA[platform]?.check ?? (() => false),\n platform,\n })\n );\n\nexport const PLATFORM_OPTIONS: Array<{\n value: Platform;\n label: string;\n hint: string;\n}> = PLATFORMS.map((platform) => ({\n value: platform,\n label: PLATFORMS_METADATA[platform]?.label ?? '',\n hint: `(${PLATFORMS_METADATA[platform]?.dir})`,\n}));\n\nexport const getDetectedPlatform = (): Platform | undefined =>\n PLATFORM_CHECKS.find(({ check }) => check())?.platform;\n\nconst getDependencies = (root: string): Record<string, string> => {\n try {\n const packageJsonPath = join(root, 'package.json');\n if (!existsSync(packageJsonPath)) return {};\n\n const { dependencies = {}, devDependencies = {} } = JSON.parse(\n readFileSync(packageJsonPath, 'utf-8')\n );\n return { ...dependencies, ...devDependencies };\n } catch {\n return {};\n }\n};\n\nexport const initSkills = async (\n projectRoot?: string,\n preselectedPlatform?: Platform\n) => {\n const root = findProjectRoot(\n projectRoot ? resolve(projectRoot) : process.cwd()\n );\n\n p.intro('Initializing Intlayer skills');\n\n let platform: Platform;\n\n if (preselectedPlatform) {\n platform = preselectedPlatform;\n } else {\n const detectedPlatform = getDetectedPlatform();\n\n try {\n const response = await enquirer.prompt<{ platforms: Platform }>({\n type: 'autocomplete',\n name: 'platforms',\n message: 'Which platforms 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 platform = response.platforms;\n } catch {\n p.cancel('Operation cancelled.');\n return;\n }\n }\n\n if (!platform) {\n p.log.warn('No platform selected. Nothing to install.');\n return;\n }\n\n const dependencies = getDependencies(root);\n const initialValues = getInitialSkills(dependencies);\n\n const selectedSkills = await p.multiselect({\n message: 'Select the documentation skills to provide to your AI:',\n initialValues,\n options: SKILLS.map((skill) => ({\n value: skill,\n label: skill,\n hint: SKILLS_METADATA[skill],\n })),\n required: false,\n });\n\n if (\n p.isCancel(selectedSkills) ||\n !selectedSkills ||\n (selectedSkills as string[]).length === 0\n ) {\n p.cancel('Operation cancelled. No skills selected.');\n return;\n }\n\n const s = p.spinner();\n s.start('Installing skills...');\n\n try {\n const result = await installSkills(root, platform, selectedSkills);\n\n s.stop('Skills installed successfully');\n\n p.note(result, 'Success');\n } catch (error) {\n s.stop('Failed to install skills');\n p.log.error(error instanceof Error ? error.message : String(error));\n }\n\n p.outro('Intlayer skills initialization complete');\n};\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,kBACJA,iCAAU,QAAQ,aAAaC,0CAAmB,WAAW,MAAM,CAAC,KACjE,cAAc;CACb,OAAOA,0CAAmB,WAAW,gBAAgB;CACrD;CACD,EACF;AAEH,MAAa,mBAIRD,iCAAU,KAAK,cAAc;CAChC,OAAO;CACP,OAAOC,0CAAmB,WAAW,SAAS;CAC9C,MAAM,IAAIA,0CAAmB,WAAW,IAAI;CAC7C,EAAE;AAEH,MAAa,4BACX,gBAAgB,MAAM,EAAE,YAAY,OAAO,CAAC,EAAE;AAEhD,MAAM,mBAAmB,SAAyC;AAChE,KAAI;EACF,MAAM,sCAAuB,MAAM,eAAe;AAClD,MAAI,yBAAY,gBAAgB,CAAE,QAAO,EAAE;EAE3C,MAAM,EAAE,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,KAAK,gCAC1C,iBAAiB,QAAQ,CACvC;AACD,SAAO;GAAE,GAAG;GAAc,GAAG;GAAiB;SACxC;AACN,SAAO,EAAE;;;AAIb,MAAa,aAAa,OACxB,aACA,wBACG;CACH,MAAM,OAAOC,6BACX,qCAAsB,YAAY,GAAG,QAAQ,KAAK,CACnD;AAED,gBAAE,MAAM,+BAA+B;CAEvC,IAAI;AAEJ,KAAI,oBACF,YAAW;MACN;EACL,MAAM,mBAAmB,qBAAqB;AAE9C,MAAI;AAeF,eAAW,MAdY,iBAAS,OAAgC;IAC9D,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,SAAS,mBACLF,iCAAU,QAAQ,iBAAiB,GACnC;IACJ,SAAS,iBAAiB,KAAK,SAAS;KACtC,MAAM,IAAI;KACV,SAAS,IAAI;KACb,MAAM,IAAI;KACX,EAAE;IACJ,CAAC,EACkB;UACd;AACN,kBAAE,OAAO,uBAAuB;AAChC;;;AAIJ,KAAI,CAAC,UAAU;AACb,iBAAE,IAAI,KAAK,4CAA4C;AACvD;;CAIF,MAAM,6DADe,gBAAgB,KACc,CAAC;CAEpD,MAAM,iBAAiB,MAAMG,eAAE,YAAY;EACzC,SAAS;EACT;EACA,SAASC,8BAAO,KAAK,WAAW;GAC9B,OAAO;GACP,OAAO;GACP,MAAMC,uCAAgB;GACvB,EAAE;EACH,UAAU;EACX,CAAC;AAEF,KACEF,eAAE,SAAS,eAAe,IAC1B,CAAC,kBACA,eAA4B,WAAW,GACxC;AACA,iBAAE,OAAO,2CAA2C;AACpD;;CAGF,MAAM,IAAIA,eAAE,SAAS;AACrB,GAAE,MAAM,uBAAuB;AAE/B,KAAI;EACF,MAAM,SAAS,gDAAoB,MAAM,UAAU,eAAe;AAElE,IAAE,KAAK,gCAAgC;AAEvC,iBAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,2BAA2B;AAClC,iBAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,gBAAE,MAAM,0CAA0C"}
@@ -11,8 +11,8 @@ let _intlayer_config_colors = require("@intlayer/config/colors");
11
11
  _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
12
12
  let _intlayer_config_logger = require("@intlayer/config/logger");
13
13
  let _intlayer_config_node = require("@intlayer/config/node");
14
- let _intlayer_config_utils = require("@intlayer/config/utils");
15
14
  let node_fs_promises = require("node:fs/promises");
15
+ let _intlayer_config_utils = require("@intlayer/config/utils");
16
16
  let _intlayer_chokidar_docReview = require("@intlayer/chokidar/docReview");
17
17
  let _intlayer_core_localization = require("@intlayer/core/localization");
18
18
  let _intlayer_types_locales = require("@intlayer/types/locales");
@@ -10,8 +10,8 @@ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
10
10
  let _intlayer_config_colors = require("@intlayer/config/colors");
11
11
  _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
12
12
  let _intlayer_config_logger = require("@intlayer/config/logger");
13
- let _intlayer_config_utils = require("@intlayer/config/utils");
14
13
  let node_fs_promises = require("node:fs/promises");
14
+ let _intlayer_config_utils = require("@intlayer/config/utils");
15
15
  let node_perf_hooks = require("node:perf_hooks");
16
16
 
17
17
  //#region src/translateDoc/translateFile.ts
@@ -96,39 +96,52 @@ const login = async (options = {}) => {
96
96
  return;
97
97
  }
98
98
  if (clientId && clientSecret) {
99
- logger("");
100
- logger("Log in successful. Client ID and Client Secret received.");
101
- logger("");
102
- logger([
103
- "1. Insert the Client ID and Client Secret in your",
104
- colorizePath(".env"),
105
- "file:"
106
- ]);
107
- logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
108
- logger([colorize("INTLAYER_CLIENT_ID=", ANSIColors.GREY_LIGHT), colorize(clientId, ANSIColors.BLUE)].join(""));
109
- logger([colorize("INTLAYER_CLIENT_SECRET=", ANSIColors.GREY_LIGHT), colorize(clientSecret, ANSIColors.BLUE)].join(""));
110
- logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
111
- logger("");
112
- logger("2. Insert in your Intlayer configuration file:");
113
- logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
114
- [
115
- `${ANSIColors.GREY_LIGHT}{`,
116
- ` editor: {`,
117
- ` enabled: true,`,
118
- ` cmsURL: '${colorizePath(cmsUrl, void 0, ANSIColors.GREY_LIGHT)}',`,
119
- ` clientId: '${colorize("process.env.INTLAYER_CLIENT_ID", ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,
120
- ` clientSecret: '${colorize("process.env.INTLAYER_CLIENT_SECRET", ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,
121
- ` },`,
122
- `}`
123
- ].forEach((line) => {
124
- logger(line);
125
- });
126
- logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
99
+ if (options.onCredentials) {
100
+ logger("");
101
+ logger("Log in successful. Configuring Intlayer CMS...");
102
+ try {
103
+ await options.onCredentials({
104
+ clientId,
105
+ clientSecret
106
+ });
107
+ } catch (error) {
108
+ logger(`Failed to persist the CMS credentials automatically: ${error instanceof Error ? error.message : String(error)}`, { level: "error" });
109
+ }
110
+ } else {
111
+ logger("");
112
+ logger("Log in successful. Client ID and Client Secret received.");
113
+ logger("");
114
+ logger([
115
+ "1. Insert the Client ID and Client Secret in your",
116
+ colorizePath(".env"),
117
+ "file:"
118
+ ]);
119
+ logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
120
+ logger([colorize("INTLAYER_CLIENT_ID=", ANSIColors.GREY_LIGHT), colorize(clientId, ANSIColors.BLUE)].join(""));
121
+ logger([colorize("INTLAYER_CLIENT_SECRET=", ANSIColors.GREY_LIGHT), colorize(clientSecret, ANSIColors.BLUE)].join(""));
122
+ logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
123
+ logger("");
124
+ logger("2. Insert in your Intlayer configuration file:");
125
+ logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
126
+ [
127
+ `${ANSIColors.GREY_LIGHT}{`,
128
+ ` editor: {`,
129
+ ` enabled: true,`,
130
+ ` cmsURL: '${colorizePath(cmsUrl, void 0, ANSIColors.GREY_LIGHT)}',`,
131
+ ` clientId: '${colorize("process.env.INTLAYER_CLIENT_ID", ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,
132
+ ` clientSecret: '${colorize("process.env.INTLAYER_CLIENT_SECRET", ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,
133
+ ` },`,
134
+ `}`
135
+ ].forEach((line) => {
136
+ logger(line);
137
+ });
138
+ logger(colorize("--------------------------------", ANSIColors.GREY_DARK));
139
+ }
127
140
  res.writeHead(200, { "Content-Type": "text/html" });
128
141
  res.end(buildSuccessHtml("You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal."));
129
142
  server.close(() => {
130
143
  resolve();
131
- process.exit(0);
144
+ if (options.exitAfter !== false) process.exit(0);
132
145
  });
133
146
  } else {
134
147
  res.writeHead(400, { "Content-Type": "text/plain" });
@@ -1 +1 @@
1
- {"version":3,"file":"login.mjs","names":[],"sources":["../../../src/auth/login.ts"],"sourcesContent":["import http from 'node:http';\nimport { URL } from 'node:url';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { openBrowser } from '../utils/openBrowser';\nimport { writeCliSessionToken } from './sessionToken';\n\nconst buildSuccessHtml = (message: string): string => `\n <!DOCTYPE html>\n <html lang=\"en\" data-theme=\"dark\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Intlayer CLI Login</title>\n <style>\n :root {\n --color-background: rgba(23, 23, 23);\n --color-card: rgba(39, 39, 39);\n --color-text: rgba(255, 245, 237);\n --color-neutral: rgba(93, 93, 93);\n --font-sans: \"Inter\", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n }\n * { box-sizing: border-box; }\n body {\n font-family: var(--font-sans);\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n margin: 0;\n padding: 1rem;\n background-color: var(--color-background);\n color: var(--color-text);\n }\n .container {\n text-align: center;\n padding: 2rem;\n border-radius: 1rem;\n background-color: var(--color-card);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 400px;\n width: 100%;\n }\n h1 { margin: 0 0 1rem 0; font-size: 1.5rem; font-weight: 700; color: var(--color-text); }\n p { color: var(--color-neutral); font-size: 0.8rem; margin: 0 0 1.5rem 0; line-height: 1.5; }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <h1>Login Successful</h1>\n <p>${message}</p>\n </div>\n <script>\n window.close();\n setTimeout(() => { window.close(); }, 1000);\n </script>\n </body>\n </html>\n`;\n\ntype LoginOptions = {\n cmsUrl?: string;\n configOptions?: GetConfigurationOptions;\n /**\n * When false, do not call process.exit(0) after a successful session-token\n * login so the caller can continue (e.g. retry a command inline).\n * Defaults to true to preserve existing standalone-login behaviour.\n * Access-key login always exits because the user must configure .env first.\n */\n exitAfter?: boolean;\n};\n\nexport const login = async (options: LoginOptions = {}) => {\n const configuration = getConfiguration(options.configOptions);\n logConfigDetails(options?.configOptions);\n\n const logger = getAppLogger(configuration);\n\n const cmsUrl = options.cmsUrl ?? configuration.editor.cmsURL;\n\n return new Promise<void>((resolve) => {\n const server = http.createServer(async (req, res) => {\n const url = new URL(req.url ?? '', `http://${req.headers.host}`);\n\n // Set CORS headers\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204);\n res.end();\n return;\n }\n\n if (url.pathname === '/callback') {\n const sessionToken = url.searchParams.get('sessionToken');\n const sessionExpiresAt = url.searchParams.get('expiresAt');\n const clientId = url.searchParams.get('clientId');\n const clientSecret = url.searchParams.get('clientSecret');\n\n if (sessionToken && sessionExpiresAt) {\n logger('');\n logger(\n `Log in successful. ${colorize('2h', ANSIColors.BLUE)} session token received.`\n );\n logger('');\n\n logger(\n colorize(\n `Token expires at: ${new Date(sessionExpiresAt).toLocaleString()}`,\n ANSIColors.GREY\n )\n );\n\n await writeCliSessionToken(\n configuration,\n sessionToken,\n new Date(sessionExpiresAt)\n );\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n buildSuccessHtml(\n 'Your 2h session token has been stored. You can now close this tab and return to your terminal.'\n )\n );\n\n server.close(() => {\n resolve();\n if (options.exitAfter !== false) {\n process.exit(0);\n }\n });\n return;\n }\n\n if (clientId && clientSecret) {\n logger('');\n logger('Log in successful. Client ID and Client Secret received.');\n\n logger('');\n logger([\n '1. Insert the Client ID and Client Secret in your',\n colorizePath('.env'),\n 'file:',\n ]);\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_ID=', ANSIColors.GREY_LIGHT),\n colorize(clientId, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_SECRET=', ANSIColors.GREY_LIGHT),\n colorize(clientSecret, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger('');\n logger('2. Insert in your Intlayer configuration file:');\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n [\n `${ANSIColors.GREY_LIGHT}{`,\n ` editor: {`,\n ` enabled: true,`,\n ` cmsURL: '${colorizePath(cmsUrl!, undefined, ANSIColors.GREY_LIGHT)}',`,\n ` clientId: '${colorize('process.env.INTLAYER_CLIENT_ID', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` clientSecret: '${colorize('process.env.INTLAYER_CLIENT_SECRET', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` },`,\n `}`,\n ].forEach((line) => {\n logger(line);\n });\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n buildSuccessHtml(\n 'You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal.'\n )\n );\n\n server.close(() => {\n resolve();\n process.exit(0);\n });\n } else {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end('Missing parameters');\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n });\n\n server.listen(0, () => {\n const address = server.address();\n const port = typeof address === 'object' && address ? address.port : 0;\n const state = Math.random().toString(36).substring(7);\n\n const websiteUrl =\n cmsUrl ?? process.env.INTLAYER_SITE_URL ?? 'http://localhost:3000';\n const backendUrl = configuration.editor.backendURL ?? '';\n const loginUrl = `${websiteUrl}/auth/cli-login?port=${port}&state=${state}&backendUrl=${encodeURIComponent(backendUrl)}`;\n\n logger('Opening browser for login...');\n logger(`If browser does not open, visit: ${colorizePath(loginUrl)}`);\n\n openBrowser(loginUrl);\n });\n });\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBAAoB,YAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA2CzC,QAAQ;;;;;;;;;AAsBrB,MAAa,QAAQ,OAAO,UAAwB,EAAE,KAAK;CACzD,MAAM,gBAAgB,iBAAiB,QAAQ,cAAc;AAC7D,kBAAiB,SAAS,cAAc;CAExC,MAAM,SAAS,aAAa,cAAc;CAE1C,MAAM,SAAS,QAAQ,UAAU,cAAc,OAAO;AAEtD,QAAO,IAAI,SAAe,YAAY;EACpC,MAAM,SAAS,KAAK,aAAa,OAAO,KAAK,QAAQ;GACnD,MAAM,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,UAAU,IAAI,QAAQ,OAAO;AAGhE,OAAI,UAAU,+BAA+B,IAAI;AACjD,OAAI,UAAU,gCAAgC,eAAe;AAC7D,OAAI,UAAU,gCAAgC,eAAe;AAE7D,OAAI,IAAI,WAAW,WAAW;AAC5B,QAAI,UAAU,IAAI;AAClB,QAAI,KAAK;AACT;;AAGF,OAAI,IAAI,aAAa,aAAa;IAChC,MAAM,eAAe,IAAI,aAAa,IAAI,eAAe;IACzD,MAAM,mBAAmB,IAAI,aAAa,IAAI,YAAY;IAC1D,MAAM,WAAW,IAAI,aAAa,IAAI,WAAW;IACjD,MAAM,eAAe,IAAI,aAAa,IAAI,eAAe;AAEzD,QAAI,gBAAgB,kBAAkB;AACpC,YAAO,GAAG;AACV,YACE,sBAAsB,SAAS,MAAM,WAAW,KAAK,CAAC,0BACvD;AACD,YAAO,GAAG;AAEV,YACE,SACE,qBAAqB,IAAI,KAAK,iBAAiB,CAAC,gBAAgB,IAChE,WAAW,KACZ,CACF;AAED,WAAM,qBACJ,eACA,cACA,IAAI,KAAK,iBAAiB,CAC3B;AAED,SAAI,UAAU,KAAK,EAAE,gBAAgB,aAAa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AAY;;IAEtB;AAEF,SAAO,OAAO,SAAS;GACrB,MAAM,UAAU,OAAO,SAAS;GAChC,MAAM,OAAO,OAAO,YAAY,YAAY,UAAU,QAAQ,OAAO;GACrE,MAAM,QAAQ,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAE;GAErD,MAAM,aACJ,UAAU,QAAQ,IAAI,qBAAqB;GAC7C,MAAM,aAAa,cAAc,OAAO,cAAc;GACtD,MAAM,WAAW,GAAG,WAAW,uBAAuB,KAAK,SAAS,MAAM,cAAc,mBAAmB,WAAW;AAEtH,UAAO,+BAA+B;AACtC,UAAO,oCAAoC,aAAa,SAAS,GAAG;AAEpE,eAAY,SAAS;IACrB;GACF"}
1
+ {"version":3,"file":"login.mjs","names":[],"sources":["../../../src/auth/login.ts"],"sourcesContent":["import http from 'node:http';\nimport { URL } from 'node:url';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { openBrowser } from '../utils/openBrowser';\nimport { writeCliSessionToken } from './sessionToken';\n\nconst buildSuccessHtml = (message: string): string => `\n <!DOCTYPE html>\n <html lang=\"en\" data-theme=\"dark\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Intlayer CLI Login</title>\n <style>\n :root {\n --color-background: rgba(23, 23, 23);\n --color-card: rgba(39, 39, 39);\n --color-text: rgba(255, 245, 237);\n --color-neutral: rgba(93, 93, 93);\n --font-sans: \"Inter\", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n }\n * { box-sizing: border-box; }\n body {\n font-family: var(--font-sans);\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 100vh;\n margin: 0;\n padding: 1rem;\n background-color: var(--color-background);\n color: var(--color-text);\n }\n .container {\n text-align: center;\n padding: 2rem;\n border-radius: 1rem;\n background-color: var(--color-card);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 400px;\n width: 100%;\n }\n h1 { margin: 0 0 1rem 0; font-size: 1.5rem; font-weight: 700; color: var(--color-text); }\n p { color: var(--color-neutral); font-size: 0.8rem; margin: 0 0 1.5rem 0; line-height: 1.5; }\n </style>\n </head>\n <body>\n <div class=\"container\">\n <h1>Login Successful</h1>\n <p>${message}</p>\n </div>\n <script>\n window.close();\n setTimeout(() => { window.close(); }, 1000);\n </script>\n </body>\n </html>\n`;\n\ntype LoginOptions = {\n cmsUrl?: string;\n configOptions?: GetConfigurationOptions;\n /**\n * When false, do not call process.exit(0) after a successful login so the\n * caller can continue (e.g. retry a command inline, or finish an interactive\n * setup). Defaults to true to preserve existing standalone-login behaviour.\n */\n exitAfter?: boolean;\n /**\n * Invoked with the access-key credentials when the login flow returns a\n * `clientId` / `clientSecret` pair. When provided, the caller takes ownership\n * of persisting the credentials (e.g. writing them to `.env` and enabling the\n * editor in the config), so the default manual-setup instructions are skipped.\n */\n onCredentials?: (credentials: {\n clientId: string;\n clientSecret: string;\n }) => void | Promise<void>;\n};\n\nexport const login = async (options: LoginOptions = {}) => {\n const configuration = getConfiguration(options.configOptions);\n logConfigDetails(options?.configOptions);\n\n const logger = getAppLogger(configuration);\n\n const cmsUrl = options.cmsUrl ?? configuration.editor.cmsURL;\n\n return new Promise<void>((resolve) => {\n const server = http.createServer(async (req, res) => {\n const url = new URL(req.url ?? '', `http://${req.headers.host}`);\n\n // Set CORS headers\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (req.method === 'OPTIONS') {\n res.writeHead(204);\n res.end();\n return;\n }\n\n if (url.pathname === '/callback') {\n const sessionToken = url.searchParams.get('sessionToken');\n const sessionExpiresAt = url.searchParams.get('expiresAt');\n const clientId = url.searchParams.get('clientId');\n const clientSecret = url.searchParams.get('clientSecret');\n\n if (sessionToken && sessionExpiresAt) {\n logger('');\n logger(\n `Log in successful. ${colorize('2h', ANSIColors.BLUE)} session token received.`\n );\n logger('');\n\n logger(\n colorize(\n `Token expires at: ${new Date(sessionExpiresAt).toLocaleString()}`,\n ANSIColors.GREY\n )\n );\n\n await writeCliSessionToken(\n configuration,\n sessionToken,\n new Date(sessionExpiresAt)\n );\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n buildSuccessHtml(\n 'Your 2h session token has been stored. You can now close this tab and return to your terminal.'\n )\n );\n\n server.close(() => {\n resolve();\n if (options.exitAfter !== false) {\n process.exit(0);\n }\n });\n return;\n }\n\n if (clientId && clientSecret) {\n if (options.onCredentials) {\n // The caller persists the credentials itself (e.g. interactive\n // init writing `.env` and enabling the editor in the config).\n logger('');\n logger('Log in successful. Configuring Intlayer CMS...');\n\n try {\n await options.onCredentials({ clientId, clientSecret });\n } catch (error) {\n logger(\n `Failed to persist the CMS credentials automatically: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { level: 'error' }\n );\n }\n } else {\n logger('');\n logger('Log in successful. Client ID and Client Secret received.');\n\n logger('');\n logger([\n '1. Insert the Client ID and Client Secret in your',\n colorizePath('.env'),\n 'file:',\n ]);\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_ID=', ANSIColors.GREY_LIGHT),\n colorize(clientId, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n [\n colorize('INTLAYER_CLIENT_SECRET=', ANSIColors.GREY_LIGHT),\n colorize(clientSecret, ANSIColors.BLUE),\n ].join('')\n );\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n logger('');\n logger('2. Insert in your Intlayer configuration file:');\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n [\n `${ANSIColors.GREY_LIGHT}{`,\n ` editor: {`,\n ` enabled: true,`,\n ` cmsURL: '${colorizePath(cmsUrl!, undefined, ANSIColors.GREY_LIGHT)}',`,\n ` clientId: '${colorize('process.env.INTLAYER_CLIENT_ID', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` clientSecret: '${colorize('process.env.INTLAYER_CLIENT_SECRET', ANSIColors.BLUE, ANSIColors.GREY_LIGHT)}',`,\n ` },`,\n `}`,\n ].forEach((line) => {\n logger(line);\n });\n logger(\n colorize('--------------------------------', ANSIColors.GREY_DARK)\n );\n }\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n buildSuccessHtml(\n 'You have successfully logged in to Intlayer CLI. You can now close this tab and return to your terminal.'\n )\n );\n\n server.close(() => {\n resolve();\n if (options.exitAfter !== false) {\n process.exit(0);\n }\n });\n } else {\n res.writeHead(400, { 'Content-Type': 'text/plain' });\n res.end('Missing parameters');\n }\n } else {\n res.writeHead(404, { 'Content-Type': 'text/plain' });\n res.end('Not found');\n }\n });\n\n server.listen(0, () => {\n const address = server.address();\n const port = typeof address === 'object' && address ? address.port : 0;\n const state = Math.random().toString(36).substring(7);\n\n const websiteUrl =\n cmsUrl ?? process.env.INTLAYER_SITE_URL ?? 'http://localhost:3000';\n const backendUrl = configuration.editor.backendURL ?? '';\n const loginUrl = `${websiteUrl}/auth/cli-login?port=${port}&state=${state}&backendUrl=${encodeURIComponent(backendUrl)}`;\n\n logger('Opening browser for login...');\n logger(`If browser does not open, visit: ${colorizePath(loginUrl)}`);\n\n openBrowser(loginUrl);\n });\n });\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBAAoB,YAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA2CzC,QAAQ;;;;;;;;;AA+BrB,MAAa,QAAQ,OAAO,UAAwB,EAAE,KAAK;CACzD,MAAM,gBAAgB,iBAAiB,QAAQ,cAAc;AAC7D,kBAAiB,SAAS,cAAc;CAExC,MAAM,SAAS,aAAa,cAAc;CAE1C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