@intlayer/cli 9.0.0-canary.3 → 9.0.0-canary.5
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/auth/login.cjs +42 -29
- package/dist/cjs/auth/login.cjs.map +1 -1
- package/dist/cjs/cli.cjs +10 -6
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/init.cjs +192 -2
- package/dist/cjs/init.cjs.map +1 -1
- package/dist/cjs/initBuildOptimization.cjs +81 -0
- package/dist/cjs/initBuildOptimization.cjs.map +1 -0
- package/dist/cjs/initCompiler.cjs +116 -0
- package/dist/cjs/initCompiler.cjs.map +1 -0
- package/dist/cjs/initMCP.cjs +22 -19
- package/dist/cjs/initMCP.cjs.map +1 -1
- package/dist/cjs/initSkills.cjs +21 -18
- package/dist/cjs/initSkills.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
- package/dist/cjs/translateDoc/translateFile.cjs +1 -1
- package/dist/esm/auth/login.mjs +42 -29
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/cli.mjs +10 -6
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/init.mjs +192 -4
- package/dist/esm/init.mjs.map +1 -1
- package/dist/esm/initBuildOptimization.mjs +78 -0
- package/dist/esm/initBuildOptimization.mjs.map +1 -0
- package/dist/esm/initCompiler.mjs +113 -0
- package/dist/esm/initCompiler.mjs.map +1 -0
- package/dist/esm/initMCP.mjs +22 -19
- package/dist/esm/initMCP.mjs.map +1 -1
- package/dist/esm/initSkills.mjs +21 -18
- package/dist/esm/initSkills.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
- package/dist/esm/translateDoc/translateFile.mjs +1 -1
- package/dist/types/auth/login.d.ts +13 -4
- package/dist/types/auth/login.d.ts.map +1 -1
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/init.d.ts +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/initBuildOptimization.d.ts +20 -0
- package/dist/types/initBuildOptimization.d.ts.map +1 -0
- package/dist/types/initCompiler.d.ts +18 -0
- package/dist/types/initCompiler.d.ts.map +1 -0
- package/dist/types/initMCP.d.ts +3 -1
- package/dist/types/initMCP.d.ts.map +1 -1
- package/dist/types/initSkills.d.ts +1 -1
- package/dist/types/initSkills.d.ts.map +1 -1
- package/package.json +13 -13
package/dist/esm/init.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { login } from "./auth/login.mjs";
|
|
2
|
+
import { initBuildOptimization } from "./initBuildOptimization.mjs";
|
|
3
|
+
import { initCompiler } from "./initCompiler.mjs";
|
|
4
|
+
import { PLATFORM_OPTIONS, getDetectedPlatform, initSkills } from "./initSkills.mjs";
|
|
5
|
+
import { initMCP } from "./initMCP.mjs";
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
7
|
import { join, resolve } from "node:path";
|
|
3
|
-
import { initIntlayer } from "@intlayer/chokidar/cli";
|
|
8
|
+
import { PLATFORMS, initIntlayer, setupCmsCredentials } from "@intlayer/chokidar/cli";
|
|
9
|
+
import enquirer from "enquirer";
|
|
10
|
+
import * as p from "@clack/prompts";
|
|
4
11
|
|
|
5
12
|
//#region src/init.ts
|
|
6
13
|
const findProjectRoot = (startDir) => {
|
|
@@ -11,8 +18,189 @@ const findProjectRoot = (startDir) => {
|
|
|
11
18
|
}
|
|
12
19
|
return startDir;
|
|
13
20
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
21
|
+
const BASE_INIT_STEP_OPTIONS = [
|
|
22
|
+
{
|
|
23
|
+
value: "packages",
|
|
24
|
+
label: "Install & upgrade packages",
|
|
25
|
+
hint: "install missing Intlayer dependencies and upgrade outdated ones"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: "gitignore",
|
|
29
|
+
label: ".gitignore entry",
|
|
30
|
+
hint: "add .intlayer to .gitignore"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
value: "githubActions",
|
|
34
|
+
label: "CI/CD (GitHub Actions)",
|
|
35
|
+
hint: "scaffold the fill and test workflows that run on every pull request"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "frameworkSetup",
|
|
39
|
+
label: "Framework setup",
|
|
40
|
+
hint: "middleware/proxy and providers in layout/page"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: "vscodeExtension",
|
|
44
|
+
label: "VS Code extension",
|
|
45
|
+
hint: "recommend the Intlayer extension"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
value: "lsp",
|
|
49
|
+
label: "Editor LSP",
|
|
50
|
+
hint: "go-to-definition from keys to .content files"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
value: "skills",
|
|
54
|
+
label: "AI skills",
|
|
55
|
+
hint: "install the Intlayer documentation as agent skills"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: "mcp",
|
|
59
|
+
label: "MCP server",
|
|
60
|
+
hint: "configure the Intlayer MCP server"
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
/** Locale routing strategies offered by the interactive init flow. */
|
|
64
|
+
const ROUTING_MODE_OPTIONS = [
|
|
65
|
+
{
|
|
66
|
+
value: "prefix-no-default",
|
|
67
|
+
label: "Prefix all except the default locale",
|
|
68
|
+
hint: "/about, /fr/about (default)"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
value: "prefix-all",
|
|
72
|
+
label: "Prefix all locales",
|
|
73
|
+
hint: "/en/about, /fr/about"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
value: "no-prefix",
|
|
77
|
+
label: "No locale in the URL",
|
|
78
|
+
hint: "/about"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: "search-params",
|
|
82
|
+
label: "Use a search parameter",
|
|
83
|
+
hint: "/about?locale=fr"
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
/** Reads the merged dependencies of the project at `root`. */
|
|
87
|
+
const getProjectDependencies = (root) => {
|
|
88
|
+
try {
|
|
89
|
+
const packageJsonPath = join(root, "package.json");
|
|
90
|
+
if (!existsSync(packageJsonPath)) return {};
|
|
91
|
+
const { dependencies = {}, devDependencies = {} } = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
92
|
+
return {
|
|
93
|
+
...dependencies,
|
|
94
|
+
...devDependencies
|
|
95
|
+
};
|
|
96
|
+
} catch {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/** Returns true when the project at `root` depends on Next.js. */
|
|
101
|
+
const isNextJsProject = (root) => Boolean(getProjectDependencies(root).next);
|
|
102
|
+
/** Returns true when the project at `root` depends on Vite. */
|
|
103
|
+
const isViteProject = (root) => Boolean(getProjectDependencies(root).vite);
|
|
104
|
+
/**
|
|
105
|
+
* Runs `init` in interactive mode: prompts the user with a checkbox of setup
|
|
106
|
+
* steps, then forwards the selection to {@link initIntlayer} (packages,
|
|
107
|
+
* .gitignore, GitHub Actions, VS Code extension, LSP) and runs the dedicated
|
|
108
|
+
* skills/MCP installers for the steps that own their own prompts.
|
|
109
|
+
*/
|
|
110
|
+
const runInteractiveInit = async (root, baseOptions) => {
|
|
111
|
+
p.intro("Initialize Intlayer");
|
|
112
|
+
const stepOptions = [...BASE_INIT_STEP_OPTIONS];
|
|
113
|
+
const nextJsProject = isNextJsProject(root);
|
|
114
|
+
if (nextJsProject || isViteProject(root)) stepOptions.push({
|
|
115
|
+
value: "compiler",
|
|
116
|
+
label: "Compiler",
|
|
117
|
+
hint: nextJsProject ? "add the Babel compiler config to extract inline content (Next.js)" : "auto-extract inline content at build time (already plugged in on Vite)"
|
|
118
|
+
});
|
|
119
|
+
if (nextJsProject) stepOptions.push({
|
|
120
|
+
value: "buildOptimization",
|
|
121
|
+
label: "Bundle optimization",
|
|
122
|
+
hint: "choose @intlayer/babel or @intlayer/swc for tree-shaking and minification (Next.js only)"
|
|
123
|
+
});
|
|
124
|
+
const selected = await p.multiselect({
|
|
125
|
+
message: "Select what you want to set up:",
|
|
126
|
+
options: stepOptions,
|
|
127
|
+
initialValues: BASE_INIT_STEP_OPTIONS.map((option) => option.value),
|
|
128
|
+
required: false
|
|
129
|
+
});
|
|
130
|
+
if (p.isCancel(selected)) {
|
|
131
|
+
p.cancel("Operation cancelled.");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const steps = selected;
|
|
135
|
+
const routingMode = await p.select({
|
|
136
|
+
message: "Which locale routing strategy do you want?",
|
|
137
|
+
options: ROUTING_MODE_OPTIONS,
|
|
138
|
+
initialValue: "prefix-no-default"
|
|
139
|
+
});
|
|
140
|
+
if (p.isCancel(routingMode)) {
|
|
141
|
+
p.cancel("Operation cancelled.");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const shouldSetUpCms = await p.confirm({
|
|
145
|
+
message: "Set up the Intlayer CMS now? (opens your browser to log in, then stores the credentials in your .env)",
|
|
146
|
+
initialValue: false
|
|
147
|
+
});
|
|
148
|
+
if (p.isCancel(shouldSetUpCms)) {
|
|
149
|
+
p.cancel("Operation cancelled.");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
await initIntlayer(root, {
|
|
153
|
+
...baseOptions,
|
|
154
|
+
routingMode,
|
|
155
|
+
noInstallPackages: !steps.includes("packages"),
|
|
156
|
+
noGitignore: baseOptions?.noGitignore || !steps.includes("gitignore"),
|
|
157
|
+
noGithubActions: baseOptions?.noGithubActions || !steps.includes("githubActions"),
|
|
158
|
+
noFrameworkSetup: baseOptions?.noFrameworkSetup || !steps.includes("frameworkSetup"),
|
|
159
|
+
noVscodeExtension: !steps.includes("vscodeExtension"),
|
|
160
|
+
noLsp: !steps.includes("lsp")
|
|
161
|
+
});
|
|
162
|
+
const needsPlatform = steps.includes("skills") || steps.includes("mcp");
|
|
163
|
+
let sharedPlatform;
|
|
164
|
+
if (needsPlatform) {
|
|
165
|
+
const detectedPlatform = getDetectedPlatform();
|
|
166
|
+
try {
|
|
167
|
+
sharedPlatform = (await enquirer.prompt({
|
|
168
|
+
type: "autocomplete",
|
|
169
|
+
name: "platforms",
|
|
170
|
+
message: "Which platform are you using? (Type to search)",
|
|
171
|
+
multiple: false,
|
|
172
|
+
initial: detectedPlatform ? PLATFORMS.indexOf(detectedPlatform) : void 0,
|
|
173
|
+
choices: PLATFORM_OPTIONS.map((opt) => ({
|
|
174
|
+
name: opt.value,
|
|
175
|
+
message: opt.label,
|
|
176
|
+
hint: opt.hint
|
|
177
|
+
}))
|
|
178
|
+
})).platforms;
|
|
179
|
+
} catch {
|
|
180
|
+
p.cancel("Operation cancelled.");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (steps.includes("skills")) await initSkills(root, sharedPlatform);
|
|
185
|
+
if (steps.includes("mcp")) await initMCP(root, sharedPlatform);
|
|
186
|
+
if (steps.includes("compiler")) await initCompiler(root);
|
|
187
|
+
if (steps.includes("buildOptimization")) await initBuildOptimization(root);
|
|
188
|
+
if (shouldSetUpCms) {
|
|
189
|
+
p.log.info("Opening your browser to log in to the Intlayer CMS...");
|
|
190
|
+
await login({
|
|
191
|
+
exitAfter: false,
|
|
192
|
+
onCredentials: (credentials) => setupCmsCredentials(root, credentials)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
p.outro("Intlayer initialization complete");
|
|
196
|
+
};
|
|
197
|
+
const init = async (projectRoot, options, interactive) => {
|
|
198
|
+
const root = projectRoot ? findProjectRoot(resolve(projectRoot)) : findProjectRoot(process.cwd());
|
|
199
|
+
if (interactive) {
|
|
200
|
+
await runInteractiveInit(root, options);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
await initIntlayer(root, options);
|
|
16
204
|
};
|
|
17
205
|
|
|
18
206
|
//#endregion
|
package/dist/esm/init.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.mjs","names":[],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { type InitOptions, initIntlayer } from '@intlayer/chokidar/cli';\n\nexport const findProjectRoot = (startDir: string) => {\n let currentDir = startDir;\n\n while (currentDir !== resolve(currentDir, '..')) {\n if (existsSync(join(currentDir, 'package.json'))) {\n return currentDir;\n }\n currentDir = resolve(currentDir, '..');\n }\n\n // If no package.json is found, return the start directory.\n // The initIntlayer function will handle the missing package.json error.\n return startDir;\n};\n\nexport const init = async (projectRoot?: string, options?: InitOptions) => {\n const root = projectRoot\n ? findProjectRoot(resolve(projectRoot))\n : findProjectRoot(process.cwd());\n\n await initIntlayer(root, options);\n};\n"],"mappings":";;;;;AAIA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;AAEjB,QAAO,eAAe,QAAQ,YAAY,KAAK,EAAE;AAC/C,MAAI,WAAW,KAAK,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,eAAa,QAAQ,YAAY,KAAK;;AAKxC,QAAO;;AAGT,MAAa,OAAO,OAAO,aAAsB,YAA0B;AAKzE,OAAM,aAJO,cACT,gBAAgB,QAAQ,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC,EAET,QAAQ"}
|
|
1
|
+
{"version":3,"file":"init.mjs","names":[],"sources":["../../src/init.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport * as p from '@clack/prompts';\nimport {\n type 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 * 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 const routingMode = 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(routingMode)) {\n p.cancel('Operation cancelled.');\n return;\n }\n\n // CMS / visual editor: opt-in browser login that persists the access-key\n // credentials to `.env` and enables the editor in the config file.\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 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 if (shouldSetUpCms) {\n p.log.info('Opening your browser to log in to the Intlayer CMS...');\n // `exitAfter: false` keeps the process alive so the flow can finish; the\n // credentials are persisted to `.env` and the editor enabled in the config.\n await login({\n exitAfter: false,\n onCredentials: (credentials) => setupCmsCredentials(root, credentials),\n });\n }\n\n p.outro('Intlayer initialization complete');\n};\n\nexport const init = async (\n projectRoot?: string,\n options?: InitOptions,\n interactive?: boolean\n) => {\n const root = projectRoot\n ? findProjectRoot(resolve(projectRoot))\n : findProjectRoot(process.cwd());\n\n if (interactive) {\n await runInteractiveInit(root, options);\n return;\n }\n\n await initIntlayer(root, options);\n};\n"],"mappings":";;;;;;;;;;;;AAsBA,MAAa,mBAAmB,aAAqB;CACnD,IAAI,aAAa;AAEjB,QAAO,eAAe,QAAQ,YAAY,KAAK,EAAE;AAC/C,MAAI,WAAW,KAAK,YAAY,eAAe,CAAC,CAC9C,QAAO;AAET,eAAa,QAAQ,YAAY,KAAK;;AAKxC,QAAO;;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;CACD;EACE,OAAO;EACP,OAAO;EACP,MAAM;EACP;CACD;EACE,OAAO;EACP,OAAO;EACP,MA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mC;;AAG7C,MAAa,OAAO,OAClB,aACA,SACA,gBACG;CACH,MAAM,OAAO,cACT,gBAAgB,QAAQ,YAAY,CAAC,GACrC,gBAAgB,QAAQ,KAAK,CAAC;AAElC,KAAI,aAAa;AACf,QAAM,mBAAmB,MAAM,QAAQ;AACvC;;AAGF,OAAM,aAAa,MAAM,QAAQ"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { findProjectRoot } from "./init.mjs";
|
|
2
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { NEXT_INTLAYER_BABEL_CONFIG_CONTENT, detectPackageManager, installPackages } from "@intlayer/chokidar/cli";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
|
|
7
|
+
//#region src/initBuildOptimization.ts
|
|
8
|
+
/** Babel config filenames Next.js picks up, ordered by preference. */
|
|
9
|
+
const BABEL_CONFIG_CANDIDATES = [
|
|
10
|
+
"babel.config.js",
|
|
11
|
+
"babel.config.cjs",
|
|
12
|
+
"babel.config.mjs",
|
|
13
|
+
"babel.config.ts"
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Interactive prompt to select a build optimization plugin for Next.js and
|
|
17
|
+
* scaffold the required files. The two options are independent — pick one:
|
|
18
|
+
*
|
|
19
|
+
* - `@intlayer/babel` — runs the full compiler pipeline (extract, purge, minify,
|
|
20
|
+
* optimize) through Babel. Installs `@intlayer/babel` and creates a
|
|
21
|
+
* `babel.config.js`.
|
|
22
|
+
* - `@intlayer/swc` — lightweight SWC plugin that rewrites `useIntlayer` imports.
|
|
23
|
+
* Installs only the dependency; `withIntlayer` wires it in automatically, so
|
|
24
|
+
* no config file is required.
|
|
25
|
+
*
|
|
26
|
+
* @param projectRoot - Optional project root; defaults to the current directory.
|
|
27
|
+
*/
|
|
28
|
+
const initBuildOptimization = async (projectRoot) => {
|
|
29
|
+
const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
|
|
30
|
+
p.intro("Configuring Next.js build optimization");
|
|
31
|
+
const plugin = await p.select({
|
|
32
|
+
message: "Which build optimization plugin do you want to use?",
|
|
33
|
+
options: [{
|
|
34
|
+
value: "babel",
|
|
35
|
+
label: "@intlayer/babel",
|
|
36
|
+
hint: "Full pipeline — extract, purge, minify and optimize via Babel; creates babel.config.js"
|
|
37
|
+
}, {
|
|
38
|
+
value: "swc",
|
|
39
|
+
label: "@intlayer/swc",
|
|
40
|
+
hint: "Lightweight — SWC plugin that rewrites useIntlayer imports; wired automatically by withIntlayer"
|
|
41
|
+
}]
|
|
42
|
+
});
|
|
43
|
+
if (p.isCancel(plugin) || !plugin) {
|
|
44
|
+
p.cancel("Operation cancelled.");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const packageManager = detectPackageManager(root);
|
|
48
|
+
const packageToInstall = plugin === "babel" ? "@intlayer/babel" : "@intlayer/swc";
|
|
49
|
+
const spinner = p.spinner();
|
|
50
|
+
spinner.start("Installing packages...");
|
|
51
|
+
try {
|
|
52
|
+
installPackages(root, [packageToInstall], packageManager, true);
|
|
53
|
+
spinner.stop(`Installed: ${packageToInstall}`);
|
|
54
|
+
} catch {
|
|
55
|
+
spinner.stop("Package installation failed");
|
|
56
|
+
p.log.warn(`Please install manually: ${packageToInstall} (dev dependency)`);
|
|
57
|
+
}
|
|
58
|
+
if (plugin === "swc") {
|
|
59
|
+
p.outro("Build optimization configuration complete");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const existingBabelConfig = BABEL_CONFIG_CANDIDATES.find((file) => existsSync(join(root, file)));
|
|
63
|
+
if (existingBabelConfig) {
|
|
64
|
+
p.log.warn(`${existingBabelConfig} already exists — add the Intlayer plugins manually.`);
|
|
65
|
+
p.note(NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "Plugins to add to your babel config");
|
|
66
|
+
} else try {
|
|
67
|
+
writeFileSync(join(root, "babel.config.js"), NEXT_INTLAYER_BABEL_CONFIG_CONTENT, { encoding: "utf-8" });
|
|
68
|
+
p.log.success("Created babel.config.js with the Intlayer compiler plugins (extract, purge, minify, optimize)");
|
|
69
|
+
} catch {
|
|
70
|
+
p.log.warn("Could not create babel.config.js — please create it manually.");
|
|
71
|
+
p.note(NEXT_INTLAYER_BABEL_CONFIG_CONTENT, "babel.config.js");
|
|
72
|
+
}
|
|
73
|
+
p.outro("Build optimization configuration complete");
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { initBuildOptimization };
|
|
78
|
+
//# sourceMappingURL=initBuildOptimization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initBuildOptimization.mjs","names":[],"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":";;;;;;;;AA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ProjectRoot } from "./init.mjs";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { detectPackageManager, installPackages } from "@intlayer/chokidar/cli";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
|
|
7
|
+
//#region src/initCompiler.ts
|
|
8
|
+
/**
|
|
9
|
+
* babel.config.js that runs the Intlayer compiler passes for Next.js.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the Next.js (Babel) tab of `docs/docs/en/compiler.md`: the extract
|
|
12
|
+
* plugin pulls inline content into dictionaries and the optimize plugin
|
|
13
|
+
* rewrites `useIntlayer` into direct dictionary imports. On Vite the same work
|
|
14
|
+
* is handled by the `intlayerCompiler()` plugin, so no Babel config is needed.
|
|
15
|
+
*/
|
|
16
|
+
const BABEL_COMPILER_CONFIG_CONTENT = `const {
|
|
17
|
+
intlayerExtractBabelPlugin,
|
|
18
|
+
intlayerOptimizeBabelPlugin,
|
|
19
|
+
getExtractPluginOptions,
|
|
20
|
+
getOptimizePluginOptions,
|
|
21
|
+
} = require("@intlayer/babel");
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
presets: ["next/babel"],
|
|
25
|
+
plugins: [
|
|
26
|
+
// Extract content from components into dictionaries
|
|
27
|
+
[intlayerExtractBabelPlugin, getExtractPluginOptions()],
|
|
28
|
+
// Optimize imports by replacing useIntlayer with direct dictionary imports
|
|
29
|
+
[intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
`;
|
|
33
|
+
/**
|
|
34
|
+
* Reads the project dependencies and detects which framework the compiler
|
|
35
|
+
* should target. Next.js is checked before Vite because a Next.js project may
|
|
36
|
+
* transitively depend on Vite tooling.
|
|
37
|
+
*/
|
|
38
|
+
const detectCompilerFramework = (root) => {
|
|
39
|
+
try {
|
|
40
|
+
const packageJsonPath = join(root, "package.json");
|
|
41
|
+
if (!existsSync(packageJsonPath)) return "unknown";
|
|
42
|
+
const { dependencies = {}, devDependencies = {} } = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
43
|
+
const allDependencies = {
|
|
44
|
+
...dependencies,
|
|
45
|
+
...devDependencies
|
|
46
|
+
};
|
|
47
|
+
if (allDependencies.next) return "nextjs";
|
|
48
|
+
if (allDependencies.vite) return "vite";
|
|
49
|
+
return "unknown";
|
|
50
|
+
} catch {
|
|
51
|
+
return "unknown";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Scaffolds the Intlayer compiler for the current project during interactive
|
|
56
|
+
* init.
|
|
57
|
+
*
|
|
58
|
+
* - **Vite** — nothing to do: the compiler is plugged in directly through the
|
|
59
|
+
* `intlayerCompiler()` plugin in `vite.config.ts`, so this only confirms the
|
|
60
|
+
* setup to the user.
|
|
61
|
+
* - **Next.js** — installs `@intlayer/babel` and writes a `babel.config.js`
|
|
62
|
+
* that runs the extract + optimize compiler passes.
|
|
63
|
+
*
|
|
64
|
+
* In non-interactive init this function is never called, so the compiler setup
|
|
65
|
+
* is left untouched.
|
|
66
|
+
*/
|
|
67
|
+
const initCompiler = async (projectRoot) => {
|
|
68
|
+
const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
|
|
69
|
+
const framework = detectCompilerFramework(root);
|
|
70
|
+
if (framework === "vite") {
|
|
71
|
+
p.log.info("Vite detected — the compiler is plugged in directly through `intlayerCompiler()` in your vite.config. Nothing to configure.");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (framework !== "nextjs") {
|
|
75
|
+
p.log.warn("No supported framework detected for the compiler — skipping. See the compiler docs for manual setup.");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
p.intro("Configuring the Intlayer compiler for Next.js");
|
|
79
|
+
const packageManager = detectPackageManager(root);
|
|
80
|
+
const devPackagesToInstall = ["@intlayer/babel"];
|
|
81
|
+
const spinner = p.spinner();
|
|
82
|
+
spinner.start("Installing packages...");
|
|
83
|
+
try {
|
|
84
|
+
installPackages(root, devPackagesToInstall, packageManager, true);
|
|
85
|
+
spinner.stop(`Installed: ${devPackagesToInstall.join(", ")}`);
|
|
86
|
+
} catch {
|
|
87
|
+
spinner.stop("Package installation failed");
|
|
88
|
+
p.log.warn(`Please install manually: ${devPackagesToInstall.join(" ")} (dev dependency)`);
|
|
89
|
+
}
|
|
90
|
+
const existingBabelConfig = [
|
|
91
|
+
"babel.config.js",
|
|
92
|
+
"babel.config.cjs",
|
|
93
|
+
"babel.config.mjs",
|
|
94
|
+
"babel.config.ts",
|
|
95
|
+
".babelrc",
|
|
96
|
+
".babelrc.js"
|
|
97
|
+
].find((file) => existsSync(join(root, file)));
|
|
98
|
+
if (existingBabelConfig) {
|
|
99
|
+
p.log.warn(`${existingBabelConfig} already exists — add the Intlayer compiler plugins manually.`);
|
|
100
|
+
p.note(BABEL_COMPILER_CONFIG_CONTENT, "Plugins to add to your babel config");
|
|
101
|
+
} else try {
|
|
102
|
+
writeFileSync(join(root, "babel.config.js"), BABEL_COMPILER_CONFIG_CONTENT, { encoding: "utf-8" });
|
|
103
|
+
p.log.success("Created babel.config.js with the Intlayer compiler extract and optimize plugins");
|
|
104
|
+
} catch {
|
|
105
|
+
p.log.warn("Could not create babel.config.js — please create it manually.");
|
|
106
|
+
p.note(BABEL_COMPILER_CONFIG_CONTENT, "babel.config.js");
|
|
107
|
+
}
|
|
108
|
+
p.outro("Compiler configuration complete");
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { initCompiler };
|
|
113
|
+
//# sourceMappingURL=initCompiler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initCompiler.mjs","names":[],"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":";;;;;;;;;;;;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DACxB;AACD,IAAE,KACA,+BACA,sCACD;OAED,KAAI;AACF,gBACE,KAAK,MAAM,kBAAkB,EAC7B,+BACA,EAAE,UAAU,SAAS,CACtB;AACD,IAAE,IAAI,QACJ,kFACD;SACK;AACN,IAAE,IAAI,KACJ,gEACD;AACD,IAAE,KAAK,+BAA+B,kBAAkB;;AAI5D,GAAE,MAAM,kCAAkC"}
|
package/dist/esm/initMCP.mjs
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
import { findProjectRoot } from "./init.mjs";
|
|
2
1
|
import { PLATFORM_OPTIONS, getDetectedPlatform } from "./initSkills.mjs";
|
|
2
|
+
import { findProjectRoot } from "./init.mjs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { PLATFORMS, installMCP } from "@intlayer/chokidar/cli";
|
|
5
5
|
import enquirer from "enquirer";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
7
|
|
|
8
8
|
//#region src/initMCP.ts
|
|
9
|
-
const initMCP = async (projectRoot) => {
|
|
9
|
+
const initMCP = async (projectRoot, preselectedPlatform) => {
|
|
10
10
|
const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
|
|
11
11
|
p.intro("Initializing Intlayer MCP Server");
|
|
12
|
-
const detectedPlatform = getDetectedPlatform();
|
|
13
12
|
let platform;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
if (preselectedPlatform) platform = preselectedPlatform;
|
|
14
|
+
else {
|
|
15
|
+
const detectedPlatform = getDetectedPlatform();
|
|
16
|
+
try {
|
|
17
|
+
platform = (await enquirer.prompt({
|
|
18
|
+
type: "autocomplete",
|
|
19
|
+
name: "platforms",
|
|
20
|
+
message: "Which platform are you using? (Type to search)",
|
|
21
|
+
multiple: false,
|
|
22
|
+
initial: detectedPlatform ? PLATFORMS.indexOf(detectedPlatform) : void 0,
|
|
23
|
+
choices: PLATFORM_OPTIONS.map((opt) => ({
|
|
24
|
+
name: opt.value,
|
|
25
|
+
message: opt.label,
|
|
26
|
+
hint: opt.hint
|
|
27
|
+
}))
|
|
28
|
+
})).platforms;
|
|
29
|
+
} catch {
|
|
30
|
+
p.cancel("Operation cancelled.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
if (!platform) {
|
|
32
35
|
p.cancel("Operation cancelled. No platform selected.");
|
package/dist/esm/initMCP.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initMCP.mjs","names":[],"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
|
|
1
|
+
{"version":3,"file":"initMCP.mjs","names":[],"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,OAAO,gBACX,cAAc,QAAQ,YAAY,GAAG,QAAQ,KAAK,CACnD;AAED,GAAE,MAAM,mCAAmC;CAE3C,IAAI;AAEJ,KAAI,oBACF,YAAW;MACN;EACL,MAAM,mBAAmB,qBAAqB;AAE9C,MAAI;AAeF,eAAW,MAdY,SAAS,OAAgC;IAC9D,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,SAAS,mBACL,UAAU,QAAQ,iBAAiB,GACnC;IACJ,SAAS,iBAAiB,KAAK,SAAS;KACtC,MAAM,IAAI;KACV,SAAS,IAAI;KACb,MAAM,IAAI;KACX,EAAE;IACJ,CAAC,EACkB;UACd;AACN,KAAE,OAAO,uBAAuB;AAChC;;;AAIJ,KAAI,CAAC,UAAU;AACb,IAAE,OAAO,6CAA6C;AACtD;;CAGF,MAAM,YAAa,MAAM,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,KAAI,EAAE,SAAS,UAAU,IAAI,CAAC,WAAW;AACvC,IAAE,OAAO,uBAAuB;AAChC;;CAGF,MAAM,IAAI,EAAE,SAAS;AACrB,GAAE,MAAM,4BAA4B;AAEpC,KAAI;EACF,MAAM,SAAS,MAAM,WAAW,MAAM,UAAU,UAAU;AAE1D,IAAE,KAAK,qCAAqC;AAE5C,IAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,iCAAiC;AACxC,IAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,GAAE,MAAM,8CAA8C"}
|
package/dist/esm/initSkills.mjs
CHANGED
|
@@ -29,27 +29,30 @@ const getDependencies = (root) => {
|
|
|
29
29
|
return {};
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
const initSkills = async (projectRoot) => {
|
|
32
|
+
const initSkills = async (projectRoot, preselectedPlatform) => {
|
|
33
33
|
const root = findProjectRoot(projectRoot ? resolve(projectRoot) : process.cwd());
|
|
34
34
|
p.intro("Initializing Intlayer skills");
|
|
35
|
-
const detectedPlatform = getDetectedPlatform();
|
|
36
35
|
let platform;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
if (preselectedPlatform) platform = preselectedPlatform;
|
|
37
|
+
else {
|
|
38
|
+
const detectedPlatform = getDetectedPlatform();
|
|
39
|
+
try {
|
|
40
|
+
platform = (await enquirer.prompt({
|
|
41
|
+
type: "autocomplete",
|
|
42
|
+
name: "platforms",
|
|
43
|
+
message: "Which platforms are you using? (Type to search)",
|
|
44
|
+
multiple: false,
|
|
45
|
+
initial: detectedPlatform ? PLATFORMS.indexOf(detectedPlatform) : void 0,
|
|
46
|
+
choices: PLATFORM_OPTIONS.map((opt) => ({
|
|
47
|
+
name: opt.value,
|
|
48
|
+
message: opt.label,
|
|
49
|
+
hint: opt.hint
|
|
50
|
+
}))
|
|
51
|
+
})).platforms;
|
|
52
|
+
} catch {
|
|
53
|
+
p.cancel("Operation cancelled.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
53
56
|
}
|
|
54
57
|
if (!platform) {
|
|
55
58
|
p.log.warn("No platform selected. Nothing to install.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initSkills.mjs","names":[],"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
|
|
1
|
+
{"version":3,"file":"initSkills.mjs","names":[],"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,kBACJ,UAAU,QAAQ,aAAa,mBAAmB,WAAW,MAAM,CAAC,KACjE,cAAc;CACb,OAAO,mBAAmB,WAAW,gBAAgB;CACrD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AE;EACH,UAAU;EACX,CAAC;AAEF,KACE,EAAE,SAAS,eAAe,IAC1B,CAAC,kBACA,eAA4B,WAAW,GACxC;AACA,IAAE,OAAO,2CAA2C;AACpD;;CAGF,MAAM,IAAI,EAAE,SAAS;AACrB,GAAE,MAAM,uBAAuB;AAE/B,KAAI;EACF,MAAM,SAAS,MAAM,cAAc,MAAM,UAAU,eAAe;AAElE,IAAE,KAAK,gCAAgC;AAEvC,IAAE,KAAK,QAAQ,UAAU;UAClB,OAAO;AACd,IAAE,KAAK,2BAA2B;AAClC,IAAE,IAAI,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;AAGrE,GAAE,MAAM,0CAA0C"}
|
|
@@ -8,8 +8,8 @@ import { formatLocale, formatPath } from "@intlayer/chokidar/utils";
|
|
|
8
8
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
9
9
|
import { colon, colorize, colorizeNumber, getAppLogger } from "@intlayer/config/logger";
|
|
10
10
|
import { getConfiguration } from "@intlayer/config/node";
|
|
11
|
-
import { retryManager } from "@intlayer/config/utils";
|
|
12
11
|
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { retryManager } from "@intlayer/config/utils";
|
|
13
13
|
import { buildAlignmentPlan, mergeReviewedSegments } from "@intlayer/chokidar/docReview";
|
|
14
14
|
import { getLocaleName } from "@intlayer/core/localization";
|
|
15
15
|
import { ENGLISH } from "@intlayer/types/locales";
|
|
@@ -7,8 +7,8 @@ import { dirname, relative } from "node:path";
|
|
|
7
7
|
import { formatLocale, formatPath } from "@intlayer/chokidar/utils";
|
|
8
8
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
9
9
|
import { colon, colorize, colorizeNumber, getAppLogger } from "@intlayer/config/logger";
|
|
10
|
-
import { retryManager } from "@intlayer/config/utils";
|
|
11
10
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
11
|
+
import { retryManager } from "@intlayer/config/utils";
|
|
12
12
|
import { performance } from "node:perf_hooks";
|
|
13
13
|
|
|
14
14
|
//#region src/translateDoc/translateFile.ts
|