create-krispya 0.4.5 → 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.
Files changed (3) hide show
  1. package/dist/cli.cjs +88 -26
  2. package/dist/cli.mjs +87 -26
  3. 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,14 +402,21 @@ async function promptForOptions(name) {
381
402
  projectType
382
403
  );
383
404
  }
384
- function openInEditor(editor, path) {
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 child = isWindows ? child_process.spawn(`${editor} "${path}"`, {
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}"`, {
388
416
  detached: true,
389
417
  stdio: "ignore",
390
418
  shell: true
391
- }) : child_process.spawn(editor, [path], {
419
+ }) : child_process.spawn(editor, args, {
392
420
  detached: true,
393
421
  stdio: "ignore"
394
422
  });
@@ -427,7 +455,12 @@ async function main() {
427
455
  ).option(
428
456
  "--node-version <version>",
429
457
  'set Node.js version for engines.node field (default: "latest")'
430
- ).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
+ }
431
464
  console.clear();
432
465
  p__namespace.intro(color__default.bgCyan(color__default.black(` create-krispya v${pkg.version} `)));
433
466
  let generateOptions;
@@ -559,33 +592,62 @@ async function main() {
559
592
  `${packageManager} run dev`
560
593
  ].join("\n");
561
594
  p__namespace.note(nextSteps, "Next steps");
562
- const openEditor = await p__namespace.select({
563
- message: "Open project in editor?",
564
- options: [
565
- { value: "skip", label: "Skip" },
566
- { value: "cursor", label: "Cursor" },
567
- { value: "code", label: "VS Code" },
568
- { value: "webstorm", label: "WebStorm" }
569
- ],
570
- initialValue: "skip"
571
- });
572
- if (!p__namespace.isCancel(openEditor) && openEditor !== "skip") {
573
- const editorNames = {
574
- cursor: "Cursor",
575
- code: "VS Code",
576
- webstorm: "WebStorm"
577
- };
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") {
578
641
  try {
579
642
  await openInEditor(
580
- openEditor,
581
- basePath
582
- );
583
- p__namespace.log.success(
584
- `Opening in ${editorNames[openEditor]}...`
643
+ selectedEditor,
644
+ basePath,
645
+ getReuseWindow()
585
646
  );
647
+ p__namespace.log.success(`Opening in ${editorNames[selectedEditor]}...`);
586
648
  } catch {
587
649
  p__namespace.log.warn(
588
- `Could not open ${editorNames[openEditor]}. Make sure the CLI command is in your PATH.`
650
+ `Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
589
651
  );
590
652
  }
591
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,14 +381,21 @@ async function promptForOptions(name) {
361
381
  projectType
362
382
  );
363
383
  }
364
- function openInEditor(editor, path) {
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 child = isWindows ? spawn(`${editor} "${path}"`, {
392
+ const useReuseFlag = reuseWindow && (editor === "cursor" || editor === "code");
393
+ const args = useReuseFlag ? ["-r", path] : [path];
394
+ const child = isWindows ? spawn(`${editor} ${useReuseFlag ? "-r " : ""}"${path}"`, {
368
395
  detached: true,
369
396
  stdio: "ignore",
370
397
  shell: true
371
- }) : spawn(editor, [path], {
398
+ }) : spawn(editor, args, {
372
399
  detached: true,
373
400
  stdio: "ignore"
374
401
  });
@@ -407,7 +434,12 @@ async function main() {
407
434
  ).option(
408
435
  "--node-version <version>",
409
436
  'set Node.js version for engines.node field (default: "latest")'
410
- ).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
+ }
411
443
  console.clear();
412
444
  p.intro(color.bgCyan(color.black(` create-krispya v${pkg.version} `)));
413
445
  let generateOptions;
@@ -539,33 +571,62 @@ async function main() {
539
571
  `${packageManager} run dev`
540
572
  ].join("\n");
541
573
  p.note(nextSteps, "Next steps");
542
- const openEditor = await p.select({
543
- message: "Open project in editor?",
544
- options: [
545
- { value: "skip", label: "Skip" },
546
- { value: "cursor", label: "Cursor" },
547
- { value: "code", label: "VS Code" },
548
- { value: "webstorm", label: "WebStorm" }
549
- ],
550
- initialValue: "skip"
551
- });
552
- if (!p.isCancel(openEditor) && openEditor !== "skip") {
553
- const editorNames = {
554
- cursor: "Cursor",
555
- code: "VS Code",
556
- webstorm: "WebStorm"
557
- };
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") {
558
620
  try {
559
621
  await openInEditor(
560
- openEditor,
561
- basePath
562
- );
563
- p.log.success(
564
- `Opening in ${editorNames[openEditor]}...`
622
+ selectedEditor,
623
+ basePath,
624
+ getReuseWindow()
565
625
  );
626
+ p.log.success(`Opening in ${editorNames[selectedEditor]}...`);
566
627
  } catch {
567
628
  p.log.warn(
568
- `Could not open ${editorNames[openEditor]}. Make sure the CLI command is in your PATH.`
629
+ `Could not open ${editorNames[selectedEditor]}. Make sure the CLI command is in your PATH.`
569
630
  );
570
631
  }
571
632
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-krispya",
3
- "version": "0.4.5",
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
  },