create-krispya 0.6.0 → 0.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/README.md +7 -346
- package/dist/index.cjs +2969 -21
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +2953 -5
- package/package.json +29 -15
- package/LICENSE +0 -15
- package/dist/chunks/index.cjs +0 -2976
- package/dist/chunks/index.mjs +0 -2947
- package/dist/cli.cjs +0 -3025
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.mjs +0 -3004
package/dist/cli.mjs
DELETED
|
@@ -1,3004 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
import { cwd } from 'process';
|
|
4
|
-
import { join, dirname, resolve } from 'path';
|
|
5
|
-
import { access, constants, readFile, mkdir, writeFile, rm, readdir, unlink } from 'fs/promises';
|
|
6
|
-
import { constants as constants$1 } from 'fs';
|
|
7
|
-
import { Command } from 'commander';
|
|
8
|
-
import * as p from '@clack/prompts';
|
|
9
|
-
import color from 'chalk';
|
|
10
|
-
import { fetch } from 'undici';
|
|
11
|
-
import { spawn } from 'child_process';
|
|
12
|
-
import { g as getBaseTemplate, a as getLanguageFromTemplate, b as generateRandomName, d as detectTooling, c as generateAiFiles, A as ALL_AI_PLATFORMS, e as generateVscodeFiles, f as generateTypescriptConfigPackage, h as generateOxlintConfigPackage, i as generateEslintConfigPackage, j as generateOxfmtConfigPackage, k as generatePrettierConfigPackage, p as parseWorkspaceYamlContent, l as getLatestNpmVersion, m as generate, n as getLatestPnpmVersion, o as getLatestYarnVersion, q as getLatestNpmCliVersion, r as getLatestNodeVersion, s as AI_PLATFORM_LABELS, t as AI_PLATFORM_HINTS, v as validatePackageName } from './chunks/index.mjs';
|
|
13
|
-
import Conf from 'conf';
|
|
14
|
-
|
|
15
|
-
const editorNames = {
|
|
16
|
-
cursor: "Cursor",
|
|
17
|
-
code: "VS Code",
|
|
18
|
-
webstorm: "WebStorm",
|
|
19
|
-
skip: "Skip"
|
|
20
|
-
};
|
|
21
|
-
function openInEditor(editor, path, reuseWindow) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const isWindows = process.platform === "win32";
|
|
24
|
-
const useReuseFlag = reuseWindow && (editor === "cursor" || editor === "code");
|
|
25
|
-
const args = useReuseFlag ? ["-r", path] : [path];
|
|
26
|
-
const child = isWindows ? spawn(`${editor} ${useReuseFlag ? "-r " : ""}"${path}"`, {
|
|
27
|
-
detached: true,
|
|
28
|
-
stdio: "ignore",
|
|
29
|
-
shell: true
|
|
30
|
-
}) : spawn(editor, args, {
|
|
31
|
-
detached: true,
|
|
32
|
-
stdio: "ignore"
|
|
33
|
-
});
|
|
34
|
-
child.on("error", reject);
|
|
35
|
-
child.unref();
|
|
36
|
-
setTimeout(resolve, 100);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function formatConfigSummary(options, inherited) {
|
|
41
|
-
const lines = [];
|
|
42
|
-
const VALUE_COL = 27;
|
|
43
|
-
const formatRow = (label, value, isInherited = false, indent = "") => {
|
|
44
|
-
const fullLabel = indent + label;
|
|
45
|
-
const dotCount = Math.max(1, VALUE_COL - fullLabel.length - 1);
|
|
46
|
-
const dots = color.gray(".".repeat(dotCount));
|
|
47
|
-
const displayValue = isInherited ? `${value} \u{1F512}` : value;
|
|
48
|
-
return `${indent}${label} ${dots} ${displayValue}`;
|
|
49
|
-
};
|
|
50
|
-
const formatLanguage = (lang) => {
|
|
51
|
-
return lang === "typescript" ? "TypeScript" : lang === "javascript" ? "JavaScript" : lang;
|
|
52
|
-
};
|
|
53
|
-
const projectType = options.projectType ?? "app";
|
|
54
|
-
const baseTemplate = options.template ? getBaseTemplate(options.template) : "vanilla";
|
|
55
|
-
if (baseTemplate === "react") {
|
|
56
|
-
lines.push(formatRow("Framework", "React"));
|
|
57
|
-
} else if (baseTemplate === "r3f") {
|
|
58
|
-
lines.push(formatRow("Framework", "React Three Fiber"));
|
|
59
|
-
}
|
|
60
|
-
const language = options.template ? getLanguageFromTemplate(options.template) : "typescript";
|
|
61
|
-
lines.push(formatRow("Language", formatLanguage(language)));
|
|
62
|
-
if (projectType === "library") {
|
|
63
|
-
lines.push(formatRow("Bundler", options.libraryBundler ?? "unbuild"));
|
|
64
|
-
} else {
|
|
65
|
-
lines.push(formatRow("Bundler", "vite"));
|
|
66
|
-
}
|
|
67
|
-
const nodeVersionInherited = inherited?.nodeVersion !== void 0;
|
|
68
|
-
lines.push(formatRow("Node version", options.nodeVersion || "latest", nodeVersionInherited));
|
|
69
|
-
const pmInherited = inherited?.packageManager !== void 0;
|
|
70
|
-
lines.push(formatRow("Package manager", options.packageManager || "pnpm", pmInherited));
|
|
71
|
-
if (options.packageManager === "pnpm") {
|
|
72
|
-
const versionManaged = options.pnpmManageVersions ? "yes" : "no";
|
|
73
|
-
const pnpmVersionInherited = inherited?.pnpmManageVersions !== void 0;
|
|
74
|
-
lines.push(formatRow("\u21B3 Version managed", versionManaged, pnpmVersionInherited, ""));
|
|
75
|
-
}
|
|
76
|
-
if (options.linter) {
|
|
77
|
-
const linterInherited = inherited?.linter !== void 0;
|
|
78
|
-
lines.push(formatRow("Linter", options.linter, linterInherited));
|
|
79
|
-
}
|
|
80
|
-
if (options.formatter) {
|
|
81
|
-
const formatterInherited = inherited?.formatter !== void 0;
|
|
82
|
-
lines.push(formatRow("Formatter", options.formatter, formatterInherited));
|
|
83
|
-
}
|
|
84
|
-
const testing = options.testing ?? (projectType === "library" ? "vitest" : "none");
|
|
85
|
-
lines.push(formatRow("Testing", testing));
|
|
86
|
-
if (!inherited) {
|
|
87
|
-
const configStrategy = options.configStrategy ?? "stealth";
|
|
88
|
-
lines.push(formatRow("Config strategy", configStrategy));
|
|
89
|
-
}
|
|
90
|
-
if (options.template && getBaseTemplate(options.template) === "r3f") {
|
|
91
|
-
const integrationNames = [
|
|
92
|
-
options.drei && "drei",
|
|
93
|
-
options.handle && "handle",
|
|
94
|
-
options.leva && "leva",
|
|
95
|
-
options.postprocessing && "postproc",
|
|
96
|
-
options.rapier && "rapier",
|
|
97
|
-
options.xr && "xr",
|
|
98
|
-
options.uikit && "uikit",
|
|
99
|
-
options.offscreen && "offscreen",
|
|
100
|
-
options.zustand && "zustand",
|
|
101
|
-
options.koota && "koota",
|
|
102
|
-
options.triplex && "triplex",
|
|
103
|
-
options.viverse && "viverse"
|
|
104
|
-
].filter(Boolean);
|
|
105
|
-
lines.push("");
|
|
106
|
-
lines.push(color.dim("Integrations"));
|
|
107
|
-
for (let i = 0; i < integrationNames.length; i += 2) {
|
|
108
|
-
const left = `${color.green("\u25CF")} ${integrationNames[i]}`;
|
|
109
|
-
const right = integrationNames[i + 1] ? `${color.green("\u25CF")} ${integrationNames[i + 1]}` : "";
|
|
110
|
-
const spacing = " ".repeat(Math.max(1, 16 - integrationNames[i].length));
|
|
111
|
-
lines.push(` ${left}${spacing}${right}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return lines.join("\n");
|
|
115
|
-
}
|
|
116
|
-
function formatMonorepoConfigSummary(options) {
|
|
117
|
-
const lines = [];
|
|
118
|
-
const VALUE_COL = 27;
|
|
119
|
-
const formatRow = (label, value, indent = "") => {
|
|
120
|
-
const fullLabel = indent + label;
|
|
121
|
-
const dotCount = Math.max(1, VALUE_COL - fullLabel.length - 1);
|
|
122
|
-
const dots = color.gray(".".repeat(dotCount));
|
|
123
|
-
return `${indent}${label} ${dots} ${value}`;
|
|
124
|
-
};
|
|
125
|
-
lines.push(formatRow("Node version", options.nodeVersion || "latest"));
|
|
126
|
-
lines.push(formatRow("Package manager", options.packageManager || "pnpm"));
|
|
127
|
-
if (options.packageManager === "pnpm") {
|
|
128
|
-
const versionManaged = options.pnpmManageVersions ? "yes" : "no";
|
|
129
|
-
lines.push(formatRow("\u21B3 Version managed", versionManaged, ""));
|
|
130
|
-
}
|
|
131
|
-
lines.push(formatRow("Linter", options.linter));
|
|
132
|
-
lines.push(formatRow("Formatter", options.formatter));
|
|
133
|
-
return lines.join("\n");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const config = new Conf({
|
|
137
|
-
projectName: "create-krispya"
|
|
138
|
-
});
|
|
139
|
-
function getPreferredEditor() {
|
|
140
|
-
return config.get("preferredEditor");
|
|
141
|
-
}
|
|
142
|
-
function setPreferredEditor(editor) {
|
|
143
|
-
config.set("preferredEditor", editor);
|
|
144
|
-
}
|
|
145
|
-
function getReuseWindow() {
|
|
146
|
-
return config.get("reuseWindow") ?? false;
|
|
147
|
-
}
|
|
148
|
-
function setReuseWindow(reuse) {
|
|
149
|
-
config.set("reuseWindow", reuse);
|
|
150
|
-
}
|
|
151
|
-
function getAiPlatforms() {
|
|
152
|
-
return config.get("aiPlatforms");
|
|
153
|
-
}
|
|
154
|
-
function setAiPlatforms(platforms) {
|
|
155
|
-
config.set("aiPlatforms", platforms);
|
|
156
|
-
}
|
|
157
|
-
function getConfigStrategy() {
|
|
158
|
-
return config.get("configStrategy") ?? "stealth";
|
|
159
|
-
}
|
|
160
|
-
function clearConfig() {
|
|
161
|
-
config.clear();
|
|
162
|
-
}
|
|
163
|
-
function getConfigPath() {
|
|
164
|
-
return config.path;
|
|
165
|
-
}
|
|
166
|
-
function getCustomTemplates() {
|
|
167
|
-
return config.get("customTemplates") ?? {};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function getDefaultOptions(template, name, projectType = "app", libraryBundler, integrations, inheritedSettings) {
|
|
171
|
-
const baseTemplate = getBaseTemplate(template);
|
|
172
|
-
const base = {
|
|
173
|
-
name,
|
|
174
|
-
template,
|
|
175
|
-
projectType,
|
|
176
|
-
libraryBundler: projectType === "library" ? libraryBundler ?? "unbuild" : void 0,
|
|
177
|
-
packageManager: inheritedSettings?.packageManager ?? "pnpm",
|
|
178
|
-
pnpmManageVersions: inheritedSettings?.pnpmManageVersions ?? true,
|
|
179
|
-
nodeVersion: inheritedSettings?.nodeVersion ?? "latest",
|
|
180
|
-
linter: inheritedSettings?.linter ?? "oxlint",
|
|
181
|
-
formatter: inheritedSettings?.formatter ?? "prettier",
|
|
182
|
-
// Libraries get vitest by default, apps don't
|
|
183
|
-
testing: projectType === "library" ? "vitest" : "none",
|
|
184
|
-
configStrategy: getConfigStrategy()
|
|
185
|
-
};
|
|
186
|
-
if (baseTemplate === "r3f" && integrations) {
|
|
187
|
-
return {
|
|
188
|
-
...base,
|
|
189
|
-
drei: integrations.includes("drei") ? {} : void 0,
|
|
190
|
-
handle: integrations.includes("handle") ? {} : void 0,
|
|
191
|
-
leva: integrations.includes("leva") ? {} : void 0,
|
|
192
|
-
postprocessing: integrations.includes("postprocessing") ? {} : void 0,
|
|
193
|
-
rapier: integrations.includes("rapier") ? {} : void 0,
|
|
194
|
-
xr: integrations.includes("xr") ? {} : void 0,
|
|
195
|
-
uikit: integrations.includes("uikit") ? {} : void 0,
|
|
196
|
-
offscreen: integrations.includes("offscreen") ? {} : void 0,
|
|
197
|
-
zustand: integrations.includes("zustand") ? {} : void 0,
|
|
198
|
-
koota: integrations.includes("koota") ? {} : void 0,
|
|
199
|
-
triplex: integrations.includes("triplex") ? {} : void 0,
|
|
200
|
-
viverse: integrations.includes("viverse") ? {} : void 0
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return base;
|
|
204
|
-
}
|
|
205
|
-
function getDefaultProjectName(template) {
|
|
206
|
-
const base = getBaseTemplate(template);
|
|
207
|
-
switch (base) {
|
|
208
|
-
case "vanilla":
|
|
209
|
-
return `vanilla-${generateRandomName()}`;
|
|
210
|
-
case "react":
|
|
211
|
-
return `react-${generateRandomName()}`;
|
|
212
|
-
case "r3f":
|
|
213
|
-
return `react-three-${generateRandomName()}`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async function promptForR3fIntegrations(presets) {
|
|
217
|
-
const initialValues = [];
|
|
218
|
-
if (presets) {
|
|
219
|
-
if (presets.drei) initialValues.push("drei");
|
|
220
|
-
if (presets.handle) initialValues.push("handle");
|
|
221
|
-
if (presets.leva) initialValues.push("leva");
|
|
222
|
-
if (presets.postprocessing) initialValues.push("postprocessing");
|
|
223
|
-
if (presets.rapier) initialValues.push("rapier");
|
|
224
|
-
if (presets.xr) initialValues.push("xr");
|
|
225
|
-
if (presets.uikit) initialValues.push("uikit");
|
|
226
|
-
if (presets.offscreen) initialValues.push("offscreen");
|
|
227
|
-
if (presets.zustand) initialValues.push("zustand");
|
|
228
|
-
if (presets.koota) initialValues.push("koota");
|
|
229
|
-
if (presets.triplex) initialValues.push("triplex");
|
|
230
|
-
if (presets.viverse) initialValues.push("viverse");
|
|
231
|
-
}
|
|
232
|
-
const selected = await p.multiselect({
|
|
233
|
-
message: "R3F integrations",
|
|
234
|
-
options: [
|
|
235
|
-
{ value: "drei", label: "Drei" },
|
|
236
|
-
{ value: "handle", label: "Handle" },
|
|
237
|
-
{ value: "leva", label: "Leva" },
|
|
238
|
-
{ value: "postprocessing", label: "Postprocessing" },
|
|
239
|
-
{ value: "rapier", label: "Rapier" },
|
|
240
|
-
{ value: "xr", label: "XR" },
|
|
241
|
-
{ value: "uikit", label: "UIKit" },
|
|
242
|
-
{ value: "offscreen", label: "Offscreen" },
|
|
243
|
-
{ value: "zustand", label: "Zustand" },
|
|
244
|
-
{ value: "koota", label: "Koota" },
|
|
245
|
-
{ value: "triplex", label: "Triplex" },
|
|
246
|
-
{ value: "viverse", label: "Viverse" }
|
|
247
|
-
],
|
|
248
|
-
initialValues: initialValues.length > 0 ? initialValues : ["drei"],
|
|
249
|
-
required: false
|
|
250
|
-
});
|
|
251
|
-
if (p.isCancel(selected)) {
|
|
252
|
-
p.cancel("Operation cancelled.");
|
|
253
|
-
process.exit(0);
|
|
254
|
-
}
|
|
255
|
-
return selected;
|
|
256
|
-
}
|
|
257
|
-
async function promptForCustomization(template, name, projectType, integrations, inheritedSettings, presets) {
|
|
258
|
-
let libraryBundler;
|
|
259
|
-
if (projectType === "library") {
|
|
260
|
-
const bundler = await p.select({
|
|
261
|
-
message: "Library bundler",
|
|
262
|
-
options: [
|
|
263
|
-
{ value: "unbuild", label: "unbuild", hint: "unjs, simple config" },
|
|
264
|
-
{ value: "tsdown", label: "tsdown", hint: "fast, esbuild-based" }
|
|
265
|
-
],
|
|
266
|
-
initialValue: presets?.bundler ?? "unbuild"
|
|
267
|
-
});
|
|
268
|
-
if (p.isCancel(bundler)) {
|
|
269
|
-
p.cancel("Operation cancelled.");
|
|
270
|
-
process.exit(0);
|
|
271
|
-
}
|
|
272
|
-
libraryBundler = bundler;
|
|
273
|
-
}
|
|
274
|
-
let nodeVersion = inheritedSettings?.nodeVersion ?? presets?.nodeVersion ?? "latest";
|
|
275
|
-
let finalPackageManager = inheritedSettings?.packageManager ?? presets?.packageManager ?? "pnpm";
|
|
276
|
-
let pnpmManageVersions = inheritedSettings?.pnpmManageVersions ?? presets?.pnpmManageVersions ?? true;
|
|
277
|
-
if (!inheritedSettings?.nodeVersion) {
|
|
278
|
-
const nodeVersionInput = await p.text({
|
|
279
|
-
message: "Node.js version",
|
|
280
|
-
placeholder: presets?.nodeVersion ?? "latest",
|
|
281
|
-
defaultValue: presets?.nodeVersion ?? "latest",
|
|
282
|
-
validate: (value) => {
|
|
283
|
-
if (!value.length) return "Required";
|
|
284
|
-
if (value !== "latest" && !/^\d+(\.\d+(\.\d+)?)?$/.test(value)) {
|
|
285
|
-
return 'Must be "latest" or a valid semver (e.g., "22" or "22.13.0")';
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
if (p.isCancel(nodeVersionInput)) {
|
|
290
|
-
p.cancel("Operation cancelled.");
|
|
291
|
-
process.exit(0);
|
|
292
|
-
}
|
|
293
|
-
nodeVersion = nodeVersionInput;
|
|
294
|
-
}
|
|
295
|
-
if (!inheritedSettings?.packageManager) {
|
|
296
|
-
const packageManager = await p.select({
|
|
297
|
-
message: "Package manager",
|
|
298
|
-
options: [
|
|
299
|
-
{ value: "pnpm", label: "pnpm" },
|
|
300
|
-
{ value: "npm", label: "npm" },
|
|
301
|
-
{ value: "yarn", label: "yarn" }
|
|
302
|
-
],
|
|
303
|
-
initialValue: presets?.packageManager ?? "pnpm"
|
|
304
|
-
});
|
|
305
|
-
if (p.isCancel(packageManager)) {
|
|
306
|
-
p.cancel("Operation cancelled.");
|
|
307
|
-
process.exit(0);
|
|
308
|
-
}
|
|
309
|
-
finalPackageManager = packageManager;
|
|
310
|
-
if (packageManager === "pnpm") {
|
|
311
|
-
const managePnpm = await p.confirm({
|
|
312
|
-
message: "Enable manage-package-manager-versions?",
|
|
313
|
-
initialValue: presets?.pnpmManageVersions ?? true
|
|
314
|
-
});
|
|
315
|
-
if (p.isCancel(managePnpm)) {
|
|
316
|
-
p.cancel("Operation cancelled.");
|
|
317
|
-
process.exit(0);
|
|
318
|
-
}
|
|
319
|
-
pnpmManageVersions = managePnpm;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
let linter = inheritedSettings?.linter ?? presets?.linter ?? "oxlint";
|
|
323
|
-
let formatter = inheritedSettings?.formatter ?? presets?.formatter ?? "prettier";
|
|
324
|
-
if (!inheritedSettings?.linter) {
|
|
325
|
-
const linterChoice = await p.select({
|
|
326
|
-
message: "Linter",
|
|
327
|
-
options: [
|
|
328
|
-
{ value: "oxlint", label: "Oxlint", hint: "fast, from OXC" },
|
|
329
|
-
{ value: "eslint", label: "ESLint", hint: "classic" },
|
|
330
|
-
{ value: "biome", label: "Biome", hint: "all-in-one" }
|
|
331
|
-
],
|
|
332
|
-
initialValue: presets?.linter ?? "oxlint"
|
|
333
|
-
});
|
|
334
|
-
if (p.isCancel(linterChoice)) {
|
|
335
|
-
p.cancel("Operation cancelled.");
|
|
336
|
-
process.exit(0);
|
|
337
|
-
}
|
|
338
|
-
linter = linterChoice;
|
|
339
|
-
}
|
|
340
|
-
if (!inheritedSettings?.formatter) {
|
|
341
|
-
const formatterChoice = await p.select({
|
|
342
|
-
message: "Formatter",
|
|
343
|
-
options: [
|
|
344
|
-
{ value: "prettier", label: "Prettier", hint: "widely adopted" },
|
|
345
|
-
{ value: "oxfmt", label: "Oxfmt", hint: "fast, Prettier-compatible" },
|
|
346
|
-
{ value: "biome", label: "Biome", hint: "all-in-one" }
|
|
347
|
-
],
|
|
348
|
-
initialValue: presets?.formatter ?? "prettier"
|
|
349
|
-
});
|
|
350
|
-
if (p.isCancel(formatterChoice)) {
|
|
351
|
-
p.cancel("Operation cancelled.");
|
|
352
|
-
process.exit(0);
|
|
353
|
-
}
|
|
354
|
-
formatter = formatterChoice;
|
|
355
|
-
}
|
|
356
|
-
const testing = await p.select({
|
|
357
|
-
message: "Testing",
|
|
358
|
-
options: [
|
|
359
|
-
{ value: "vitest", label: "Vitest", hint: "fast, Vite-native" },
|
|
360
|
-
{ value: "none", label: "None" }
|
|
361
|
-
],
|
|
362
|
-
initialValue: projectType === "library" ? "vitest" : "none"
|
|
363
|
-
});
|
|
364
|
-
if (p.isCancel(testing)) {
|
|
365
|
-
p.cancel("Operation cancelled.");
|
|
366
|
-
process.exit(0);
|
|
367
|
-
}
|
|
368
|
-
const language = await p.select({
|
|
369
|
-
message: "Language",
|
|
370
|
-
options: [
|
|
371
|
-
{ value: "typescript", label: "TypeScript" },
|
|
372
|
-
{ value: "javascript", label: "JavaScript" }
|
|
373
|
-
],
|
|
374
|
-
initialValue: "typescript"
|
|
375
|
-
});
|
|
376
|
-
if (p.isCancel(language)) {
|
|
377
|
-
p.cancel("Operation cancelled.");
|
|
378
|
-
process.exit(0);
|
|
379
|
-
}
|
|
380
|
-
const configStrategyChoice = await p.select({
|
|
381
|
-
message: "Config strategy",
|
|
382
|
-
options: [
|
|
383
|
-
{ value: "stealth", label: "stealth", hint: "configs in .config/" },
|
|
384
|
-
{ value: "root", label: "root", hint: "configs at project root" }
|
|
385
|
-
],
|
|
386
|
-
initialValue: getConfigStrategy()
|
|
387
|
-
});
|
|
388
|
-
if (p.isCancel(configStrategyChoice)) {
|
|
389
|
-
p.cancel("Operation cancelled.");
|
|
390
|
-
process.exit(0);
|
|
391
|
-
}
|
|
392
|
-
const baseTemplate = getBaseTemplate(template);
|
|
393
|
-
const finalTemplate = language === "javascript" ? `${baseTemplate}-js` : baseTemplate;
|
|
394
|
-
const base = {
|
|
395
|
-
name,
|
|
396
|
-
template: finalTemplate,
|
|
397
|
-
projectType,
|
|
398
|
-
libraryBundler: projectType === "library" ? libraryBundler : void 0,
|
|
399
|
-
nodeVersion,
|
|
400
|
-
packageManager: finalPackageManager,
|
|
401
|
-
pnpmManageVersions,
|
|
402
|
-
linter,
|
|
403
|
-
formatter,
|
|
404
|
-
testing,
|
|
405
|
-
configStrategy: configStrategyChoice
|
|
406
|
-
};
|
|
407
|
-
if (baseTemplate === "r3f" && integrations) {
|
|
408
|
-
return {
|
|
409
|
-
...base,
|
|
410
|
-
drei: integrations.includes("drei") ? {} : void 0,
|
|
411
|
-
handle: integrations.includes("handle") ? {} : void 0,
|
|
412
|
-
leva: integrations.includes("leva") ? {} : void 0,
|
|
413
|
-
postprocessing: integrations.includes("postprocessing") ? {} : void 0,
|
|
414
|
-
rapier: integrations.includes("rapier") ? {} : void 0,
|
|
415
|
-
xr: integrations.includes("xr") ? {} : void 0,
|
|
416
|
-
uikit: integrations.includes("uikit") ? {} : void 0,
|
|
417
|
-
offscreen: integrations.includes("offscreen") ? {} : void 0,
|
|
418
|
-
zustand: integrations.includes("zustand") ? {} : void 0,
|
|
419
|
-
koota: integrations.includes("koota") ? {} : void 0,
|
|
420
|
-
triplex: integrations.includes("triplex") ? {} : void 0,
|
|
421
|
-
viverse: integrations.includes("viverse") ? {} : void 0
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
return base;
|
|
425
|
-
}
|
|
426
|
-
async function promptForInitialPackage() {
|
|
427
|
-
const choice = await p.select({
|
|
428
|
-
message: "Add an initial package?",
|
|
429
|
-
options: [
|
|
430
|
-
{ value: "app", label: "Application" },
|
|
431
|
-
{ value: "library", label: "Library" },
|
|
432
|
-
{ value: "skip", label: "Skip" }
|
|
433
|
-
],
|
|
434
|
-
initialValue: "app"
|
|
435
|
-
});
|
|
436
|
-
if (p.isCancel(choice)) {
|
|
437
|
-
p.cancel("Operation cancelled.");
|
|
438
|
-
process.exit(0);
|
|
439
|
-
}
|
|
440
|
-
return choice;
|
|
441
|
-
}
|
|
442
|
-
function getDefaultMonorepoOptions(name) {
|
|
443
|
-
return {
|
|
444
|
-
name,
|
|
445
|
-
projectType: "monorepo",
|
|
446
|
-
packageManager: "pnpm",
|
|
447
|
-
pnpmManageVersions: true,
|
|
448
|
-
nodeVersion: "latest",
|
|
449
|
-
linter: "oxlint",
|
|
450
|
-
formatter: "prettier"
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
async function promptForMonorepoCustomization(name, presets) {
|
|
454
|
-
const nodeVersion = await p.text({
|
|
455
|
-
message: "Node.js version",
|
|
456
|
-
placeholder: presets?.nodeVersion ?? "latest",
|
|
457
|
-
defaultValue: presets?.nodeVersion ?? "latest",
|
|
458
|
-
validate: (value) => {
|
|
459
|
-
if (!value.length) return "Required";
|
|
460
|
-
if (value !== "latest" && !/^\d+(\.\d+(\.\d+)?)?$/.test(value)) {
|
|
461
|
-
return 'Must be "latest" or a valid semver (e.g., "22" or "22.13.0")';
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
if (p.isCancel(nodeVersion)) {
|
|
466
|
-
p.cancel("Operation cancelled.");
|
|
467
|
-
process.exit(0);
|
|
468
|
-
}
|
|
469
|
-
const managePnpm = await p.confirm({
|
|
470
|
-
message: "Enable manage-package-manager-versions?",
|
|
471
|
-
initialValue: presets?.pnpmManageVersions ?? true
|
|
472
|
-
});
|
|
473
|
-
if (p.isCancel(managePnpm)) {
|
|
474
|
-
p.cancel("Operation cancelled.");
|
|
475
|
-
process.exit(0);
|
|
476
|
-
}
|
|
477
|
-
const linter = await p.select({
|
|
478
|
-
message: "Linter",
|
|
479
|
-
options: [
|
|
480
|
-
{ value: "oxlint", label: "Oxlint", hint: "fast, from OXC" },
|
|
481
|
-
{ value: "eslint", label: "ESLint", hint: "classic" },
|
|
482
|
-
{ value: "biome", label: "Biome", hint: "all-in-one" }
|
|
483
|
-
],
|
|
484
|
-
initialValue: presets?.linter ?? "oxlint"
|
|
485
|
-
});
|
|
486
|
-
if (p.isCancel(linter)) {
|
|
487
|
-
p.cancel("Operation cancelled.");
|
|
488
|
-
process.exit(0);
|
|
489
|
-
}
|
|
490
|
-
const formatter = await p.select({
|
|
491
|
-
message: "Formatter",
|
|
492
|
-
options: [
|
|
493
|
-
{ value: "prettier", label: "Prettier", hint: "widely adopted" },
|
|
494
|
-
{ value: "oxfmt", label: "Oxfmt", hint: "fast, Prettier-compatible" },
|
|
495
|
-
{ value: "biome", label: "Biome", hint: "all-in-one" }
|
|
496
|
-
],
|
|
497
|
-
initialValue: presets?.formatter ?? "prettier"
|
|
498
|
-
});
|
|
499
|
-
if (p.isCancel(formatter)) {
|
|
500
|
-
p.cancel("Operation cancelled.");
|
|
501
|
-
process.exit(0);
|
|
502
|
-
}
|
|
503
|
-
return {
|
|
504
|
-
name,
|
|
505
|
-
projectType: "monorepo",
|
|
506
|
-
nodeVersion,
|
|
507
|
-
packageManager: "pnpm",
|
|
508
|
-
pnpmManageVersions: managePnpm,
|
|
509
|
-
linter,
|
|
510
|
-
formatter
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
async function promptForMonorepo(workspaceName, presets) {
|
|
514
|
-
const defaultOptions = getDefaultMonorepoOptions(workspaceName);
|
|
515
|
-
if (presets) {
|
|
516
|
-
if (presets.linter) defaultOptions.linter = presets.linter;
|
|
517
|
-
if (presets.formatter) defaultOptions.formatter = presets.formatter;
|
|
518
|
-
if (presets.nodeVersion) defaultOptions.nodeVersion = presets.nodeVersion;
|
|
519
|
-
if (presets.pnpmManageVersions !== void 0)
|
|
520
|
-
defaultOptions.pnpmManageVersions = presets.pnpmManageVersions;
|
|
521
|
-
}
|
|
522
|
-
p.note(
|
|
523
|
-
formatMonorepoConfigSummary({
|
|
524
|
-
name: defaultOptions.name,
|
|
525
|
-
nodeVersion: defaultOptions.nodeVersion ?? "latest",
|
|
526
|
-
packageManager: defaultOptions.packageManager ?? "pnpm",
|
|
527
|
-
pnpmManageVersions: defaultOptions.pnpmManageVersions,
|
|
528
|
-
linter: defaultOptions.linter ?? "oxlint",
|
|
529
|
-
formatter: defaultOptions.formatter ?? "prettier"
|
|
530
|
-
}),
|
|
531
|
-
"Workspace Configuration"
|
|
532
|
-
);
|
|
533
|
-
const proceed = await p.select({
|
|
534
|
-
message: "Proceed with these settings?",
|
|
535
|
-
options: [
|
|
536
|
-
{ value: "continue", label: "Yes, continue" },
|
|
537
|
-
{ value: "customize", label: "No, customize settings" }
|
|
538
|
-
],
|
|
539
|
-
initialValue: "continue"
|
|
540
|
-
});
|
|
541
|
-
if (p.isCancel(proceed)) {
|
|
542
|
-
p.cancel("Operation cancelled.");
|
|
543
|
-
process.exit(0);
|
|
544
|
-
}
|
|
545
|
-
if (proceed === "continue") {
|
|
546
|
-
return defaultOptions;
|
|
547
|
-
}
|
|
548
|
-
return promptForMonorepoCustomization(workspaceName, presets);
|
|
549
|
-
}
|
|
550
|
-
async function promptForOptions(name, presets) {
|
|
551
|
-
let projectName = name;
|
|
552
|
-
if (!projectName) {
|
|
553
|
-
const nameResult = await p.text({
|
|
554
|
-
message: "What is your project named?",
|
|
555
|
-
placeholder: generateRandomName(),
|
|
556
|
-
defaultValue: generateRandomName(),
|
|
557
|
-
validate: (value) => {
|
|
558
|
-
if (!value.length) return "Project name is required";
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
if (p.isCancel(nameResult)) {
|
|
562
|
-
p.cancel("Operation cancelled.");
|
|
563
|
-
process.exit(0);
|
|
564
|
-
}
|
|
565
|
-
projectName = nameResult;
|
|
566
|
-
}
|
|
567
|
-
const projectType = await p.select({
|
|
568
|
-
message: "Project type",
|
|
569
|
-
options: [
|
|
570
|
-
{ value: "app", label: "Application" },
|
|
571
|
-
{ value: "library", label: "Library" },
|
|
572
|
-
{ value: "monorepo", label: "Monorepo" }
|
|
573
|
-
],
|
|
574
|
-
initialValue: presets?.type ?? "app"
|
|
575
|
-
});
|
|
576
|
-
if (p.isCancel(projectType)) {
|
|
577
|
-
p.cancel("Operation cancelled.");
|
|
578
|
-
process.exit(0);
|
|
579
|
-
}
|
|
580
|
-
if (projectType === "monorepo") {
|
|
581
|
-
return promptForMonorepo(projectName, presets);
|
|
582
|
-
}
|
|
583
|
-
return promptForPackageOptions(
|
|
584
|
-
projectName,
|
|
585
|
-
projectType,
|
|
586
|
-
void 0,
|
|
587
|
-
presets
|
|
588
|
-
);
|
|
589
|
-
}
|
|
590
|
-
function customTemplateToOptions(customTemplate, name, projectType, inheritedSettings) {
|
|
591
|
-
const baseTemplate = customTemplate.baseTemplate;
|
|
592
|
-
const template = baseTemplate;
|
|
593
|
-
const base = {
|
|
594
|
-
name,
|
|
595
|
-
template,
|
|
596
|
-
projectType,
|
|
597
|
-
packageManager: inheritedSettings?.packageManager ?? "pnpm",
|
|
598
|
-
pnpmManageVersions: inheritedSettings?.pnpmManageVersions ?? true,
|
|
599
|
-
nodeVersion: inheritedSettings?.nodeVersion ?? "latest",
|
|
600
|
-
linter: inheritedSettings?.linter ?? customTemplate.linter,
|
|
601
|
-
formatter: inheritedSettings?.formatter ?? customTemplate.formatter,
|
|
602
|
-
testing: customTemplate.testing,
|
|
603
|
-
configStrategy: customTemplate.configStrategy ?? getConfigStrategy()
|
|
604
|
-
};
|
|
605
|
-
if (baseTemplate === "r3f" && customTemplate.integrations) {
|
|
606
|
-
const integrations = customTemplate.integrations;
|
|
607
|
-
return {
|
|
608
|
-
...base,
|
|
609
|
-
drei: integrations.includes("drei") ? {} : void 0,
|
|
610
|
-
handle: integrations.includes("handle") ? {} : void 0,
|
|
611
|
-
leva: integrations.includes("leva") ? {} : void 0,
|
|
612
|
-
postprocessing: integrations.includes("postprocessing") ? {} : void 0,
|
|
613
|
-
rapier: integrations.includes("rapier") ? {} : void 0,
|
|
614
|
-
xr: integrations.includes("xr") ? {} : void 0,
|
|
615
|
-
uikit: integrations.includes("uikit") ? {} : void 0,
|
|
616
|
-
offscreen: integrations.includes("offscreen") ? {} : void 0,
|
|
617
|
-
zustand: integrations.includes("zustand") ? {} : void 0,
|
|
618
|
-
koota: integrations.includes("koota") ? {} : void 0,
|
|
619
|
-
triplex: integrations.includes("triplex") ? {} : void 0,
|
|
620
|
-
viverse: integrations.includes("viverse") ? {} : void 0
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
return base;
|
|
624
|
-
}
|
|
625
|
-
function presetsToInheritedSettings(presets) {
|
|
626
|
-
if (!presets) return void 0;
|
|
627
|
-
return {
|
|
628
|
-
linter: presets.linter,
|
|
629
|
-
formatter: presets.formatter,
|
|
630
|
-
packageManager: presets.packageManager,
|
|
631
|
-
nodeVersion: presets.nodeVersion,
|
|
632
|
-
pnpmManageVersions: presets.pnpmManageVersions
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
async function promptForPackageOptions(projectName, projectType, inheritedSettings, presets) {
|
|
636
|
-
const builtInOptions = [
|
|
637
|
-
{ value: "vanilla", label: "Vanilla" },
|
|
638
|
-
{ value: "react", label: "React" },
|
|
639
|
-
{ value: "r3f", label: "React Three Fiber" }
|
|
640
|
-
];
|
|
641
|
-
const customTemplates = getCustomTemplates();
|
|
642
|
-
const customOptions = Object.keys(customTemplates).map((name) => ({
|
|
643
|
-
value: `custom:${name}`,
|
|
644
|
-
label: name,
|
|
645
|
-
hint: "saved template"
|
|
646
|
-
}));
|
|
647
|
-
const allOptions = [...builtInOptions, ...customOptions];
|
|
648
|
-
const templateSelection = await p.select({
|
|
649
|
-
message: "Select a template",
|
|
650
|
-
options: allOptions,
|
|
651
|
-
initialValue: presets?.template ?? "vanilla"
|
|
652
|
-
});
|
|
653
|
-
if (p.isCancel(templateSelection)) {
|
|
654
|
-
p.cancel("Operation cancelled.");
|
|
655
|
-
process.exit(0);
|
|
656
|
-
}
|
|
657
|
-
const selection = templateSelection;
|
|
658
|
-
if (selection.startsWith("custom:")) {
|
|
659
|
-
const customName = selection.slice(7);
|
|
660
|
-
const customTemplate = customTemplates[customName];
|
|
661
|
-
const defaultOptions2 = customTemplateToOptions(
|
|
662
|
-
customTemplate,
|
|
663
|
-
projectName,
|
|
664
|
-
projectType,
|
|
665
|
-
inheritedSettings
|
|
666
|
-
);
|
|
667
|
-
const configTitle2 = inheritedSettings ? `Template: ${customName} (using workspace settings)` : `Template: ${customName}`;
|
|
668
|
-
p.note(formatConfigSummary(defaultOptions2, inheritedSettings), configTitle2);
|
|
669
|
-
const proceed2 = await p.select({
|
|
670
|
-
message: "Proceed with these settings?",
|
|
671
|
-
options: [
|
|
672
|
-
{ value: "continue", label: "Yes, continue" },
|
|
673
|
-
{ value: "customize", label: "No, customize settings" }
|
|
674
|
-
],
|
|
675
|
-
initialValue: "continue"
|
|
676
|
-
});
|
|
677
|
-
if (p.isCancel(proceed2)) {
|
|
678
|
-
p.cancel("Operation cancelled.");
|
|
679
|
-
process.exit(0);
|
|
680
|
-
}
|
|
681
|
-
if (proceed2 === "continue") {
|
|
682
|
-
return defaultOptions2;
|
|
683
|
-
}
|
|
684
|
-
return promptForCustomization(
|
|
685
|
-
customTemplate.baseTemplate,
|
|
686
|
-
projectName,
|
|
687
|
-
projectType,
|
|
688
|
-
customTemplate.integrations,
|
|
689
|
-
inheritedSettings
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
const template = selection;
|
|
693
|
-
const baseTemplate = getBaseTemplate(template);
|
|
694
|
-
let integrations;
|
|
695
|
-
if (baseTemplate === "r3f") {
|
|
696
|
-
integrations = await promptForR3fIntegrations(presets);
|
|
697
|
-
}
|
|
698
|
-
const defaultOptions = getDefaultOptions(
|
|
699
|
-
template,
|
|
700
|
-
projectName,
|
|
701
|
-
projectType,
|
|
702
|
-
presets?.bundler,
|
|
703
|
-
integrations,
|
|
704
|
-
inheritedSettings ?? presetsToInheritedSettings(presets)
|
|
705
|
-
);
|
|
706
|
-
const configTitle = inheritedSettings ? "Template Configuration (using workspace settings)" : "Template Configuration";
|
|
707
|
-
p.note(formatConfigSummary(defaultOptions, inheritedSettings), configTitle);
|
|
708
|
-
const proceed = await p.select({
|
|
709
|
-
message: "Proceed with these settings?",
|
|
710
|
-
options: [
|
|
711
|
-
{ value: "continue", label: "Yes, continue" },
|
|
712
|
-
{ value: "customize", label: "No, customize settings" }
|
|
713
|
-
],
|
|
714
|
-
initialValue: "continue"
|
|
715
|
-
});
|
|
716
|
-
if (p.isCancel(proceed)) {
|
|
717
|
-
p.cancel("Operation cancelled.");
|
|
718
|
-
process.exit(0);
|
|
719
|
-
}
|
|
720
|
-
if (proceed === "continue") {
|
|
721
|
-
return defaultOptions;
|
|
722
|
-
}
|
|
723
|
-
return promptForCustomization(
|
|
724
|
-
template,
|
|
725
|
-
projectName,
|
|
726
|
-
projectType,
|
|
727
|
-
integrations,
|
|
728
|
-
inheritedSettings,
|
|
729
|
-
presets
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
async function checkAnyExists(paths) {
|
|
734
|
-
for (const path of paths) {
|
|
735
|
-
try {
|
|
736
|
-
await access(path, constants.F_OK);
|
|
737
|
-
return true;
|
|
738
|
-
} catch {
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return false;
|
|
742
|
-
}
|
|
743
|
-
async function validateWorkspace(monorepoRoot) {
|
|
744
|
-
const errors = [];
|
|
745
|
-
const tsConfigPath = join(monorepoRoot, ".config/typescript/package.json");
|
|
746
|
-
try {
|
|
747
|
-
await access(tsConfigPath, constants.F_OK);
|
|
748
|
-
} catch {
|
|
749
|
-
errors.push("Missing .config/typescript package");
|
|
750
|
-
}
|
|
751
|
-
const linterPaths = [
|
|
752
|
-
join(monorepoRoot, ".config/oxlint/package.json"),
|
|
753
|
-
join(monorepoRoot, ".config/eslint/package.json"),
|
|
754
|
-
join(monorepoRoot, "eslint.config.js"),
|
|
755
|
-
join(monorepoRoot, "biome.json")
|
|
756
|
-
];
|
|
757
|
-
const hasLinter = await checkAnyExists(linterPaths);
|
|
758
|
-
if (!hasLinter) {
|
|
759
|
-
errors.push(
|
|
760
|
-
"Missing linter config (.config/oxlint, .config/eslint, eslint.config.js, or biome.json)"
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
const formatterPaths = [
|
|
764
|
-
join(monorepoRoot, ".config/oxfmt/package.json"),
|
|
765
|
-
join(monorepoRoot, ".config/prettier/package.json"),
|
|
766
|
-
join(monorepoRoot, ".prettierrc.json"),
|
|
767
|
-
join(monorepoRoot, "biome.json")
|
|
768
|
-
];
|
|
769
|
-
const hasFormatter = await checkAnyExists(formatterPaths);
|
|
770
|
-
if (!hasFormatter) {
|
|
771
|
-
errors.push(
|
|
772
|
-
"Missing formatter config (.config/oxfmt, .config/prettier, .prettierrc.json, or biome.json)"
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
return { valid: errors.length === 0, errors };
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
async function detectCurrentConfig(root) {
|
|
779
|
-
let name = root.split(/[/\\]/).pop() ?? "workspace";
|
|
780
|
-
try {
|
|
781
|
-
const pkgPath = join(root, "package.json");
|
|
782
|
-
const content = await readFile(pkgPath, "utf-8");
|
|
783
|
-
const pkgJson = JSON.parse(content);
|
|
784
|
-
if (pkgJson.name) {
|
|
785
|
-
name = pkgJson.name.replace(/^@/, "").replace(/\/.*$/, "");
|
|
786
|
-
}
|
|
787
|
-
} catch {
|
|
788
|
-
}
|
|
789
|
-
const tooling = await detectTooling(root);
|
|
790
|
-
return {
|
|
791
|
-
name,
|
|
792
|
-
linter: tooling.linter ?? "oxlint",
|
|
793
|
-
formatter: tooling.formatter ?? "prettier",
|
|
794
|
-
packageManager: "pnpm"
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
function generateExpectedFiles(config) {
|
|
798
|
-
const { name, linter, formatter, packageManager } = config;
|
|
799
|
-
const aiFilesMap = {};
|
|
800
|
-
generateAiFiles(aiFilesMap, {
|
|
801
|
-
name,
|
|
802
|
-
packageManager,
|
|
803
|
-
linter,
|
|
804
|
-
formatter,
|
|
805
|
-
isMonorepo: true,
|
|
806
|
-
platforms: ALL_AI_PLATFORMS
|
|
807
|
-
});
|
|
808
|
-
const vscodeFiles = {};
|
|
809
|
-
generateVscodeFiles(vscodeFiles, linter, formatter);
|
|
810
|
-
const configPackages = {};
|
|
811
|
-
generateTypescriptConfigPackage(configPackages);
|
|
812
|
-
if (linter === "oxlint") {
|
|
813
|
-
generateOxlintConfigPackage(configPackages);
|
|
814
|
-
} else if (linter === "eslint") {
|
|
815
|
-
generateEslintConfigPackage(configPackages);
|
|
816
|
-
}
|
|
817
|
-
if (formatter === "oxfmt") {
|
|
818
|
-
generateOxfmtConfigPackage(configPackages);
|
|
819
|
-
} else if (formatter === "prettier") {
|
|
820
|
-
generatePrettierConfigPackage(configPackages);
|
|
821
|
-
}
|
|
822
|
-
const workspaceConfig = {};
|
|
823
|
-
const rootConfig = {};
|
|
824
|
-
rootConfig[".gitignore"] = {
|
|
825
|
-
type: "text",
|
|
826
|
-
content: ["node_modules", "dist", "*.tsbuildinfo", ".DS_Store"].join("\n")
|
|
827
|
-
};
|
|
828
|
-
rootConfig[".gitattributes"] = {
|
|
829
|
-
type: "text",
|
|
830
|
-
content: `* text=auto eol=lf
|
|
831
|
-
*.{cmd,[cC][mM][dD]} text eol=crlf
|
|
832
|
-
*.{bat,[bB][aA][tT]} text eol=crlf
|
|
833
|
-
`
|
|
834
|
-
};
|
|
835
|
-
if (linter === "biome" || formatter === "biome") {
|
|
836
|
-
const biomeConfig = {
|
|
837
|
-
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
838
|
-
vcs: {
|
|
839
|
-
enabled: true,
|
|
840
|
-
clientKind: "git",
|
|
841
|
-
useIgnoreFile: true
|
|
842
|
-
},
|
|
843
|
-
linter: {
|
|
844
|
-
enabled: linter === "biome",
|
|
845
|
-
rules: {
|
|
846
|
-
recommended: true
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
formatter: {
|
|
850
|
-
enabled: formatter === "biome"
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
rootConfig["biome.json"] = {
|
|
854
|
-
type: "text",
|
|
855
|
-
content: JSON.stringify(biomeConfig, null, 2)
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
return {
|
|
859
|
-
"ai-files": aiFilesMap,
|
|
860
|
-
vscode: vscodeFiles,
|
|
861
|
-
"config-packages": configPackages,
|
|
862
|
-
"workspace-config": workspaceConfig,
|
|
863
|
-
"root-config": rootConfig
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
async function fileExists$1(path) {
|
|
867
|
-
try {
|
|
868
|
-
await access(path, constants$1.F_OK);
|
|
869
|
-
return true;
|
|
870
|
-
} catch {
|
|
871
|
-
return false;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
async function compareWithDisk(expected, root) {
|
|
875
|
-
const categoryLabels = {
|
|
876
|
-
"ai-files": "AI Files",
|
|
877
|
-
vscode: "VS Code",
|
|
878
|
-
"config-packages": "Config Packages",
|
|
879
|
-
"workspace-config": "Workspace Config",
|
|
880
|
-
"root-config": "Root Config"
|
|
881
|
-
};
|
|
882
|
-
const categories = [];
|
|
883
|
-
for (const [category, files] of Object.entries(expected)) {
|
|
884
|
-
const changes = [];
|
|
885
|
-
for (const [filePath, file] of Object.entries(files)) {
|
|
886
|
-
if (file.type !== "text") continue;
|
|
887
|
-
const fullPath = join(root, filePath);
|
|
888
|
-
const newContent = file.content;
|
|
889
|
-
if (await fileExists$1(fullPath)) {
|
|
890
|
-
const currentContent = await readFile(fullPath, "utf-8");
|
|
891
|
-
if (currentContent === newContent) {
|
|
892
|
-
changes.push({
|
|
893
|
-
path: filePath,
|
|
894
|
-
status: "unchanged",
|
|
895
|
-
currentContent,
|
|
896
|
-
newContent
|
|
897
|
-
});
|
|
898
|
-
} else {
|
|
899
|
-
changes.push({
|
|
900
|
-
path: filePath,
|
|
901
|
-
status: "modified",
|
|
902
|
-
currentContent,
|
|
903
|
-
newContent
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
} else {
|
|
907
|
-
changes.push({
|
|
908
|
-
path: filePath,
|
|
909
|
-
status: "added",
|
|
910
|
-
newContent
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
if (changes.length === 0) continue;
|
|
915
|
-
const hasUserModifications = changes.some((c) => c.status === "modified");
|
|
916
|
-
categories.push({
|
|
917
|
-
category,
|
|
918
|
-
label: categoryLabels[category],
|
|
919
|
-
changes,
|
|
920
|
-
hasUserModifications
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
return categories;
|
|
924
|
-
}
|
|
925
|
-
async function getWorkspaceConfigUpdates(root) {
|
|
926
|
-
const workspacePath = join(root, "pnpm-workspace.yaml");
|
|
927
|
-
const changes = [];
|
|
928
|
-
let currentContent = "";
|
|
929
|
-
let exists = false;
|
|
930
|
-
try {
|
|
931
|
-
currentContent = await readFile(workspacePath, "utf-8");
|
|
932
|
-
exists = true;
|
|
933
|
-
} catch {
|
|
934
|
-
}
|
|
935
|
-
if (!exists) {
|
|
936
|
-
const newContent = `manage-package-manager-versions: true
|
|
937
|
-
|
|
938
|
-
packages:
|
|
939
|
-
- ".config/*"
|
|
940
|
-
- "apps/*"
|
|
941
|
-
- "packages/*"
|
|
942
|
-
|
|
943
|
-
onlyBuiltDependencies:
|
|
944
|
-
- esbuild
|
|
945
|
-
`;
|
|
946
|
-
changes.push({
|
|
947
|
-
path: "pnpm-workspace.yaml",
|
|
948
|
-
status: "added",
|
|
949
|
-
newContent
|
|
950
|
-
});
|
|
951
|
-
return changes;
|
|
952
|
-
}
|
|
953
|
-
let updatedContent = currentContent;
|
|
954
|
-
let needsUpdate = false;
|
|
955
|
-
if (!currentContent.includes("manage-package-manager-versions")) {
|
|
956
|
-
updatedContent = `manage-package-manager-versions: true
|
|
957
|
-
|
|
958
|
-
${updatedContent}`;
|
|
959
|
-
needsUpdate = true;
|
|
960
|
-
}
|
|
961
|
-
if (!currentContent.includes("onlyBuiltDependencies")) {
|
|
962
|
-
updatedContent = `${updatedContent.trimEnd()}
|
|
963
|
-
|
|
964
|
-
onlyBuiltDependencies:
|
|
965
|
-
- esbuild
|
|
966
|
-
`;
|
|
967
|
-
needsUpdate = true;
|
|
968
|
-
}
|
|
969
|
-
if (!currentContent.includes(".config/*") && !currentContent.includes('".config/*"')) {
|
|
970
|
-
const lines = updatedContent.split("\n");
|
|
971
|
-
const packagesIndex = lines.findIndex(
|
|
972
|
-
(line) => line.trim().startsWith("packages:")
|
|
973
|
-
);
|
|
974
|
-
if (packagesIndex !== -1) {
|
|
975
|
-
lines.splice(packagesIndex + 1, 0, ' - ".config/*"');
|
|
976
|
-
updatedContent = lines.join("\n");
|
|
977
|
-
needsUpdate = true;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
if (needsUpdate) {
|
|
981
|
-
changes.push({
|
|
982
|
-
path: "pnpm-workspace.yaml",
|
|
983
|
-
status: "modified",
|
|
984
|
-
currentContent,
|
|
985
|
-
newContent: updatedContent
|
|
986
|
-
});
|
|
987
|
-
} else {
|
|
988
|
-
changes.push({
|
|
989
|
-
path: "pnpm-workspace.yaml",
|
|
990
|
-
status: "unchanged",
|
|
991
|
-
currentContent,
|
|
992
|
-
newContent: currentContent
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
return changes;
|
|
996
|
-
}
|
|
997
|
-
async function applyUpdates(changes, root) {
|
|
998
|
-
for (const change of changes) {
|
|
999
|
-
if (change.status === "unchanged") continue;
|
|
1000
|
-
const fullPath = join(root, change.path);
|
|
1001
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
1002
|
-
await writeFile(fullPath, change.newContent);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
function formatFileChange(change) {
|
|
1006
|
-
const icon = change.status === "added" ? "+" : change.status === "modified" ? "~" : "=";
|
|
1007
|
-
return ` ${icon} ${change.path}`;
|
|
1008
|
-
}
|
|
1009
|
-
const LINTER_DEPS = {
|
|
1010
|
-
oxlint: "oxlint",
|
|
1011
|
-
eslint: "eslint",
|
|
1012
|
-
biome: "@biomejs/biome"
|
|
1013
|
-
};
|
|
1014
|
-
const FORMATTER_DEPS = {
|
|
1015
|
-
oxfmt: "oxfmt",
|
|
1016
|
-
prettier: "prettier",
|
|
1017
|
-
biome: "@biomejs/biome"
|
|
1018
|
-
};
|
|
1019
|
-
const LINTER_CONFIG_PACKAGES = {
|
|
1020
|
-
oxlint: "@config/oxlint",
|
|
1021
|
-
eslint: "@config/eslint",
|
|
1022
|
-
biome: null
|
|
1023
|
-
// biome uses root biome.json
|
|
1024
|
-
};
|
|
1025
|
-
const FORMATTER_CONFIG_PACKAGES = {
|
|
1026
|
-
oxfmt: "@config/oxfmt",
|
|
1027
|
-
prettier: "@config/prettier",
|
|
1028
|
-
biome: null
|
|
1029
|
-
// biome uses root biome.json
|
|
1030
|
-
};
|
|
1031
|
-
function needsMigration(current, target) {
|
|
1032
|
-
const linterChange = target.linter && target.linter !== current.linter;
|
|
1033
|
-
const formatterChange = target.formatter && target.formatter !== current.formatter;
|
|
1034
|
-
return linterChange || formatterChange || false;
|
|
1035
|
-
}
|
|
1036
|
-
async function getMigrationPlan(current, target, root) {
|
|
1037
|
-
const toLinter = target.linter ?? current.linter;
|
|
1038
|
-
const toFormatter = target.formatter ?? current.formatter;
|
|
1039
|
-
const changes = [];
|
|
1040
|
-
if (toLinter !== current.linter) {
|
|
1041
|
-
if (current.linter !== "biome") {
|
|
1042
|
-
changes.push({
|
|
1043
|
-
type: "remove-dir",
|
|
1044
|
-
path: `.config/${current.linter}`,
|
|
1045
|
-
description: `Remove @config/${current.linter} package`
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
if (toLinter !== "biome") {
|
|
1049
|
-
const files = {};
|
|
1050
|
-
if (toLinter === "oxlint") {
|
|
1051
|
-
generateOxlintConfigPackage(files);
|
|
1052
|
-
} else if (toLinter === "eslint") {
|
|
1053
|
-
generateEslintConfigPackage(files);
|
|
1054
|
-
}
|
|
1055
|
-
for (const [path, file] of Object.entries(files)) {
|
|
1056
|
-
if (file.type === "text") {
|
|
1057
|
-
changes.push({
|
|
1058
|
-
type: "add-file",
|
|
1059
|
-
path,
|
|
1060
|
-
description: `Add ${path}`,
|
|
1061
|
-
content: file.content
|
|
1062
|
-
});
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
if (toLinter === "biome" && toFormatter === "biome") {
|
|
1067
|
-
changes.push({
|
|
1068
|
-
type: "add-file",
|
|
1069
|
-
path: "biome.json",
|
|
1070
|
-
description: "Add biome.json config",
|
|
1071
|
-
content: JSON.stringify(
|
|
1072
|
-
{
|
|
1073
|
-
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
1074
|
-
vcs: { enabled: true, clientKind: "git", useIgnoreFile: true },
|
|
1075
|
-
linter: { enabled: true, rules: { recommended: true } },
|
|
1076
|
-
formatter: { enabled: true }
|
|
1077
|
-
},
|
|
1078
|
-
null,
|
|
1079
|
-
2
|
|
1080
|
-
)
|
|
1081
|
-
});
|
|
1082
|
-
} else if (toLinter === "biome" && toFormatter !== "biome") {
|
|
1083
|
-
changes.push({
|
|
1084
|
-
type: "add-file",
|
|
1085
|
-
path: "biome.json",
|
|
1086
|
-
description: "Add biome.json config (linter only)",
|
|
1087
|
-
content: JSON.stringify(
|
|
1088
|
-
{
|
|
1089
|
-
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
1090
|
-
vcs: { enabled: true, clientKind: "git", useIgnoreFile: true },
|
|
1091
|
-
linter: { enabled: true, rules: { recommended: true } },
|
|
1092
|
-
formatter: { enabled: false }
|
|
1093
|
-
},
|
|
1094
|
-
null,
|
|
1095
|
-
2
|
|
1096
|
-
)
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
|
-
if (current.linter === "biome" && toLinter !== "biome" && current.formatter !== "biome" && toFormatter !== "biome") {
|
|
1100
|
-
changes.push({
|
|
1101
|
-
type: "remove-file",
|
|
1102
|
-
path: "biome.json",
|
|
1103
|
-
description: "Remove biome.json"
|
|
1104
|
-
});
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
if (toFormatter !== current.formatter) {
|
|
1108
|
-
const formatterSameAsLinter = current.formatter === current.linter;
|
|
1109
|
-
if (current.formatter !== "biome" && !formatterSameAsLinter) {
|
|
1110
|
-
changes.push({
|
|
1111
|
-
type: "remove-dir",
|
|
1112
|
-
path: `.config/${current.formatter}`,
|
|
1113
|
-
description: `Remove @config/${current.formatter} package`
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
const newFormatterSameAsLinter = toFormatter === toLinter;
|
|
1117
|
-
if (toFormatter !== "biome" && !newFormatterSameAsLinter) {
|
|
1118
|
-
const files = {};
|
|
1119
|
-
if (toFormatter === "oxfmt") {
|
|
1120
|
-
generateOxfmtConfigPackage(files);
|
|
1121
|
-
} else if (toFormatter === "prettier") {
|
|
1122
|
-
generatePrettierConfigPackage(files);
|
|
1123
|
-
}
|
|
1124
|
-
for (const [path, file] of Object.entries(files)) {
|
|
1125
|
-
if (file.type === "text") {
|
|
1126
|
-
changes.push({
|
|
1127
|
-
type: "add-file",
|
|
1128
|
-
path,
|
|
1129
|
-
description: `Add ${path}`,
|
|
1130
|
-
content: file.content
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
if (toFormatter === "biome" && toLinter !== "biome") {
|
|
1136
|
-
changes.push({
|
|
1137
|
-
type: "add-file",
|
|
1138
|
-
path: "biome.json",
|
|
1139
|
-
description: "Add biome.json config (formatter only)",
|
|
1140
|
-
content: JSON.stringify(
|
|
1141
|
-
{
|
|
1142
|
-
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
1143
|
-
vcs: { enabled: true, clientKind: "git", useIgnoreFile: true },
|
|
1144
|
-
linter: { enabled: false },
|
|
1145
|
-
formatter: { enabled: true }
|
|
1146
|
-
},
|
|
1147
|
-
null,
|
|
1148
|
-
2
|
|
1149
|
-
)
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
if (current.formatter === "biome" && toFormatter !== "biome" && current.linter !== "biome" && toLinter !== "biome") {
|
|
1153
|
-
changes.push({
|
|
1154
|
-
type: "remove-file",
|
|
1155
|
-
path: "biome.json",
|
|
1156
|
-
description: "Remove biome.json"
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
changes.push({
|
|
1161
|
-
type: "update-package-json",
|
|
1162
|
-
path: "package.json",
|
|
1163
|
-
description: "Update root package.json (devDependencies, scripts)"
|
|
1164
|
-
});
|
|
1165
|
-
const subPackageUpdates = await getSubPackageUpdates(
|
|
1166
|
-
root,
|
|
1167
|
-
current,
|
|
1168
|
-
toLinter,
|
|
1169
|
-
toFormatter
|
|
1170
|
-
);
|
|
1171
|
-
return {
|
|
1172
|
-
fromLinter: current.linter,
|
|
1173
|
-
toLinter,
|
|
1174
|
-
fromFormatter: current.formatter,
|
|
1175
|
-
toFormatter,
|
|
1176
|
-
changes,
|
|
1177
|
-
subPackageUpdates
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
async function getSubPackageUpdates(root, current, toLinter, toFormatter) {
|
|
1181
|
-
const updates = [];
|
|
1182
|
-
const workspacePath = join(root, "pnpm-workspace.yaml");
|
|
1183
|
-
let workspaceContent;
|
|
1184
|
-
try {
|
|
1185
|
-
workspaceContent = await readFile(workspacePath, "utf-8");
|
|
1186
|
-
} catch {
|
|
1187
|
-
return updates;
|
|
1188
|
-
}
|
|
1189
|
-
const packageGlobs = parseWorkspaceYamlContent(workspaceContent);
|
|
1190
|
-
for (const glob of packageGlobs) {
|
|
1191
|
-
if (glob.includes(".config")) continue;
|
|
1192
|
-
const baseDir = glob.replace(/\/\*$/, "").replace(/^["']|["']$/g, "");
|
|
1193
|
-
const basePath = join(root, baseDir);
|
|
1194
|
-
try {
|
|
1195
|
-
const entries = await readdir(basePath, { withFileTypes: true });
|
|
1196
|
-
for (const entry of entries) {
|
|
1197
|
-
if (!entry.isDirectory()) continue;
|
|
1198
|
-
const pkgJsonPath = join(basePath, entry.name, "package.json");
|
|
1199
|
-
try {
|
|
1200
|
-
const content = await readFile(pkgJsonPath, "utf-8");
|
|
1201
|
-
const pkg = JSON.parse(content);
|
|
1202
|
-
const devDeps = pkg.devDependencies ?? {};
|
|
1203
|
-
const remove = [];
|
|
1204
|
-
const add = [];
|
|
1205
|
-
const oldLinterPkg = LINTER_CONFIG_PACKAGES[current.linter];
|
|
1206
|
-
const newLinterPkg = LINTER_CONFIG_PACKAGES[toLinter];
|
|
1207
|
-
if (oldLinterPkg && oldLinterPkg !== newLinterPkg && devDeps[oldLinterPkg]) {
|
|
1208
|
-
remove.push(oldLinterPkg);
|
|
1209
|
-
}
|
|
1210
|
-
if (newLinterPkg && newLinterPkg !== oldLinterPkg && oldLinterPkg && devDeps[oldLinterPkg]) {
|
|
1211
|
-
add.push(newLinterPkg);
|
|
1212
|
-
}
|
|
1213
|
-
if (current.formatter !== current.linter) {
|
|
1214
|
-
const oldFormatterPkg = FORMATTER_CONFIG_PACKAGES[current.formatter];
|
|
1215
|
-
const newFormatterPkg = FORMATTER_CONFIG_PACKAGES[toFormatter];
|
|
1216
|
-
if (oldFormatterPkg && oldFormatterPkg !== newFormatterPkg && devDeps[oldFormatterPkg]) {
|
|
1217
|
-
remove.push(oldFormatterPkg);
|
|
1218
|
-
}
|
|
1219
|
-
if (newFormatterPkg && newFormatterPkg !== oldFormatterPkg && oldFormatterPkg && devDeps[oldFormatterPkg]) {
|
|
1220
|
-
add.push(newFormatterPkg);
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
if (remove.length > 0 || add.length > 0) {
|
|
1224
|
-
updates.push({
|
|
1225
|
-
path: join(baseDir, entry.name, "package.json"),
|
|
1226
|
-
remove,
|
|
1227
|
-
add
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
} catch {
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
} catch {
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
return updates;
|
|
1237
|
-
}
|
|
1238
|
-
async function applyMigration(plan, root) {
|
|
1239
|
-
for (const change of plan.changes) {
|
|
1240
|
-
if (change.type === "remove-dir") {
|
|
1241
|
-
const fullPath = join(root, change.path);
|
|
1242
|
-
try {
|
|
1243
|
-
await rm(fullPath, { recursive: true });
|
|
1244
|
-
} catch {
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
for (const change of plan.changes) {
|
|
1249
|
-
if (change.type === "remove-file") {
|
|
1250
|
-
const fullPath = join(root, change.path);
|
|
1251
|
-
try {
|
|
1252
|
-
await rm(fullPath);
|
|
1253
|
-
} catch {
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
for (const change of plan.changes) {
|
|
1258
|
-
if (change.type === "add-file" && change.content) {
|
|
1259
|
-
const fullPath = join(root, change.path);
|
|
1260
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
1261
|
-
await writeFile(fullPath, change.content);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
await updateRootPackageJson(root, plan);
|
|
1265
|
-
for (const update of plan.subPackageUpdates) {
|
|
1266
|
-
await updateSubPackageJson(root, update);
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
async function updateRootPackageJson(root, plan) {
|
|
1270
|
-
const pkgPath = join(root, "package.json");
|
|
1271
|
-
const content = await readFile(pkgPath, "utf-8");
|
|
1272
|
-
const pkg = JSON.parse(content);
|
|
1273
|
-
const devDeps = pkg.devDependencies ?? {};
|
|
1274
|
-
const oldLinterDep = LINTER_DEPS[plan.fromLinter];
|
|
1275
|
-
delete devDeps[oldLinterDep];
|
|
1276
|
-
if (plan.fromFormatter !== plan.fromLinter) {
|
|
1277
|
-
const oldFormatterDep = FORMATTER_DEPS[plan.fromFormatter];
|
|
1278
|
-
delete devDeps[oldFormatterDep];
|
|
1279
|
-
}
|
|
1280
|
-
const newLinterDep = LINTER_DEPS[plan.toLinter];
|
|
1281
|
-
if (plan.toLinter === "oxlint") {
|
|
1282
|
-
devDeps[newLinterDep] = "^1.36.0";
|
|
1283
|
-
} else if (plan.toLinter === "eslint") {
|
|
1284
|
-
devDeps[newLinterDep] = "^9.17.0";
|
|
1285
|
-
} else if (plan.toLinter === "biome") {
|
|
1286
|
-
devDeps[newLinterDep] = "^1.9.4";
|
|
1287
|
-
}
|
|
1288
|
-
if (plan.toFormatter !== plan.toLinter) {
|
|
1289
|
-
const newFormatterDep = FORMATTER_DEPS[plan.toFormatter];
|
|
1290
|
-
if (plan.toFormatter === "oxfmt") {
|
|
1291
|
-
devDeps[newFormatterDep] = "^0.21.0";
|
|
1292
|
-
} else if (plan.toFormatter === "prettier") {
|
|
1293
|
-
devDeps[newFormatterDep] = "^3.4.2";
|
|
1294
|
-
} else if (plan.toFormatter === "biome") {
|
|
1295
|
-
devDeps[newFormatterDep] = "^1.9.4";
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
pkg.devDependencies = Object.fromEntries(
|
|
1299
|
-
Object.entries(devDeps).sort(([a], [b]) => a.localeCompare(b))
|
|
1300
|
-
);
|
|
1301
|
-
const scripts = pkg.scripts ?? {};
|
|
1302
|
-
if (plan.toLinter === "oxlint") {
|
|
1303
|
-
scripts.lint = "oxlint .";
|
|
1304
|
-
} else if (plan.toLinter === "eslint") {
|
|
1305
|
-
scripts.lint = "eslint .";
|
|
1306
|
-
} else if (plan.toLinter === "biome") {
|
|
1307
|
-
scripts.lint = "biome check .";
|
|
1308
|
-
}
|
|
1309
|
-
if (plan.toFormatter === "oxfmt") {
|
|
1310
|
-
scripts.format = "oxfmt .";
|
|
1311
|
-
} else if (plan.toFormatter === "prettier") {
|
|
1312
|
-
scripts.format = "prettier --write .";
|
|
1313
|
-
} else if (plan.toFormatter === "biome") {
|
|
1314
|
-
scripts.format = "biome format . --write";
|
|
1315
|
-
}
|
|
1316
|
-
pkg.scripts = scripts;
|
|
1317
|
-
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
1318
|
-
}
|
|
1319
|
-
async function updateSubPackageJson(root, update) {
|
|
1320
|
-
const pkgPath = join(root, update.path);
|
|
1321
|
-
const content = await readFile(pkgPath, "utf-8");
|
|
1322
|
-
const pkg = JSON.parse(content);
|
|
1323
|
-
const devDeps = pkg.devDependencies ?? {};
|
|
1324
|
-
for (const dep of update.remove) {
|
|
1325
|
-
delete devDeps[dep];
|
|
1326
|
-
}
|
|
1327
|
-
for (const dep of update.add) {
|
|
1328
|
-
devDeps[dep] = "workspace:*";
|
|
1329
|
-
}
|
|
1330
|
-
pkg.devDependencies = Object.fromEntries(
|
|
1331
|
-
Object.entries(devDeps).sort(([a], [b]) => a.localeCompare(b))
|
|
1332
|
-
);
|
|
1333
|
-
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
1334
|
-
}
|
|
1335
|
-
function formatMigrationChange(change) {
|
|
1336
|
-
const icon = change.type === "remove-dir" || change.type === "remove-file" ? "-" : change.type === "add-file" ? "+" : "~";
|
|
1337
|
-
return ` ${icon} ${change.description}`;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
const require$1 = createRequire(import.meta.url);
|
|
1341
|
-
const pkg = require$1("../package.json");
|
|
1342
|
-
const META_OPTIONS = [
|
|
1343
|
-
"clearConfig",
|
|
1344
|
-
"configPath",
|
|
1345
|
-
"check",
|
|
1346
|
-
"fix",
|
|
1347
|
-
"update",
|
|
1348
|
-
"yes",
|
|
1349
|
-
"workspace",
|
|
1350
|
-
"path",
|
|
1351
|
-
"dir"
|
|
1352
|
-
];
|
|
1353
|
-
function hasConfigOptions(options) {
|
|
1354
|
-
return Object.keys(options).some(
|
|
1355
|
-
(key) => !META_OPTIONS.includes(key)
|
|
1356
|
-
);
|
|
1357
|
-
}
|
|
1358
|
-
async function fileExists(path) {
|
|
1359
|
-
try {
|
|
1360
|
-
await access(path, constants$1.F_OK);
|
|
1361
|
-
return true;
|
|
1362
|
-
} catch {
|
|
1363
|
-
return false;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
async function promptForAiPlatforms(isNonInteractive) {
|
|
1367
|
-
const savedPlatforms = getAiPlatforms();
|
|
1368
|
-
if (isNonInteractive) {
|
|
1369
|
-
return savedPlatforms ?? ALL_AI_PLATFORMS;
|
|
1370
|
-
}
|
|
1371
|
-
if (savedPlatforms && savedPlatforms.length > 0) {
|
|
1372
|
-
const savedLabels = savedPlatforms.map((plat) => AI_PLATFORM_LABELS[plat]).join(", ");
|
|
1373
|
-
const useDefault = await p.confirm({
|
|
1374
|
-
message: `Add AI rules? ${color.dim(`(${savedLabels})`)}`,
|
|
1375
|
-
initialValue: true
|
|
1376
|
-
});
|
|
1377
|
-
if (p.isCancel(useDefault)) {
|
|
1378
|
-
return [];
|
|
1379
|
-
}
|
|
1380
|
-
if (useDefault) {
|
|
1381
|
-
return savedPlatforms;
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
const selected = await p.multiselect({
|
|
1385
|
-
message: "Add AI rules?",
|
|
1386
|
-
options: ALL_AI_PLATFORMS.map((platform) => ({
|
|
1387
|
-
value: platform,
|
|
1388
|
-
label: AI_PLATFORM_LABELS[platform],
|
|
1389
|
-
hint: AI_PLATFORM_HINTS[platform]
|
|
1390
|
-
})),
|
|
1391
|
-
initialValues: [],
|
|
1392
|
-
required: false
|
|
1393
|
-
});
|
|
1394
|
-
if (p.isCancel(selected)) {
|
|
1395
|
-
return [];
|
|
1396
|
-
}
|
|
1397
|
-
const platforms = selected;
|
|
1398
|
-
if (platforms.length === 0) {
|
|
1399
|
-
return [];
|
|
1400
|
-
}
|
|
1401
|
-
const saveChoice = await p.confirm({
|
|
1402
|
-
message: "Save selection for future projects?",
|
|
1403
|
-
initialValue: true
|
|
1404
|
-
});
|
|
1405
|
-
if (!p.isCancel(saveChoice) && saveChoice) {
|
|
1406
|
-
setAiPlatforms(platforms);
|
|
1407
|
-
}
|
|
1408
|
-
return platforms;
|
|
1409
|
-
}
|
|
1410
|
-
async function writeGeneratedFiles(basePath, files) {
|
|
1411
|
-
const filePaths = Object.keys(files).sort();
|
|
1412
|
-
for (const filePath of filePaths) {
|
|
1413
|
-
const fullFilePath = join(basePath, filePath);
|
|
1414
|
-
await mkdir(dirname(fullFilePath), { recursive: true });
|
|
1415
|
-
const file = files[filePath];
|
|
1416
|
-
if (file.type === "text") {
|
|
1417
|
-
await writeFile(fullFilePath, file.content);
|
|
1418
|
-
} else {
|
|
1419
|
-
const response = await fetch(file.url);
|
|
1420
|
-
await writeFile(fullFilePath, response.body);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
function calculateWorkspaceRoot(packagePath) {
|
|
1425
|
-
const segments = packagePath.split(/[/\\]/).filter(Boolean);
|
|
1426
|
-
return segments.map(() => "..").join("/");
|
|
1427
|
-
}
|
|
1428
|
-
async function detectMonorepoRoot() {
|
|
1429
|
-
let currentDir = cwd();
|
|
1430
|
-
const root = resolve("/");
|
|
1431
|
-
while (currentDir !== root) {
|
|
1432
|
-
const workspaceFile = join(currentDir, "pnpm-workspace.yaml");
|
|
1433
|
-
try {
|
|
1434
|
-
await access(workspaceFile, constants$1.F_OK);
|
|
1435
|
-
const content = await readFile(workspaceFile, "utf-8");
|
|
1436
|
-
if (content.includes("packages:")) {
|
|
1437
|
-
return currentDir;
|
|
1438
|
-
}
|
|
1439
|
-
} catch {
|
|
1440
|
-
}
|
|
1441
|
-
currentDir = dirname(currentDir);
|
|
1442
|
-
}
|
|
1443
|
-
return null;
|
|
1444
|
-
}
|
|
1445
|
-
async function parseWorkspaceDirectories(monorepoRoot) {
|
|
1446
|
-
try {
|
|
1447
|
-
const workspaceFile = join(monorepoRoot, "pnpm-workspace.yaml");
|
|
1448
|
-
const content = await readFile(workspaceFile, "utf-8");
|
|
1449
|
-
return parseWorkspaceYamlContent(content);
|
|
1450
|
-
} catch {
|
|
1451
|
-
return [];
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
async function detectWorkspaceSettings(monorepoRoot) {
|
|
1455
|
-
try {
|
|
1456
|
-
const tooling = await detectTooling(monorepoRoot);
|
|
1457
|
-
const pkgPath = join(monorepoRoot, "package.json");
|
|
1458
|
-
const content = await readFile(pkgPath, "utf-8");
|
|
1459
|
-
const pkgJson = JSON.parse(content);
|
|
1460
|
-
let packageManager;
|
|
1461
|
-
if (pkgJson.packageManager) {
|
|
1462
|
-
packageManager = pkgJson.packageManager.split("@")[0];
|
|
1463
|
-
}
|
|
1464
|
-
let nodeVersion;
|
|
1465
|
-
if (pkgJson.engines?.node) {
|
|
1466
|
-
const match = pkgJson.engines.node.match(/(\d+)/);
|
|
1467
|
-
if (match) {
|
|
1468
|
-
nodeVersion = match[1];
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
let pnpmManageVersions;
|
|
1472
|
-
try {
|
|
1473
|
-
const workspaceFile = join(monorepoRoot, "pnpm-workspace.yaml");
|
|
1474
|
-
const workspaceContent = await readFile(workspaceFile, "utf-8");
|
|
1475
|
-
pnpmManageVersions = workspaceContent.includes(
|
|
1476
|
-
"manage-package-manager-versions: true"
|
|
1477
|
-
);
|
|
1478
|
-
} catch {
|
|
1479
|
-
}
|
|
1480
|
-
return {
|
|
1481
|
-
linter: tooling.linter,
|
|
1482
|
-
formatter: tooling.formatter,
|
|
1483
|
-
packageManager,
|
|
1484
|
-
nodeVersion,
|
|
1485
|
-
pnpmManageVersions
|
|
1486
|
-
};
|
|
1487
|
-
} catch {
|
|
1488
|
-
return {};
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
async function detectExistingConfigs(monorepoRoot) {
|
|
1492
|
-
const configs = {};
|
|
1493
|
-
const eslintPath = join(monorepoRoot, "eslint.config.js");
|
|
1494
|
-
if (await fileExists(eslintPath)) {
|
|
1495
|
-
configs.linter = "eslint";
|
|
1496
|
-
configs.eslintConfigPath = eslintPath;
|
|
1497
|
-
}
|
|
1498
|
-
const prettierPath = join(monorepoRoot, ".prettierrc.json");
|
|
1499
|
-
if (await fileExists(prettierPath)) {
|
|
1500
|
-
configs.formatter = "prettier";
|
|
1501
|
-
configs.prettierConfigPath = prettierPath;
|
|
1502
|
-
}
|
|
1503
|
-
const biomePath = join(monorepoRoot, "biome.json");
|
|
1504
|
-
if (await fileExists(biomePath)) {
|
|
1505
|
-
configs.biomeConfigPath = biomePath;
|
|
1506
|
-
if (!configs.linter) configs.linter = "biome";
|
|
1507
|
-
if (!configs.formatter) configs.formatter = "biome";
|
|
1508
|
-
}
|
|
1509
|
-
return configs;
|
|
1510
|
-
}
|
|
1511
|
-
async function getMonorepoScope(monorepoRoot) {
|
|
1512
|
-
try {
|
|
1513
|
-
const pkgPath = join(monorepoRoot, "package.json");
|
|
1514
|
-
const content = await readFile(pkgPath, "utf-8");
|
|
1515
|
-
const pkgJson = JSON.parse(content);
|
|
1516
|
-
if (pkgJson.name) {
|
|
1517
|
-
return pkgJson.name.replace(/^@/, "").replace(/\/.*$/, "");
|
|
1518
|
-
}
|
|
1519
|
-
} catch {
|
|
1520
|
-
}
|
|
1521
|
-
return monorepoRoot.split(/[/\\]/).pop() ?? "workspace";
|
|
1522
|
-
}
|
|
1523
|
-
async function getWorkspacePackages(monorepoRoot) {
|
|
1524
|
-
const packagesDir = join(monorepoRoot, "packages");
|
|
1525
|
-
try {
|
|
1526
|
-
const { readdir } = await import('fs/promises');
|
|
1527
|
-
const entries = await readdir(packagesDir, { withFileTypes: true });
|
|
1528
|
-
const names = [];
|
|
1529
|
-
for (const entry of entries) {
|
|
1530
|
-
if (!entry.isDirectory()) continue;
|
|
1531
|
-
try {
|
|
1532
|
-
const content = await readFile(
|
|
1533
|
-
join(packagesDir, entry.name, "package.json"),
|
|
1534
|
-
"utf-8"
|
|
1535
|
-
);
|
|
1536
|
-
const pkg2 = JSON.parse(content);
|
|
1537
|
-
if (pkg2.name) names.push(pkg2.name);
|
|
1538
|
-
} catch {
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
return names;
|
|
1542
|
-
} catch {
|
|
1543
|
-
return [];
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
async function ensureConfigInWorkspace(monorepoRoot) {
|
|
1547
|
-
const workspacePath = join(monorepoRoot, "pnpm-workspace.yaml");
|
|
1548
|
-
let content;
|
|
1549
|
-
try {
|
|
1550
|
-
content = await readFile(workspacePath, "utf-8");
|
|
1551
|
-
} catch {
|
|
1552
|
-
content = `packages:
|
|
1553
|
-
- ".config/*"
|
|
1554
|
-
- "packages/*"
|
|
1555
|
-
`;
|
|
1556
|
-
await writeFile(workspacePath, content);
|
|
1557
|
-
return;
|
|
1558
|
-
}
|
|
1559
|
-
if (content.includes(".config/*") || content.includes('".config/*"')) {
|
|
1560
|
-
return;
|
|
1561
|
-
}
|
|
1562
|
-
const lines = content.split("\n");
|
|
1563
|
-
const packagesIndex = lines.findIndex(
|
|
1564
|
-
(line) => line.trim().startsWith("packages:")
|
|
1565
|
-
);
|
|
1566
|
-
if (packagesIndex === -1) {
|
|
1567
|
-
content = `packages:
|
|
1568
|
-
- ".config/*"
|
|
1569
|
-
${content}`;
|
|
1570
|
-
} else {
|
|
1571
|
-
lines.splice(packagesIndex + 1, 0, ' - ".config/*"');
|
|
1572
|
-
content = lines.join("\n");
|
|
1573
|
-
}
|
|
1574
|
-
await writeFile(workspacePath, content);
|
|
1575
|
-
}
|
|
1576
|
-
async function migrateEslintConfig(monorepoRoot, files) {
|
|
1577
|
-
const configBasePath = ".config/eslint";
|
|
1578
|
-
const existingConfigPath = join(monorepoRoot, "eslint.config.js");
|
|
1579
|
-
let existingContent;
|
|
1580
|
-
try {
|
|
1581
|
-
existingContent = await readFile(existingConfigPath, "utf-8");
|
|
1582
|
-
} catch {
|
|
1583
|
-
generateEslintConfigPackage(files);
|
|
1584
|
-
return;
|
|
1585
|
-
}
|
|
1586
|
-
files[`${configBasePath}/package.json`] = {
|
|
1587
|
-
type: "text",
|
|
1588
|
-
content: JSON.stringify(
|
|
1589
|
-
{
|
|
1590
|
-
name: "@config/eslint",
|
|
1591
|
-
version: "0.1.0",
|
|
1592
|
-
private: true,
|
|
1593
|
-
type: "module",
|
|
1594
|
-
exports: {
|
|
1595
|
-
"./base": "./base.js",
|
|
1596
|
-
"./react": "./react.js"
|
|
1597
|
-
}
|
|
1598
|
-
},
|
|
1599
|
-
null,
|
|
1600
|
-
2
|
|
1601
|
-
)
|
|
1602
|
-
};
|
|
1603
|
-
files[`${configBasePath}/README.md`] = {
|
|
1604
|
-
type: "text",
|
|
1605
|
-
content: `# \`@config/eslint\`
|
|
1606
|
-
|
|
1607
|
-
Shared ESLint configurations.
|
|
1608
|
-
|
|
1609
|
-
## Usage
|
|
1610
|
-
|
|
1611
|
-
In your package's \`eslint.config.js\`:
|
|
1612
|
-
|
|
1613
|
-
\`\`\`js
|
|
1614
|
-
import base from "@config/eslint/base";
|
|
1615
|
-
|
|
1616
|
-
export default [...base];
|
|
1617
|
-
\`\`\`
|
|
1618
|
-
|
|
1619
|
-
## Available Configs
|
|
1620
|
-
|
|
1621
|
-
- \`base\` - Base ESLint rules (migrated from root)
|
|
1622
|
-
- \`react\` - React-specific rules
|
|
1623
|
-
`
|
|
1624
|
-
};
|
|
1625
|
-
files[`${configBasePath}/base.js`] = {
|
|
1626
|
-
type: "text",
|
|
1627
|
-
content: existingContent
|
|
1628
|
-
};
|
|
1629
|
-
files[`${configBasePath}/react.js`] = {
|
|
1630
|
-
type: "text",
|
|
1631
|
-
content: `import react from "eslint-plugin-react";
|
|
1632
|
-
import reactHooks from "eslint-plugin-react-hooks";
|
|
1633
|
-
|
|
1634
|
-
export default [
|
|
1635
|
-
{
|
|
1636
|
-
plugins: {
|
|
1637
|
-
react,
|
|
1638
|
-
"react-hooks": reactHooks,
|
|
1639
|
-
},
|
|
1640
|
-
rules: {
|
|
1641
|
-
...react.configs.recommended.rules,
|
|
1642
|
-
...reactHooks.configs.recommended.rules,
|
|
1643
|
-
"react/react-in-jsx-scope": "off",
|
|
1644
|
-
},
|
|
1645
|
-
settings: {
|
|
1646
|
-
react: {
|
|
1647
|
-
version: "detect",
|
|
1648
|
-
},
|
|
1649
|
-
},
|
|
1650
|
-
},
|
|
1651
|
-
];
|
|
1652
|
-
`
|
|
1653
|
-
};
|
|
1654
|
-
}
|
|
1655
|
-
async function migratePrettierConfig(monorepoRoot, files) {
|
|
1656
|
-
const configBasePath = ".config/prettier";
|
|
1657
|
-
const existingConfigPath = join(monorepoRoot, ".prettierrc.json");
|
|
1658
|
-
let existingContent;
|
|
1659
|
-
try {
|
|
1660
|
-
existingContent = await readFile(existingConfigPath, "utf-8");
|
|
1661
|
-
} catch {
|
|
1662
|
-
generatePrettierConfigPackage(files);
|
|
1663
|
-
return;
|
|
1664
|
-
}
|
|
1665
|
-
files[`${configBasePath}/package.json`] = {
|
|
1666
|
-
type: "text",
|
|
1667
|
-
content: JSON.stringify(
|
|
1668
|
-
{
|
|
1669
|
-
name: "@config/prettier",
|
|
1670
|
-
version: "0.1.0",
|
|
1671
|
-
private: true,
|
|
1672
|
-
exports: {
|
|
1673
|
-
"./base": "./base.json"
|
|
1674
|
-
}
|
|
1675
|
-
},
|
|
1676
|
-
null,
|
|
1677
|
-
2
|
|
1678
|
-
)
|
|
1679
|
-
};
|
|
1680
|
-
files[`${configBasePath}/README.md`] = {
|
|
1681
|
-
type: "text",
|
|
1682
|
-
content: `# \`@config/prettier\`
|
|
1683
|
-
|
|
1684
|
-
Shared Prettier configurations.
|
|
1685
|
-
|
|
1686
|
-
## Usage
|
|
1687
|
-
|
|
1688
|
-
In your package's \`.prettierrc\`:
|
|
1689
|
-
|
|
1690
|
-
\`\`\`json
|
|
1691
|
-
"@config/prettier/base"
|
|
1692
|
-
\`\`\`
|
|
1693
|
-
|
|
1694
|
-
Or in \`package.json\`:
|
|
1695
|
-
|
|
1696
|
-
\`\`\`json
|
|
1697
|
-
{
|
|
1698
|
-
"prettier": "@config/prettier/base"
|
|
1699
|
-
}
|
|
1700
|
-
\`\`\`
|
|
1701
|
-
|
|
1702
|
-
## Available Configs
|
|
1703
|
-
|
|
1704
|
-
- \`base\` - Base Prettier rules (migrated from root)
|
|
1705
|
-
`
|
|
1706
|
-
};
|
|
1707
|
-
files[`${configBasePath}/base.json`] = {
|
|
1708
|
-
type: "text",
|
|
1709
|
-
content: existingContent
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1712
|
-
async function createPackageInWorkspace(monorepoRoot, packageManager, inheritedSettings, scope) {
|
|
1713
|
-
const workspaceDirectories = await parseWorkspaceDirectories(monorepoRoot);
|
|
1714
|
-
const defaultDirectories = ["apps", "packages"];
|
|
1715
|
-
const hasCustomDirectories = workspaceDirectories.length > 0 && !workspaceDirectories.every((dir) => defaultDirectories.includes(dir));
|
|
1716
|
-
const packageType = await promptForInitialPackage();
|
|
1717
|
-
if (packageType === "skip") {
|
|
1718
|
-
return false;
|
|
1719
|
-
}
|
|
1720
|
-
const defaultDir = packageType === "app" ? "apps" : "packages";
|
|
1721
|
-
const packageNameInput = await p.text({
|
|
1722
|
-
message: "Package name?",
|
|
1723
|
-
initialValue: `@${scope}/`,
|
|
1724
|
-
validate: (value) => {
|
|
1725
|
-
const validationError = validatePackageName(value);
|
|
1726
|
-
if (validationError) return validationError;
|
|
1727
|
-
const dirName = value.includes("/") ? value.split("/").pop() : value;
|
|
1728
|
-
if (!dirName) return "Package name is required";
|
|
1729
|
-
if (!hasCustomDirectories) {
|
|
1730
|
-
const targetPath = join(monorepoRoot, defaultDir, dirName);
|
|
1731
|
-
try {
|
|
1732
|
-
const { statSync } = require$1("fs");
|
|
1733
|
-
statSync(targetPath);
|
|
1734
|
-
return `Directory ${defaultDir}/${dirName} already exists`;
|
|
1735
|
-
} catch {
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
});
|
|
1740
|
-
if (p.isCancel(packageNameInput)) {
|
|
1741
|
-
return false;
|
|
1742
|
-
}
|
|
1743
|
-
const scopedName = packageNameInput;
|
|
1744
|
-
const shortName = scopedName.includes("/") ? scopedName.split("/").pop() : scopedName;
|
|
1745
|
-
const packageOptions = await promptForPackageOptions(
|
|
1746
|
-
scopedName,
|
|
1747
|
-
packageType,
|
|
1748
|
-
inheritedSettings
|
|
1749
|
-
);
|
|
1750
|
-
let targetDir = defaultDir;
|
|
1751
|
-
if (hasCustomDirectories && workspaceDirectories.length > 0) {
|
|
1752
|
-
const dirChoice = await p.select({
|
|
1753
|
-
message: "Target directory",
|
|
1754
|
-
options: workspaceDirectories.map((dir) => ({
|
|
1755
|
-
value: dir,
|
|
1756
|
-
label: dir
|
|
1757
|
-
})),
|
|
1758
|
-
initialValue: workspaceDirectories.includes(defaultDir) ? defaultDir : workspaceDirectories[0]
|
|
1759
|
-
});
|
|
1760
|
-
if (p.isCancel(dirChoice)) {
|
|
1761
|
-
return false;
|
|
1762
|
-
}
|
|
1763
|
-
targetDir = dirChoice;
|
|
1764
|
-
const targetPath = join(monorepoRoot, targetDir, shortName);
|
|
1765
|
-
try {
|
|
1766
|
-
const { statSync } = require$1("fs");
|
|
1767
|
-
statSync(targetPath);
|
|
1768
|
-
p.log.error(`Directory ${targetDir}/${shortName} already exists`);
|
|
1769
|
-
return false;
|
|
1770
|
-
} catch {
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
const relativePkgPath = join(targetDir, shortName);
|
|
1774
|
-
const workspaceRoot = calculateWorkspaceRoot(relativePkgPath);
|
|
1775
|
-
packageOptions.workspaceRoot = workspaceRoot;
|
|
1776
|
-
packageOptions.name = scopedName;
|
|
1777
|
-
if (packageManager === "pnpm") {
|
|
1778
|
-
packageOptions.pnpmVersion = await getLatestPnpmVersion();
|
|
1779
|
-
} else if (packageManager === "yarn") {
|
|
1780
|
-
packageOptions.yarnVersion = await getLatestYarnVersion();
|
|
1781
|
-
} else if (packageManager === "npm") {
|
|
1782
|
-
packageOptions.npmVersion = await getLatestNpmCliVersion();
|
|
1783
|
-
}
|
|
1784
|
-
const nodeVersion = packageOptions.nodeVersion ?? "latest";
|
|
1785
|
-
if (nodeVersion === "latest") {
|
|
1786
|
-
packageOptions.nodeVersion = await getLatestNodeVersion();
|
|
1787
|
-
}
|
|
1788
|
-
const versions = {};
|
|
1789
|
-
const versionPromises = [];
|
|
1790
|
-
const pkgIsLibrary = packageOptions.projectType === "library";
|
|
1791
|
-
const pkgTesting = packageOptions.testing ?? (pkgIsLibrary ? "vitest" : "none");
|
|
1792
|
-
if (pkgTesting === "vitest") {
|
|
1793
|
-
versionPromises.push(
|
|
1794
|
-
getLatestNpmVersion("vitest", "4.0.0").then((v) => {
|
|
1795
|
-
versions.vitest = v;
|
|
1796
|
-
})
|
|
1797
|
-
);
|
|
1798
|
-
}
|
|
1799
|
-
if (!pkgIsLibrary) {
|
|
1800
|
-
versionPromises.push(
|
|
1801
|
-
getLatestNpmVersion("vite", "6.3.4").then((v) => {
|
|
1802
|
-
versions.vite = v;
|
|
1803
|
-
})
|
|
1804
|
-
);
|
|
1805
|
-
}
|
|
1806
|
-
const linter = packageOptions.linter ?? "oxlint";
|
|
1807
|
-
if (linter === "eslint") {
|
|
1808
|
-
versionPromises.push(
|
|
1809
|
-
getLatestNpmVersion("eslint", "9.17.0").then((v) => {
|
|
1810
|
-
versions.eslint = v;
|
|
1811
|
-
})
|
|
1812
|
-
);
|
|
1813
|
-
} else if (linter === "oxlint") {
|
|
1814
|
-
versionPromises.push(
|
|
1815
|
-
getLatestNpmVersion("oxlint", "0.16.0").then((v) => {
|
|
1816
|
-
versions.oxlint = v;
|
|
1817
|
-
})
|
|
1818
|
-
);
|
|
1819
|
-
} else if (linter === "biome") {
|
|
1820
|
-
versionPromises.push(
|
|
1821
|
-
getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
|
|
1822
|
-
versions.biome = v;
|
|
1823
|
-
})
|
|
1824
|
-
);
|
|
1825
|
-
}
|
|
1826
|
-
const formatter = packageOptions.formatter ?? "prettier";
|
|
1827
|
-
if (formatter === "prettier") {
|
|
1828
|
-
versionPromises.push(
|
|
1829
|
-
getLatestNpmVersion("prettier", "3.4.2").then((v) => {
|
|
1830
|
-
versions.prettier = v;
|
|
1831
|
-
})
|
|
1832
|
-
);
|
|
1833
|
-
} else if (formatter === "oxfmt") {
|
|
1834
|
-
versionPromises.push(
|
|
1835
|
-
getLatestNpmVersion("oxfmt", "0.1.0").then((v) => {
|
|
1836
|
-
versions.oxfmt = v;
|
|
1837
|
-
})
|
|
1838
|
-
);
|
|
1839
|
-
} else if (formatter === "biome" && linter !== "biome") {
|
|
1840
|
-
versionPromises.push(
|
|
1841
|
-
getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
|
|
1842
|
-
versions.biome = v;
|
|
1843
|
-
})
|
|
1844
|
-
);
|
|
1845
|
-
}
|
|
1846
|
-
await Promise.all(versionPromises);
|
|
1847
|
-
packageOptions.versions = versions;
|
|
1848
|
-
const workspacePackages = packageType === "app" ? await getWorkspacePackages(monorepoRoot) : [];
|
|
1849
|
-
if (workspacePackages.length > 0) {
|
|
1850
|
-
const selectedDeps = await p.multiselect({
|
|
1851
|
-
message: "Add workspace dependencies?",
|
|
1852
|
-
options: workspacePackages.map((name) => ({ value: name, label: name })),
|
|
1853
|
-
required: false
|
|
1854
|
-
});
|
|
1855
|
-
if (!p.isCancel(selectedDeps) && selectedDeps.length > 0) {
|
|
1856
|
-
packageOptions.workspaceDependencies = selectedDeps;
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
const outputPath = join(monorepoRoot, relativePkgPath);
|
|
1860
|
-
const spinner = p.spinner();
|
|
1861
|
-
spinner.start("Creating package...");
|
|
1862
|
-
try {
|
|
1863
|
-
const files = generate(packageOptions);
|
|
1864
|
-
await writeGeneratedFiles(outputPath, files);
|
|
1865
|
-
spinner.stop(
|
|
1866
|
-
color.green.inverse(` \u2713 Package created at ${relativePkgPath}! `)
|
|
1867
|
-
);
|
|
1868
|
-
const addAnother = await p.select({
|
|
1869
|
-
message: "Add another package?",
|
|
1870
|
-
options: [
|
|
1871
|
-
{ value: "no", label: "No, I'm done" },
|
|
1872
|
-
{ value: "yes", label: "Yes, add another" }
|
|
1873
|
-
],
|
|
1874
|
-
initialValue: "no"
|
|
1875
|
-
});
|
|
1876
|
-
return !p.isCancel(addAnother) && addAnother === "yes";
|
|
1877
|
-
} catch (error) {
|
|
1878
|
-
spinner.stop("Failed to create package");
|
|
1879
|
-
p.log.error(String(error));
|
|
1880
|
-
return false;
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
async function promptAndOpenEditor(projectPath) {
|
|
1884
|
-
const savedEditor = getPreferredEditor();
|
|
1885
|
-
let selectedEditor;
|
|
1886
|
-
if (savedEditor && savedEditor !== "skip") {
|
|
1887
|
-
const useDefault = await p.confirm({
|
|
1888
|
-
message: `Open in editor? ${color.dim(`(${editorNames[savedEditor]})`)}`,
|
|
1889
|
-
initialValue: true
|
|
1890
|
-
});
|
|
1891
|
-
if (p.isCancel(useDefault)) {
|
|
1892
|
-
selectedEditor = void 0;
|
|
1893
|
-
} else if (useDefault) {
|
|
1894
|
-
selectedEditor = savedEditor;
|
|
1895
|
-
} else {
|
|
1896
|
-
selectedEditor = "skip";
|
|
1897
|
-
}
|
|
1898
|
-
} else {
|
|
1899
|
-
const openEditor = await p.select({
|
|
1900
|
-
message: "Open project in editor?",
|
|
1901
|
-
options: [
|
|
1902
|
-
{ value: "skip", label: "Skip" },
|
|
1903
|
-
{ value: "cursor", label: "Cursor" },
|
|
1904
|
-
{ value: "code", label: "VS Code" },
|
|
1905
|
-
{ value: "webstorm", label: "WebStorm" }
|
|
1906
|
-
],
|
|
1907
|
-
initialValue: "skip"
|
|
1908
|
-
});
|
|
1909
|
-
if (!p.isCancel(openEditor)) {
|
|
1910
|
-
selectedEditor = openEditor;
|
|
1911
|
-
const saveChoice = await p.confirm({
|
|
1912
|
-
message: `Save ${editorNames[selectedEditor] ?? "Skip"} as default editor?`,
|
|
1913
|
-
initialValue: true
|
|
1914
|
-
});
|
|
1915
|
-
if (!p.isCancel(saveChoice) && saveChoice) {
|
|
1916
|
-
setPreferredEditor(selectedEditor);
|
|
1917
|
-
if (selectedEditor === "cursor" || selectedEditor === "code") {
|
|
1918
|
-
const reuseChoice = await p.confirm({
|
|
1919
|
-
message: "Reuse current window when opening projects?",
|
|
1920
|
-
initialValue: false
|
|
1921
|
-
});
|
|
1922
|
-
if (!p.isCancel(reuseChoice)) {
|
|
1923
|
-
setReuseWindow(reuseChoice);
|
|
1924
|
-
}
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
if (selectedEditor && selectedEditor !== "skip") {
|
|
1930
|
-
try {
|
|
1931
|
-
await openInEditor(
|
|
1932
|
-
selectedEditor,
|
|
1933
|
-
projectPath,
|
|
1934
|
-
getReuseWindow()
|
|
1935
|
-
);
|
|
1936
|
-
p.log.success(`Opening in ${editorNames[selectedEditor]}...`);
|
|
1937
|
-
} catch {
|
|
1938
|
-
p.log.warn(
|
|
1939
|
-
`Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
|
|
1940
|
-
);
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
async function handleCheckCommand() {
|
|
1945
|
-
const monorepoRoot = await detectMonorepoRoot();
|
|
1946
|
-
if (!monorepoRoot) {
|
|
1947
|
-
console.log(color.red("\u2717") + " Not a monorepo workspace");
|
|
1948
|
-
process.exit(1);
|
|
1949
|
-
}
|
|
1950
|
-
const { valid, errors } = await validateWorkspace(monorepoRoot);
|
|
1951
|
-
if (valid) {
|
|
1952
|
-
console.log(color.green("\u2713") + " Valid monorepo workspace");
|
|
1953
|
-
console.log(color.dim(` ${monorepoRoot}`));
|
|
1954
|
-
} else {
|
|
1955
|
-
console.log(color.red("\u2717") + " Invalid monorepo workspace");
|
|
1956
|
-
console.log(color.dim(` ${monorepoRoot}`));
|
|
1957
|
-
for (const error of errors) {
|
|
1958
|
-
console.log(color.red(` \u2022 ${error}`));
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
process.exit(valid ? 0 : 1);
|
|
1962
|
-
}
|
|
1963
|
-
async function handleFixCommand(options) {
|
|
1964
|
-
const monorepoRoot = await detectMonorepoRoot();
|
|
1965
|
-
if (!monorepoRoot) {
|
|
1966
|
-
console.log(color.red("\u2717") + " Not a monorepo workspace");
|
|
1967
|
-
console.log(color.dim(" Run this command from within a monorepo"));
|
|
1968
|
-
process.exit(1);
|
|
1969
|
-
}
|
|
1970
|
-
const { valid, errors } = await validateWorkspace(monorepoRoot);
|
|
1971
|
-
if (valid) {
|
|
1972
|
-
console.log(color.green("\u2713") + " Workspace is already valid");
|
|
1973
|
-
console.log(color.dim(` ${monorepoRoot}`));
|
|
1974
|
-
process.exit(0);
|
|
1975
|
-
}
|
|
1976
|
-
console.log(color.yellow("!") + " Invalid monorepo workspace");
|
|
1977
|
-
for (const error of errors) {
|
|
1978
|
-
console.log(color.dim(` \u2022 ${error}`));
|
|
1979
|
-
}
|
|
1980
|
-
console.log();
|
|
1981
|
-
const tooling = await detectWorkspaceSettings(monorepoRoot);
|
|
1982
|
-
const existingConfigs = await detectExistingConfigs(monorepoRoot);
|
|
1983
|
-
const detectedLinter = tooling.linter ?? existingConfigs.linter ?? "oxlint";
|
|
1984
|
-
const detectedFormatter = tooling.formatter ?? existingConfigs.formatter ?? "prettier";
|
|
1985
|
-
const isNonInteractive = Boolean(options.linter && options.formatter);
|
|
1986
|
-
let linter;
|
|
1987
|
-
let formatter;
|
|
1988
|
-
if (isNonInteractive) {
|
|
1989
|
-
linter = options.linter;
|
|
1990
|
-
formatter = options.formatter;
|
|
1991
|
-
} else {
|
|
1992
|
-
const linterChoice = await p.select({
|
|
1993
|
-
message: "Linter",
|
|
1994
|
-
options: [
|
|
1995
|
-
{
|
|
1996
|
-
value: "oxlint",
|
|
1997
|
-
label: "oxlint" + (tooling.linter === "oxlint" ? color.dim(" (installed)") : "")
|
|
1998
|
-
},
|
|
1999
|
-
{
|
|
2000
|
-
value: "eslint",
|
|
2001
|
-
label: "eslint" + (tooling.linter === "eslint" || existingConfigs.linter === "eslint" ? color.dim(" (installed)") : "")
|
|
2002
|
-
},
|
|
2003
|
-
{
|
|
2004
|
-
value: "biome",
|
|
2005
|
-
label: "biome" + (tooling.linter === "biome" ? color.dim(" (installed)") : "")
|
|
2006
|
-
}
|
|
2007
|
-
],
|
|
2008
|
-
initialValue: detectedLinter
|
|
2009
|
-
});
|
|
2010
|
-
if (p.isCancel(linterChoice)) {
|
|
2011
|
-
p.cancel("Operation cancelled.");
|
|
2012
|
-
process.exit(0);
|
|
2013
|
-
}
|
|
2014
|
-
const formatterChoice = await p.select({
|
|
2015
|
-
message: "Formatter",
|
|
2016
|
-
options: [
|
|
2017
|
-
{
|
|
2018
|
-
value: "oxfmt",
|
|
2019
|
-
label: "oxfmt" + (tooling.formatter === "oxfmt" ? color.dim(" (installed)") : "")
|
|
2020
|
-
},
|
|
2021
|
-
{
|
|
2022
|
-
value: "prettier",
|
|
2023
|
-
label: "prettier" + (tooling.formatter === "prettier" || existingConfigs.formatter === "prettier" ? color.dim(" (installed)") : "")
|
|
2024
|
-
},
|
|
2025
|
-
{
|
|
2026
|
-
value: "biome",
|
|
2027
|
-
label: "biome" + (tooling.formatter === "biome" ? color.dim(" (installed)") : "")
|
|
2028
|
-
}
|
|
2029
|
-
],
|
|
2030
|
-
initialValue: detectedFormatter
|
|
2031
|
-
});
|
|
2032
|
-
if (p.isCancel(formatterChoice)) {
|
|
2033
|
-
p.cancel("Operation cancelled.");
|
|
2034
|
-
process.exit(0);
|
|
2035
|
-
}
|
|
2036
|
-
linter = linterChoice;
|
|
2037
|
-
formatter = formatterChoice;
|
|
2038
|
-
}
|
|
2039
|
-
console.log();
|
|
2040
|
-
const spinner = p.spinner();
|
|
2041
|
-
spinner.start("Fixing workspace...");
|
|
2042
|
-
try {
|
|
2043
|
-
const files = {};
|
|
2044
|
-
const tsConfigExists = await fileExists(
|
|
2045
|
-
join(monorepoRoot, ".config/typescript/package.json")
|
|
2046
|
-
);
|
|
2047
|
-
if (!tsConfigExists) {
|
|
2048
|
-
generateTypescriptConfigPackage(files);
|
|
2049
|
-
}
|
|
2050
|
-
if (linter === "oxlint") {
|
|
2051
|
-
const oxlintExists = await fileExists(
|
|
2052
|
-
join(monorepoRoot, ".config/oxlint/package.json")
|
|
2053
|
-
);
|
|
2054
|
-
if (!oxlintExists) generateOxlintConfigPackage(files);
|
|
2055
|
-
} else if (linter === "eslint") {
|
|
2056
|
-
const eslintPkgExists = await fileExists(
|
|
2057
|
-
join(monorepoRoot, ".config/eslint/package.json")
|
|
2058
|
-
);
|
|
2059
|
-
if (!eslintPkgExists) {
|
|
2060
|
-
if (existingConfigs.eslintConfigPath) {
|
|
2061
|
-
await migrateEslintConfig(monorepoRoot, files);
|
|
2062
|
-
} else {
|
|
2063
|
-
generateEslintConfigPackage(files);
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
}
|
|
2067
|
-
if (formatter === "oxfmt") {
|
|
2068
|
-
const oxfmtExists = await fileExists(
|
|
2069
|
-
join(monorepoRoot, ".config/oxfmt/package.json")
|
|
2070
|
-
);
|
|
2071
|
-
if (!oxfmtExists) generateOxfmtConfigPackage(files);
|
|
2072
|
-
} else if (formatter === "prettier") {
|
|
2073
|
-
const prettierPkgExists = await fileExists(
|
|
2074
|
-
join(monorepoRoot, ".config/prettier/package.json")
|
|
2075
|
-
);
|
|
2076
|
-
if (!prettierPkgExists) {
|
|
2077
|
-
if (existingConfigs.prettierConfigPath) {
|
|
2078
|
-
await migratePrettierConfig(monorepoRoot, files);
|
|
2079
|
-
} else {
|
|
2080
|
-
generatePrettierConfigPackage(files);
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
if ((linter === "biome" || formatter === "biome") && !existingConfigs.biomeConfigPath) {
|
|
2085
|
-
const biomeConfig = {
|
|
2086
|
-
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
2087
|
-
vcs: {
|
|
2088
|
-
enabled: true,
|
|
2089
|
-
clientKind: "git",
|
|
2090
|
-
useIgnoreFile: true
|
|
2091
|
-
},
|
|
2092
|
-
linter: {
|
|
2093
|
-
enabled: linter === "biome",
|
|
2094
|
-
rules: {
|
|
2095
|
-
recommended: true
|
|
2096
|
-
}
|
|
2097
|
-
},
|
|
2098
|
-
formatter: {
|
|
2099
|
-
enabled: formatter === "biome"
|
|
2100
|
-
}
|
|
2101
|
-
};
|
|
2102
|
-
files["biome.json"] = {
|
|
2103
|
-
type: "text",
|
|
2104
|
-
content: JSON.stringify(biomeConfig, null, 2)
|
|
2105
|
-
};
|
|
2106
|
-
}
|
|
2107
|
-
for (const [filePath, file] of Object.entries(files)) {
|
|
2108
|
-
const fullPath = join(monorepoRoot, filePath);
|
|
2109
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
2110
|
-
await writeFile(fullPath, file.content);
|
|
2111
|
-
}
|
|
2112
|
-
await ensureConfigInWorkspace(monorepoRoot);
|
|
2113
|
-
if (existingConfigs.eslintConfigPath && linter === "eslint") {
|
|
2114
|
-
try {
|
|
2115
|
-
await unlink(existingConfigs.eslintConfigPath);
|
|
2116
|
-
} catch {
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
if (existingConfigs.prettierConfigPath && formatter === "prettier") {
|
|
2120
|
-
try {
|
|
2121
|
-
await unlink(existingConfigs.prettierConfigPath);
|
|
2122
|
-
} catch {
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
spinner.stop(color.green("\u2713") + " Workspace fixed!");
|
|
2126
|
-
const generated = Object.keys(files).filter(
|
|
2127
|
-
(f) => f.endsWith("package.json")
|
|
2128
|
-
);
|
|
2129
|
-
for (const pkgFile of generated) {
|
|
2130
|
-
const pkgName = pkgFile.replace("/package.json", "");
|
|
2131
|
-
console.log(color.dim(` Generated ${pkgName}`));
|
|
2132
|
-
}
|
|
2133
|
-
const vscodeSettingsExists = await fileExists(
|
|
2134
|
-
join(monorepoRoot, ".vscode/settings.json")
|
|
2135
|
-
);
|
|
2136
|
-
const vscodeExtensionsExists = await fileExists(
|
|
2137
|
-
join(monorepoRoot, ".vscode/extensions.json")
|
|
2138
|
-
);
|
|
2139
|
-
const vscodeExists = vscodeSettingsExists && vscodeExtensionsExists;
|
|
2140
|
-
if (!vscodeExists) {
|
|
2141
|
-
let addVscode = false;
|
|
2142
|
-
if (isNonInteractive) {
|
|
2143
|
-
addVscode = true;
|
|
2144
|
-
} else {
|
|
2145
|
-
const vscodeChoice = await p.confirm({
|
|
2146
|
-
message: "Generate VS Code settings?",
|
|
2147
|
-
initialValue: true
|
|
2148
|
-
});
|
|
2149
|
-
addVscode = !p.isCancel(vscodeChoice) && vscodeChoice;
|
|
2150
|
-
}
|
|
2151
|
-
if (addVscode) {
|
|
2152
|
-
const vscodeFiles = {};
|
|
2153
|
-
generateVscodeFiles(vscodeFiles, linter, formatter);
|
|
2154
|
-
for (const [filePath, file] of Object.entries(vscodeFiles)) {
|
|
2155
|
-
const fullPath = join(monorepoRoot, filePath);
|
|
2156
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
2157
|
-
await writeFile(fullPath, file.content);
|
|
2158
|
-
}
|
|
2159
|
-
console.log(color.dim(" Generated .vscode/settings.json"));
|
|
2160
|
-
console.log(color.dim(" Generated .vscode/extensions.json"));
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
const aiRulesExist = await fileExists(
|
|
2164
|
-
join(monorepoRoot, ".ai/workspace.md")
|
|
2165
|
-
);
|
|
2166
|
-
if (!aiRulesExist) {
|
|
2167
|
-
const platforms = await promptForAiPlatforms(isNonInteractive);
|
|
2168
|
-
if (platforms.length > 0) {
|
|
2169
|
-
const scope = await getMonorepoScope(monorepoRoot);
|
|
2170
|
-
const aiFilesOutput = {};
|
|
2171
|
-
generateAiFiles(aiFilesOutput, {
|
|
2172
|
-
name: scope,
|
|
2173
|
-
packageManager: "pnpm",
|
|
2174
|
-
linter,
|
|
2175
|
-
formatter,
|
|
2176
|
-
isMonorepo: true,
|
|
2177
|
-
platforms
|
|
2178
|
-
});
|
|
2179
|
-
for (const [filePath, file] of Object.entries(aiFilesOutput)) {
|
|
2180
|
-
const fullPath = join(monorepoRoot, filePath);
|
|
2181
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
2182
|
-
await writeFile(fullPath, file.content);
|
|
2183
|
-
console.log(color.dim(` Generated ${filePath}`));
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
process.exit(0);
|
|
2188
|
-
} catch (error) {
|
|
2189
|
-
spinner.stop(color.red("\u2717") + " Failed to fix workspace");
|
|
2190
|
-
console.error(error);
|
|
2191
|
-
process.exit(1);
|
|
2192
|
-
}
|
|
2193
|
-
}
|
|
2194
|
-
async function handleMigration(config, target, root, options) {
|
|
2195
|
-
const plan = await getMigrationPlan(config, target, root);
|
|
2196
|
-
console.log(color.cyan("Migration:"));
|
|
2197
|
-
if (plan.fromLinter !== plan.toLinter) {
|
|
2198
|
-
console.log(
|
|
2199
|
-
` Linter: ${color.dim(plan.fromLinter)} \u2192 ${color.green(plan.toLinter)}`
|
|
2200
|
-
);
|
|
2201
|
-
}
|
|
2202
|
-
if (plan.fromFormatter !== plan.toFormatter) {
|
|
2203
|
-
console.log(
|
|
2204
|
-
` Formatter: ${color.dim(plan.fromFormatter)} \u2192 ${color.green(
|
|
2205
|
-
plan.toFormatter
|
|
2206
|
-
)}`
|
|
2207
|
-
);
|
|
2208
|
-
}
|
|
2209
|
-
console.log();
|
|
2210
|
-
console.log(color.cyan("Changes:"));
|
|
2211
|
-
for (const change of plan.changes) {
|
|
2212
|
-
console.log(formatMigrationChange(change));
|
|
2213
|
-
}
|
|
2214
|
-
if (plan.subPackageUpdates.length > 0) {
|
|
2215
|
-
console.log();
|
|
2216
|
-
console.log(color.cyan(`Sub-packages (${plan.subPackageUpdates.length}):`));
|
|
2217
|
-
for (const update of plan.subPackageUpdates) {
|
|
2218
|
-
const changes = [
|
|
2219
|
-
...update.remove.map((d) => `-${d}`),
|
|
2220
|
-
...update.add.map((d) => `+${d}`)
|
|
2221
|
-
].join(", ");
|
|
2222
|
-
console.log(` ~ ${update.path} (${changes})`);
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
console.log();
|
|
2226
|
-
if (!options.yes) {
|
|
2227
|
-
const confirm = await p.confirm({
|
|
2228
|
-
message: "Apply migration?",
|
|
2229
|
-
initialValue: true
|
|
2230
|
-
});
|
|
2231
|
-
if (p.isCancel(confirm) || !confirm) {
|
|
2232
|
-
console.log(color.dim(" Migration cancelled"));
|
|
2233
|
-
process.exit(0);
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
await applyMigration(plan, root);
|
|
2237
|
-
const aiWorkspacePath = join(root, ".ai/workspace.md");
|
|
2238
|
-
const aiRulesExist = await fileExists(aiWorkspacePath);
|
|
2239
|
-
if (aiRulesExist) {
|
|
2240
|
-
console.log();
|
|
2241
|
-
console.log(color.cyan("Updating AI rules..."));
|
|
2242
|
-
const scope = await getMonorepoScope(root);
|
|
2243
|
-
const existingPlatforms = [];
|
|
2244
|
-
if (await fileExists(join(root, "AGENTS.md"))) {
|
|
2245
|
-
existingPlatforms.push("agents");
|
|
2246
|
-
}
|
|
2247
|
-
if (await fileExists(join(root, "CLAUDE.md"))) {
|
|
2248
|
-
existingPlatforms.push("claude");
|
|
2249
|
-
}
|
|
2250
|
-
const aiFilesOutput = {};
|
|
2251
|
-
generateAiFiles(aiFilesOutput, {
|
|
2252
|
-
name: scope,
|
|
2253
|
-
packageManager: "pnpm",
|
|
2254
|
-
linter: plan.toLinter,
|
|
2255
|
-
formatter: plan.toFormatter,
|
|
2256
|
-
isMonorepo: true,
|
|
2257
|
-
platforms: existingPlatforms.length > 0 ? existingPlatforms : ["agents"]
|
|
2258
|
-
});
|
|
2259
|
-
for (const [filePath, file] of Object.entries(aiFilesOutput)) {
|
|
2260
|
-
const fullPath = join(root, filePath);
|
|
2261
|
-
await mkdir(dirname(fullPath), { recursive: true });
|
|
2262
|
-
await writeFile(fullPath, file.content);
|
|
2263
|
-
console.log(color.dim(` ${filePath}`));
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
console.log();
|
|
2267
|
-
console.log(
|
|
2268
|
-
color.green("\u2713") + ` Migrated to ${plan.toLinter}/${plan.toFormatter}`
|
|
2269
|
-
);
|
|
2270
|
-
console.log(color.dim(" Run `pnpm install` to update dependencies"));
|
|
2271
|
-
process.exit(0);
|
|
2272
|
-
}
|
|
2273
|
-
async function handleUpdateCommand(options) {
|
|
2274
|
-
const monorepoRoot = await detectMonorepoRoot();
|
|
2275
|
-
if (!monorepoRoot) {
|
|
2276
|
-
console.log(color.red("\u2717") + " Not a monorepo workspace");
|
|
2277
|
-
console.log(color.dim(" --update only supports pnpm monorepos"));
|
|
2278
|
-
process.exit(1);
|
|
2279
|
-
}
|
|
2280
|
-
const { valid, errors } = await validateWorkspace(monorepoRoot);
|
|
2281
|
-
if (!valid) {
|
|
2282
|
-
console.log(color.yellow("!") + " Workspace has issues:");
|
|
2283
|
-
for (const error of errors) {
|
|
2284
|
-
console.log(color.dim(` \u2022 ${error}`));
|
|
2285
|
-
}
|
|
2286
|
-
console.log();
|
|
2287
|
-
const shouldFix = options.yes || await p.confirm({
|
|
2288
|
-
message: "Run fix first to resolve these issues?",
|
|
2289
|
-
initialValue: true
|
|
2290
|
-
});
|
|
2291
|
-
if (p.isCancel(shouldFix) || !shouldFix) {
|
|
2292
|
-
console.log(
|
|
2293
|
-
color.dim(" Run `pnpm create krispya --fix` to fix manually")
|
|
2294
|
-
);
|
|
2295
|
-
process.exit(1);
|
|
2296
|
-
}
|
|
2297
|
-
const preFixConfig = await detectCurrentConfig(monorepoRoot);
|
|
2298
|
-
const fixOptions = {
|
|
2299
|
-
...options,
|
|
2300
|
-
linter: options.linter ?? preFixConfig.linter,
|
|
2301
|
-
formatter: options.formatter ?? preFixConfig.formatter
|
|
2302
|
-
};
|
|
2303
|
-
await handleFixCommand(fixOptions);
|
|
2304
|
-
}
|
|
2305
|
-
const config = await detectCurrentConfig(monorepoRoot);
|
|
2306
|
-
const targetLinter = options.linter;
|
|
2307
|
-
const targetFormatter = options.formatter;
|
|
2308
|
-
const migrationTarget = { linter: targetLinter, formatter: targetFormatter };
|
|
2309
|
-
if (needsMigration(config, migrationTarget)) {
|
|
2310
|
-
await handleMigration(config, migrationTarget, monorepoRoot, options);
|
|
2311
|
-
return;
|
|
2312
|
-
}
|
|
2313
|
-
console.log(
|
|
2314
|
-
color.cyan("Checking for updates...") + color.dim(` (${config.linter}/${config.formatter})`)
|
|
2315
|
-
);
|
|
2316
|
-
console.log();
|
|
2317
|
-
const expected = generateExpectedFiles(config);
|
|
2318
|
-
const categories = await compareWithDisk(expected, monorepoRoot);
|
|
2319
|
-
const workspaceConfigChanges = await getWorkspaceConfigUpdates(monorepoRoot);
|
|
2320
|
-
const workspaceCategory = {
|
|
2321
|
-
category: "workspace-config",
|
|
2322
|
-
label: "Workspace Config",
|
|
2323
|
-
changes: workspaceConfigChanges,
|
|
2324
|
-
hasUserModifications: workspaceConfigChanges.some(
|
|
2325
|
-
(c) => c.status === "modified"
|
|
2326
|
-
)
|
|
2327
|
-
};
|
|
2328
|
-
const allCategories = categories.filter(
|
|
2329
|
-
(c) => c.category !== "workspace-config"
|
|
2330
|
-
);
|
|
2331
|
-
if (workspaceConfigChanges.length > 0) {
|
|
2332
|
-
const configPkgIndex = allCategories.findIndex(
|
|
2333
|
-
(c) => c.category === "config-packages"
|
|
2334
|
-
);
|
|
2335
|
-
if (configPkgIndex !== -1) {
|
|
2336
|
-
allCategories.splice(configPkgIndex + 1, 0, workspaceCategory);
|
|
2337
|
-
} else {
|
|
2338
|
-
allCategories.push(workspaceCategory);
|
|
2339
|
-
}
|
|
2340
|
-
}
|
|
2341
|
-
let updatedCount = 0;
|
|
2342
|
-
let skippedCount = 0;
|
|
2343
|
-
for (const category of allCategories) {
|
|
2344
|
-
const newChanges = category.changes.filter((c) => c.status === "added");
|
|
2345
|
-
const modifiedChanges = category.changes.filter(
|
|
2346
|
-
(c) => c.status === "modified"
|
|
2347
|
-
);
|
|
2348
|
-
const hasNew = newChanges.length > 0;
|
|
2349
|
-
const hasModified = modifiedChanges.length > 0;
|
|
2350
|
-
const hasChanges = hasNew || hasModified;
|
|
2351
|
-
if (!hasChanges) {
|
|
2352
|
-
console.log(color.green("\u2713") + ` ${category.label}: Up to date`);
|
|
2353
|
-
continue;
|
|
2354
|
-
}
|
|
2355
|
-
if (category.category === "ai-files") {
|
|
2356
|
-
if (hasNew) {
|
|
2357
|
-
console.log(color.cyan(category.label + ":"));
|
|
2358
|
-
console.log(
|
|
2359
|
-
color.dim(` ${newChanges.length} AI file(s) can be added`)
|
|
2360
|
-
);
|
|
2361
|
-
console.log();
|
|
2362
|
-
const applyAi = options.yes ? true : await p.confirm({
|
|
2363
|
-
message: "Add AI rules?",
|
|
2364
|
-
initialValue: true
|
|
2365
|
-
});
|
|
2366
|
-
if (!p.isCancel(applyAi) && applyAi) {
|
|
2367
|
-
await applyUpdates(newChanges, monorepoRoot);
|
|
2368
|
-
console.log(
|
|
2369
|
-
color.green("\u2713") + ` Added ${newChanges.length} AI file(s)`
|
|
2370
|
-
);
|
|
2371
|
-
updatedCount++;
|
|
2372
|
-
} else {
|
|
2373
|
-
console.log(color.dim(` Skipped ${category.label}`));
|
|
2374
|
-
skippedCount++;
|
|
2375
|
-
}
|
|
2376
|
-
}
|
|
2377
|
-
if (hasModified) {
|
|
2378
|
-
console.log(color.cyan("AI Files (existing):"));
|
|
2379
|
-
for (const change of modifiedChanges) {
|
|
2380
|
-
console.log(formatFileChange(change));
|
|
2381
|
-
}
|
|
2382
|
-
console.log();
|
|
2383
|
-
if (options.yes) {
|
|
2384
|
-
console.log(color.dim(" (--yes mode: keeping existing AI files)"));
|
|
2385
|
-
} else {
|
|
2386
|
-
const updateExisting = await p.confirm({
|
|
2387
|
-
message: "Update existing AI files to latest template?",
|
|
2388
|
-
initialValue: false
|
|
2389
|
-
});
|
|
2390
|
-
if (!p.isCancel(updateExisting) && updateExisting) {
|
|
2391
|
-
await applyUpdates(modifiedChanges, monorepoRoot);
|
|
2392
|
-
console.log(color.green("\u2713") + " Updated existing AI files");
|
|
2393
|
-
}
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
console.log();
|
|
2397
|
-
continue;
|
|
2398
|
-
}
|
|
2399
|
-
let changesToApply = [];
|
|
2400
|
-
if (options.yes) {
|
|
2401
|
-
console.log(color.cyan(category.label + ":"));
|
|
2402
|
-
for (const change of [...newChanges, ...modifiedChanges]) {
|
|
2403
|
-
console.log(formatFileChange(change));
|
|
2404
|
-
}
|
|
2405
|
-
console.log();
|
|
2406
|
-
if (category.category === "workspace-config") {
|
|
2407
|
-
changesToApply = [...newChanges, ...modifiedChanges];
|
|
2408
|
-
if (changesToApply.length > 0) {
|
|
2409
|
-
console.log(color.dim(" (--yes mode: applying merge updates)"));
|
|
2410
|
-
}
|
|
2411
|
-
} else {
|
|
2412
|
-
changesToApply = newChanges;
|
|
2413
|
-
if (newChanges.length > 0) {
|
|
2414
|
-
console.log(color.dim(" (--yes mode: adding new files only)"));
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
} else if (hasNew && hasModified) {
|
|
2418
|
-
const allChanges = [...newChanges, ...modifiedChanges];
|
|
2419
|
-
const selectedFiles = await p.multiselect({
|
|
2420
|
-
message: `${category.label} (+ new, ~ changed)`,
|
|
2421
|
-
options: allChanges.map((change) => ({
|
|
2422
|
-
value: change.path,
|
|
2423
|
-
label: change.status === "added" ? `+ ${change.path}` : `~ ${change.path}`
|
|
2424
|
-
})),
|
|
2425
|
-
initialValues: newChanges.map((c) => c.path),
|
|
2426
|
-
// Pre-select new files
|
|
2427
|
-
required: false
|
|
2428
|
-
});
|
|
2429
|
-
if (p.isCancel(selectedFiles)) {
|
|
2430
|
-
p.cancel("Operation cancelled.");
|
|
2431
|
-
process.exit(0);
|
|
2432
|
-
}
|
|
2433
|
-
if (selectedFiles.length > 0) {
|
|
2434
|
-
changesToApply = allChanges.filter(
|
|
2435
|
-
(c) => selectedFiles.includes(c.path)
|
|
2436
|
-
);
|
|
2437
|
-
}
|
|
2438
|
-
} else if (hasNew) {
|
|
2439
|
-
console.log(color.cyan(category.label + ":"));
|
|
2440
|
-
for (const change of newChanges) {
|
|
2441
|
-
console.log(formatFileChange(change));
|
|
2442
|
-
}
|
|
2443
|
-
console.log();
|
|
2444
|
-
const shouldAdd = await p.confirm({
|
|
2445
|
-
message: `Add ${newChanges.length} new file(s)?`,
|
|
2446
|
-
initialValue: true
|
|
2447
|
-
});
|
|
2448
|
-
if (p.isCancel(shouldAdd)) {
|
|
2449
|
-
p.cancel("Operation cancelled.");
|
|
2450
|
-
process.exit(0);
|
|
2451
|
-
}
|
|
2452
|
-
if (shouldAdd) {
|
|
2453
|
-
changesToApply = newChanges;
|
|
2454
|
-
}
|
|
2455
|
-
} else if (hasModified) {
|
|
2456
|
-
console.log(color.cyan(category.label + ":"));
|
|
2457
|
-
for (const change of modifiedChanges) {
|
|
2458
|
-
console.log(formatFileChange(change));
|
|
2459
|
-
}
|
|
2460
|
-
console.log();
|
|
2461
|
-
const shouldUpdate = await p.confirm({
|
|
2462
|
-
message: `Update ${modifiedChanges.length} file(s)? (will overwrite)`,
|
|
2463
|
-
initialValue: false
|
|
2464
|
-
});
|
|
2465
|
-
if (p.isCancel(shouldUpdate)) {
|
|
2466
|
-
p.cancel("Operation cancelled.");
|
|
2467
|
-
process.exit(0);
|
|
2468
|
-
}
|
|
2469
|
-
if (shouldUpdate) {
|
|
2470
|
-
changesToApply = modifiedChanges;
|
|
2471
|
-
}
|
|
2472
|
-
}
|
|
2473
|
-
if (changesToApply.length > 0) {
|
|
2474
|
-
await applyUpdates(changesToApply, monorepoRoot);
|
|
2475
|
-
const addedCount = changesToApply.filter(
|
|
2476
|
-
(c) => c.status === "added"
|
|
2477
|
-
).length;
|
|
2478
|
-
const updatedFilesCount = changesToApply.filter(
|
|
2479
|
-
(c) => c.status === "modified"
|
|
2480
|
-
).length;
|
|
2481
|
-
const parts = [];
|
|
2482
|
-
if (addedCount > 0) parts.push(`added ${addedCount}`);
|
|
2483
|
-
if (updatedFilesCount > 0) parts.push(`updated ${updatedFilesCount}`);
|
|
2484
|
-
console.log(color.green("\u2713") + ` ${category.label}: ${parts.join(", ")}`);
|
|
2485
|
-
updatedCount++;
|
|
2486
|
-
} else {
|
|
2487
|
-
console.log(color.dim(` Skipped ${category.label}`));
|
|
2488
|
-
skippedCount++;
|
|
2489
|
-
}
|
|
2490
|
-
console.log();
|
|
2491
|
-
}
|
|
2492
|
-
if (updatedCount === 0 && skippedCount === 0) {
|
|
2493
|
-
console.log(color.green("\u2713") + " Everything is up to date!");
|
|
2494
|
-
} else if (updatedCount > 0) {
|
|
2495
|
-
console.log(
|
|
2496
|
-
color.green("\u2713") + ` Updated ${updatedCount} ${updatedCount === 1 ? "category" : "categories"}`
|
|
2497
|
-
);
|
|
2498
|
-
if (skippedCount > 0) {
|
|
2499
|
-
console.log(color.dim(` Skipped ${skippedCount}`));
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
process.exit(0);
|
|
2503
|
-
}
|
|
2504
|
-
async function handleWorkspaceCommand(name, options) {
|
|
2505
|
-
const monorepoRoot = await detectMonorepoRoot();
|
|
2506
|
-
if (!monorepoRoot) {
|
|
2507
|
-
console.error(
|
|
2508
|
-
color.red("Error:") + " --workspace flag requires being inside a monorepo"
|
|
2509
|
-
);
|
|
2510
|
-
process.exit(1);
|
|
2511
|
-
}
|
|
2512
|
-
if (!name) {
|
|
2513
|
-
console.error(
|
|
2514
|
-
color.red("Error:") + " Package name is required with --workspace flag"
|
|
2515
|
-
);
|
|
2516
|
-
console.log(
|
|
2517
|
-
color.dim(
|
|
2518
|
-
" Example: pnpm create krispya my-lib --workspace --type library"
|
|
2519
|
-
)
|
|
2520
|
-
);
|
|
2521
|
-
process.exit(1);
|
|
2522
|
-
}
|
|
2523
|
-
const scope = await getMonorepoScope(monorepoRoot);
|
|
2524
|
-
const inheritedSettings = await detectWorkspaceSettings(monorepoRoot);
|
|
2525
|
-
const projectType = options.type ?? "app";
|
|
2526
|
-
const defaultDir = projectType === "library" ? "packages" : "apps";
|
|
2527
|
-
const targetDir = options.dir ?? defaultDir;
|
|
2528
|
-
const template = options.template ?? "vanilla";
|
|
2529
|
-
const baseTemplate = getBaseTemplate(template);
|
|
2530
|
-
const scopedName = name.startsWith("@") ? name : `@${scope}/${name}`;
|
|
2531
|
-
const fullPackagePath = join(monorepoRoot, targetDir, name);
|
|
2532
|
-
try {
|
|
2533
|
-
await access(fullPackagePath, constants$1.F_OK);
|
|
2534
|
-
console.error(
|
|
2535
|
-
color.red("Error:") + ` Directory ${targetDir}/${name} already exists`
|
|
2536
|
-
);
|
|
2537
|
-
process.exit(1);
|
|
2538
|
-
} catch {
|
|
2539
|
-
}
|
|
2540
|
-
const versions = {};
|
|
2541
|
-
const versionPromises = [];
|
|
2542
|
-
const isLibrary = projectType === "library";
|
|
2543
|
-
if (!isLibrary) {
|
|
2544
|
-
versionPromises.push(
|
|
2545
|
-
getLatestNpmVersion("vite", "6.3.4").then((v) => {
|
|
2546
|
-
versions.vite = v;
|
|
2547
|
-
})
|
|
2548
|
-
);
|
|
2549
|
-
}
|
|
2550
|
-
const linter = inheritedSettings.linter ?? options.linter ?? "oxlint";
|
|
2551
|
-
const formatter = inheritedSettings.formatter ?? options.formatter ?? "prettier";
|
|
2552
|
-
const packageManager = inheritedSettings.packageManager ?? "pnpm";
|
|
2553
|
-
const nodeVersion = inheritedSettings.nodeVersion ?? "latest";
|
|
2554
|
-
const pnpmManageVersions = inheritedSettings.pnpmManageVersions ?? true;
|
|
2555
|
-
await Promise.all(versionPromises);
|
|
2556
|
-
const relativePkgPath = join(targetDir, name);
|
|
2557
|
-
const workspaceRoot = calculateWorkspaceRoot(relativePkgPath);
|
|
2558
|
-
const generateOptions = {
|
|
2559
|
-
name: scopedName,
|
|
2560
|
-
projectType,
|
|
2561
|
-
libraryBundler: isLibrary ? options.bundler ?? "unbuild" : void 0,
|
|
2562
|
-
template,
|
|
2563
|
-
linter,
|
|
2564
|
-
formatter,
|
|
2565
|
-
packageManager,
|
|
2566
|
-
nodeVersion,
|
|
2567
|
-
pnpmManageVersions,
|
|
2568
|
-
workspaceRoot,
|
|
2569
|
-
versions,
|
|
2570
|
-
...baseTemplate === "r3f" && {
|
|
2571
|
-
drei: options.drei ? {} : void 0,
|
|
2572
|
-
handle: options.handle ? {} : void 0,
|
|
2573
|
-
leva: options.leva ? {} : void 0,
|
|
2574
|
-
postprocessing: options.postprocessing ? {} : void 0,
|
|
2575
|
-
rapier: options.rapier ? {} : void 0,
|
|
2576
|
-
xr: options.xr ? {} : void 0,
|
|
2577
|
-
uikit: options.uikit ? {} : void 0,
|
|
2578
|
-
offscreen: options.offscreen ? {} : void 0,
|
|
2579
|
-
zustand: options.zustand ? {} : void 0,
|
|
2580
|
-
koota: options.koota ? {} : void 0,
|
|
2581
|
-
viverse: options.viverse ? {} : void 0,
|
|
2582
|
-
triplex: options.triplex ? {} : void 0
|
|
2583
|
-
}
|
|
2584
|
-
};
|
|
2585
|
-
console.log(
|
|
2586
|
-
color.cyan("Creating") + ` ${scopedName} in ${targetDir}/${name}...`
|
|
2587
|
-
);
|
|
2588
|
-
try {
|
|
2589
|
-
const files = generate(generateOptions);
|
|
2590
|
-
await writeGeneratedFiles(fullPackagePath, files);
|
|
2591
|
-
console.log(
|
|
2592
|
-
color.green("\u2713") + ` Created ${scopedName} at ${targetDir}/${name}`
|
|
2593
|
-
);
|
|
2594
|
-
process.exit(0);
|
|
2595
|
-
} catch (error) {
|
|
2596
|
-
console.error(color.red("Error:") + " Failed to create package");
|
|
2597
|
-
console.error(String(error));
|
|
2598
|
-
process.exit(1);
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
async function handleMonorepoCreation(generateOptions, isNonInteractive) {
|
|
2602
|
-
const { generateMonorepo } = await import('./chunks/index.mjs').then(function (n) { return n.w; });
|
|
2603
|
-
const packageManager = generateOptions.packageManager || "pnpm";
|
|
2604
|
-
if (packageManager === "pnpm") {
|
|
2605
|
-
generateOptions.pnpmVersion = await getLatestPnpmVersion();
|
|
2606
|
-
} else if (packageManager === "yarn") {
|
|
2607
|
-
generateOptions.yarnVersion = await getLatestYarnVersion();
|
|
2608
|
-
} else if (packageManager === "npm") {
|
|
2609
|
-
generateOptions.npmVersion = await getLatestNpmCliVersion();
|
|
2610
|
-
}
|
|
2611
|
-
const nodeVersion = generateOptions.nodeVersion ?? "latest";
|
|
2612
|
-
if (nodeVersion === "latest") {
|
|
2613
|
-
generateOptions.nodeVersion = await getLatestNodeVersion();
|
|
2614
|
-
}
|
|
2615
|
-
const aiPlatforms = await promptForAiPlatforms(isNonInteractive);
|
|
2616
|
-
const projectPath = join(cwd(), generateOptions.name);
|
|
2617
|
-
const spinner = p.spinner();
|
|
2618
|
-
spinner.start("Creating monorepo workspace...");
|
|
2619
|
-
try {
|
|
2620
|
-
const { files } = generateMonorepo({
|
|
2621
|
-
name: generateOptions.name,
|
|
2622
|
-
linter: generateOptions.linter ?? "oxlint",
|
|
2623
|
-
formatter: generateOptions.formatter ?? "prettier",
|
|
2624
|
-
packageManager,
|
|
2625
|
-
pnpmVersion: generateOptions.pnpmVersion,
|
|
2626
|
-
pnpmManageVersions: generateOptions.pnpmManageVersions,
|
|
2627
|
-
nodeVersion: generateOptions.nodeVersion,
|
|
2628
|
-
aiPlatforms: aiPlatforms.length > 0 ? aiPlatforms : void 0
|
|
2629
|
-
});
|
|
2630
|
-
const filePaths = Object.keys(files).sort();
|
|
2631
|
-
for (const filePath of filePaths) {
|
|
2632
|
-
const fullFilePath = join(projectPath, filePath);
|
|
2633
|
-
await mkdir(dirname(fullFilePath), { recursive: true });
|
|
2634
|
-
const file = files[filePath];
|
|
2635
|
-
if (file.type === "text") {
|
|
2636
|
-
await writeFile(fullFilePath, file.content);
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
spinner.stop(color.green.inverse(" \u2713 Monorepo workspace created! "));
|
|
2640
|
-
if (isNonInteractive) {
|
|
2641
|
-
process.exit(0);
|
|
2642
|
-
}
|
|
2643
|
-
const newWorkspaceSettings = {
|
|
2644
|
-
linter: generateOptions.linter,
|
|
2645
|
-
formatter: generateOptions.formatter,
|
|
2646
|
-
packageManager,
|
|
2647
|
-
nodeVersion: generateOptions.nodeVersion,
|
|
2648
|
-
pnpmManageVersions: generateOptions.pnpmManageVersions
|
|
2649
|
-
};
|
|
2650
|
-
const scope = generateOptions.name;
|
|
2651
|
-
let addMore = true;
|
|
2652
|
-
while (addMore) {
|
|
2653
|
-
addMore = await createPackageInWorkspace(
|
|
2654
|
-
projectPath,
|
|
2655
|
-
packageManager,
|
|
2656
|
-
newWorkspaceSettings,
|
|
2657
|
-
scope
|
|
2658
|
-
);
|
|
2659
|
-
}
|
|
2660
|
-
const nextSteps = [
|
|
2661
|
-
`cd ${generateOptions.name}`,
|
|
2662
|
-
`${packageManager} install`,
|
|
2663
|
-
`${packageManager} run dev`
|
|
2664
|
-
].join("\n");
|
|
2665
|
-
p.note(nextSteps, "Next steps");
|
|
2666
|
-
await promptAndOpenEditor(projectPath);
|
|
2667
|
-
p.outro(color.green("Happy coding! \u2728"));
|
|
2668
|
-
process.exit(0);
|
|
2669
|
-
} catch (error) {
|
|
2670
|
-
spinner.stop("Failed to create monorepo workspace");
|
|
2671
|
-
p.log.error(String(error));
|
|
2672
|
-
process.exit(1);
|
|
2673
|
-
}
|
|
2674
|
-
}
|
|
2675
|
-
async function handleStandaloneProjectCreation(generateOptions, isNonInteractive) {
|
|
2676
|
-
const base = generateOptions.template ? getBaseTemplate(generateOptions.template) : "vanilla";
|
|
2677
|
-
const defaultFallbackName = base === "vanilla" ? "vanilla-app" : base === "react" ? "react-app" : "react-three-app";
|
|
2678
|
-
generateOptions.name ??= defaultFallbackName;
|
|
2679
|
-
const aiPlatforms = await promptForAiPlatforms(isNonInteractive);
|
|
2680
|
-
if (aiPlatforms.length > 0) {
|
|
2681
|
-
generateOptions.aiPlatforms = aiPlatforms;
|
|
2682
|
-
}
|
|
2683
|
-
const packageManager = generateOptions.packageManager || "pnpm";
|
|
2684
|
-
if (packageManager === "pnpm") {
|
|
2685
|
-
generateOptions.pnpmVersion = await getLatestPnpmVersion();
|
|
2686
|
-
} else if (packageManager === "yarn") {
|
|
2687
|
-
generateOptions.yarnVersion = await getLatestYarnVersion();
|
|
2688
|
-
} else if (packageManager === "npm") {
|
|
2689
|
-
generateOptions.npmVersion = await getLatestNpmCliVersion();
|
|
2690
|
-
}
|
|
2691
|
-
const nodeVersion = generateOptions.nodeVersion ?? "latest";
|
|
2692
|
-
if (nodeVersion === "latest") {
|
|
2693
|
-
generateOptions.nodeVersion = await getLatestNodeVersion();
|
|
2694
|
-
}
|
|
2695
|
-
const versions = {};
|
|
2696
|
-
const versionPromises = [];
|
|
2697
|
-
const isLibrary = generateOptions.projectType === "library";
|
|
2698
|
-
const testing = generateOptions.testing ?? (isLibrary ? "vitest" : "none");
|
|
2699
|
-
if (testing === "vitest") {
|
|
2700
|
-
versionPromises.push(
|
|
2701
|
-
getLatestNpmVersion("vitest", "4.0.0").then((v) => {
|
|
2702
|
-
versions.vitest = v;
|
|
2703
|
-
})
|
|
2704
|
-
);
|
|
2705
|
-
}
|
|
2706
|
-
if (!isLibrary) {
|
|
2707
|
-
versionPromises.push(
|
|
2708
|
-
getLatestNpmVersion("vite", "6.3.4").then((v) => {
|
|
2709
|
-
versions.vite = v;
|
|
2710
|
-
})
|
|
2711
|
-
);
|
|
2712
|
-
}
|
|
2713
|
-
const linter = generateOptions.linter ?? "oxlint";
|
|
2714
|
-
if (linter === "eslint") {
|
|
2715
|
-
versionPromises.push(
|
|
2716
|
-
getLatestNpmVersion("eslint", "9.17.0").then((v) => {
|
|
2717
|
-
versions.eslint = v;
|
|
2718
|
-
})
|
|
2719
|
-
);
|
|
2720
|
-
} else if (linter === "oxlint") {
|
|
2721
|
-
versionPromises.push(
|
|
2722
|
-
getLatestNpmVersion("oxlint", "0.16.0").then((v) => {
|
|
2723
|
-
versions.oxlint = v;
|
|
2724
|
-
})
|
|
2725
|
-
);
|
|
2726
|
-
} else if (linter === "biome") {
|
|
2727
|
-
versionPromises.push(
|
|
2728
|
-
getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
|
|
2729
|
-
versions.biome = v;
|
|
2730
|
-
})
|
|
2731
|
-
);
|
|
2732
|
-
}
|
|
2733
|
-
const formatter = generateOptions.formatter ?? "prettier";
|
|
2734
|
-
if (formatter === "prettier") {
|
|
2735
|
-
versionPromises.push(
|
|
2736
|
-
getLatestNpmVersion("prettier", "3.4.2").then((v) => {
|
|
2737
|
-
versions.prettier = v;
|
|
2738
|
-
})
|
|
2739
|
-
);
|
|
2740
|
-
} else if (formatter === "oxfmt") {
|
|
2741
|
-
versionPromises.push(
|
|
2742
|
-
getLatestNpmVersion("oxfmt", "0.1.0").then((v) => {
|
|
2743
|
-
versions.oxfmt = v;
|
|
2744
|
-
})
|
|
2745
|
-
);
|
|
2746
|
-
} else if (formatter === "biome" && linter !== "biome") {
|
|
2747
|
-
versionPromises.push(
|
|
2748
|
-
getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
|
|
2749
|
-
versions.biome = v;
|
|
2750
|
-
})
|
|
2751
|
-
);
|
|
2752
|
-
}
|
|
2753
|
-
await Promise.all(versionPromises);
|
|
2754
|
-
generateOptions.versions = versions;
|
|
2755
|
-
const projectPath = join(cwd(), generateOptions.name);
|
|
2756
|
-
const spinner = p.spinner();
|
|
2757
|
-
spinner.start("Creating project...");
|
|
2758
|
-
try {
|
|
2759
|
-
const files = generate(generateOptions);
|
|
2760
|
-
await writeGeneratedFiles(projectPath, files);
|
|
2761
|
-
spinner.stop(color.green.inverse(" \u2713 Project created! "));
|
|
2762
|
-
if (isNonInteractive) {
|
|
2763
|
-
process.exit(0);
|
|
2764
|
-
}
|
|
2765
|
-
const nextSteps = isLibrary ? [
|
|
2766
|
-
`cd ${generateOptions.name}`,
|
|
2767
|
-
`${packageManager} install`,
|
|
2768
|
-
`${packageManager} run build`
|
|
2769
|
-
].join("\n") : [
|
|
2770
|
-
`cd ${generateOptions.name}`,
|
|
2771
|
-
`${packageManager} install`,
|
|
2772
|
-
`${packageManager} run dev`
|
|
2773
|
-
].join("\n");
|
|
2774
|
-
p.note(nextSteps, "Next steps");
|
|
2775
|
-
await promptAndOpenEditor(projectPath);
|
|
2776
|
-
p.outro(color.green("Happy coding! \u2728"));
|
|
2777
|
-
} catch (error) {
|
|
2778
|
-
spinner.stop("Failed to create project");
|
|
2779
|
-
p.log.error(String(error));
|
|
2780
|
-
process.exit(1);
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
async function handleInteractiveMonorepoMode(monorepoRoot) {
|
|
2784
|
-
const choice = await p.select({
|
|
2785
|
-
message: "Detected monorepo workspace",
|
|
2786
|
-
options: [
|
|
2787
|
-
{ value: "add", label: "Add new package to this workspace" },
|
|
2788
|
-
{ value: "standalone", label: "Create standalone project" }
|
|
2789
|
-
],
|
|
2790
|
-
initialValue: "add"
|
|
2791
|
-
});
|
|
2792
|
-
if (p.isCancel(choice)) {
|
|
2793
|
-
p.cancel("Operation cancelled.");
|
|
2794
|
-
process.exit(0);
|
|
2795
|
-
}
|
|
2796
|
-
if (choice === "add") {
|
|
2797
|
-
const inheritedSettings = await detectWorkspaceSettings(monorepoRoot);
|
|
2798
|
-
const hasSettings = Object.values(inheritedSettings).some(Boolean);
|
|
2799
|
-
if (hasSettings) {
|
|
2800
|
-
const settingsInfo = [
|
|
2801
|
-
inheritedSettings.linter && `linter: ${inheritedSettings.linter}`,
|
|
2802
|
-
inheritedSettings.formatter && `formatter: ${inheritedSettings.formatter}`,
|
|
2803
|
-
inheritedSettings.packageManager && `pm: ${inheritedSettings.packageManager}`
|
|
2804
|
-
].filter(Boolean).join(", ");
|
|
2805
|
-
p.log.info(`Using workspace settings (${settingsInfo})`);
|
|
2806
|
-
}
|
|
2807
|
-
const scope = await getMonorepoScope(monorepoRoot);
|
|
2808
|
-
let addMore = true;
|
|
2809
|
-
while (addMore) {
|
|
2810
|
-
addMore = await createPackageInWorkspace(
|
|
2811
|
-
monorepoRoot,
|
|
2812
|
-
inheritedSettings.packageManager ?? "pnpm",
|
|
2813
|
-
inheritedSettings,
|
|
2814
|
-
scope
|
|
2815
|
-
);
|
|
2816
|
-
}
|
|
2817
|
-
p.note(
|
|
2818
|
-
[`cd ${monorepoRoot}`, "pnpm install", "pnpm run dev"].join("\n"),
|
|
2819
|
-
"Next steps"
|
|
2820
|
-
);
|
|
2821
|
-
await promptAndOpenEditor(monorepoRoot);
|
|
2822
|
-
p.outro(color.green("Happy coding! \u2728"));
|
|
2823
|
-
process.exit(0);
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
async function main() {
|
|
2827
|
-
const program = new Command().name("create-krispya").description(
|
|
2828
|
-
"CLI for creating Vanilla, React, and React Three Fiber projects"
|
|
2829
|
-
).argument("[name]", "name for the project").option("--type <type>", "project type: app or library (default: app)").option(
|
|
2830
|
-
"--bundler <bundler>",
|
|
2831
|
-
"library bundler: unbuild or tsdown (default: unbuild, only for libraries)"
|
|
2832
|
-
).option(
|
|
2833
|
-
"--template <type>",
|
|
2834
|
-
"project template: vanilla, vanilla-js, react, react-js, r3f, r3f-js (default: vanilla)"
|
|
2835
|
-
).option(
|
|
2836
|
-
"--linter <type>",
|
|
2837
|
-
"linter: eslint, oxlint, or biome (default: oxlint)"
|
|
2838
|
-
).option(
|
|
2839
|
-
"--formatter <type>",
|
|
2840
|
-
"formatter: prettier, oxfmt, or biome (default: prettier)"
|
|
2841
|
-
).option("--drei", "add @react-three/drei (r3f only)").option("--handle", "add @react-three/handle (r3f only)").option("--leva", "add leva (r3f only)").option("--postprocessing", "add @react-three/postprocessing (r3f only)").option("--rapier", "add @react-three/rapier (r3f only)").option("--xr", "add @react-three/xr (r3f only)").option("--uikit", "add @react-three/uikit (r3f only)").option("--offscreen", "add @react-three/offscreen (r3f only)").option("--zustand", "add zustand (r3f only)").option("--koota", "add koota (r3f only)").option("--triplex", "set up triplex development environment (r3f only)").option("--viverse", "set up viverse deployment (r3f only)").option(
|
|
2842
|
-
"--package-manager <manager>",
|
|
2843
|
-
"specify package manager (e.g. npm, yarn, pnpm)"
|
|
2844
|
-
).option(
|
|
2845
|
-
"--pnpm-manage-versions",
|
|
2846
|
-
"enable manage-package-manager-versions in pnpm-workspace.yaml (default: true)"
|
|
2847
|
-
).option(
|
|
2848
|
-
"--no-pnpm-manage-versions",
|
|
2849
|
-
"disable manage-package-manager-versions in pnpm-workspace.yaml"
|
|
2850
|
-
).option(
|
|
2851
|
-
"--node-version <version>",
|
|
2852
|
-
'set Node.js version for engines.node field (default: "latest")'
|
|
2853
|
-
).option(
|
|
2854
|
-
"--workspace",
|
|
2855
|
-
"Add package to current monorepo workspace (non-interactive)"
|
|
2856
|
-
).option(
|
|
2857
|
-
"--dir <directory>",
|
|
2858
|
-
"Target directory for --workspace (default: apps/ or packages/)"
|
|
2859
|
-
).option("--clear-config", "Clear saved preferences (e.g. editor choice)").option("--config-path", "Print the path to the config file").option(
|
|
2860
|
-
"--check",
|
|
2861
|
-
"Check if current directory is in a valid monorepo workspace"
|
|
2862
|
-
).option("--fix", "Fix monorepo by generating missing .config packages").option("--update", "Update monorepo workspace to latest configuration").option("-y, --yes", "Non-interactive mode - accept all prompts").option(
|
|
2863
|
-
"--path <directory>",
|
|
2864
|
-
"Run in specified directory instead of current working directory"
|
|
2865
|
-
).action(async (name, options) => {
|
|
2866
|
-
if (options.path) {
|
|
2867
|
-
process.chdir(options.path);
|
|
2868
|
-
}
|
|
2869
|
-
if (options.clearConfig) {
|
|
2870
|
-
clearConfig();
|
|
2871
|
-
console.log("Configuration cleared.");
|
|
2872
|
-
process.exit(0);
|
|
2873
|
-
}
|
|
2874
|
-
if (options.configPath) {
|
|
2875
|
-
console.log(getConfigPath());
|
|
2876
|
-
process.exit(0);
|
|
2877
|
-
}
|
|
2878
|
-
if (name?.startsWith("-")) {
|
|
2879
|
-
switch (name) {
|
|
2880
|
-
case "--version":
|
|
2881
|
-
case "-V":
|
|
2882
|
-
console.log(pkg.version);
|
|
2883
|
-
process.exit(0);
|
|
2884
|
-
case "--help":
|
|
2885
|
-
case "-h":
|
|
2886
|
-
program.help();
|
|
2887
|
-
break;
|
|
2888
|
-
case "--clear-config":
|
|
2889
|
-
clearConfig();
|
|
2890
|
-
console.log("Configuration cleared.");
|
|
2891
|
-
process.exit(0);
|
|
2892
|
-
case "--config-path":
|
|
2893
|
-
console.log(getConfigPath());
|
|
2894
|
-
process.exit(0);
|
|
2895
|
-
case "--check":
|
|
2896
|
-
await handleCheckCommand();
|
|
2897
|
-
break;
|
|
2898
|
-
case "--fix":
|
|
2899
|
-
options.fix = true;
|
|
2900
|
-
break;
|
|
2901
|
-
case "--update":
|
|
2902
|
-
options.update = true;
|
|
2903
|
-
break;
|
|
2904
|
-
case "--yes":
|
|
2905
|
-
options.yes = true;
|
|
2906
|
-
break;
|
|
2907
|
-
default:
|
|
2908
|
-
console.error(color.red(`Unknown option: ${name}`));
|
|
2909
|
-
process.exit(1);
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
if (options.check) {
|
|
2913
|
-
await handleCheckCommand();
|
|
2914
|
-
}
|
|
2915
|
-
if (options.fix) {
|
|
2916
|
-
await handleFixCommand(options);
|
|
2917
|
-
}
|
|
2918
|
-
if (options.update) {
|
|
2919
|
-
await handleUpdateCommand(options);
|
|
2920
|
-
}
|
|
2921
|
-
if (options.dir && !options.workspace) {
|
|
2922
|
-
console.error(color.red("Error:") + " --dir requires --workspace flag");
|
|
2923
|
-
console.log(
|
|
2924
|
-
color.dim(
|
|
2925
|
-
" Example: pnpm create krispya my-lib --workspace --dir examples"
|
|
2926
|
-
)
|
|
2927
|
-
);
|
|
2928
|
-
process.exit(1);
|
|
2929
|
-
}
|
|
2930
|
-
if (options.workspace) {
|
|
2931
|
-
await handleWorkspaceCommand(name, options);
|
|
2932
|
-
}
|
|
2933
|
-
console.clear();
|
|
2934
|
-
p.intro(color.bgCyan(color.black(` create-krispya v${pkg.version} `)));
|
|
2935
|
-
const monorepoRoot = await detectMonorepoRoot();
|
|
2936
|
-
if (monorepoRoot && !hasConfigOptions(options)) {
|
|
2937
|
-
await handleInteractiveMonorepoMode(monorepoRoot);
|
|
2938
|
-
}
|
|
2939
|
-
let generateOptions;
|
|
2940
|
-
if (options.yes) {
|
|
2941
|
-
const template = options.template ?? "vanilla";
|
|
2942
|
-
const baseTemplate = getBaseTemplate(template);
|
|
2943
|
-
const defaultName = getDefaultProjectName(template);
|
|
2944
|
-
const projectType = options.type ?? "app";
|
|
2945
|
-
generateOptions = {
|
|
2946
|
-
name: name || defaultName,
|
|
2947
|
-
projectType,
|
|
2948
|
-
libraryBundler: projectType === "library" ? options.bundler ?? "unbuild" : void 0,
|
|
2949
|
-
template,
|
|
2950
|
-
linter: options.linter ?? "oxlint",
|
|
2951
|
-
formatter: options.formatter ?? "prettier",
|
|
2952
|
-
...baseTemplate === "r3f" && {
|
|
2953
|
-
drei: options.drei ? {} : void 0,
|
|
2954
|
-
handle: options.handle ? {} : void 0,
|
|
2955
|
-
leva: options.leva ? {} : void 0,
|
|
2956
|
-
postprocessing: options.postprocessing ? {} : void 0,
|
|
2957
|
-
rapier: options.rapier ? {} : void 0,
|
|
2958
|
-
xr: options.xr ? {} : void 0,
|
|
2959
|
-
uikit: options.uikit ? {} : void 0,
|
|
2960
|
-
offscreen: options.offscreen ? {} : void 0,
|
|
2961
|
-
zustand: options.zustand ? {} : void 0,
|
|
2962
|
-
koota: options.koota ? {} : void 0,
|
|
2963
|
-
viverse: options.viverse ? {} : void 0,
|
|
2964
|
-
triplex: options.triplex ? {} : void 0
|
|
2965
|
-
},
|
|
2966
|
-
packageManager: options.packageManager,
|
|
2967
|
-
pnpmManageVersions: options.pnpmManageVersions,
|
|
2968
|
-
nodeVersion: options.nodeVersion ?? "latest"
|
|
2969
|
-
};
|
|
2970
|
-
} else {
|
|
2971
|
-
const presets = hasConfigOptions(options) ? {
|
|
2972
|
-
type: options.type,
|
|
2973
|
-
template: options.template,
|
|
2974
|
-
bundler: options.bundler,
|
|
2975
|
-
linter: options.linter,
|
|
2976
|
-
formatter: options.formatter,
|
|
2977
|
-
packageManager: options.packageManager,
|
|
2978
|
-
nodeVersion: options.nodeVersion,
|
|
2979
|
-
pnpmManageVersions: options.pnpmManageVersions,
|
|
2980
|
-
drei: options.drei,
|
|
2981
|
-
handle: options.handle,
|
|
2982
|
-
leva: options.leva,
|
|
2983
|
-
postprocessing: options.postprocessing,
|
|
2984
|
-
rapier: options.rapier,
|
|
2985
|
-
xr: options.xr,
|
|
2986
|
-
uikit: options.uikit,
|
|
2987
|
-
offscreen: options.offscreen,
|
|
2988
|
-
zustand: options.zustand,
|
|
2989
|
-
koota: options.koota,
|
|
2990
|
-
triplex: options.triplex,
|
|
2991
|
-
viverse: options.viverse
|
|
2992
|
-
} : void 0;
|
|
2993
|
-
generateOptions = await promptForOptions(name, presets);
|
|
2994
|
-
}
|
|
2995
|
-
const isNonInteractive = options.yes ?? false;
|
|
2996
|
-
if (generateOptions.projectType === "monorepo") {
|
|
2997
|
-
await handleMonorepoCreation(generateOptions, isNonInteractive);
|
|
2998
|
-
} else {
|
|
2999
|
-
await handleStandaloneProjectCreation(generateOptions, isNonInteractive);
|
|
3000
|
-
}
|
|
3001
|
-
});
|
|
3002
|
-
await program.parseAsync();
|
|
3003
|
-
}
|
|
3004
|
-
main().catch(console.error);
|