create-krispya 0.5.3 → 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/dist/cli.cjs DELETED
@@ -1,2037 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const module$1 = require('module');
5
- const process$1 = require('process');
6
- const path = require('path');
7
- const promises = require('fs/promises');
8
- const fs = require('fs');
9
- const commander = require('commander');
10
- const p = require('@clack/prompts');
11
- const color = require('chalk');
12
- const undici = require('undici');
13
- const child_process = require('child_process');
14
- const index = require('./chunks/index.cjs');
15
- const Conf = require('conf');
16
-
17
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
18
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
-
20
- function _interopNamespaceCompat(e) {
21
- if (e && typeof e === 'object' && 'default' in e) return e;
22
- const n = Object.create(null);
23
- if (e) {
24
- for (const k in e) {
25
- n[k] = e[k];
26
- }
27
- }
28
- n.default = e;
29
- return n;
30
- }
31
-
32
- const p__namespace = /*#__PURE__*/_interopNamespaceCompat(p);
33
- const color__default = /*#__PURE__*/_interopDefaultCompat(color);
34
- const Conf__default = /*#__PURE__*/_interopDefaultCompat(Conf);
35
-
36
- const editorNames = {
37
- cursor: "Cursor",
38
- code: "VS Code",
39
- webstorm: "WebStorm",
40
- skip: "Skip"
41
- };
42
- function openInEditor(editor, path, reuseWindow) {
43
- return new Promise((resolve, reject) => {
44
- const isWindows = process.platform === "win32";
45
- const useReuseFlag = reuseWindow && (editor === "cursor" || editor === "code");
46
- const args = useReuseFlag ? ["-r", path] : [path];
47
- const child = isWindows ? child_process.spawn(`${editor} ${useReuseFlag ? "-r " : ""}"${path}"`, {
48
- detached: true,
49
- stdio: "ignore",
50
- shell: true
51
- }) : child_process.spawn(editor, args, {
52
- detached: true,
53
- stdio: "ignore"
54
- });
55
- child.on("error", reject);
56
- child.unref();
57
- setTimeout(resolve, 100);
58
- });
59
- }
60
-
61
- function formatConfigSummary(options) {
62
- const lines = [];
63
- const VALUE_COL = 27;
64
- const formatRow = (label, value, indent = "") => {
65
- const fullLabel = indent + label;
66
- const dotCount = Math.max(1, VALUE_COL - fullLabel.length - 1);
67
- const dots = color__default.gray(".".repeat(dotCount));
68
- return `${indent}${label} ${dots} ${value}`;
69
- };
70
- const formatLanguage = (lang) => {
71
- return lang === "typescript" ? "TypeScript" : lang === "javascript" ? "JavaScript" : lang;
72
- };
73
- const projectType = options.projectType ?? "app";
74
- const baseTemplate = options.template ? index.getBaseTemplate(options.template) : "vanilla";
75
- if (baseTemplate === "react") {
76
- lines.push(formatRow("Framework", "React"));
77
- } else if (baseTemplate === "r3f") {
78
- lines.push(formatRow("Framework", "React Three Fiber"));
79
- }
80
- const language = options.template ? index.getLanguageFromTemplate(options.template) : "typescript";
81
- lines.push(formatRow("Language", formatLanguage(language)));
82
- if (projectType === "library") {
83
- lines.push(formatRow("Bundler", options.libraryBundler ?? "unbuild"));
84
- } else {
85
- lines.push(formatRow("Bundler", "vite"));
86
- }
87
- lines.push(formatRow("Node version", options.nodeVersion || "latest"));
88
- lines.push(formatRow("Package manager", options.packageManager || "pnpm"));
89
- if (options.packageManager === "pnpm") {
90
- const versionManaged = options.pnpmManageVersions ? "yes" : "no";
91
- lines.push(formatRow("\u21B3 Version managed", versionManaged, ""));
92
- }
93
- if (options.linter) {
94
- lines.push(formatRow("Linter", options.linter));
95
- }
96
- if (options.formatter) {
97
- lines.push(formatRow("Formatter", options.formatter));
98
- }
99
- const testing = options.testing ?? (projectType === "library" ? "vitest" : "none");
100
- lines.push(formatRow("Testing", testing));
101
- if (options.template && index.getBaseTemplate(options.template) === "r3f") {
102
- const integrationNames = [
103
- options.drei && "drei",
104
- options.handle && "handle",
105
- options.leva && "leva",
106
- options.postprocessing && "postproc",
107
- options.rapier && "rapier",
108
- options.xr && "xr",
109
- options.uikit && "uikit",
110
- options.offscreen && "offscreen",
111
- options.zustand && "zustand",
112
- options.koota && "koota",
113
- options.triplex && "triplex",
114
- options.viverse && "viverse"
115
- ].filter(Boolean);
116
- lines.push("");
117
- lines.push(color__default.dim("Integrations"));
118
- for (let i = 0; i < integrationNames.length; i += 2) {
119
- const left = `${color__default.green("\u25CF")} ${integrationNames[i]}`;
120
- const right = integrationNames[i + 1] ? `${color__default.green("\u25CF")} ${integrationNames[i + 1]}` : "";
121
- const spacing = " ".repeat(Math.max(1, 16 - integrationNames[i].length));
122
- lines.push(` ${left}${spacing}${right}`);
123
- }
124
- }
125
- return lines.join("\n");
126
- }
127
- function formatMonorepoConfigSummary(options) {
128
- const lines = [];
129
- const VALUE_COL = 27;
130
- const formatRow = (label, value, indent = "") => {
131
- const fullLabel = indent + label;
132
- const dotCount = Math.max(1, VALUE_COL - fullLabel.length - 1);
133
- const dots = color__default.gray(".".repeat(dotCount));
134
- return `${indent}${label} ${dots} ${value}`;
135
- };
136
- lines.push(formatRow("Node version", options.nodeVersion || "latest"));
137
- lines.push(formatRow("Package manager", options.packageManager || "pnpm"));
138
- if (options.packageManager === "pnpm") {
139
- const versionManaged = options.pnpmManageVersions ? "yes" : "no";
140
- lines.push(formatRow("\u21B3 Version managed", versionManaged, ""));
141
- }
142
- lines.push(formatRow("Linter", options.linter));
143
- lines.push(formatRow("Formatter", options.formatter));
144
- return lines.join("\n");
145
- }
146
-
147
- const config = new Conf__default({
148
- projectName: "create-krispya"
149
- });
150
- function getPreferredEditor() {
151
- return config.get("preferredEditor");
152
- }
153
- function setPreferredEditor(editor) {
154
- config.set("preferredEditor", editor);
155
- }
156
- function getReuseWindow() {
157
- return config.get("reuseWindow") ?? false;
158
- }
159
- function setReuseWindow(reuse) {
160
- config.set("reuseWindow", reuse);
161
- }
162
- function getAiFiles() {
163
- return config.get("aiFiles");
164
- }
165
- function setAiFiles(files) {
166
- config.set("aiFiles", files);
167
- }
168
- function clearConfig() {
169
- config.clear();
170
- }
171
- function getConfigPath() {
172
- return config.path;
173
- }
174
- function getCustomTemplates() {
175
- return config.get("customTemplates") ?? {};
176
- }
177
-
178
- function getDefaultOptions(template, name, projectType = "app", libraryBundler, integrations, inheritedTooling) {
179
- const baseTemplate = index.getBaseTemplate(template);
180
- const base = {
181
- name,
182
- template,
183
- projectType,
184
- libraryBundler: projectType === "library" ? libraryBundler ?? "unbuild" : void 0,
185
- packageManager: "pnpm",
186
- pnpmManageVersions: true,
187
- nodeVersion: "latest",
188
- linter: inheritedTooling?.linter ?? "oxlint",
189
- formatter: inheritedTooling?.formatter ?? "oxfmt",
190
- // Libraries get vitest by default, apps don't
191
- testing: projectType === "library" ? "vitest" : "none"
192
- };
193
- if (baseTemplate === "r3f" && integrations) {
194
- return {
195
- ...base,
196
- drei: integrations.includes("drei") ? {} : void 0,
197
- handle: integrations.includes("handle") ? {} : void 0,
198
- leva: integrations.includes("leva") ? {} : void 0,
199
- postprocessing: integrations.includes("postprocessing") ? {} : void 0,
200
- rapier: integrations.includes("rapier") ? {} : void 0,
201
- xr: integrations.includes("xr") ? {} : void 0,
202
- uikit: integrations.includes("uikit") ? {} : void 0,
203
- offscreen: integrations.includes("offscreen") ? {} : void 0,
204
- zustand: integrations.includes("zustand") ? {} : void 0,
205
- koota: integrations.includes("koota") ? {} : void 0,
206
- triplex: integrations.includes("triplex") ? {} : void 0,
207
- viverse: integrations.includes("viverse") ? {} : void 0
208
- };
209
- }
210
- return base;
211
- }
212
- function getDefaultProjectName(template) {
213
- const base = index.getBaseTemplate(template);
214
- switch (base) {
215
- case "vanilla":
216
- return `vanilla-${index.generateRandomName()}`;
217
- case "react":
218
- return `react-${index.generateRandomName()}`;
219
- case "r3f":
220
- return `react-three-${index.generateRandomName()}`;
221
- }
222
- }
223
- async function promptForR3fIntegrations() {
224
- const selected = await p__namespace.multiselect({
225
- message: "R3F integrations",
226
- options: [
227
- { value: "drei", label: "Drei" },
228
- { value: "handle", label: "Handle" },
229
- { value: "leva", label: "Leva" },
230
- { value: "postprocessing", label: "Postprocessing" },
231
- { value: "rapier", label: "Rapier" },
232
- { value: "xr", label: "XR" },
233
- { value: "uikit", label: "UIKit" },
234
- { value: "offscreen", label: "Offscreen" },
235
- { value: "zustand", label: "Zustand" },
236
- { value: "koota", label: "Koota" },
237
- { value: "triplex", label: "Triplex" },
238
- { value: "viverse", label: "Viverse" }
239
- ],
240
- initialValues: ["drei"],
241
- required: false
242
- });
243
- if (p__namespace.isCancel(selected)) {
244
- p__namespace.cancel("Operation cancelled.");
245
- process.exit(0);
246
- }
247
- return selected;
248
- }
249
- async function promptForCustomization(template, name, projectType, integrations, inheritedTooling) {
250
- let libraryBundler;
251
- if (projectType === "library") {
252
- const bundler = await p__namespace.select({
253
- message: "Library bundler",
254
- options: [
255
- { value: "unbuild", label: "unbuild", hint: "unjs, simple config" },
256
- { value: "tsdown", label: "tsdown", hint: "fast, esbuild-based" }
257
- ],
258
- initialValue: "unbuild"
259
- });
260
- if (p__namespace.isCancel(bundler)) {
261
- p__namespace.cancel("Operation cancelled.");
262
- process.exit(0);
263
- }
264
- libraryBundler = bundler;
265
- }
266
- const nodeVersion = await p__namespace.text({
267
- message: "Node.js version",
268
- placeholder: "latest",
269
- defaultValue: "latest",
270
- validate: (value) => {
271
- if (!value.length) return "Required";
272
- if (value !== "latest" && !/^\d+(\.\d+(\.\d+)?)?$/.test(value)) {
273
- return 'Must be "latest" or a valid semver (e.g., "22" or "22.13.0")';
274
- }
275
- }
276
- });
277
- if (p__namespace.isCancel(nodeVersion)) {
278
- p__namespace.cancel("Operation cancelled.");
279
- process.exit(0);
280
- }
281
- const packageManager = await p__namespace.select({
282
- message: "Package manager",
283
- options: [
284
- { value: "pnpm", label: "pnpm" },
285
- { value: "npm", label: "npm" },
286
- { value: "yarn", label: "yarn" },
287
- { value: "custom", label: "Other (custom)" }
288
- ],
289
- initialValue: "pnpm"
290
- });
291
- if (p__namespace.isCancel(packageManager)) {
292
- p__namespace.cancel("Operation cancelled.");
293
- process.exit(0);
294
- }
295
- let finalPackageManager = packageManager;
296
- if (packageManager === "custom") {
297
- const customPm = await p__namespace.text({
298
- message: "Enter package manager command",
299
- validate: (value) => {
300
- if (!value.length) return "Required";
301
- }
302
- });
303
- if (p__namespace.isCancel(customPm)) {
304
- p__namespace.cancel("Operation cancelled.");
305
- process.exit(0);
306
- }
307
- finalPackageManager = customPm;
308
- }
309
- let pnpmManageVersions = true;
310
- if (packageManager === "pnpm") {
311
- const managePnpm = await p__namespace.confirm({
312
- message: "Enable manage-package-manager-versions?",
313
- initialValue: true
314
- });
315
- if (p__namespace.isCancel(managePnpm)) {
316
- p__namespace.cancel("Operation cancelled.");
317
- process.exit(0);
318
- }
319
- pnpmManageVersions = managePnpm;
320
- }
321
- let linter = inheritedTooling?.linter ?? "oxlint";
322
- let formatter = inheritedTooling?.formatter ?? "oxfmt";
323
- if (!inheritedTooling?.linter) {
324
- const linterChoice = await p__namespace.select({
325
- message: "Linter",
326
- options: [
327
- { value: "oxlint", label: "Oxlint", hint: "fast, from OXC" },
328
- { value: "eslint", label: "ESLint", hint: "classic" },
329
- { value: "biome", label: "Biome", hint: "all-in-one" }
330
- ],
331
- initialValue: "oxlint"
332
- });
333
- if (p__namespace.isCancel(linterChoice)) {
334
- p__namespace.cancel("Operation cancelled.");
335
- process.exit(0);
336
- }
337
- linter = linterChoice;
338
- }
339
- if (!inheritedTooling?.formatter) {
340
- const formatterChoice = await p__namespace.select({
341
- message: "Formatter",
342
- options: [
343
- { value: "oxfmt", label: "Oxfmt", hint: "fast, Prettier-compatible" },
344
- { value: "prettier", label: "Prettier", hint: "classic" },
345
- { value: "biome", label: "Biome", hint: "all-in-one" }
346
- ],
347
- initialValue: "oxfmt"
348
- });
349
- if (p__namespace.isCancel(formatterChoice)) {
350
- p__namespace.cancel("Operation cancelled.");
351
- process.exit(0);
352
- }
353
- formatter = formatterChoice;
354
- }
355
- const testing = await p__namespace.select({
356
- message: "Testing",
357
- options: [
358
- { value: "vitest", label: "Vitest", hint: "fast, Vite-native" },
359
- { value: "none", label: "None" }
360
- ],
361
- initialValue: projectType === "library" ? "vitest" : "none"
362
- });
363
- if (p__namespace.isCancel(testing)) {
364
- p__namespace.cancel("Operation cancelled.");
365
- process.exit(0);
366
- }
367
- const language = await p__namespace.select({
368
- message: "Language",
369
- options: [
370
- { value: "typescript", label: "TypeScript" },
371
- { value: "javascript", label: "JavaScript" }
372
- ],
373
- initialValue: "typescript"
374
- });
375
- if (p__namespace.isCancel(language)) {
376
- p__namespace.cancel("Operation cancelled.");
377
- process.exit(0);
378
- }
379
- const baseTemplate = index.getBaseTemplate(template);
380
- const finalTemplate = language === "javascript" ? `${baseTemplate}-js` : baseTemplate;
381
- const base = {
382
- name,
383
- template: finalTemplate,
384
- projectType,
385
- libraryBundler: projectType === "library" ? libraryBundler : void 0,
386
- nodeVersion,
387
- packageManager: finalPackageManager,
388
- pnpmManageVersions,
389
- linter,
390
- formatter,
391
- testing
392
- };
393
- if (baseTemplate === "r3f" && integrations) {
394
- return {
395
- ...base,
396
- drei: integrations.includes("drei") ? {} : void 0,
397
- handle: integrations.includes("handle") ? {} : void 0,
398
- leva: integrations.includes("leva") ? {} : void 0,
399
- postprocessing: integrations.includes("postprocessing") ? {} : void 0,
400
- rapier: integrations.includes("rapier") ? {} : void 0,
401
- xr: integrations.includes("xr") ? {} : void 0,
402
- uikit: integrations.includes("uikit") ? {} : void 0,
403
- offscreen: integrations.includes("offscreen") ? {} : void 0,
404
- zustand: integrations.includes("zustand") ? {} : void 0,
405
- koota: integrations.includes("koota") ? {} : void 0,
406
- triplex: integrations.includes("triplex") ? {} : void 0,
407
- viverse: integrations.includes("viverse") ? {} : void 0
408
- };
409
- }
410
- return base;
411
- }
412
- async function promptForInitialPackage() {
413
- const choice = await p__namespace.select({
414
- message: "Add an initial package?",
415
- options: [
416
- { value: "app", label: "Application" },
417
- { value: "library", label: "Library" },
418
- { value: "skip", label: "Skip" }
419
- ],
420
- initialValue: "app"
421
- });
422
- if (p__namespace.isCancel(choice)) {
423
- p__namespace.cancel("Operation cancelled.");
424
- process.exit(0);
425
- }
426
- return choice;
427
- }
428
- function getDefaultMonorepoOptions(name) {
429
- return {
430
- name,
431
- projectType: "monorepo",
432
- packageManager: "pnpm",
433
- pnpmManageVersions: true,
434
- nodeVersion: "latest",
435
- linter: "oxlint",
436
- formatter: "oxfmt"
437
- };
438
- }
439
- async function promptForMonorepoCustomization(name) {
440
- const nodeVersion = await p__namespace.text({
441
- message: "Node.js version",
442
- placeholder: "latest",
443
- defaultValue: "latest",
444
- validate: (value) => {
445
- if (!value.length) return "Required";
446
- if (value !== "latest" && !/^\d+(\.\d+(\.\d+)?)?$/.test(value)) {
447
- return 'Must be "latest" or a valid semver (e.g., "22" or "22.13.0")';
448
- }
449
- }
450
- });
451
- if (p__namespace.isCancel(nodeVersion)) {
452
- p__namespace.cancel("Operation cancelled.");
453
- process.exit(0);
454
- }
455
- const managePnpm = await p__namespace.confirm({
456
- message: "Enable manage-package-manager-versions?",
457
- initialValue: true
458
- });
459
- if (p__namespace.isCancel(managePnpm)) {
460
- p__namespace.cancel("Operation cancelled.");
461
- process.exit(0);
462
- }
463
- const linter = await p__namespace.select({
464
- message: "Linter",
465
- options: [
466
- { value: "oxlint", label: "Oxlint", hint: "fast, from OXC" },
467
- { value: "eslint", label: "ESLint", hint: "classic" },
468
- { value: "biome", label: "Biome", hint: "all-in-one" }
469
- ],
470
- initialValue: "oxlint"
471
- });
472
- if (p__namespace.isCancel(linter)) {
473
- p__namespace.cancel("Operation cancelled.");
474
- process.exit(0);
475
- }
476
- const formatter = await p__namespace.select({
477
- message: "Formatter",
478
- options: [
479
- { value: "oxfmt", label: "Oxfmt", hint: "fast, Prettier-compatible" },
480
- { value: "prettier", label: "Prettier", hint: "classic" },
481
- { value: "biome", label: "Biome", hint: "all-in-one" }
482
- ],
483
- initialValue: "oxfmt"
484
- });
485
- if (p__namespace.isCancel(formatter)) {
486
- p__namespace.cancel("Operation cancelled.");
487
- process.exit(0);
488
- }
489
- return {
490
- name,
491
- projectType: "monorepo",
492
- nodeVersion,
493
- packageManager: "pnpm",
494
- pnpmManageVersions: managePnpm,
495
- linter,
496
- formatter
497
- };
498
- }
499
- async function promptForMonorepo(workspaceName) {
500
- const defaultOptions = getDefaultMonorepoOptions(workspaceName);
501
- p__namespace.note(
502
- formatMonorepoConfigSummary({
503
- name: defaultOptions.name,
504
- nodeVersion: defaultOptions.nodeVersion ?? "latest",
505
- packageManager: defaultOptions.packageManager ?? "pnpm",
506
- pnpmManageVersions: defaultOptions.pnpmManageVersions,
507
- linter: defaultOptions.linter ?? "oxlint",
508
- formatter: defaultOptions.formatter ?? "oxfmt"
509
- }),
510
- "Workspace Configuration"
511
- );
512
- const proceed = await p__namespace.confirm({
513
- message: "Proceed with these settings?",
514
- initialValue: true
515
- });
516
- if (p__namespace.isCancel(proceed)) {
517
- p__namespace.cancel("Operation cancelled.");
518
- process.exit(0);
519
- }
520
- if (proceed) {
521
- return defaultOptions;
522
- }
523
- return promptForMonorepoCustomization(workspaceName);
524
- }
525
- async function promptForOptions(name) {
526
- let projectName = name;
527
- if (!projectName) {
528
- const nameResult = await p__namespace.text({
529
- message: "What is your project named?",
530
- placeholder: index.generateRandomName(),
531
- defaultValue: index.generateRandomName(),
532
- validate: (value) => {
533
- if (!value.length) return "Project name is required";
534
- }
535
- });
536
- if (p__namespace.isCancel(nameResult)) {
537
- p__namespace.cancel("Operation cancelled.");
538
- process.exit(0);
539
- }
540
- projectName = nameResult;
541
- }
542
- const projectType = await p__namespace.select({
543
- message: "Project type",
544
- options: [
545
- { value: "app", label: "Application" },
546
- { value: "library", label: "Library" },
547
- { value: "monorepo", label: "Monorepo" }
548
- ],
549
- initialValue: "app"
550
- });
551
- if (p__namespace.isCancel(projectType)) {
552
- p__namespace.cancel("Operation cancelled.");
553
- process.exit(0);
554
- }
555
- if (projectType === "monorepo") {
556
- return promptForMonorepo(projectName);
557
- }
558
- return promptForPackageOptions(projectName, projectType);
559
- }
560
- function customTemplateToOptions(customTemplate, name, projectType) {
561
- const baseTemplate = customTemplate.baseTemplate;
562
- const template = baseTemplate;
563
- const base = {
564
- name,
565
- template,
566
- projectType,
567
- packageManager: "pnpm",
568
- pnpmManageVersions: true,
569
- nodeVersion: "latest",
570
- linter: customTemplate.linter,
571
- formatter: customTemplate.formatter,
572
- testing: customTemplate.testing
573
- };
574
- if (baseTemplate === "r3f" && customTemplate.integrations) {
575
- const integrations = customTemplate.integrations;
576
- return {
577
- ...base,
578
- drei: integrations.includes("drei") ? {} : void 0,
579
- handle: integrations.includes("handle") ? {} : void 0,
580
- leva: integrations.includes("leva") ? {} : void 0,
581
- postprocessing: integrations.includes("postprocessing") ? {} : void 0,
582
- rapier: integrations.includes("rapier") ? {} : void 0,
583
- xr: integrations.includes("xr") ? {} : void 0,
584
- uikit: integrations.includes("uikit") ? {} : void 0,
585
- offscreen: integrations.includes("offscreen") ? {} : void 0,
586
- zustand: integrations.includes("zustand") ? {} : void 0,
587
- koota: integrations.includes("koota") ? {} : void 0,
588
- triplex: integrations.includes("triplex") ? {} : void 0,
589
- viverse: integrations.includes("viverse") ? {} : void 0
590
- };
591
- }
592
- return base;
593
- }
594
- async function promptForPackageOptions(projectName, projectType, inheritedTooling) {
595
- const builtInOptions = [
596
- { value: "vanilla", label: "Vanilla" },
597
- { value: "react", label: "React" },
598
- { value: "r3f", label: "React Three Fiber" }
599
- ];
600
- const customTemplates = getCustomTemplates();
601
- const customOptions = Object.keys(customTemplates).map((name) => ({
602
- value: `custom:${name}`,
603
- label: name,
604
- hint: "saved template"
605
- }));
606
- const allOptions = [...builtInOptions, ...customOptions];
607
- const templateSelection = await p__namespace.select({
608
- message: "Select a template",
609
- options: allOptions,
610
- initialValue: "vanilla"
611
- });
612
- if (p__namespace.isCancel(templateSelection)) {
613
- p__namespace.cancel("Operation cancelled.");
614
- process.exit(0);
615
- }
616
- const selection = templateSelection;
617
- if (selection.startsWith("custom:")) {
618
- const customName = selection.slice(7);
619
- const customTemplate = customTemplates[customName];
620
- const defaultOptions2 = customTemplateToOptions(customTemplate, projectName, projectType);
621
- if (inheritedTooling?.linter) {
622
- defaultOptions2.linter = inheritedTooling.linter;
623
- }
624
- if (inheritedTooling?.formatter) {
625
- defaultOptions2.formatter = inheritedTooling.formatter;
626
- }
627
- const configTitle2 = inheritedTooling ? `Template: ${customName} (using workspace tooling)` : `Template: ${customName}`;
628
- p__namespace.note(formatConfigSummary(defaultOptions2), configTitle2);
629
- const proceed2 = await p__namespace.confirm({
630
- message: "Proceed with these settings?",
631
- initialValue: true
632
- });
633
- if (p__namespace.isCancel(proceed2)) {
634
- p__namespace.cancel("Operation cancelled.");
635
- process.exit(0);
636
- }
637
- if (proceed2) {
638
- return defaultOptions2;
639
- }
640
- return promptForCustomization(
641
- customTemplate.baseTemplate,
642
- projectName,
643
- projectType,
644
- customTemplate.integrations,
645
- inheritedTooling
646
- );
647
- }
648
- const template = selection;
649
- const baseTemplate = index.getBaseTemplate(template);
650
- let integrations;
651
- if (baseTemplate === "r3f") {
652
- integrations = await promptForR3fIntegrations();
653
- }
654
- const defaultOptions = getDefaultOptions(
655
- template,
656
- projectName,
657
- projectType,
658
- void 0,
659
- integrations,
660
- inheritedTooling
661
- );
662
- const configTitle = inheritedTooling ? "Template Configuration (using workspace tooling)" : "Template Configuration";
663
- p__namespace.note(formatConfigSummary(defaultOptions), configTitle);
664
- const proceed = await p__namespace.confirm({
665
- message: "Proceed with these settings?",
666
- initialValue: true
667
- });
668
- if (p__namespace.isCancel(proceed)) {
669
- p__namespace.cancel("Operation cancelled.");
670
- process.exit(0);
671
- }
672
- if (proceed) {
673
- return defaultOptions;
674
- }
675
- return promptForCustomization(template, projectName, projectType, integrations, inheritedTooling);
676
- }
677
-
678
- async function checkAnyExists(paths) {
679
- for (const path of paths) {
680
- try {
681
- await promises.access(path, promises.constants.F_OK);
682
- return true;
683
- } catch {
684
- }
685
- }
686
- return false;
687
- }
688
- async function validateWorkspace(monorepoRoot) {
689
- const errors = [];
690
- const tsConfigPath = path.join(monorepoRoot, ".config/typescript/package.json");
691
- try {
692
- await promises.access(tsConfigPath, promises.constants.F_OK);
693
- } catch {
694
- errors.push("Missing .config/typescript package");
695
- }
696
- const linterPaths = [
697
- path.join(monorepoRoot, ".config/oxlint/package.json"),
698
- path.join(monorepoRoot, ".config/eslint/package.json"),
699
- path.join(monorepoRoot, "eslint.config.js"),
700
- path.join(monorepoRoot, "biome.json")
701
- ];
702
- const hasLinter = await checkAnyExists(linterPaths);
703
- if (!hasLinter) {
704
- errors.push(
705
- "Missing linter config (.config/oxlint, .config/eslint, eslint.config.js, or biome.json)"
706
- );
707
- }
708
- const formatterPaths = [
709
- path.join(monorepoRoot, ".config/oxfmt/package.json"),
710
- path.join(monorepoRoot, ".config/prettier/package.json"),
711
- path.join(monorepoRoot, ".prettierrc.json"),
712
- path.join(monorepoRoot, "biome.json")
713
- ];
714
- const hasFormatter = await checkAnyExists(formatterPaths);
715
- if (!hasFormatter) {
716
- errors.push(
717
- "Missing formatter config (.config/oxfmt, .config/prettier, .prettierrc.json, or biome.json)"
718
- );
719
- }
720
- return { valid: errors.length === 0, errors };
721
- }
722
-
723
- const require$1 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
724
- const pkg = require$1("../package.json");
725
- async function fileExists(path) {
726
- try {
727
- await promises.access(path, fs.constants.F_OK);
728
- return true;
729
- } catch {
730
- return false;
731
- }
732
- }
733
- async function writeGeneratedFiles(basePath, files) {
734
- const filePaths = Object.keys(files).sort();
735
- for (const filePath of filePaths) {
736
- const fullFilePath = path.join(basePath, filePath);
737
- await promises.mkdir(path.dirname(fullFilePath), { recursive: true });
738
- const file = files[filePath];
739
- if (file.type === "text") {
740
- await promises.writeFile(fullFilePath, file.content);
741
- } else {
742
- const response = await undici.fetch(file.url);
743
- await promises.writeFile(fullFilePath, response.body);
744
- }
745
- }
746
- }
747
- function calculateWorkspaceRoot(packagePath) {
748
- const segments = packagePath.split(/[/\\]/).filter(Boolean);
749
- return segments.map(() => "..").join("/");
750
- }
751
- async function detectMonorepoRoot() {
752
- let currentDir = process$1.cwd();
753
- const root = path.resolve("/");
754
- while (currentDir !== root) {
755
- const workspaceFile = path.join(currentDir, "pnpm-workspace.yaml");
756
- try {
757
- await promises.access(workspaceFile, fs.constants.F_OK);
758
- const content = await promises.readFile(workspaceFile, "utf-8");
759
- if (content.includes("packages:")) {
760
- return currentDir;
761
- }
762
- } catch {
763
- }
764
- currentDir = path.dirname(currentDir);
765
- }
766
- return null;
767
- }
768
- async function parseWorkspaceDirectories(monorepoRoot) {
769
- try {
770
- const workspaceFile = path.join(monorepoRoot, "pnpm-workspace.yaml");
771
- const content = await promises.readFile(workspaceFile, "utf-8");
772
- return index.parseWorkspaceYamlContent(content);
773
- } catch {
774
- return [];
775
- }
776
- }
777
- async function detectWorkspaceTooling(monorepoRoot) {
778
- try {
779
- const pkgPath = path.join(monorepoRoot, "package.json");
780
- const content = await promises.readFile(pkgPath, "utf-8");
781
- const pkgJson = JSON.parse(content);
782
- const devDeps = pkgJson.devDependencies ?? {};
783
- const linter = devDeps.oxlint ? "oxlint" : devDeps.eslint ? "eslint" : devDeps["@biomejs/biome"] ? "biome" : void 0;
784
- const formatter = devDeps.oxfmt ? "oxfmt" : devDeps.prettier ? "prettier" : devDeps["@biomejs/biome"] ? "biome" : void 0;
785
- return { linter, formatter };
786
- } catch {
787
- return {};
788
- }
789
- }
790
- async function detectExistingConfigs(monorepoRoot) {
791
- const configs = {};
792
- const eslintPath = path.join(monorepoRoot, "eslint.config.js");
793
- if (await fileExists(eslintPath)) {
794
- configs.linter = "eslint";
795
- configs.eslintConfigPath = eslintPath;
796
- }
797
- const prettierPath = path.join(monorepoRoot, ".prettierrc.json");
798
- if (await fileExists(prettierPath)) {
799
- configs.formatter = "prettier";
800
- configs.prettierConfigPath = prettierPath;
801
- }
802
- const biomePath = path.join(monorepoRoot, "biome.json");
803
- if (await fileExists(biomePath)) {
804
- configs.biomeConfigPath = biomePath;
805
- if (!configs.linter) configs.linter = "biome";
806
- if (!configs.formatter) configs.formatter = "biome";
807
- }
808
- return configs;
809
- }
810
- async function getMonorepoScope(monorepoRoot) {
811
- try {
812
- const pkgPath = path.join(monorepoRoot, "package.json");
813
- const content = await promises.readFile(pkgPath, "utf-8");
814
- const pkgJson = JSON.parse(content);
815
- if (pkgJson.name) {
816
- return pkgJson.name.replace(/^@/, "").replace(/\/.*$/, "");
817
- }
818
- } catch {
819
- }
820
- return monorepoRoot.split(/[/\\]/).pop() ?? "workspace";
821
- }
822
- async function getWorkspacePackages(monorepoRoot) {
823
- const packagesDir = path.join(monorepoRoot, "packages");
824
- try {
825
- const { readdir } = await import('fs/promises');
826
- const entries = await readdir(packagesDir, { withFileTypes: true });
827
- const names = [];
828
- for (const entry of entries) {
829
- if (!entry.isDirectory()) continue;
830
- try {
831
- const content = await promises.readFile(
832
- path.join(packagesDir, entry.name, "package.json"),
833
- "utf-8"
834
- );
835
- const pkg2 = JSON.parse(content);
836
- if (pkg2.name) names.push(pkg2.name);
837
- } catch {
838
- }
839
- }
840
- return names;
841
- } catch {
842
- return [];
843
- }
844
- }
845
- async function ensureConfigInWorkspace(monorepoRoot) {
846
- const workspacePath = path.join(monorepoRoot, "pnpm-workspace.yaml");
847
- let content;
848
- try {
849
- content = await promises.readFile(workspacePath, "utf-8");
850
- } catch {
851
- content = `packages:
852
- - ".config/*"
853
- - "packages/*"
854
- `;
855
- await promises.writeFile(workspacePath, content);
856
- return;
857
- }
858
- if (content.includes(".config/*") || content.includes('".config/*"')) {
859
- return;
860
- }
861
- const lines = content.split("\n");
862
- const packagesIndex = lines.findIndex(
863
- (line) => line.trim().startsWith("packages:")
864
- );
865
- if (packagesIndex === -1) {
866
- content = `packages:
867
- - ".config/*"
868
- ${content}`;
869
- } else {
870
- lines.splice(packagesIndex + 1, 0, ' - ".config/*"');
871
- content = lines.join("\n");
872
- }
873
- await promises.writeFile(workspacePath, content);
874
- }
875
- async function migrateEslintConfig(monorepoRoot, files) {
876
- const configBasePath = ".config/eslint";
877
- const existingConfigPath = path.join(monorepoRoot, "eslint.config.js");
878
- let existingContent;
879
- try {
880
- existingContent = await promises.readFile(existingConfigPath, "utf-8");
881
- } catch {
882
- index.generateEslintConfigPackage(files);
883
- return;
884
- }
885
- files[`${configBasePath}/package.json`] = {
886
- type: "text",
887
- content: JSON.stringify(
888
- {
889
- name: "@config/eslint",
890
- version: "0.1.0",
891
- private: true,
892
- type: "module",
893
- exports: {
894
- "./base": "./base.js",
895
- "./react": "./react.js"
896
- }
897
- },
898
- null,
899
- 2
900
- )
901
- };
902
- files[`${configBasePath}/README.md`] = {
903
- type: "text",
904
- content: `# \`@config/eslint\`
905
-
906
- Shared ESLint configurations.
907
-
908
- ## Usage
909
-
910
- In your package's \`eslint.config.js\`:
911
-
912
- \`\`\`js
913
- import base from "@config/eslint/base";
914
-
915
- export default [...base];
916
- \`\`\`
917
-
918
- ## Available Configs
919
-
920
- - \`base\` - Base ESLint rules (migrated from root)
921
- - \`react\` - React-specific rules
922
- `
923
- };
924
- files[`${configBasePath}/base.js`] = {
925
- type: "text",
926
- content: existingContent
927
- };
928
- files[`${configBasePath}/react.js`] = {
929
- type: "text",
930
- content: `import react from "eslint-plugin-react";
931
- import reactHooks from "eslint-plugin-react-hooks";
932
-
933
- export default [
934
- {
935
- plugins: {
936
- react,
937
- "react-hooks": reactHooks,
938
- },
939
- rules: {
940
- ...react.configs.recommended.rules,
941
- ...reactHooks.configs.recommended.rules,
942
- "react/react-in-jsx-scope": "off",
943
- },
944
- settings: {
945
- react: {
946
- version: "detect",
947
- },
948
- },
949
- },
950
- ];
951
- `
952
- };
953
- }
954
- async function migratePrettierConfig(monorepoRoot, files) {
955
- const configBasePath = ".config/prettier";
956
- const existingConfigPath = path.join(monorepoRoot, ".prettierrc.json");
957
- let existingContent;
958
- try {
959
- existingContent = await promises.readFile(existingConfigPath, "utf-8");
960
- } catch {
961
- index.generatePrettierConfigPackage(files);
962
- return;
963
- }
964
- files[`${configBasePath}/package.json`] = {
965
- type: "text",
966
- content: JSON.stringify(
967
- {
968
- name: "@config/prettier",
969
- version: "0.1.0",
970
- private: true,
971
- exports: {
972
- "./base": "./base.json"
973
- }
974
- },
975
- null,
976
- 2
977
- )
978
- };
979
- files[`${configBasePath}/README.md`] = {
980
- type: "text",
981
- content: `# \`@config/prettier\`
982
-
983
- Shared Prettier configurations.
984
-
985
- ## Usage
986
-
987
- In your package's \`.prettierrc\`:
988
-
989
- \`\`\`json
990
- "@config/prettier/base"
991
- \`\`\`
992
-
993
- Or in \`package.json\`:
994
-
995
- \`\`\`json
996
- {
997
- "prettier": "@config/prettier/base"
998
- }
999
- \`\`\`
1000
-
1001
- ## Available Configs
1002
-
1003
- - \`base\` - Base Prettier rules (migrated from root)
1004
- `
1005
- };
1006
- files[`${configBasePath}/base.json`] = {
1007
- type: "text",
1008
- content: existingContent
1009
- };
1010
- }
1011
- async function createPackageInWorkspace(monorepoRoot, packageManager, inheritedTooling, scope) {
1012
- const workspaceDirectories = await parseWorkspaceDirectories(monorepoRoot);
1013
- const defaultDirectories = ["apps", "packages"];
1014
- const hasCustomDirectories = workspaceDirectories.length > 0 && !workspaceDirectories.every((dir) => defaultDirectories.includes(dir));
1015
- const packageType = await promptForInitialPackage();
1016
- if (packageType === "skip") {
1017
- return false;
1018
- }
1019
- const defaultDir = packageType === "app" ? "apps" : "packages";
1020
- const packageNameInput = await p__namespace.text({
1021
- message: "Package name?",
1022
- initialValue: `@${scope}/`,
1023
- validate: (value) => {
1024
- const validationError = index.validatePackageName(value);
1025
- if (validationError) return validationError;
1026
- const dirName = value.includes("/") ? value.split("/").pop() : value;
1027
- if (!dirName) return "Package name is required";
1028
- if (!hasCustomDirectories) {
1029
- const targetPath = path.join(monorepoRoot, defaultDir, dirName);
1030
- try {
1031
- const { statSync } = require$1("fs");
1032
- statSync(targetPath);
1033
- return `Directory ${defaultDir}/${dirName} already exists`;
1034
- } catch {
1035
- }
1036
- }
1037
- }
1038
- });
1039
- if (p__namespace.isCancel(packageNameInput)) {
1040
- return false;
1041
- }
1042
- const scopedName = packageNameInput;
1043
- const shortName = scopedName.includes("/") ? scopedName.split("/").pop() : scopedName;
1044
- const packageOptions = await promptForPackageOptions(
1045
- scopedName,
1046
- packageType,
1047
- inheritedTooling
1048
- );
1049
- let targetDir = defaultDir;
1050
- if (hasCustomDirectories && workspaceDirectories.length > 0) {
1051
- const dirChoice = await p__namespace.select({
1052
- message: "Target directory",
1053
- options: workspaceDirectories.map((dir) => ({
1054
- value: dir,
1055
- label: dir
1056
- })),
1057
- initialValue: workspaceDirectories.includes(defaultDir) ? defaultDir : workspaceDirectories[0]
1058
- });
1059
- if (p__namespace.isCancel(dirChoice)) {
1060
- return false;
1061
- }
1062
- targetDir = dirChoice;
1063
- const targetPath = path.join(monorepoRoot, targetDir, shortName);
1064
- try {
1065
- const { statSync } = require$1("fs");
1066
- statSync(targetPath);
1067
- p__namespace.log.error(`Directory ${targetDir}/${shortName} already exists`);
1068
- return false;
1069
- } catch {
1070
- }
1071
- }
1072
- const relativePkgPath = path.join(targetDir, shortName);
1073
- const workspaceRoot = calculateWorkspaceRoot(relativePkgPath);
1074
- packageOptions.workspaceRoot = workspaceRoot;
1075
- packageOptions.name = scopedName;
1076
- if (packageManager === "pnpm") {
1077
- packageOptions.pnpmVersion = await index.getLatestPnpmVersion();
1078
- } else if (packageManager === "yarn") {
1079
- packageOptions.yarnVersion = await index.getLatestYarnVersion();
1080
- } else if (packageManager === "npm") {
1081
- packageOptions.npmVersion = await index.getLatestNpmCliVersion();
1082
- }
1083
- const nodeVersion = packageOptions.nodeVersion ?? "latest";
1084
- if (nodeVersion === "latest") {
1085
- packageOptions.nodeVersion = await index.getLatestNodeVersion();
1086
- }
1087
- const versions = {};
1088
- const versionPromises = [];
1089
- const pkgIsLibrary = packageOptions.projectType === "library";
1090
- const pkgTesting = packageOptions.testing ?? (pkgIsLibrary ? "vitest" : "none");
1091
- if (pkgTesting === "vitest") {
1092
- versionPromises.push(
1093
- index.getLatestNpmVersion("vitest", "4.0.0").then((v) => {
1094
- versions.vitest = v;
1095
- })
1096
- );
1097
- }
1098
- if (!pkgIsLibrary) {
1099
- versionPromises.push(
1100
- index.getLatestNpmVersion("vite", "6.3.4").then((v) => {
1101
- versions.vite = v;
1102
- })
1103
- );
1104
- }
1105
- const linter = packageOptions.linter ?? "oxlint";
1106
- if (linter === "eslint") {
1107
- versionPromises.push(
1108
- index.getLatestNpmVersion("eslint", "9.17.0").then((v) => {
1109
- versions.eslint = v;
1110
- })
1111
- );
1112
- } else if (linter === "oxlint") {
1113
- versionPromises.push(
1114
- index.getLatestNpmVersion("oxlint", "0.16.0").then((v) => {
1115
- versions.oxlint = v;
1116
- })
1117
- );
1118
- } else if (linter === "biome") {
1119
- versionPromises.push(
1120
- index.getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
1121
- versions.biome = v;
1122
- })
1123
- );
1124
- }
1125
- const formatter = packageOptions.formatter ?? "oxfmt";
1126
- if (formatter === "prettier") {
1127
- versionPromises.push(
1128
- index.getLatestNpmVersion("prettier", "3.4.2").then((v) => {
1129
- versions.prettier = v;
1130
- })
1131
- );
1132
- } else if (formatter === "oxfmt") {
1133
- versionPromises.push(
1134
- index.getLatestNpmVersion("oxfmt", "0.1.0").then((v) => {
1135
- versions.oxfmt = v;
1136
- })
1137
- );
1138
- } else if (formatter === "biome" && linter !== "biome") {
1139
- versionPromises.push(
1140
- index.getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
1141
- versions.biome = v;
1142
- })
1143
- );
1144
- }
1145
- await Promise.all(versionPromises);
1146
- packageOptions.versions = versions;
1147
- const workspacePackages = packageType === "app" ? await getWorkspacePackages(monorepoRoot) : [];
1148
- if (workspacePackages.length > 0) {
1149
- const selectedDeps = await p__namespace.multiselect({
1150
- message: "Add workspace dependencies?",
1151
- options: workspacePackages.map((name) => ({ value: name, label: name })),
1152
- required: false
1153
- });
1154
- if (!p__namespace.isCancel(selectedDeps) && selectedDeps.length > 0) {
1155
- packageOptions.workspaceDependencies = selectedDeps;
1156
- }
1157
- }
1158
- const outputPath = path.join(monorepoRoot, relativePkgPath);
1159
- const spinner = p__namespace.spinner();
1160
- spinner.start("Creating package...");
1161
- try {
1162
- const files = index.generate(packageOptions);
1163
- await writeGeneratedFiles(outputPath, files);
1164
- spinner.stop(
1165
- color__default.green.inverse(` \u2713 Package created at ${relativePkgPath}! `)
1166
- );
1167
- const addAnother = await p__namespace.select({
1168
- message: "Add another package?",
1169
- options: [
1170
- { value: "no", label: "No, I'm done" },
1171
- { value: "yes", label: "Yes, add another" }
1172
- ],
1173
- initialValue: "no"
1174
- });
1175
- return !p__namespace.isCancel(addAnother) && addAnother === "yes";
1176
- } catch (error) {
1177
- spinner.stop("Failed to create package");
1178
- p__namespace.log.error(String(error));
1179
- return false;
1180
- }
1181
- }
1182
- async function promptAndOpenEditor(projectPath) {
1183
- const savedEditor = getPreferredEditor();
1184
- let selectedEditor;
1185
- if (savedEditor && savedEditor !== "skip") {
1186
- const useDefault = await p__namespace.confirm({
1187
- message: `Open in editor? ${color__default.dim(`(${editorNames[savedEditor]})`)}`,
1188
- initialValue: true
1189
- });
1190
- if (p__namespace.isCancel(useDefault)) {
1191
- selectedEditor = void 0;
1192
- } else if (useDefault) {
1193
- selectedEditor = savedEditor;
1194
- } else {
1195
- selectedEditor = "skip";
1196
- }
1197
- } else {
1198
- const openEditor = await p__namespace.select({
1199
- message: "Open project in editor?",
1200
- options: [
1201
- { value: "skip", label: "Skip" },
1202
- { value: "cursor", label: "Cursor" },
1203
- { value: "code", label: "VS Code" },
1204
- { value: "webstorm", label: "WebStorm" }
1205
- ],
1206
- initialValue: "skip"
1207
- });
1208
- if (!p__namespace.isCancel(openEditor)) {
1209
- selectedEditor = openEditor;
1210
- const saveChoice = await p__namespace.confirm({
1211
- message: `Save ${editorNames[selectedEditor] ?? "Skip"} as default editor?`,
1212
- initialValue: true
1213
- });
1214
- if (!p__namespace.isCancel(saveChoice) && saveChoice) {
1215
- setPreferredEditor(selectedEditor);
1216
- if (selectedEditor === "cursor" || selectedEditor === "code") {
1217
- const reuseChoice = await p__namespace.confirm({
1218
- message: "Reuse current window when opening projects?",
1219
- initialValue: false
1220
- });
1221
- if (!p__namespace.isCancel(reuseChoice)) {
1222
- setReuseWindow(reuseChoice);
1223
- }
1224
- }
1225
- }
1226
- }
1227
- }
1228
- if (selectedEditor && selectedEditor !== "skip") {
1229
- try {
1230
- await openInEditor(
1231
- selectedEditor,
1232
- projectPath,
1233
- getReuseWindow()
1234
- );
1235
- p__namespace.log.success(`Opening in ${editorNames[selectedEditor]}...`);
1236
- } catch {
1237
- p__namespace.log.warn(
1238
- `Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
1239
- );
1240
- }
1241
- }
1242
- }
1243
- async function handleCheckCommand() {
1244
- const monorepoRoot = await detectMonorepoRoot();
1245
- if (!monorepoRoot) {
1246
- console.log(color__default.red("\u2717") + " Not a monorepo workspace");
1247
- process.exit(1);
1248
- }
1249
- const { valid, errors } = await validateWorkspace(monorepoRoot);
1250
- if (valid) {
1251
- console.log(color__default.green("\u2713") + " Valid monorepo workspace");
1252
- console.log(color__default.dim(` ${monorepoRoot}`));
1253
- } else {
1254
- console.log(color__default.red("\u2717") + " Invalid monorepo workspace");
1255
- console.log(color__default.dim(` ${monorepoRoot}`));
1256
- for (const error of errors) {
1257
- console.log(color__default.red(` \u2022 ${error}`));
1258
- }
1259
- }
1260
- process.exit(valid ? 0 : 1);
1261
- }
1262
- async function handleFixCommand(options) {
1263
- const monorepoRoot = await detectMonorepoRoot();
1264
- if (!monorepoRoot) {
1265
- console.log(color__default.red("\u2717") + " Not a monorepo workspace");
1266
- console.log(color__default.dim(" Run this command from within a monorepo"));
1267
- process.exit(1);
1268
- }
1269
- const { valid, errors } = await validateWorkspace(monorepoRoot);
1270
- if (valid) {
1271
- console.log(color__default.green("\u2713") + " Workspace is already valid");
1272
- console.log(color__default.dim(` ${monorepoRoot}`));
1273
- process.exit(0);
1274
- }
1275
- console.log(color__default.yellow("!") + " Invalid monorepo workspace");
1276
- for (const error of errors) {
1277
- console.log(color__default.dim(` \u2022 ${error}`));
1278
- }
1279
- console.log();
1280
- const tooling = await detectWorkspaceTooling(monorepoRoot);
1281
- const existingConfigs = await detectExistingConfigs(monorepoRoot);
1282
- const detectedLinter = tooling.linter ?? existingConfigs.linter ?? "oxlint";
1283
- const detectedFormatter = tooling.formatter ?? existingConfigs.formatter ?? "oxfmt";
1284
- const isNonInteractive = options.linter && options.formatter;
1285
- let linter;
1286
- let formatter;
1287
- if (isNonInteractive) {
1288
- linter = options.linter;
1289
- formatter = options.formatter;
1290
- } else {
1291
- const linterChoice = await p__namespace.select({
1292
- message: "Linter",
1293
- options: [
1294
- {
1295
- value: "oxlint",
1296
- label: "oxlint" + (tooling.linter === "oxlint" ? color__default.dim(" (installed)") : "")
1297
- },
1298
- {
1299
- value: "eslint",
1300
- label: "eslint" + (tooling.linter === "eslint" || existingConfigs.linter === "eslint" ? color__default.dim(" (installed)") : "")
1301
- },
1302
- {
1303
- value: "biome",
1304
- label: "biome" + (tooling.linter === "biome" ? color__default.dim(" (installed)") : "")
1305
- }
1306
- ],
1307
- initialValue: detectedLinter
1308
- });
1309
- if (p__namespace.isCancel(linterChoice)) {
1310
- p__namespace.cancel("Operation cancelled.");
1311
- process.exit(0);
1312
- }
1313
- const formatterChoice = await p__namespace.select({
1314
- message: "Formatter",
1315
- options: [
1316
- {
1317
- value: "oxfmt",
1318
- label: "oxfmt" + (tooling.formatter === "oxfmt" ? color__default.dim(" (installed)") : "")
1319
- },
1320
- {
1321
- value: "prettier",
1322
- label: "prettier" + (tooling.formatter === "prettier" || existingConfigs.formatter === "prettier" ? color__default.dim(" (installed)") : "")
1323
- },
1324
- {
1325
- value: "biome",
1326
- label: "biome" + (tooling.formatter === "biome" ? color__default.dim(" (installed)") : "")
1327
- }
1328
- ],
1329
- initialValue: detectedFormatter
1330
- });
1331
- if (p__namespace.isCancel(formatterChoice)) {
1332
- p__namespace.cancel("Operation cancelled.");
1333
- process.exit(0);
1334
- }
1335
- linter = linterChoice;
1336
- formatter = formatterChoice;
1337
- }
1338
- console.log();
1339
- const spinner = p__namespace.spinner();
1340
- spinner.start("Fixing workspace...");
1341
- try {
1342
- const files = {};
1343
- const tsConfigExists = await fileExists(
1344
- path.join(monorepoRoot, ".config/typescript/package.json")
1345
- );
1346
- if (!tsConfigExists) {
1347
- index.generateTypescriptConfigPackage(files);
1348
- }
1349
- if (linter === "oxlint") {
1350
- const oxlintExists = await fileExists(
1351
- path.join(monorepoRoot, ".config/oxlint/package.json")
1352
- );
1353
- if (!oxlintExists) index.generateOxlintConfigPackage(files);
1354
- } else if (linter === "eslint") {
1355
- const eslintPkgExists = await fileExists(
1356
- path.join(monorepoRoot, ".config/eslint/package.json")
1357
- );
1358
- if (!eslintPkgExists) {
1359
- if (existingConfigs.eslintConfigPath) {
1360
- await migrateEslintConfig(monorepoRoot, files);
1361
- } else {
1362
- index.generateEslintConfigPackage(files);
1363
- }
1364
- }
1365
- }
1366
- if (formatter === "oxfmt") {
1367
- const oxfmtExists = await fileExists(
1368
- path.join(monorepoRoot, ".config/oxfmt/package.json")
1369
- );
1370
- if (!oxfmtExists) index.generateOxfmtConfigPackage(files);
1371
- } else if (formatter === "prettier") {
1372
- const prettierPkgExists = await fileExists(
1373
- path.join(monorepoRoot, ".config/prettier/package.json")
1374
- );
1375
- if (!prettierPkgExists) {
1376
- if (existingConfigs.prettierConfigPath) {
1377
- await migratePrettierConfig(monorepoRoot, files);
1378
- } else {
1379
- index.generatePrettierConfigPackage(files);
1380
- }
1381
- }
1382
- }
1383
- if ((linter === "biome" || formatter === "biome") && !existingConfigs.biomeConfigPath) {
1384
- const biomeConfig = {
1385
- $schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
1386
- vcs: {
1387
- enabled: true,
1388
- clientKind: "git",
1389
- useIgnoreFile: true
1390
- },
1391
- linter: {
1392
- enabled: linter === "biome",
1393
- rules: {
1394
- recommended: true
1395
- }
1396
- },
1397
- formatter: {
1398
- enabled: formatter === "biome"
1399
- }
1400
- };
1401
- files["biome.json"] = {
1402
- type: "text",
1403
- content: JSON.stringify(biomeConfig, null, 2)
1404
- };
1405
- }
1406
- for (const [filePath, file] of Object.entries(files)) {
1407
- const fullPath = path.join(monorepoRoot, filePath);
1408
- await promises.mkdir(path.dirname(fullPath), { recursive: true });
1409
- await promises.writeFile(fullPath, file.content);
1410
- }
1411
- await ensureConfigInWorkspace(monorepoRoot);
1412
- if (existingConfigs.eslintConfigPath && linter === "eslint") {
1413
- try {
1414
- await promises.unlink(existingConfigs.eslintConfigPath);
1415
- } catch {
1416
- }
1417
- }
1418
- if (existingConfigs.prettierConfigPath && formatter === "prettier") {
1419
- try {
1420
- await promises.unlink(existingConfigs.prettierConfigPath);
1421
- } catch {
1422
- }
1423
- }
1424
- spinner.stop(color__default.green("\u2713") + " Workspace fixed!");
1425
- const generated = Object.keys(files).filter(
1426
- (f) => f.endsWith("package.json")
1427
- );
1428
- for (const pkgFile of generated) {
1429
- const pkgName = pkgFile.replace("/package.json", "");
1430
- console.log(color__default.dim(` Generated ${pkgName}`));
1431
- }
1432
- const vscodeSettingsExists = await fileExists(
1433
- path.join(monorepoRoot, ".vscode/settings.json")
1434
- );
1435
- const vscodeExtensionsExists = await fileExists(
1436
- path.join(monorepoRoot, ".vscode/extensions.json")
1437
- );
1438
- const vscodeExists = vscodeSettingsExists && vscodeExtensionsExists;
1439
- if (!vscodeExists) {
1440
- let addVscode = false;
1441
- if (isNonInteractive) {
1442
- addVscode = true;
1443
- } else {
1444
- const vscodeChoice = await p__namespace.confirm({
1445
- message: "Generate VS Code settings?",
1446
- initialValue: true
1447
- });
1448
- addVscode = !p__namespace.isCancel(vscodeChoice) && vscodeChoice;
1449
- }
1450
- if (addVscode) {
1451
- const vscodeFiles = {};
1452
- index.generateVscodeFiles(vscodeFiles, linter, formatter);
1453
- for (const [filePath, file] of Object.entries(vscodeFiles)) {
1454
- const fullPath = path.join(monorepoRoot, filePath);
1455
- await promises.mkdir(path.dirname(fullPath), { recursive: true });
1456
- await promises.writeFile(fullPath, file.content);
1457
- }
1458
- console.log(color__default.dim(" Generated .vscode/settings.json"));
1459
- console.log(color__default.dim(" Generated .vscode/extensions.json"));
1460
- }
1461
- }
1462
- const aiFilePaths = {
1463
- "cursor-rules": ".cursor/rules",
1464
- "agents-md": "AGENTS.md",
1465
- "claude-md": "CLAUDE.md",
1466
- "copilot-md": ".github/copilot-instructions.md"
1467
- };
1468
- const existingAiFiles = [];
1469
- for (const [choice, path$1] of Object.entries(aiFilePaths)) {
1470
- if (await fileExists(path.join(monorepoRoot, path$1))) {
1471
- existingAiFiles.push(choice);
1472
- }
1473
- }
1474
- let selectedAiFiles = [];
1475
- const savedAiFiles = getAiFiles();
1476
- const availableChoices = ["cursor-rules", "agents-md", "claude-md", "copilot-md"].filter((c) => !existingAiFiles.includes(c));
1477
- if (availableChoices.length === 0) {
1478
- } else if (isNonInteractive) {
1479
- const preferred = savedAiFiles ?? ["cursor-rules"];
1480
- selectedAiFiles = preferred.filter((f) => availableChoices.includes(f));
1481
- } else if (savedAiFiles && savedAiFiles.length > 0) {
1482
- const availableSaved = savedAiFiles.filter(
1483
- (f) => availableChoices.includes(f)
1484
- );
1485
- if (availableSaved.length > 0) {
1486
- const savedLabels = availableSaved.map((f) => aiFilePaths[f]).join(", ");
1487
- const useDefault = await p__namespace.confirm({
1488
- message: `Generate AI instruction files? ${color__default.dim(
1489
- `(${savedLabels})`
1490
- )}`,
1491
- initialValue: true
1492
- });
1493
- if (!p__namespace.isCancel(useDefault) && useDefault) {
1494
- selectedAiFiles = availableSaved;
1495
- }
1496
- }
1497
- } else {
1498
- const aiFilesChoice = await p__namespace.multiselect({
1499
- message: "Generate AI instruction files?",
1500
- options: availableChoices.map((c) => ({
1501
- value: c,
1502
- label: aiFilePaths[c],
1503
- hint: c === "cursor-rules" ? "Cursor AI" : c === "agents-md" ? "GitHub Copilot, general" : c === "claude-md" ? "Claude" : "GitHub Copilot"
1504
- })),
1505
- required: false
1506
- });
1507
- if (!p__namespace.isCancel(aiFilesChoice) && aiFilesChoice.length > 0) {
1508
- selectedAiFiles = aiFilesChoice;
1509
- const saveChoice = await p__namespace.confirm({
1510
- message: "Save as default for future?",
1511
- initialValue: true
1512
- });
1513
- if (!p__namespace.isCancel(saveChoice) && saveChoice) {
1514
- setAiFiles(selectedAiFiles);
1515
- }
1516
- }
1517
- }
1518
- if (selectedAiFiles.length > 0) {
1519
- const scope = await getMonorepoScope(monorepoRoot);
1520
- const aiFilesOutput = {};
1521
- index.generateAiFiles(aiFilesOutput, {
1522
- name: scope,
1523
- packageManager: "pnpm",
1524
- linter,
1525
- formatter,
1526
- aiFiles: selectedAiFiles
1527
- });
1528
- for (const [filePath, file] of Object.entries(aiFilesOutput)) {
1529
- const fullPath = path.join(monorepoRoot, filePath);
1530
- await promises.mkdir(path.dirname(fullPath), { recursive: true });
1531
- await promises.writeFile(fullPath, file.content);
1532
- console.log(color__default.dim(` Generated ${filePath}`));
1533
- }
1534
- }
1535
- process.exit(0);
1536
- } catch (error) {
1537
- spinner.stop(color__default.red("\u2717") + " Failed to fix workspace");
1538
- console.error(error);
1539
- process.exit(1);
1540
- }
1541
- }
1542
- async function handleWorkspaceCommand(name, options) {
1543
- const monorepoRoot = await detectMonorepoRoot();
1544
- if (!monorepoRoot) {
1545
- console.error(
1546
- color__default.red("Error:") + " --workspace flag requires being inside a monorepo"
1547
- );
1548
- process.exit(1);
1549
- }
1550
- if (!name) {
1551
- console.error(
1552
- color__default.red("Error:") + " Package name is required with --workspace flag"
1553
- );
1554
- console.log(
1555
- color__default.dim(
1556
- " Example: pnpm create krispya my-lib --workspace --type library"
1557
- )
1558
- );
1559
- process.exit(1);
1560
- }
1561
- const scope = await getMonorepoScope(monorepoRoot);
1562
- const inheritedTooling = await detectWorkspaceTooling(monorepoRoot);
1563
- const projectType = options.type ?? "app";
1564
- const defaultDir = projectType === "library" ? "packages" : "apps";
1565
- const targetDir = options.dir ?? defaultDir;
1566
- const template = options.template ?? "vanilla";
1567
- const baseTemplate = index.getBaseTemplate(template);
1568
- const scopedName = name.startsWith("@") ? name : `@${scope}/${name}`;
1569
- const fullPackagePath = path.join(monorepoRoot, targetDir, name);
1570
- try {
1571
- await promises.access(fullPackagePath, fs.constants.F_OK);
1572
- console.error(
1573
- color__default.red("Error:") + ` Directory ${targetDir}/${name} already exists`
1574
- );
1575
- process.exit(1);
1576
- } catch {
1577
- }
1578
- const versions = {};
1579
- const versionPromises = [];
1580
- const isLibrary = projectType === "library";
1581
- if (!isLibrary) {
1582
- versionPromises.push(
1583
- index.getLatestNpmVersion("vite", "6.3.4").then((v) => {
1584
- versions.vite = v;
1585
- })
1586
- );
1587
- }
1588
- const linter = inheritedTooling.linter ?? options.linter ?? "oxlint";
1589
- const formatter = inheritedTooling.formatter ?? options.formatter ?? "oxfmt";
1590
- await Promise.all(versionPromises);
1591
- const relativePkgPath = path.join(targetDir, name);
1592
- const workspaceRoot = calculateWorkspaceRoot(relativePkgPath);
1593
- const generateOptions = {
1594
- name: scopedName,
1595
- projectType,
1596
- libraryBundler: isLibrary ? options.bundler ?? "unbuild" : void 0,
1597
- template,
1598
- linter,
1599
- formatter,
1600
- workspaceRoot,
1601
- versions,
1602
- ...baseTemplate === "r3f" && {
1603
- drei: options.drei ? {} : void 0,
1604
- handle: options.handle ? {} : void 0,
1605
- leva: options.leva ? {} : void 0,
1606
- postprocessing: options.postprocessing ? {} : void 0,
1607
- rapier: options.rapier ? {} : void 0,
1608
- xr: options.xr ? {} : void 0,
1609
- uikit: options.uikit ? {} : void 0,
1610
- offscreen: options.offscreen ? {} : void 0,
1611
- zustand: options.zustand ? {} : void 0,
1612
- koota: options.koota ? {} : void 0,
1613
- viverse: options.viverse ? {} : void 0,
1614
- triplex: options.triplex ? {} : void 0
1615
- }
1616
- };
1617
- console.log(
1618
- color__default.cyan("Creating") + ` ${scopedName} in ${targetDir}/${name}...`
1619
- );
1620
- try {
1621
- const files = index.generate(generateOptions);
1622
- await writeGeneratedFiles(fullPackagePath, files);
1623
- console.log(
1624
- color__default.green("\u2713") + ` Created ${scopedName} at ${targetDir}/${name}`
1625
- );
1626
- process.exit(0);
1627
- } catch (error) {
1628
- console.error(color__default.red("Error:") + " Failed to create package");
1629
- console.error(String(error));
1630
- process.exit(1);
1631
- }
1632
- }
1633
- async function handleMonorepoCreation(generateOptions) {
1634
- const { generateMonorepo } = await import('./chunks/index.cjs').then(function (n) { return n.monorepo; });
1635
- const packageManager = generateOptions.packageManager || "pnpm";
1636
- if (packageManager === "pnpm") {
1637
- generateOptions.pnpmVersion = await index.getLatestPnpmVersion();
1638
- } else if (packageManager === "yarn") {
1639
- generateOptions.yarnVersion = await index.getLatestYarnVersion();
1640
- } else if (packageManager === "npm") {
1641
- generateOptions.npmVersion = await index.getLatestNpmCliVersion();
1642
- }
1643
- const nodeVersion = generateOptions.nodeVersion ?? "latest";
1644
- if (nodeVersion === "latest") {
1645
- generateOptions.nodeVersion = await index.getLatestNodeVersion();
1646
- }
1647
- const savedAiFiles = getAiFiles();
1648
- let selectedAiFiles = [];
1649
- if (savedAiFiles && savedAiFiles.length > 0) {
1650
- const aiFileLabels = {
1651
- "cursor-rules": ".cursor/rules",
1652
- "agents-md": "AGENTS.md",
1653
- "claude-md": "CLAUDE.md",
1654
- "copilot-md": ".github/copilot-instructions.md"
1655
- };
1656
- const savedLabels = savedAiFiles.map((f) => aiFileLabels[f]).join(", ");
1657
- const useDefault = await p__namespace.confirm({
1658
- message: `Generate AI instruction files? ${color__default.dim(
1659
- `(${savedLabels})`
1660
- )}`,
1661
- initialValue: true
1662
- });
1663
- if (!p__namespace.isCancel(useDefault) && useDefault) {
1664
- selectedAiFiles = savedAiFiles;
1665
- }
1666
- } else {
1667
- const aiFilesChoice = await p__namespace.multiselect({
1668
- message: "Generate AI instruction files?",
1669
- options: [
1670
- { value: "cursor-rules", label: ".cursor/rules", hint: "Cursor AI" },
1671
- {
1672
- value: "agents-md",
1673
- label: "AGENTS.md",
1674
- hint: "GitHub Copilot, general"
1675
- },
1676
- { value: "claude-md", label: "CLAUDE.md", hint: "Claude" },
1677
- {
1678
- value: "copilot-md",
1679
- label: ".github/copilot-instructions.md",
1680
- hint: "GitHub Copilot"
1681
- }
1682
- ],
1683
- required: false
1684
- });
1685
- if (!p__namespace.isCancel(aiFilesChoice) && aiFilesChoice.length > 0) {
1686
- selectedAiFiles = aiFilesChoice;
1687
- const saveChoice = await p__namespace.confirm({
1688
- message: "Save as default for future monorepos?",
1689
- initialValue: true
1690
- });
1691
- if (!p__namespace.isCancel(saveChoice) && saveChoice) {
1692
- setAiFiles(selectedAiFiles);
1693
- }
1694
- }
1695
- }
1696
- const projectPath = path.join(process$1.cwd(), generateOptions.name);
1697
- const spinner = p__namespace.spinner();
1698
- spinner.start("Creating monorepo workspace...");
1699
- try {
1700
- const { files } = generateMonorepo({
1701
- name: generateOptions.name,
1702
- linter: generateOptions.linter ?? "oxlint",
1703
- formatter: generateOptions.formatter ?? "oxfmt",
1704
- packageManager,
1705
- pnpmVersion: generateOptions.pnpmVersion,
1706
- pnpmManageVersions: generateOptions.pnpmManageVersions,
1707
- nodeVersion: generateOptions.nodeVersion,
1708
- aiFiles: selectedAiFiles.length > 0 ? selectedAiFiles : void 0
1709
- });
1710
- const filePaths = Object.keys(files).sort();
1711
- for (const filePath of filePaths) {
1712
- const fullFilePath = path.join(projectPath, filePath);
1713
- await promises.mkdir(path.dirname(fullFilePath), { recursive: true });
1714
- const file = files[filePath];
1715
- if (file.type === "text") {
1716
- await promises.writeFile(fullFilePath, file.content);
1717
- }
1718
- }
1719
- spinner.stop(color__default.green.inverse(" \u2713 Monorepo workspace created! "));
1720
- const newMonorepoTooling = {
1721
- linter: generateOptions.linter,
1722
- formatter: generateOptions.formatter
1723
- };
1724
- const scope = generateOptions.name;
1725
- let addMore = true;
1726
- while (addMore) {
1727
- addMore = await createPackageInWorkspace(
1728
- projectPath,
1729
- packageManager,
1730
- newMonorepoTooling,
1731
- scope
1732
- );
1733
- }
1734
- const nextSteps = [
1735
- `cd ${generateOptions.name}`,
1736
- `${packageManager} install`,
1737
- `${packageManager} run dev`
1738
- ].join("\n");
1739
- p__namespace.note(nextSteps, "Next steps");
1740
- await promptAndOpenEditor(projectPath);
1741
- p__namespace.outro(color__default.green("Happy coding! \u2728"));
1742
- process.exit(0);
1743
- } catch (error) {
1744
- spinner.stop("Failed to create monorepo workspace");
1745
- p__namespace.log.error(String(error));
1746
- process.exit(1);
1747
- }
1748
- }
1749
- async function handleStandaloneProjectCreation(generateOptions) {
1750
- const base = generateOptions.template ? index.getBaseTemplate(generateOptions.template) : "vanilla";
1751
- const defaultFallbackName = base === "vanilla" ? "vanilla-app" : base === "react" ? "react-app" : "react-three-app";
1752
- generateOptions.name ??= defaultFallbackName;
1753
- const packageManager = generateOptions.packageManager || "pnpm";
1754
- if (packageManager === "pnpm") {
1755
- generateOptions.pnpmVersion = await index.getLatestPnpmVersion();
1756
- } else if (packageManager === "yarn") {
1757
- generateOptions.yarnVersion = await index.getLatestYarnVersion();
1758
- } else if (packageManager === "npm") {
1759
- generateOptions.npmVersion = await index.getLatestNpmCliVersion();
1760
- }
1761
- const nodeVersion = generateOptions.nodeVersion ?? "latest";
1762
- if (nodeVersion === "latest") {
1763
- generateOptions.nodeVersion = await index.getLatestNodeVersion();
1764
- }
1765
- const versions = {};
1766
- const versionPromises = [];
1767
- const isLibrary = generateOptions.projectType === "library";
1768
- const testing = generateOptions.testing ?? (isLibrary ? "vitest" : "none");
1769
- if (testing === "vitest") {
1770
- versionPromises.push(
1771
- index.getLatestNpmVersion("vitest", "4.0.0").then((v) => {
1772
- versions.vitest = v;
1773
- })
1774
- );
1775
- }
1776
- if (!isLibrary) {
1777
- versionPromises.push(
1778
- index.getLatestNpmVersion("vite", "6.3.4").then((v) => {
1779
- versions.vite = v;
1780
- })
1781
- );
1782
- }
1783
- const linter = generateOptions.linter ?? "oxlint";
1784
- if (linter === "eslint") {
1785
- versionPromises.push(
1786
- index.getLatestNpmVersion("eslint", "9.17.0").then((v) => {
1787
- versions.eslint = v;
1788
- })
1789
- );
1790
- } else if (linter === "oxlint") {
1791
- versionPromises.push(
1792
- index.getLatestNpmVersion("oxlint", "0.16.0").then((v) => {
1793
- versions.oxlint = v;
1794
- })
1795
- );
1796
- } else if (linter === "biome") {
1797
- versionPromises.push(
1798
- index.getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
1799
- versions.biome = v;
1800
- })
1801
- );
1802
- }
1803
- const formatter = generateOptions.formatter ?? "oxfmt";
1804
- if (formatter === "prettier") {
1805
- versionPromises.push(
1806
- index.getLatestNpmVersion("prettier", "3.4.2").then((v) => {
1807
- versions.prettier = v;
1808
- })
1809
- );
1810
- } else if (formatter === "oxfmt") {
1811
- versionPromises.push(
1812
- index.getLatestNpmVersion("oxfmt", "0.1.0").then((v) => {
1813
- versions.oxfmt = v;
1814
- })
1815
- );
1816
- } else if (formatter === "biome" && linter !== "biome") {
1817
- versionPromises.push(
1818
- index.getLatestNpmVersion("@biomejs/biome", "1.9.4").then((v) => {
1819
- versions.biome = v;
1820
- })
1821
- );
1822
- }
1823
- await Promise.all(versionPromises);
1824
- generateOptions.versions = versions;
1825
- const projectPath = path.join(process$1.cwd(), generateOptions.name);
1826
- const spinner = p__namespace.spinner();
1827
- spinner.start("Creating project...");
1828
- try {
1829
- const files = index.generate(generateOptions);
1830
- await writeGeneratedFiles(projectPath, files);
1831
- spinner.stop(color__default.green.inverse(" \u2713 Project created! "));
1832
- const nextSteps = isLibrary ? [
1833
- `cd ${generateOptions.name}`,
1834
- `${packageManager} install`,
1835
- `${packageManager} run build`
1836
- ].join("\n") : [
1837
- `cd ${generateOptions.name}`,
1838
- `${packageManager} install`,
1839
- `${packageManager} run dev`
1840
- ].join("\n");
1841
- p__namespace.note(nextSteps, "Next steps");
1842
- await promptAndOpenEditor(projectPath);
1843
- p__namespace.outro(color__default.green("Happy coding! \u2728"));
1844
- } catch (error) {
1845
- spinner.stop("Failed to create project");
1846
- p__namespace.log.error(String(error));
1847
- process.exit(1);
1848
- }
1849
- }
1850
- async function handleInteractiveMonorepoMode(monorepoRoot) {
1851
- const choice = await p__namespace.select({
1852
- message: "Detected monorepo workspace",
1853
- options: [
1854
- { value: "add", label: "Add new package to this workspace" },
1855
- { value: "standalone", label: "Create standalone project" }
1856
- ],
1857
- initialValue: "add"
1858
- });
1859
- if (p__namespace.isCancel(choice)) {
1860
- p__namespace.cancel("Operation cancelled.");
1861
- process.exit(0);
1862
- }
1863
- if (choice === "add") {
1864
- const inheritedTooling = await detectWorkspaceTooling(monorepoRoot);
1865
- if (inheritedTooling.linter || inheritedTooling.formatter) {
1866
- const toolingInfo = [
1867
- inheritedTooling.linter && `linter: ${inheritedTooling.linter}`,
1868
- inheritedTooling.formatter && `formatter: ${inheritedTooling.formatter}`
1869
- ].filter(Boolean).join(", ");
1870
- p__namespace.log.info(`Using workspace tooling (${toolingInfo})`);
1871
- }
1872
- const scope = await getMonorepoScope(monorepoRoot);
1873
- let addMore = true;
1874
- while (addMore) {
1875
- addMore = await createPackageInWorkspace(
1876
- monorepoRoot,
1877
- "pnpm",
1878
- inheritedTooling,
1879
- scope
1880
- );
1881
- }
1882
- p__namespace.note(
1883
- [`cd ${monorepoRoot}`, "pnpm install", "pnpm run dev"].join("\n"),
1884
- "Next steps"
1885
- );
1886
- await promptAndOpenEditor(monorepoRoot);
1887
- p__namespace.outro(color__default.green("Happy coding! \u2728"));
1888
- process.exit(0);
1889
- }
1890
- }
1891
- async function main() {
1892
- const program = new commander.Command().name("create-krispya").description(
1893
- "CLI for creating Vanilla, React, and React Three Fiber projects"
1894
- ).argument("[name]", "name for the project").option("--type <type>", "project type: app or library (default: app)").option(
1895
- "--bundler <bundler>",
1896
- "library bundler: unbuild or tsdown (default: unbuild, only for libraries)"
1897
- ).option(
1898
- "--template <type>",
1899
- "project template: vanilla, vanilla-js, react, react-js, r3f, r3f-js (default: vanilla)"
1900
- ).option(
1901
- "--linter <type>",
1902
- "linter: eslint, oxlint, or biome (default: oxlint)"
1903
- ).option(
1904
- "--formatter <type>",
1905
- "formatter: prettier, oxfmt, or biome (default: oxfmt)"
1906
- ).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(
1907
- "--package-manager <manager>",
1908
- "specify package manager (e.g. npm, yarn, pnpm)"
1909
- ).option(
1910
- "--pnpm-manage-versions",
1911
- "enable manage-package-manager-versions in pnpm-workspace.yaml (default: true)"
1912
- ).option(
1913
- "--no-pnpm-manage-versions",
1914
- "disable manage-package-manager-versions in pnpm-workspace.yaml"
1915
- ).option(
1916
- "--node-version <version>",
1917
- 'set Node.js version for engines.node field (default: "latest")'
1918
- ).option(
1919
- "--workspace",
1920
- "Add package to current monorepo workspace (non-interactive)"
1921
- ).option(
1922
- "--dir <directory>",
1923
- "Target directory for --workspace (default: apps/ or packages/)"
1924
- ).option("--clear-config", "Clear saved preferences (e.g. editor choice)").option("--config-path", "Print the path to the config file").option(
1925
- "--check",
1926
- "Check if current directory is in a valid monorepo workspace"
1927
- ).option("--fix", "Fix monorepo by generating missing .config packages").option(
1928
- "--path <directory>",
1929
- "Run in specified directory instead of current working directory"
1930
- ).action(async (name, options) => {
1931
- if (options.path) {
1932
- process.chdir(options.path);
1933
- }
1934
- if (options.clearConfig) {
1935
- clearConfig();
1936
- console.log("Configuration cleared.");
1937
- process.exit(0);
1938
- }
1939
- if (options.configPath) {
1940
- console.log(getConfigPath());
1941
- process.exit(0);
1942
- }
1943
- if (name?.startsWith("-")) {
1944
- switch (name) {
1945
- case "--version":
1946
- case "-V":
1947
- console.log(pkg.version);
1948
- process.exit(0);
1949
- case "--help":
1950
- case "-h":
1951
- program.help();
1952
- break;
1953
- case "--clear-config":
1954
- clearConfig();
1955
- console.log("Configuration cleared.");
1956
- process.exit(0);
1957
- case "--config-path":
1958
- console.log(getConfigPath());
1959
- process.exit(0);
1960
- case "--check":
1961
- await handleCheckCommand();
1962
- break;
1963
- case "--fix":
1964
- options.fix = true;
1965
- break;
1966
- default:
1967
- console.error(color__default.red(`Unknown option: ${name}`));
1968
- process.exit(1);
1969
- }
1970
- }
1971
- if (options.check) {
1972
- await handleCheckCommand();
1973
- }
1974
- if (options.fix) {
1975
- await handleFixCommand(options);
1976
- }
1977
- if (options.dir && !options.workspace) {
1978
- console.error(color__default.red("Error:") + " --dir requires --workspace flag");
1979
- console.log(
1980
- color__default.dim(
1981
- " Example: pnpm create krispya my-lib --workspace --dir examples"
1982
- )
1983
- );
1984
- process.exit(1);
1985
- }
1986
- if (options.workspace) {
1987
- await handleWorkspaceCommand(name, options);
1988
- }
1989
- console.clear();
1990
- p__namespace.intro(color__default.bgCyan(color__default.black(` create-krispya v${pkg.version} `)));
1991
- const monorepoRoot = await detectMonorepoRoot();
1992
- if (monorepoRoot && Object.keys(options).length === 0) {
1993
- await handleInteractiveMonorepoMode(monorepoRoot);
1994
- }
1995
- let generateOptions;
1996
- if (Object.keys(options).length > 0) {
1997
- const template = options.template ?? "vanilla";
1998
- const baseTemplate = index.getBaseTemplate(template);
1999
- const defaultName = getDefaultProjectName(template);
2000
- const projectType = options.type ?? "app";
2001
- generateOptions = {
2002
- name: name || defaultName,
2003
- projectType,
2004
- libraryBundler: projectType === "library" ? options.bundler ?? "unbuild" : void 0,
2005
- template,
2006
- linter: options.linter ?? "oxlint",
2007
- formatter: options.formatter ?? "oxfmt",
2008
- ...baseTemplate === "r3f" && {
2009
- drei: options.drei ? {} : void 0,
2010
- handle: options.handle ? {} : void 0,
2011
- leva: options.leva ? {} : void 0,
2012
- postprocessing: options.postprocessing ? {} : void 0,
2013
- rapier: options.rapier ? {} : void 0,
2014
- xr: options.xr ? {} : void 0,
2015
- uikit: options.uikit ? {} : void 0,
2016
- offscreen: options.offscreen ? {} : void 0,
2017
- zustand: options.zustand ? {} : void 0,
2018
- koota: options.koota ? {} : void 0,
2019
- viverse: options.viverse ? {} : void 0,
2020
- triplex: options.triplex ? {} : void 0
2021
- },
2022
- packageManager: options.packageManager,
2023
- pnpmManageVersions: options.pnpmManageVersions,
2024
- nodeVersion: options.nodeVersion ?? "latest"
2025
- };
2026
- } else {
2027
- generateOptions = await promptForOptions(name);
2028
- }
2029
- if (generateOptions.projectType === "monorepo") {
2030
- await handleMonorepoCreation(generateOptions);
2031
- } else {
2032
- await handleStandaloneProjectCreation(generateOptions);
2033
- }
2034
- });
2035
- await program.parseAsync();
2036
- }
2037
- main().catch(console.error);