create-krispya 0.4.7 → 0.4.8
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 +87 -27
- package/dist/cli.mjs +86 -27
- package/package.json +2 -1
package/dist/cli.cjs
CHANGED
|
@@ -11,6 +11,7 @@ const p = require('@clack/prompts');
|
|
|
11
11
|
const color = require('chalk');
|
|
12
12
|
const undici = require('undici');
|
|
13
13
|
const child_process = require('child_process');
|
|
14
|
+
const Conf = require('conf');
|
|
14
15
|
|
|
15
16
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
17
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -29,6 +30,26 @@ function _interopNamespaceCompat(e) {
|
|
|
29
30
|
|
|
30
31
|
const p__namespace = /*#__PURE__*/_interopNamespaceCompat(p);
|
|
31
32
|
const color__default = /*#__PURE__*/_interopDefaultCompat(color);
|
|
33
|
+
const Conf__default = /*#__PURE__*/_interopDefaultCompat(Conf);
|
|
34
|
+
|
|
35
|
+
const config = new Conf__default({
|
|
36
|
+
projectName: "create-krispya"
|
|
37
|
+
});
|
|
38
|
+
function getPreferredEditor() {
|
|
39
|
+
return config.get("preferredEditor");
|
|
40
|
+
}
|
|
41
|
+
function setPreferredEditor(editor) {
|
|
42
|
+
config.set("preferredEditor", editor);
|
|
43
|
+
}
|
|
44
|
+
function getReuseWindow() {
|
|
45
|
+
return config.get("reuseWindow") ?? false;
|
|
46
|
+
}
|
|
47
|
+
function setReuseWindow(reuse) {
|
|
48
|
+
config.set("reuseWindow", reuse);
|
|
49
|
+
}
|
|
50
|
+
function clearConfig() {
|
|
51
|
+
config.clear();
|
|
52
|
+
}
|
|
32
53
|
|
|
33
54
|
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)));
|
|
34
55
|
const pkg = require$1("../package.json");
|
|
@@ -381,12 +402,17 @@ async function promptForOptions(name) {
|
|
|
381
402
|
projectType
|
|
382
403
|
);
|
|
383
404
|
}
|
|
384
|
-
|
|
405
|
+
const editorNames = {
|
|
406
|
+
cursor: "Cursor",
|
|
407
|
+
code: "VS Code",
|
|
408
|
+
webstorm: "WebStorm"
|
|
409
|
+
};
|
|
410
|
+
function openInEditor(editor, path, reuseWindow) {
|
|
385
411
|
return new Promise((resolve, reject) => {
|
|
386
412
|
const isWindows = process.platform === "win32";
|
|
387
|
-
const
|
|
388
|
-
const args =
|
|
389
|
-
const child = isWindows ? child_process.spawn(`${editor} ${
|
|
413
|
+
const useReuseFlag = reuseWindow && (editor === "cursor" || editor === "code");
|
|
414
|
+
const args = useReuseFlag ? ["-r", path] : [path];
|
|
415
|
+
const child = isWindows ? child_process.spawn(`${editor} ${useReuseFlag ? "-r " : ""}"${path}"`, {
|
|
390
416
|
detached: true,
|
|
391
417
|
stdio: "ignore",
|
|
392
418
|
shell: true
|
|
@@ -429,7 +455,12 @@ async function main() {
|
|
|
429
455
|
).option(
|
|
430
456
|
"--node-version <version>",
|
|
431
457
|
'set Node.js version for engines.node field (default: "latest")'
|
|
432
|
-
).option("-y, --yes", "Skip prompts and use default values").action(async (name, options) => {
|
|
458
|
+
).option("-y, --yes", "Skip prompts and use default values").option("--clear-config", "Clear saved preferences (e.g. editor choice)").action(async (name, options) => {
|
|
459
|
+
if (options.clearConfig) {
|
|
460
|
+
clearConfig();
|
|
461
|
+
console.log("Configuration cleared.");
|
|
462
|
+
process.exit(0);
|
|
463
|
+
}
|
|
433
464
|
console.clear();
|
|
434
465
|
p__namespace.intro(color__default.bgCyan(color__default.black(` create-krispya v${pkg.version} `)));
|
|
435
466
|
let generateOptions;
|
|
@@ -561,33 +592,62 @@ async function main() {
|
|
|
561
592
|
`${packageManager} run dev`
|
|
562
593
|
].join("\n");
|
|
563
594
|
p__namespace.note(nextSteps, "Next steps");
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
595
|
+
const savedEditor = getPreferredEditor();
|
|
596
|
+
let selectedEditor;
|
|
597
|
+
if (savedEditor && savedEditor !== "skip") {
|
|
598
|
+
const useDefault = await p__namespace.confirm({
|
|
599
|
+
message: `Open in editor? ${color__default.dim(`(${editorNames[savedEditor]})`)}`,
|
|
600
|
+
initialValue: true
|
|
601
|
+
});
|
|
602
|
+
if (p__namespace.isCancel(useDefault)) {
|
|
603
|
+
selectedEditor = void 0;
|
|
604
|
+
} else if (useDefault) {
|
|
605
|
+
selectedEditor = savedEditor;
|
|
606
|
+
} else {
|
|
607
|
+
selectedEditor = "skip";
|
|
608
|
+
}
|
|
609
|
+
} else {
|
|
610
|
+
const openEditor = await p__namespace.select({
|
|
611
|
+
message: "Open project in editor?",
|
|
612
|
+
options: [
|
|
613
|
+
{ value: "skip", label: "Skip" },
|
|
614
|
+
{ value: "cursor", label: "Cursor" },
|
|
615
|
+
{ value: "code", label: "VS Code" },
|
|
616
|
+
{ value: "webstorm", label: "WebStorm" }
|
|
617
|
+
],
|
|
618
|
+
initialValue: "skip"
|
|
619
|
+
});
|
|
620
|
+
if (!p__namespace.isCancel(openEditor)) {
|
|
621
|
+
selectedEditor = openEditor;
|
|
622
|
+
const saveChoice = await p__namespace.confirm({
|
|
623
|
+
message: `Save ${editorNames[selectedEditor] ?? "Skip"} as default editor?`,
|
|
624
|
+
initialValue: true
|
|
625
|
+
});
|
|
626
|
+
if (!p__namespace.isCancel(saveChoice) && saveChoice) {
|
|
627
|
+
setPreferredEditor(selectedEditor);
|
|
628
|
+
if (selectedEditor === "cursor" || selectedEditor === "code") {
|
|
629
|
+
const reuseChoice = await p__namespace.confirm({
|
|
630
|
+
message: "Reuse current window when opening projects?",
|
|
631
|
+
initialValue: false
|
|
632
|
+
});
|
|
633
|
+
if (!p__namespace.isCancel(reuseChoice)) {
|
|
634
|
+
setReuseWindow(reuseChoice);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
if (selectedEditor && selectedEditor !== "skip") {
|
|
580
641
|
try {
|
|
581
642
|
await openInEditor(
|
|
582
|
-
|
|
583
|
-
basePath
|
|
584
|
-
|
|
585
|
-
p__namespace.log.success(
|
|
586
|
-
`Opening in ${editorNames[openEditor]}...`
|
|
643
|
+
selectedEditor,
|
|
644
|
+
basePath,
|
|
645
|
+
getReuseWindow()
|
|
587
646
|
);
|
|
647
|
+
p__namespace.log.success(`Opening in ${editorNames[selectedEditor]}...`);
|
|
588
648
|
} catch {
|
|
589
649
|
p__namespace.log.warn(
|
|
590
|
-
`Could not open ${editorNames[
|
|
650
|
+
`Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
|
|
591
651
|
);
|
|
592
652
|
}
|
|
593
653
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -9,6 +9,26 @@ import * as p from '@clack/prompts';
|
|
|
9
9
|
import color from 'chalk';
|
|
10
10
|
import { fetch } from 'undici';
|
|
11
11
|
import { spawn } from 'child_process';
|
|
12
|
+
import Conf from 'conf';
|
|
13
|
+
|
|
14
|
+
const config = new Conf({
|
|
15
|
+
projectName: "create-krispya"
|
|
16
|
+
});
|
|
17
|
+
function getPreferredEditor() {
|
|
18
|
+
return config.get("preferredEditor");
|
|
19
|
+
}
|
|
20
|
+
function setPreferredEditor(editor) {
|
|
21
|
+
config.set("preferredEditor", editor);
|
|
22
|
+
}
|
|
23
|
+
function getReuseWindow() {
|
|
24
|
+
return config.get("reuseWindow") ?? false;
|
|
25
|
+
}
|
|
26
|
+
function setReuseWindow(reuse) {
|
|
27
|
+
config.set("reuseWindow", reuse);
|
|
28
|
+
}
|
|
29
|
+
function clearConfig() {
|
|
30
|
+
config.clear();
|
|
31
|
+
}
|
|
12
32
|
|
|
13
33
|
const require$1 = createRequire(import.meta.url);
|
|
14
34
|
const pkg = require$1("../package.json");
|
|
@@ -361,12 +381,17 @@ async function promptForOptions(name) {
|
|
|
361
381
|
projectType
|
|
362
382
|
);
|
|
363
383
|
}
|
|
364
|
-
|
|
384
|
+
const editorNames = {
|
|
385
|
+
cursor: "Cursor",
|
|
386
|
+
code: "VS Code",
|
|
387
|
+
webstorm: "WebStorm"
|
|
388
|
+
};
|
|
389
|
+
function openInEditor(editor, path, reuseWindow) {
|
|
365
390
|
return new Promise((resolve, reject) => {
|
|
366
391
|
const isWindows = process.platform === "win32";
|
|
367
|
-
const
|
|
368
|
-
const args =
|
|
369
|
-
const child = isWindows ? spawn(`${editor} ${
|
|
392
|
+
const useReuseFlag = reuseWindow && (editor === "cursor" || editor === "code");
|
|
393
|
+
const args = useReuseFlag ? ["-r", path] : [path];
|
|
394
|
+
const child = isWindows ? spawn(`${editor} ${useReuseFlag ? "-r " : ""}"${path}"`, {
|
|
370
395
|
detached: true,
|
|
371
396
|
stdio: "ignore",
|
|
372
397
|
shell: true
|
|
@@ -409,7 +434,12 @@ async function main() {
|
|
|
409
434
|
).option(
|
|
410
435
|
"--node-version <version>",
|
|
411
436
|
'set Node.js version for engines.node field (default: "latest")'
|
|
412
|
-
).option("-y, --yes", "Skip prompts and use default values").action(async (name, options) => {
|
|
437
|
+
).option("-y, --yes", "Skip prompts and use default values").option("--clear-config", "Clear saved preferences (e.g. editor choice)").action(async (name, options) => {
|
|
438
|
+
if (options.clearConfig) {
|
|
439
|
+
clearConfig();
|
|
440
|
+
console.log("Configuration cleared.");
|
|
441
|
+
process.exit(0);
|
|
442
|
+
}
|
|
413
443
|
console.clear();
|
|
414
444
|
p.intro(color.bgCyan(color.black(` create-krispya v${pkg.version} `)));
|
|
415
445
|
let generateOptions;
|
|
@@ -541,33 +571,62 @@ async function main() {
|
|
|
541
571
|
`${packageManager} run dev`
|
|
542
572
|
].join("\n");
|
|
543
573
|
p.note(nextSteps, "Next steps");
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
574
|
+
const savedEditor = getPreferredEditor();
|
|
575
|
+
let selectedEditor;
|
|
576
|
+
if (savedEditor && savedEditor !== "skip") {
|
|
577
|
+
const useDefault = await p.confirm({
|
|
578
|
+
message: `Open in editor? ${color.dim(`(${editorNames[savedEditor]})`)}`,
|
|
579
|
+
initialValue: true
|
|
580
|
+
});
|
|
581
|
+
if (p.isCancel(useDefault)) {
|
|
582
|
+
selectedEditor = void 0;
|
|
583
|
+
} else if (useDefault) {
|
|
584
|
+
selectedEditor = savedEditor;
|
|
585
|
+
} else {
|
|
586
|
+
selectedEditor = "skip";
|
|
587
|
+
}
|
|
588
|
+
} else {
|
|
589
|
+
const openEditor = await p.select({
|
|
590
|
+
message: "Open project in editor?",
|
|
591
|
+
options: [
|
|
592
|
+
{ value: "skip", label: "Skip" },
|
|
593
|
+
{ value: "cursor", label: "Cursor" },
|
|
594
|
+
{ value: "code", label: "VS Code" },
|
|
595
|
+
{ value: "webstorm", label: "WebStorm" }
|
|
596
|
+
],
|
|
597
|
+
initialValue: "skip"
|
|
598
|
+
});
|
|
599
|
+
if (!p.isCancel(openEditor)) {
|
|
600
|
+
selectedEditor = openEditor;
|
|
601
|
+
const saveChoice = await p.confirm({
|
|
602
|
+
message: `Save ${editorNames[selectedEditor] ?? "Skip"} as default editor?`,
|
|
603
|
+
initialValue: true
|
|
604
|
+
});
|
|
605
|
+
if (!p.isCancel(saveChoice) && saveChoice) {
|
|
606
|
+
setPreferredEditor(selectedEditor);
|
|
607
|
+
if (selectedEditor === "cursor" || selectedEditor === "code") {
|
|
608
|
+
const reuseChoice = await p.confirm({
|
|
609
|
+
message: "Reuse current window when opening projects?",
|
|
610
|
+
initialValue: false
|
|
611
|
+
});
|
|
612
|
+
if (!p.isCancel(reuseChoice)) {
|
|
613
|
+
setReuseWindow(reuseChoice);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (selectedEditor && selectedEditor !== "skip") {
|
|
560
620
|
try {
|
|
561
621
|
await openInEditor(
|
|
562
|
-
|
|
563
|
-
basePath
|
|
564
|
-
|
|
565
|
-
p.log.success(
|
|
566
|
-
`Opening in ${editorNames[openEditor]}...`
|
|
622
|
+
selectedEditor,
|
|
623
|
+
basePath,
|
|
624
|
+
getReuseWindow()
|
|
567
625
|
);
|
|
626
|
+
p.log.success(`Opening in ${editorNames[selectedEditor]}...`);
|
|
568
627
|
} catch {
|
|
569
628
|
p.log.warn(
|
|
570
|
-
`Could not open ${editorNames[
|
|
629
|
+
`Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
|
|
571
630
|
);
|
|
572
631
|
}
|
|
573
632
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-krispya",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"description": "🌹 CLI for creating web projects with (my) sensible defaults",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@clack/prompts": "^0.11.0",
|
|
25
25
|
"chalk": "^5.4.1",
|
|
26
26
|
"commander": "^13.1.0",
|
|
27
|
+
"conf": "^13.0.0",
|
|
27
28
|
"ora": "^8.2.0",
|
|
28
29
|
"undici": "^5.28.4"
|
|
29
30
|
},
|