@intlayer/cli 9.5.12 → 9.7.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.
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
- package/dist/cjs/auth/login.cjs +11 -0
- package/dist/cjs/auth/login.cjs.map +1 -1
- package/dist/cjs/auth/setupRepository.cjs +95 -0
- package/dist/cjs/auth/setupRepository.cjs.map +1 -0
- package/dist/cjs/ci.cjs +1 -1
- package/dist/cjs/cli.cjs +59 -14
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/editor.cjs +61 -32
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/extract.cjs +1 -1
- package/dist/cjs/fill/fill.cjs +25 -9
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
- package/dist/cjs/getTargetDictionary.cjs +1 -1
- package/dist/cjs/index.cjs +29 -1
- package/dist/cjs/init.cjs +261 -36
- package/dist/cjs/init.cjs.map +1 -1
- package/dist/cjs/initChromeExtension.cjs +26 -3
- package/dist/cjs/initChromeExtension.cjs.map +1 -1
- package/dist/cjs/initInfra.cjs +6 -0
- package/dist/cjs/initInfra.cjs.map +1 -1
- package/dist/cjs/initMCP.cjs +18 -7
- package/dist/cjs/initMCP.cjs.map +1 -1
- package/dist/cjs/initSkills.cjs +37 -34
- package/dist/cjs/initSkills.cjs.map +1 -1
- package/dist/cjs/listContentDeclaration.cjs +1 -1
- package/dist/cjs/listProjects.cjs +1 -1
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +1 -1
- package/dist/cjs/push/push.cjs +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
- package/dist/cjs/translateDoc/translateDoc.cjs +1 -1
- package/dist/cjs/upgrade.cjs +1 -1
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/detectGitRepository.cjs +87 -0
- package/dist/cjs/utils/detectGitRepository.cjs.map +1 -0
- package/dist/cjs/utils/getParentPackageJSON.cjs +1 -1
- package/dist/cjs/utils/isInteractiveTerminal.cjs +12 -0
- package/dist/cjs/utils/isInteractiveTerminal.cjs.map +1 -0
- package/dist/cjs/utils/parseChoice.cjs +21 -0
- package/dist/cjs/utils/parseChoice.cjs.map +1 -0
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +1 -1
- package/dist/esm/auth/login.mjs +11 -0
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/auth/setupRepository.mjs +90 -0
- package/dist/esm/auth/setupRepository.mjs.map +1 -0
- package/dist/esm/ci.mjs +1 -1
- package/dist/esm/cli.mjs +59 -14
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/editor.mjs +62 -34
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/extract.mjs +1 -1
- package/dist/esm/fill/fill.mjs +25 -9
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/translateDictionary.mjs.map +1 -1
- package/dist/esm/getTargetDictionary.mjs +1 -1
- package/dist/esm/index.mjs +10 -5
- package/dist/esm/init.mjs +253 -38
- package/dist/esm/init.mjs.map +1 -1
- package/dist/esm/initChromeExtension.mjs +24 -4
- package/dist/esm/initChromeExtension.mjs.map +1 -1
- package/dist/esm/initInfra.mjs +6 -0
- package/dist/esm/initInfra.mjs.map +1 -1
- package/dist/esm/initMCP.mjs +21 -11
- package/dist/esm/initMCP.mjs.map +1 -1
- package/dist/esm/initSkills.mjs +37 -36
- package/dist/esm/initSkills.mjs.map +1 -1
- package/dist/esm/listContentDeclaration.mjs +1 -1
- package/dist/esm/listProjects.mjs +1 -1
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +1 -1
- package/dist/esm/push/push.mjs +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
- package/dist/esm/translateDoc/translateDoc.mjs +1 -1
- package/dist/esm/upgrade.mjs +1 -1
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/detectGitRepository.mjs +85 -0
- package/dist/esm/utils/detectGitRepository.mjs.map +1 -0
- package/dist/esm/utils/getParentPackageJSON.mjs +1 -1
- package/dist/esm/utils/isInteractiveTerminal.mjs +11 -0
- package/dist/esm/utils/isInteractiveTerminal.mjs.map +1 -0
- package/dist/esm/utils/parseChoice.mjs +20 -0
- package/dist/esm/utils/parseChoice.mjs.map +1 -0
- package/dist/types/IntlayerEventListener.d.ts +1 -1
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/auth/login.d.ts +5 -0
- package/dist/types/auth/login.d.ts.map +1 -1
- package/dist/types/auth/setupRepository.d.ts +25 -0
- package/dist/types/auth/setupRepository.d.ts.map +1 -0
- package/dist/types/editor.d.ts +10 -0
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +23 -2
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/index.d.ts +2 -2
- package/dist/types/fill/translateDictionary.d.ts +1 -2
- package/dist/types/fill/translateDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -6
- package/dist/types/init.d.ts +55 -2
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/initChromeExtension.d.ts +19 -1
- package/dist/types/initChromeExtension.d.ts.map +1 -1
- package/dist/types/initInfra.d.ts.map +1 -1
- package/dist/types/initMCP.d.ts +16 -2
- package/dist/types/initMCP.d.ts.map +1 -1
- package/dist/types/initSkills.d.ts +23 -6
- package/dist/types/initSkills.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -2
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
- package/dist/types/translateDoc/types.d.ts +1 -1
- package/dist/types/utils/checkAccess.d.ts +2 -1
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/utils/detectGitRepository.d.ts +34 -0
- package/dist/types/utils/detectGitRepository.d.ts.map +1 -0
- package/dist/types/utils/isInteractiveTerminal.d.ts +9 -0
- package/dist/types/utils/isInteractiveTerminal.d.ts.map +1 -0
- package/dist/types/utils/parseChoice.d.ts +13 -0
- package/dist/types/utils/parseChoice.d.ts.map +1 -0
- package/dist/types/utils/selectCmsEnvironment.d.ts +1 -1
- package/package.json +12 -12
package/dist/esm/init.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { login } from "./auth/login.mjs";
|
|
2
|
+
import { setupRepository } from "./auth/setupRepository.mjs";
|
|
2
3
|
import { loadPrompts } from "./loadPrompts.mjs";
|
|
4
|
+
import { isInteractiveTerminal } from "./utils/isInteractiveTerminal.mjs";
|
|
5
|
+
import { parseChoice } from "./utils/parseChoice.mjs";
|
|
3
6
|
import { initChromeExtension } from "./initChromeExtension.mjs";
|
|
4
7
|
import { initInfra } from "./initInfra.mjs";
|
|
5
8
|
import { initSkills } from "./initSkills.mjs";
|
|
9
|
+
import { detectGitRepository } from "./utils/detectGitRepository.mjs";
|
|
6
10
|
import { initMCP } from "./initMCP.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { detectCompatI18nLibraries, hasLintTooling, hasUrlRoutingFramework, initIntlayer, logInitSuccessMessage, setupCmsCredentials } from "@intlayer/engine/cli";
|
|
11
|
+
import { CATALOG_MESSAGE_FORMATS, CONTENT_FORMATS_BY_LAYOUT, detectCompatI18nLibraries, hasLintTooling, hasUrlRoutingFramework, initIntlayer, logInitSuccessMessage, setupCmsCredentials } from "@intlayer/engine/cli";
|
|
9
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { join, resolve } from "node:path";
|
|
10
14
|
|
|
11
15
|
//#region src/init.ts
|
|
12
16
|
const findProjectRoot = (startDir) => {
|
|
@@ -17,12 +21,94 @@ const findProjectRoot = (startDir) => {
|
|
|
17
21
|
}
|
|
18
22
|
return startDir;
|
|
19
23
|
};
|
|
24
|
+
/** Resolves the project root from `--project-root`, else the working directory. */
|
|
25
|
+
const resolveProjectRoot = (projectRoot) => findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
|
|
20
26
|
/**
|
|
21
27
|
* Steps shown but not pre-selected. The infrastructure installer touches the
|
|
22
28
|
* machine (downloads an app, pulls Docker images) and browser extensions open external URLs
|
|
23
29
|
* rather than modifying the project, so they must be an explicit choice.
|
|
24
30
|
*/
|
|
25
31
|
const OPT_IN_INIT_STEPS = ["infra", "chromeExtension"];
|
|
32
|
+
/**
|
|
33
|
+
* Steps run by `intlayer init` without `--interactive`: install the packages
|
|
34
|
+
* and set up the framework. Every other step has its own command
|
|
35
|
+
* ({@link INIT_STEP_COMMANDS}), so nothing outside the app code is touched
|
|
36
|
+
* unless asked for.
|
|
37
|
+
*/
|
|
38
|
+
const DEFAULT_INIT_STEPS = ["packages", "projectSetup"];
|
|
39
|
+
/**
|
|
40
|
+
* Command running each interactive step on its own, without prompts when every
|
|
41
|
+
* value is passed as a flag. Printed when `--interactive` has no terminal.
|
|
42
|
+
*/
|
|
43
|
+
const INIT_STEP_COMMANDS = {
|
|
44
|
+
packages: "intlayer init packages",
|
|
45
|
+
projectSetup: "intlayer init project [--routing <routing>] [--content <layout>] [--content-format <format>] [--message-format <format>]",
|
|
46
|
+
githubActions: "intlayer init github-actions",
|
|
47
|
+
vscodeExtension: "intlayer init vscode-extension",
|
|
48
|
+
eslint: "intlayer init eslint",
|
|
49
|
+
chromeExtension: "intlayer init extension [--browser <chrome|firefox>]",
|
|
50
|
+
skills: "intlayer init skills [--platform <platform>] [--skills <skills...>]",
|
|
51
|
+
mcp: "intlayer init mcp [--platform <platform>] [--transport <stdio|sse>]",
|
|
52
|
+
lsp: "intlayer init lsp",
|
|
53
|
+
cms: "intlayer init cms",
|
|
54
|
+
repository: "intlayer init repository",
|
|
55
|
+
infra: "intlayer init infra --mode <desktop|docker|compose>"
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Maps setup steps to the {@link initIntlayer} options: every step handled by
|
|
59
|
+
* `initIntlayer` that is not listed is skipped. Explicit `--no-*` flags in
|
|
60
|
+
* `baseOptions` still win over a listed step.
|
|
61
|
+
*/
|
|
62
|
+
const getInitOptionsForSteps = (steps, baseOptions) => ({
|
|
63
|
+
...baseOptions,
|
|
64
|
+
noInstallPackages: baseOptions?.noInstallPackages || !steps.includes("packages"),
|
|
65
|
+
noGitignore: baseOptions?.noGitignore || !steps.includes("projectSetup"),
|
|
66
|
+
noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
|
|
67
|
+
noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("projectSetup"),
|
|
68
|
+
noVscodeExtension: baseOptions?.noVscodeExtension || !steps.includes("vscodeExtension"),
|
|
69
|
+
noLsp: baseOptions?.noLsp || !steps.includes("lsp"),
|
|
70
|
+
noEslint: baseOptions?.noEslint || !steps.includes("eslint"),
|
|
71
|
+
skipFinalMessage: baseOptions?.skipFinalMessage || !steps.includes("projectSetup")
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Runs the given {@link initIntlayer} steps only (packages, project setup, CI,
|
|
75
|
+
* VS Code extension, LSP, lint rules). Backs `intlayer init` and its
|
|
76
|
+
* single-step subcommands.
|
|
77
|
+
*/
|
|
78
|
+
const initSteps = async (projectRoot, steps, options) => {
|
|
79
|
+
await initIntlayer(resolveProjectRoot(projectRoot), getInitOptionsForSteps(steps, options));
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Logs in to the Intlayer CMS through the browser, then stores the access-key
|
|
83
|
+
* credentials in `.env` and enables the editor in the config file.
|
|
84
|
+
*/
|
|
85
|
+
const initCms = async (projectRoot) => {
|
|
86
|
+
const root = resolveProjectRoot(projectRoot);
|
|
87
|
+
(await loadPrompts()).log.info("Opening your browser to log in to the Intlayer CMS...");
|
|
88
|
+
await login({
|
|
89
|
+
exitAfter: false,
|
|
90
|
+
onCredentials: (credentials) => setupCmsCredentials(root, credentials)
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Connects the git repository of the project to its CMS project (and sets
|
|
95
|
+
* its build settings) in the browser, pre-filled with the `origin` remote.
|
|
96
|
+
*/
|
|
97
|
+
const initRepository = async (projectRoot) => {
|
|
98
|
+
const root = resolveProjectRoot(projectRoot);
|
|
99
|
+
const p = await loadPrompts();
|
|
100
|
+
const detectedRepository = detectGitRepository(root);
|
|
101
|
+
p.log.info(detectedRepository ? `Detected repository: ${detectedRepository.provider} ${detectedRepository.owner}/${detectedRepository.repository}` : "No supported git remote detected: pick the repository in the browser.");
|
|
102
|
+
p.log.info("Opening your browser to connect the repository...");
|
|
103
|
+
await setupRepository({ detectedRepository });
|
|
104
|
+
};
|
|
105
|
+
/** Explains why `--interactive` cannot run, and what to run instead. */
|
|
106
|
+
const getNoTerminalMessage = () => [
|
|
107
|
+
"`intlayer init --interactive` needs a terminal to answer its prompts (none is attached, e.g. when run by an AI agent or in CI).",
|
|
108
|
+
"Run the steps directly instead:",
|
|
109
|
+
" intlayer init (installs the packages and sets up the framework)",
|
|
110
|
+
...Object.values(INIT_STEP_COMMANDS).map((command) => ` ${command}`)
|
|
111
|
+
].join("\n");
|
|
26
112
|
/** Grouped checkbox entries of the interactive init flow, in display order. */
|
|
27
113
|
const INIT_STEP_GROUPS = {
|
|
28
114
|
Codebase: [
|
|
@@ -76,15 +162,23 @@ const INIT_STEP_GROUPS = {
|
|
|
76
162
|
hint: "go-to-definition from keys to .content files"
|
|
77
163
|
}
|
|
78
164
|
],
|
|
79
|
-
CMS: [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
165
|
+
CMS: [
|
|
166
|
+
{
|
|
167
|
+
value: "cms",
|
|
168
|
+
label: "CMS",
|
|
169
|
+
hint: "log in through your browser, then store the credentials in your .env"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
value: "repository",
|
|
173
|
+
label: "Git repository",
|
|
174
|
+
hint: "connect the git repository to the CMS project and set its build settings (GitHub, GitLab, Bitbucket, Codeberg, Gitee)"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
value: "infra",
|
|
178
|
+
label: "Infrastructure (desktop app / self-hosting)",
|
|
179
|
+
hint: "install the desktop app, or self-host with Docker (all-in-one or Compose)"
|
|
180
|
+
}
|
|
181
|
+
]
|
|
88
182
|
};
|
|
89
183
|
/** Locale routing strategies offered by the interactive init flow. */
|
|
90
184
|
const ROUTING_OPTIONS = [
|
|
@@ -117,11 +211,7 @@ const ROUTING_OPTIONS = [
|
|
|
117
211
|
/** Locale routing choices accepted by `--routing`. */
|
|
118
212
|
const LOCALE_ROUTING_CHOICES = ROUTING_OPTIONS.map((option) => option.value);
|
|
119
213
|
/** 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
|
-
};
|
|
214
|
+
const parseLocaleRoutingChoice = (value) => parseChoice(value, LOCALE_ROUTING_CHOICES, "--routing");
|
|
125
215
|
/** Maps a routing choice to the init options it sets. */
|
|
126
216
|
const getRoutingInitOptions = (choice) => choice === "none" ? {
|
|
127
217
|
routingMode: "no-prefix",
|
|
@@ -130,6 +220,83 @@ const getRoutingInitOptions = (choice) => choice === "none" ? {
|
|
|
130
220
|
routingMode: choice,
|
|
131
221
|
enableProxy: true
|
|
132
222
|
};
|
|
223
|
+
/** Content declaration layouts offered by the interactive init flow. */
|
|
224
|
+
const CONTENT_LAYOUT_OPTIONS = [
|
|
225
|
+
{
|
|
226
|
+
value: "multilingual",
|
|
227
|
+
label: "Multilingual content declaration",
|
|
228
|
+
hint: "/**/{fileName}.content.{ts,json} — every locale in one file"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
value: "per-locale",
|
|
232
|
+
label: "Per-locale content declaration",
|
|
233
|
+
hint: "/**/{fileName}.{locale}.content.{ts,json}"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
value: "centralized",
|
|
237
|
+
label: "Centralized",
|
|
238
|
+
hint: "/locales/{locale}.{json,po}"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
value: "namespaces",
|
|
242
|
+
label: "Namespaces",
|
|
243
|
+
hint: "/locales/{locale}/{namespace}.{json,po}"
|
|
244
|
+
}
|
|
245
|
+
];
|
|
246
|
+
/** Labels of the content formats offered by the interactive init flow. */
|
|
247
|
+
const CONTENT_FORMAT_LABELS = {
|
|
248
|
+
ts: "TypeScript (.ts)",
|
|
249
|
+
json: "JSON (.json)",
|
|
250
|
+
po: "Gettext (.po)"
|
|
251
|
+
};
|
|
252
|
+
/** Labels of the JSON catalog message formats, in display order. */
|
|
253
|
+
const CATALOG_MESSAGE_FORMAT_OPTIONS = {
|
|
254
|
+
icu: {
|
|
255
|
+
label: "ICU",
|
|
256
|
+
hint: "{count, plural, one {# item} other {# items}}"
|
|
257
|
+
},
|
|
258
|
+
i18next: {
|
|
259
|
+
label: "i18next",
|
|
260
|
+
hint: "{{count}} item, key_one / key_other"
|
|
261
|
+
},
|
|
262
|
+
"vue-i18n": {
|
|
263
|
+
label: "vue-i18n",
|
|
264
|
+
hint: "{count} item | {count} items"
|
|
265
|
+
},
|
|
266
|
+
intlayer: {
|
|
267
|
+
label: "Intlayer",
|
|
268
|
+
hint: "Intlayer dictionary content"
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
/** Content layouts accepted by `--content`. */
|
|
272
|
+
const CONTENT_LAYOUT_CHOICES = CONTENT_LAYOUT_OPTIONS.map((option) => option.value);
|
|
273
|
+
/** Validates a `--content` value, throwing on an unknown layout. */
|
|
274
|
+
const parseContentLayoutChoice = (value) => parseChoice(value, CONTENT_LAYOUT_CHOICES, "--content");
|
|
275
|
+
/** Whether a layout + format pair produces a JSON catalog (sync plugin). */
|
|
276
|
+
const isJsonCatalog = (layout, format) => (layout === "centralized" || layout === "namespaces") && format === "json";
|
|
277
|
+
/**
|
|
278
|
+
* Validates `--content` / `--content-format` / `--message-format` and maps
|
|
279
|
+
* them to the init options. The format must be one the layout accepts, and the
|
|
280
|
+
* message format only applies to JSON catalogs.
|
|
281
|
+
*/
|
|
282
|
+
const getContentInitOptions = (layoutValue, formatValue, messageFormatValue) => {
|
|
283
|
+
if (!layoutValue) {
|
|
284
|
+
if (formatValue || messageFormatValue) throw new Error("--content-format and --message-format require --content.");
|
|
285
|
+
return {};
|
|
286
|
+
}
|
|
287
|
+
const contentLayout = parseContentLayoutChoice(layoutValue);
|
|
288
|
+
const contentFormat = formatValue ? parseChoice(formatValue, CONTENT_FORMATS_BY_LAYOUT[contentLayout], "--content-format") : void 0;
|
|
289
|
+
if (!messageFormatValue) return {
|
|
290
|
+
contentLayout,
|
|
291
|
+
contentFormat
|
|
292
|
+
};
|
|
293
|
+
if (!isJsonCatalog(contentLayout, contentFormat ?? "json")) throw new Error("--message-format only applies to JSON catalogs (--content centralized | namespaces with json).");
|
|
294
|
+
return {
|
|
295
|
+
contentLayout,
|
|
296
|
+
contentFormat,
|
|
297
|
+
contentMessageFormat: parseChoice(messageFormatValue, CATALOG_MESSAGE_FORMATS, "--message-format")
|
|
298
|
+
};
|
|
299
|
+
};
|
|
133
300
|
/** Known ESLint and oxlint configuration file names. */
|
|
134
301
|
const ESLINT_CONFIG_FILES = [
|
|
135
302
|
"eslint.config.js",
|
|
@@ -221,42 +388,90 @@ const runInteractiveInit = async (root, baseOptions) => {
|
|
|
221
388
|
}
|
|
222
389
|
routingOptions = getRoutingInitOptions(selectedRouting);
|
|
223
390
|
}
|
|
391
|
+
let contentOptions = {};
|
|
392
|
+
if (steps.includes("projectSetup") && baseOptions?.contentLayout === void 0 && !hasCompatLib) {
|
|
393
|
+
const contentLayout = await p.select({
|
|
394
|
+
message: "How do you want to declare your content?",
|
|
395
|
+
options: CONTENT_LAYOUT_OPTIONS,
|
|
396
|
+
initialValue: "multilingual"
|
|
397
|
+
});
|
|
398
|
+
if (p.isCancel(contentLayout)) {
|
|
399
|
+
p.cancel("Operation cancelled.");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const acceptedFormats = CONTENT_FORMATS_BY_LAYOUT[contentLayout];
|
|
403
|
+
const hasTypeScript = existsSync(join(root, "tsconfig.json"));
|
|
404
|
+
const contentFormat = await p.select({
|
|
405
|
+
message: "Which format for your content?",
|
|
406
|
+
options: acceptedFormats.map((format) => ({
|
|
407
|
+
value: format,
|
|
408
|
+
label: CONTENT_FORMAT_LABELS[format]
|
|
409
|
+
})),
|
|
410
|
+
initialValue: acceptedFormats.includes("ts") && !hasTypeScript ? "json" : acceptedFormats[0]
|
|
411
|
+
});
|
|
412
|
+
if (p.isCancel(contentFormat)) {
|
|
413
|
+
p.cancel("Operation cancelled.");
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
contentOptions = {
|
|
417
|
+
contentLayout,
|
|
418
|
+
contentFormat
|
|
419
|
+
};
|
|
420
|
+
if (isJsonCatalog(contentLayout, contentFormat)) {
|
|
421
|
+
const contentMessageFormat = await p.select({
|
|
422
|
+
message: "Which message format do your JSON catalogs use?",
|
|
423
|
+
options: CATALOG_MESSAGE_FORMATS.map((messageFormat) => ({
|
|
424
|
+
value: messageFormat,
|
|
425
|
+
...CATALOG_MESSAGE_FORMAT_OPTIONS[messageFormat]
|
|
426
|
+
})),
|
|
427
|
+
initialValue: CATALOG_MESSAGE_FORMATS[0]
|
|
428
|
+
});
|
|
429
|
+
if (p.isCancel(contentMessageFormat)) {
|
|
430
|
+
p.cancel("Operation cancelled.");
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
contentOptions = {
|
|
434
|
+
...contentOptions,
|
|
435
|
+
contentMessageFormat
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
224
439
|
const options = {
|
|
225
|
-
...
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("projectSetup"),
|
|
231
|
-
noVscodeExtension: !steps.includes("vscodeExtension"),
|
|
232
|
-
noLsp: !steps.includes("lsp"),
|
|
233
|
-
noEslint: !steps.includes("eslint"),
|
|
440
|
+
...getInitOptionsForSteps(steps, {
|
|
441
|
+
...baseOptions,
|
|
442
|
+
...routingOptions,
|
|
443
|
+
...contentOptions
|
|
444
|
+
}),
|
|
234
445
|
skipFinalMessage: true
|
|
235
446
|
};
|
|
236
447
|
const { guideUrl } = await initIntlayer(root, options);
|
|
237
448
|
const skillsPlatform = steps.includes("skills") ? await initSkills(root) : void 0;
|
|
238
|
-
if (steps.includes("mcp")) await initMCP(root, skillsPlatform);
|
|
449
|
+
if (steps.includes("mcp")) await initMCP(root, { platform: skillsPlatform });
|
|
239
450
|
if (steps.includes("infra")) await initInfra();
|
|
240
451
|
if (steps.includes("chromeExtension")) await initChromeExtension();
|
|
241
|
-
if (steps.includes("cms"))
|
|
242
|
-
|
|
243
|
-
await login({
|
|
244
|
-
exitAfter: false,
|
|
245
|
-
onCredentials: (credentials) => setupCmsCredentials(root, credentials)
|
|
246
|
-
});
|
|
247
|
-
}
|
|
452
|
+
if (steps.includes("cms")) await initCms(root);
|
|
453
|
+
if (steps.includes("repository")) await initRepository(root);
|
|
248
454
|
p.outro("Intlayer initialization complete");
|
|
249
455
|
if (guideUrl) logInitSuccessMessage(guideUrl);
|
|
250
456
|
};
|
|
457
|
+
/**
|
|
458
|
+
* `intlayer init`: installs the packages and sets up the framework, or, with
|
|
459
|
+
* `interactive`, lets the user pick every setup step. `--interactive` needs a
|
|
460
|
+
* terminal; without one it fails and lists the single-step commands instead.
|
|
461
|
+
*/
|
|
251
462
|
const init = async (projectRoot, options, interactive) => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
463
|
+
if (!interactive) {
|
|
464
|
+
await initSteps(projectRoot, DEFAULT_INIT_STEPS, options);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (!isInteractiveTerminal()) {
|
|
468
|
+
(await loadPrompts()).log.error(getNoTerminalMessage());
|
|
469
|
+
process.exitCode = 1;
|
|
255
470
|
return;
|
|
256
471
|
}
|
|
257
|
-
await
|
|
472
|
+
await runInteractiveInit(resolveProjectRoot(projectRoot), options);
|
|
258
473
|
};
|
|
259
474
|
|
|
260
475
|
//#endregion
|
|
261
|
-
export { ESLINT_CONFIG_FILES, INIT_STEP_GROUPS, LOCALE_ROUTING_CHOICES, OPT_IN_INIT_STEPS, findProjectRoot, getInitialInitSteps, getProjectDependencies, getRoutingInitOptions, init, isEslintInstalled, parseLocaleRoutingChoice };
|
|
476
|
+
export { CONTENT_LAYOUT_CHOICES, DEFAULT_INIT_STEPS, ESLINT_CONFIG_FILES, INIT_STEP_COMMANDS, INIT_STEP_GROUPS, LOCALE_ROUTING_CHOICES, OPT_IN_INIT_STEPS, findProjectRoot, getContentInitOptions, getInitOptionsForSteps, getInitialInitSteps, getProjectDependencies, getRoutingInitOptions, init, initCms, initRepository, initSteps, isEslintInstalled, parseContentLayoutChoice, parseLocaleRoutingChoice, resolveProjectRoot };
|
|
262
477
|
//# sourceMappingURL=init.mjs.map
|
package/dist/esm/init.mjs.map
CHANGED
|
@@ -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,O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7C,aAAa,aAAa,eAAe,CAAC,MAAM,SAAS,cAAc;EAGvE,iBACE,aAAa,mBAAmB,CAAC,MAAM,SAAS,eAAe;EACjE,kBACE,aAAa,oBAAoB,CAAC,MAAM,SAAS,cAAc;EACjE,mBAAmB,CAAC,MAAM,SAAS,iBAAiB;EACpD,OAAO,CAAC,MAAM,SAAS,KAAK;EAC5B,UAAU,CAAC,MAAM,SAAS,QAAQ;EAClC,kBAAkB;CACpB;CAEA,MAAM,EAAE,aAAa,MAAM,aAAa,MAAM,OAAO;CAGrD,MAAM,iBAAiB,MAAM,SAAS,QAAQ,IAC1C,MAAM,WAAW,IAAI,IACrB;CAEJ,IAAI,MAAM,SAAS,KAAK,GACtB,MAAM,QAAQ,MAAM,cAAc;CAIpC,IAAI,MAAM,SAAS,OAAO,GACxB,MAAM,UAAU;CAGlB,IAAI,MAAM,SAAS,iBAAiB,GAClC,MAAM,oBAAoB;CAM5B,IAAI,MAAM,SAAS,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 CATALOG_MESSAGE_FORMATS,\n type CatalogMessageFormat,\n CONTENT_FORMATS_BY_LAYOUT,\n type ContentFormat,\n type ContentLayout,\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 { setupRepository } from './auth/setupRepository';\nimport { initChromeExtension } from './initChromeExtension';\nimport { initInfra } from './initInfra';\nimport { initMCP } from './initMCP';\nimport { initSkills } from './initSkills';\nimport { loadPrompts } from './loadPrompts';\nimport { detectGitRepository } from './utils/detectGitRepository';\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 | 'repository'\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:\n 'intlayer init project [--routing <routing>] [--content <layout>] [--content-format <format>] [--message-format <format>]',\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 repository: 'intlayer init repository',\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/**\n * Connects the git repository of the project to its CMS project (and sets\n * its build settings) in the browser, pre-filled with the `origin` remote.\n */\nexport const initRepository = async (projectRoot?: string): Promise<void> => {\n const root = resolveProjectRoot(projectRoot);\n const p = await loadPrompts();\n const detectedRepository = detectGitRepository(root);\n\n p.log.info(\n detectedRepository\n ? `Detected repository: ${detectedRepository.provider} ${detectedRepository.owner}/${detectedRepository.repository}`\n : 'No supported git remote detected: pick the repository in the browser.'\n );\n p.log.info('Opening your browser to connect the repository...');\n\n await setupRepository({ detectedRepository });\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: 'repository',\n label: 'Git repository',\n hint: 'connect the git repository to the CMS project and set its build settings (GitHub, GitLab, Bitbucket, Codeberg, Gitee)',\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/** Content declaration layouts offered by the interactive init flow. */\nconst CONTENT_LAYOUT_OPTIONS: Array<{\n value: ContentLayout;\n label: string;\n hint: string;\n}> = [\n {\n value: 'multilingual',\n label: 'Multilingual content declaration',\n hint: '/**/{fileName}.content.{ts,json} — every locale in one file',\n },\n {\n value: 'per-locale',\n label: 'Per-locale content declaration',\n hint: '/**/{fileName}.{locale}.content.{ts,json}',\n },\n {\n value: 'centralized',\n label: 'Centralized',\n hint: '/locales/{locale}.{json,po}',\n },\n {\n value: 'namespaces',\n label: 'Namespaces',\n hint: '/locales/{locale}/{namespace}.{json,po}',\n },\n];\n\n/** Labels of the content formats offered by the interactive init flow. */\nconst CONTENT_FORMAT_LABELS: Record<ContentFormat, string> = {\n ts: 'TypeScript (.ts)',\n json: 'JSON (.json)',\n po: 'Gettext (.po)',\n};\n\n/** Labels of the JSON catalog message formats, in display order. */\nconst CATALOG_MESSAGE_FORMAT_OPTIONS: Record<\n CatalogMessageFormat,\n { label: string; hint: string }\n> = {\n icu: { label: 'ICU', hint: '{count, plural, one {# item} other {# items}}' },\n i18next: { label: 'i18next', hint: '{{count}} item, key_one / key_other' },\n 'vue-i18n': { label: 'vue-i18n', hint: '{count} item | {count} items' },\n intlayer: { label: 'Intlayer', hint: 'Intlayer dictionary content' },\n};\n\n/** Content layouts accepted by `--content`. */\nexport const CONTENT_LAYOUT_CHOICES = CONTENT_LAYOUT_OPTIONS.map(\n (option) => option.value\n);\n\n/** Validates a `--content` value, throwing on an unknown layout. */\nexport const parseContentLayoutChoice = (value: string): ContentLayout =>\n parseChoice(value, CONTENT_LAYOUT_CHOICES, '--content');\n\n/** Init options set by the content layout questions / flags. */\ntype ContentInitOptions = Pick<\n InitOptions,\n 'contentLayout' | 'contentFormat' | 'contentMessageFormat'\n>;\n\n/** Whether a layout + format pair produces a JSON catalog (sync plugin). */\nconst isJsonCatalog = (layout: ContentLayout, format: ContentFormat): boolean =>\n (layout === 'centralized' || layout === 'namespaces') && format === 'json';\n\n/**\n * Validates `--content` / `--content-format` / `--message-format` and maps\n * them to the init options. The format must be one the layout accepts, and the\n * message format only applies to JSON catalogs.\n */\nexport const getContentInitOptions = (\n layoutValue?: string,\n formatValue?: string,\n messageFormatValue?: string\n): ContentInitOptions => {\n if (!layoutValue) {\n if (formatValue || messageFormatValue) {\n throw new Error(\n '--content-format and --message-format require --content.'\n );\n }\n return {};\n }\n\n const contentLayout = parseContentLayoutChoice(layoutValue);\n const contentFormat = formatValue\n ? parseChoice(\n formatValue,\n CONTENT_FORMATS_BY_LAYOUT[contentLayout],\n '--content-format'\n )\n : undefined;\n\n if (!messageFormatValue) return { contentLayout, contentFormat };\n\n // Catalog layouts default to JSON.\n if (!isJsonCatalog(contentLayout, contentFormat ?? 'json')) {\n throw new Error(\n '--message-format only applies to JSON catalogs (--content centralized | namespaces with json).'\n );\n }\n\n return {\n contentLayout,\n contentFormat,\n contentMessageFormat: parseChoice(\n messageFormatValue,\n CATALOG_MESSAGE_FORMATS,\n '--message-format'\n ),\n };\n};\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 // Content layout → `compiler.output` (+ `dictionary.locale`) for `.content`\n // files, or the syncJSON / syncPO plugin for catalogs. Skipped for compat\n // i18n libraries, which keep their own catalogs.\n let contentOptions: ContentInitOptions = {};\n\n if (\n steps.includes('projectSetup') &&\n baseOptions?.contentLayout === undefined &&\n !hasCompatLib\n ) {\n const contentLayout = await p.select<ContentLayout>({\n message: 'How do you want to declare your content?',\n options: CONTENT_LAYOUT_OPTIONS,\n initialValue: 'multilingual',\n });\n\n if (p.isCancel(contentLayout)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n const acceptedFormats = CONTENT_FORMATS_BY_LAYOUT[contentLayout];\n const hasTypeScript = existsSync(join(root, 'tsconfig.json'));\n\n const contentFormat = await p.select<ContentFormat>({\n message: 'Which format for your content?',\n options: acceptedFormats.map((format) => ({\n value: format,\n label: CONTENT_FORMAT_LABELS[format],\n })),\n initialValue:\n acceptedFormats.includes('ts') && !hasTypeScript\n ? 'json'\n : acceptedFormats[0],\n });\n\n if (p.isCancel(contentFormat)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n contentOptions = { contentLayout, contentFormat };\n\n // JSON catalogs carry a message syntax (plurals, interpolation…).\n if (isJsonCatalog(contentLayout, contentFormat)) {\n const contentMessageFormat = await p.select<CatalogMessageFormat>({\n message: 'Which message format do your JSON catalogs use?',\n options: CATALOG_MESSAGE_FORMATS.map((messageFormat) => ({\n value: messageFormat,\n ...CATALOG_MESSAGE_FORMAT_OPTIONS[messageFormat],\n })),\n initialValue: CATALOG_MESSAGE_FORMATS[0],\n });\n\n if (p.isCancel(contentMessageFormat)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n contentOptions = { ...contentOptions, contentMessageFormat };\n }\n }\n\n const options: InitOptions = {\n ...getInitOptionsForSteps(steps, {\n ...baseOptions,\n ...routingOptions,\n ...contentOptions,\n }),\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 // After the CMS login, so the browser is already signed in\n if (steps.includes('repository')) {\n await initRepository(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 = 1;\n return;\n }\n\n await runInteractiveInit(resolveProjectRoot(projectRoot), options);\n};\n"],"mappings":";;;;;;;;;;;;;;;AA4BA,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;;AAGA,MAAa,sBAAsB,gBACjC,gBAAgB,cAAc,QAAQ,WAAW,IAAI,QAAQ,IAAI,CAAC;;;;;;AA6BpE,MAAa,oBAAgC,CAAC,SAAS,iBAAiB;;;;;;;AAQxE,MAAa,qBAAiC,CAAC,YAAY,cAAc;;;;;AAMzE,MAAa,qBAA+C;CAC1D,UAAU;CACV,cACE;CACF,eAAe;CACf,iBAAiB;CACjB,QAAQ;CACR,iBAAiB;CACjB,QAAQ;CACR,KAAK;CACL,KAAK;CACL,KAAK;CACL,YAAY;CACZ,OAAO;AACT;;;;;;AAOA,MAAa,0BACX,OACA,iBACiB;CACjB,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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;EACH;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;EACA;GACE,OAAO;GACP,OAAO;GACP,MAAM;EACR;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,WAEA,WAAW,SACP;CAAE,aAAa;CAAa,aAAa;AAAM,IAC/C;CAAE,aAAa;CAAQ,aAAa;AAAK;;AAG/C,MAAM,yBAID;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;AACF;;AAGA,MAAM,wBAAuD;CAC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ACpB;CAEA,MAAM,EAAE,aAAa,MAAM,aAAa,MAAM,OAAO;CAGrD,MAAM,iBAAiB,MAAM,SAAS,QAAQ,IAC1C,MAAM,WAAW,IAAI,IACrB;CAEJ,IAAI,MAAM,SAAS,KAAK,GACtB,MAAM,QAAQ,MAAM,EAAE,UAAU,eAAe,CAAC;CAIlD,IAAI,MAAM,SAAS,OAAO,GACxB,MAAM,UAAU;CAGlB,IAAI,MAAM,SAAS,iBAAiB,GAClC,MAAM,oBAAoB;CAM5B,IAAI,MAAM,SAAS,KAAK,GACtB,MAAM,QAAQ,IAAI;CAIpB,IAAI,MAAM,SAAS,YAAY,GAC7B,MAAM,eAAe,IAAI;CAG3B,EAAE,MAAM,kCAAkC;CAE1C,IAAI,UACF,sBAAsB,QAAQ;AAElC;;;;;;AAOA,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,IAAI,CAAC,aAAa;EAChB,MAAM,UAAU,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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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"}
|
package/dist/esm/initInfra.mjs
CHANGED
|
@@ -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":"
|
|
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;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;;;;;;;AAQ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