@snelusha/noto 1.2.8 → 1.2.9

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/index.d.ts CHANGED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/dist/index.js CHANGED
@@ -12,21 +12,19 @@ var parse = (schema, raw) => {
12
12
  };
13
13
  };
14
14
  var safeParse = (schema, raw) => {
15
- let current2 = { ...schema };
15
+ let current = { ...schema };
16
16
  let iterations = 0;
17
- const maxIterations = Object.keys(current2).filter(
18
- (key2) => current2[key2] === String
19
- ).length;
17
+ const maxIterations = Object.keys(current).filter((key) => current[key] === String).length;
20
18
  while (iterations++ < maxIterations) {
21
19
  try {
22
- return parse(current2, raw);
20
+ return parse(current, raw);
23
21
  } catch (error) {
24
22
  if (error.code === "ARG_MISSING_REQUIRED_LONGARG") {
25
23
  const match = error.message.match(/(--\w[\w-]*)/);
26
24
  if (match) {
27
25
  const missingFlag = match[0];
28
- if (current2[missingFlag] === String) {
29
- current2[missingFlag] = Boolean;
26
+ if (current[missingFlag] === String) {
27
+ current[missingFlag] = Boolean;
30
28
  continue;
31
29
  }
32
30
  }
@@ -34,7 +32,7 @@ var safeParse = (schema, raw) => {
34
32
  throw error;
35
33
  }
36
34
  }
37
- return parse(current2, raw);
35
+ return parse(current, raw);
38
36
  };
39
37
 
40
38
  // src/commands/noto.ts
@@ -77,11 +75,9 @@ var StorageSchema = z2.object({
77
75
  }).optional(),
78
76
  lastGeneratedMessage: z2.string().optional()
79
77
  });
80
- var StorageManager = class {
81
- static storagePath = resolve(
82
- join(os.homedir(), ".noto"),
83
- "storage.sithi"
84
- );
78
+
79
+ class StorageManager {
80
+ static storagePath = resolve(join(os.homedir(), ".noto"), "storage.sithi");
85
81
  static storage = {};
86
82
  static async load() {
87
83
  try {
@@ -89,8 +85,10 @@ var StorageManager = class {
89
85
  const data = await fs.readFile(this.storagePath, "utf-8");
90
86
  const json = data ? JSON.parse(data) : {};
91
87
  const result = StorageSchema.safeParse(json);
92
- if (!result.success) this.storage = {};
93
- else this.storage = result.data;
88
+ if (!result.success)
89
+ this.storage = {};
90
+ else
91
+ this.storage = result.data;
94
92
  } catch {
95
93
  this.storage = {};
96
94
  }
@@ -102,18 +100,17 @@ var StorageManager = class {
102
100
  await fs.mkdir(directory, { recursive: true });
103
101
  const data = JSON.stringify(this.storage, null, 2);
104
102
  await fs.writeFile(this.storagePath, data, "utf-8");
105
- } catch {
106
- }
103
+ } catch {}
107
104
  }
108
105
  static async update(updater) {
109
106
  try {
110
107
  const updatedStorage = await updater(this.storage);
111
108
  const result = StorageSchema.safeParse(updatedStorage);
112
- if (!result.success) return this.storage;
109
+ if (!result.success)
110
+ return this.storage;
113
111
  this.storage = result.data;
114
112
  await this.save();
115
- } catch {
116
- }
113
+ } catch {}
117
114
  return this.storage;
118
115
  }
119
116
  static async get() {
@@ -124,7 +121,7 @@ var StorageManager = class {
124
121
  this.storage = {};
125
122
  await this.save();
126
123
  }
127
- };
124
+ }
128
125
 
129
126
  // src/utils/process.ts
130
127
  var exit = async (code) => {
@@ -139,10 +136,8 @@ var withAuth = (fn, options = { enabled: true }) => {
139
136
  const storage = await StorageManager.get();
140
137
  const apiKey = process.env.NOTO_API_KEY || storage.llm?.apiKey;
141
138
  if (!apiKey && options.enabled) {
142
- p.log.error(
143
- dedent`${color.red("noto api key is missing.")}
144
- ${color.dim(`run ${color.cyan("`noto config key`")} to set it up.`)}`
145
- );
139
+ p.log.error(dedent`${color.red("noto api key is missing.")}
140
+ ${color.dim(`run ${color.cyan("`noto config key`")} to set it up.`)}`);
146
141
  return await exit(1);
147
142
  }
148
143
  return fn(opts);
@@ -168,7 +163,8 @@ var getCommitCount = async () => {
168
163
  } catch (error) {
169
164
  const message = error.message;
170
165
  const regex = /(ambiguous argument.*HEAD|unknown revision or path.*HEAD)/;
171
- if (regex.test(message)) return 0;
166
+ if (regex.test(message))
167
+ return 0;
172
168
  throw error;
173
169
  }
174
170
  };
@@ -185,10 +181,10 @@ var getStagedDiff = async () => {
185
181
  };
186
182
  var commit = async (message, amend) => {
187
183
  try {
188
- const options = amend ? { "--amend": null } : void 0;
184
+ const options = amend ? { "--amend": null } : undefined;
189
185
  const {
190
186
  summary: { changes }
191
- } = await git.commit(message, void 0, options);
187
+ } = await git.commit(message, undefined, options);
192
188
  return Boolean(changes);
193
189
  } catch {
194
190
  return false;
@@ -248,20 +244,16 @@ var withRepository = (fn, options = { enabled: true }) => {
248
244
  return async (opts) => {
249
245
  const isRepo = await isGitRepository();
250
246
  if (!isRepo && options.enabled) {
251
- p2.log.error(
252
- dedent2`${color2.red("no git repository found in cwd.")}
253
- ${color2.dim(`run ${color2.cyan("`git init`")} to initialize a new repository.`)}`
254
- );
247
+ p2.log.error(dedent2`${color2.red("no git repository found in cwd.")}
248
+ ${color2.dim(`run ${color2.cyan("`git init`")} to initialize a new repository.`)}`);
255
249
  return await exit(1);
256
250
  }
257
251
  opts.isRepo = isRepo;
258
252
  if (isRepo) {
259
253
  const diff = await getStagedDiff();
260
254
  if (!diff && options.enabled) {
261
- p2.log.error(
262
- dedent2`${color2.red("no staged changes found.")}
263
- ${color2.dim(`run ${color2.cyan("`git add <file>`")} or ${color2.cyan("`git add .`")} to stage changes.`)}`
264
- );
255
+ p2.log.error(dedent2`${color2.red("no staged changes found.")}
256
+ ${color2.dim(`run ${color2.cyan("`git add <file>`")} or ${color2.cyan("`git add .`")} to stage changes.`)}`);
265
257
  return await exit(1);
266
258
  }
267
259
  opts.diff = diff;
@@ -290,33 +282,31 @@ var models = {
290
282
  "gemini-1.5-pro-latest": google("gemini-1.5-pro-latest"),
291
283
  "gemini-2.0-flash-001": google("gemini-2.0-flash-001"),
292
284
  "gemini-2.0-flash": google("gemini-2.0-flash"),
293
- "gemini-2.0-flash-lite-preview-02-05": google(
294
- "gemini-2.0-flash-lite-preview-02-05"
295
- ),
285
+ "gemini-2.0-flash-lite-preview-02-05": google("gemini-2.0-flash-lite-preview-02-05"),
296
286
  "gemini-2.5-flash-preview-04-17": google("gemini-2.5-flash-preview-04-17"),
297
287
  "gemini-2.5-pro-preview-05-06": google("gemini-2.5-pro-preview-05-06")
298
288
  };
299
289
  var availableModels = Object.keys(models);
300
290
  var getModel = async () => {
301
- let model2 = (await StorageManager.get()).llm?.model;
302
- if (!model2 || !availableModels.includes(model2)) {
303
- model2 = defaultModel;
304
- await StorageManager.update((current2) => ({
305
- ...current2,
291
+ let model = (await StorageManager.get()).llm?.model;
292
+ if (!model || !availableModels.includes(model)) {
293
+ model = defaultModel;
294
+ await StorageManager.update((current) => ({
295
+ ...current,
306
296
  llm: {
307
- ...current2.llm,
297
+ ...current.llm,
308
298
  model: defaultModel
309
299
  }
310
300
  }));
311
301
  }
312
- return models[model2];
302
+ return models[model];
313
303
  };
314
304
 
315
305
  // src/ai/index.ts
316
306
  var generateCommitMessage = async (diff, type, context) => {
317
- const model2 = await getModel();
307
+ const model = await getModel();
318
308
  const { object } = await generateObject({
319
- model: model2,
309
+ model,
320
310
  schema: z3.object({
321
311
  message: z3.string()
322
312
  }),
@@ -441,118 +431,112 @@ var command = {
441
431
  description: "commit and push the changes"
442
432
  }
443
433
  ],
444
- execute: withAuth(
445
- withRepository(async (options) => {
446
- const spin = p3.spinner();
447
- try {
448
- const { diff } = options;
449
- const manual = options["--manual"];
450
- if (manual) {
451
- const message2 = await p3.text({
452
- message: "edit the generated commit message",
453
- placeholder: "chore: init repo"
454
- });
455
- if (p3.isCancel(message2)) {
456
- p3.log.error(color3.red("nothing changed!"));
457
- return await exit(1);
458
- }
459
- p3.log.step(color3.green(message2));
460
- await StorageManager.update((current2) => ({
461
- ...current2,
462
- lastGeneratedMessage: message2
463
- }));
464
- if (options["--apply"]) {
465
- const success = await commit(message2);
466
- if (success) {
467
- p3.log.step(color3.dim("commit successful"));
468
- } else {
469
- p3.log.error(color3.red("failed to commit changes"));
470
- }
471
- }
472
- return await exit(0);
473
- }
474
- const type = options["--type"];
475
- if (typeof type === "string" && !availableTypes.includes(type) || typeof type === "boolean") {
476
- const type2 = await p3.select({
477
- message: "select the type of commit message",
478
- options: commitTypeOptions
479
- });
480
- if (p3.isCancel(type2)) {
481
- p3.log.error(color3.red("nothing selected!"));
482
- return await exit(1);
483
- }
484
- options.type = type2;
485
- } else if (typeof type === "string") {
486
- options.type = type;
487
- }
488
- const context = options["--message"];
489
- if (typeof context === "string") {
490
- options.context = context;
491
- } else if (typeof context === "boolean") {
492
- const context2 = await p3.text({
493
- message: "provide context for the commit message",
494
- placeholder: "describe the changes"
495
- });
496
- if (p3.isCancel(context2)) {
497
- p3.log.error(color3.red("nothing changed!"));
498
- return await exit(1);
499
- }
500
- options.context = context2;
501
- }
502
- spin.start("generating commit message");
503
- let message = null;
504
- if (!await isFirstCommit()) {
505
- message = await generateCommitMessage(
506
- diff,
507
- options.type,
508
- options.context
509
- );
510
- } else {
511
- message = INIT_COMMIT_MESSAGE;
512
- }
513
- spin.stop(color3.white(message));
514
- const editedMessage = await p3.text({
434
+ execute: withAuth(withRepository(async (options) => {
435
+ const spin = p3.spinner();
436
+ try {
437
+ const { diff } = options;
438
+ const manual = options["--manual"];
439
+ if (manual) {
440
+ const message2 = await p3.text({
515
441
  message: "edit the generated commit message",
516
- initialValue: message,
517
- placeholder: message
442
+ placeholder: "chore: init repo"
518
443
  });
519
- if (p3.isCancel(editedMessage)) {
444
+ if (p3.isCancel(message2)) {
520
445
  p3.log.error(color3.red("nothing changed!"));
521
446
  return await exit(1);
522
447
  }
523
- message = editedMessage;
524
- p3.log.step(color3.green(message));
525
- await StorageManager.update((current2) => ({
526
- ...current2,
527
- lastGeneratedMessage: message
448
+ p3.log.step(color3.green(message2));
449
+ await StorageManager.update((current) => ({
450
+ ...current,
451
+ lastGeneratedMessage: message2
528
452
  }));
529
- if (options["--copy"]) {
530
- clipboard.writeSync(message);
531
- p3.log.step(color3.dim("copied commit message to clipboard"));
532
- }
533
453
  if (options["--apply"]) {
534
- const success = await commit(message);
454
+ const success = await commit(message2);
535
455
  if (success) {
536
456
  p3.log.step(color3.dim("commit successful"));
537
457
  } else {
538
458
  p3.log.error(color3.red("failed to commit changes"));
539
459
  }
540
460
  }
541
- if (options["--push"]) {
542
- const success = await push();
543
- if (success) {
544
- p3.log.step(color3.dim("push successful"));
545
- } else {
546
- p3.log.error(color3.red("failed to push changes"));
547
- }
548
- }
549
461
  return await exit(0);
550
- } catch {
551
- spin.stop(color3.red("failed to generate commit message"), 1);
462
+ }
463
+ const type = options["--type"];
464
+ if (typeof type === "string" && !availableTypes.includes(type) || typeof type === "boolean") {
465
+ const type2 = await p3.select({
466
+ message: "select the type of commit message",
467
+ options: commitTypeOptions
468
+ });
469
+ if (p3.isCancel(type2)) {
470
+ p3.log.error(color3.red("nothing selected!"));
471
+ return await exit(1);
472
+ }
473
+ options.type = type2;
474
+ } else if (typeof type === "string") {
475
+ options.type = type;
476
+ }
477
+ const context = options["--message"];
478
+ if (typeof context === "string") {
479
+ options.context = context;
480
+ } else if (typeof context === "boolean") {
481
+ const context2 = await p3.text({
482
+ message: "provide context for the commit message",
483
+ placeholder: "describe the changes"
484
+ });
485
+ if (p3.isCancel(context2)) {
486
+ p3.log.error(color3.red("nothing changed!"));
487
+ return await exit(1);
488
+ }
489
+ options.context = context2;
490
+ }
491
+ spin.start("generating commit message");
492
+ let message = null;
493
+ if (!await isFirstCommit()) {
494
+ message = await generateCommitMessage(diff, options.type, options.context);
495
+ } else {
496
+ message = INIT_COMMIT_MESSAGE;
497
+ }
498
+ spin.stop(color3.white(message));
499
+ const editedMessage = await p3.text({
500
+ message: "edit the generated commit message",
501
+ initialValue: message,
502
+ placeholder: message
503
+ });
504
+ if (p3.isCancel(editedMessage)) {
505
+ p3.log.error(color3.red("nothing changed!"));
552
506
  return await exit(1);
553
507
  }
554
- })
555
- )
508
+ message = editedMessage;
509
+ p3.log.step(color3.green(message));
510
+ await StorageManager.update((current) => ({
511
+ ...current,
512
+ lastGeneratedMessage: message
513
+ }));
514
+ if (options["--copy"]) {
515
+ clipboard.writeSync(message);
516
+ p3.log.step(color3.dim("copied commit message to clipboard"));
517
+ }
518
+ if (options["--apply"]) {
519
+ const success = await commit(message);
520
+ if (success) {
521
+ p3.log.step(color3.dim("commit successful"));
522
+ } else {
523
+ p3.log.error(color3.red("failed to commit changes"));
524
+ }
525
+ }
526
+ if (options["--push"]) {
527
+ const success = await push();
528
+ if (success) {
529
+ p3.log.step(color3.dim("push successful"));
530
+ } else {
531
+ p3.log.error(color3.red("failed to push changes"));
532
+ }
533
+ }
534
+ return await exit(0);
535
+ } catch {
536
+ spin.stop(color3.red("failed to generate commit message"), 1);
537
+ return await exit(1);
538
+ }
539
+ }))
556
540
  };
557
541
  var noto_default = command;
558
542
 
@@ -590,75 +574,60 @@ var command2 = {
590
574
  description: "amend the last commit with the last generated message"
591
575
  }
592
576
  ],
593
- execute: withAuth(
594
- withRepository(
595
- async (options) => {
596
- let lastGeneratedMessage = (await StorageManager.get()).lastGeneratedMessage;
597
- if (!lastGeneratedMessage) {
598
- p4.log.error(color4.red("no previous commit message found"));
599
- return await exit(1);
600
- }
601
- const isEditMode = options["--edit"];
602
- const isAmend = options["--amend"];
603
- if (isAmend && !isEditMode) {
604
- p4.log.error(
605
- color4.red("the --amend option requires the --edit option")
606
- );
607
- return await exit(1);
608
- }
609
- p4.log.step(
610
- isEditMode ? color4.white(lastGeneratedMessage) : color4.green(lastGeneratedMessage)
611
- );
612
- if (options["--edit"]) {
613
- const editedMessage = await p4.text({
614
- message: "edit the last generated commit message",
615
- initialValue: lastGeneratedMessage,
616
- placeholder: lastGeneratedMessage
617
- });
618
- if (p4.isCancel(editedMessage)) {
619
- p4.log.error(color4.red("nothing changed!"));
620
- return await exit(1);
621
- }
622
- lastGeneratedMessage = editedMessage;
623
- await StorageManager.update((current2) => ({
624
- ...current2,
625
- lastGeneratedMessage: editedMessage
626
- }));
627
- p4.log.step(color4.green(lastGeneratedMessage));
628
- }
629
- if (options["--copy"]) {
630
- clipboard2.writeSync(lastGeneratedMessage);
631
- p4.log.step(
632
- color4.dim("copied last generated commit message to clipboard")
633
- );
634
- }
635
- if (options["--apply"] || isAmend) {
636
- if (!options.isRepo) {
637
- p4.log.error(
638
- dedent4`${color4.red("no git repository found in cwd.")}
639
- ${color4.dim(`run ${color4.cyan("`git init`")} to initialize a new repository.`)}`
640
- );
641
- return await exit(1);
642
- }
643
- if (!options.diff && !isAmend) {
644
- p4.log.error(
645
- dedent4`${color4.red("no staged changes found.")}
646
- ${color4.dim(`run ${color4.cyan("`git add <file>`")} or ${color4.cyan("`git add .`")} to stage changes.`)}`
647
- );
648
- return await exit(1);
649
- }
650
- const success = await commit(lastGeneratedMessage, isAmend);
651
- if (success) {
652
- p4.log.step(color4.dim("commit successful"));
653
- } else {
654
- p4.log.error(color4.red("failed to commit changes"));
655
- }
656
- }
657
- return await exit(0);
658
- },
659
- { enabled: false }
660
- )
661
- )
577
+ execute: withAuth(withRepository(async (options) => {
578
+ let lastGeneratedMessage = (await StorageManager.get()).lastGeneratedMessage;
579
+ if (!lastGeneratedMessage) {
580
+ p4.log.error(color4.red("no previous commit message found"));
581
+ return await exit(1);
582
+ }
583
+ const isEditMode = options["--edit"];
584
+ const isAmend = options["--amend"];
585
+ if (isAmend && !isEditMode) {
586
+ p4.log.error(color4.red("the --amend option requires the --edit option"));
587
+ return await exit(1);
588
+ }
589
+ p4.log.step(isEditMode ? color4.white(lastGeneratedMessage) : color4.green(lastGeneratedMessage));
590
+ if (options["--edit"]) {
591
+ const editedMessage = await p4.text({
592
+ message: "edit the last generated commit message",
593
+ initialValue: lastGeneratedMessage,
594
+ placeholder: lastGeneratedMessage
595
+ });
596
+ if (p4.isCancel(editedMessage)) {
597
+ p4.log.error(color4.red("nothing changed!"));
598
+ return await exit(1);
599
+ }
600
+ lastGeneratedMessage = editedMessage;
601
+ await StorageManager.update((current) => ({
602
+ ...current,
603
+ lastGeneratedMessage: editedMessage
604
+ }));
605
+ p4.log.step(color4.green(lastGeneratedMessage));
606
+ }
607
+ if (options["--copy"]) {
608
+ clipboard2.writeSync(lastGeneratedMessage);
609
+ p4.log.step(color4.dim("copied last generated commit message to clipboard"));
610
+ }
611
+ if (options["--apply"] || isAmend) {
612
+ if (!options.isRepo) {
613
+ p4.log.error(dedent4`${color4.red("no git repository found in cwd.")}
614
+ ${color4.dim(`run ${color4.cyan("`git init`")} to initialize a new repository.`)}`);
615
+ return await exit(1);
616
+ }
617
+ if (!options.diff && !isAmend) {
618
+ p4.log.error(dedent4`${color4.red("no staged changes found.")}
619
+ ${color4.dim(`run ${color4.cyan("`git add <file>`")} or ${color4.cyan("`git add .`")} to stage changes.`)}`);
620
+ return await exit(1);
621
+ }
622
+ const success = await commit(lastGeneratedMessage, isAmend);
623
+ if (success) {
624
+ p4.log.step(color4.dim("commit successful"));
625
+ } else {
626
+ p4.log.error(color4.red("failed to commit changes"));
627
+ }
628
+ }
629
+ return await exit(0);
630
+ }, { enabled: false }))
662
631
  };
663
632
  var prev_default = command2;
664
633
 
@@ -679,29 +648,24 @@ var current = {
679
648
  description: "copy the selected branch to clipboard"
680
649
  }
681
650
  ],
682
- execute: withRepository(
683
- async (options) => {
684
- if (!options.isRepo) {
685
- p5.log.error(
686
- dedent5`${color5.red("no git repository found in cwd.")}
687
- ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`
688
- );
689
- return await exit(1);
690
- }
691
- const branch = await getCurrentBranch();
692
- if (!branch) {
693
- p5.log.error("failed to fetch current branch");
694
- return await exit(1);
695
- }
696
- p5.log.success(`current branch: ${color5.bold(branch)}`);
697
- if (options["--copy"]) {
698
- clipboard3.writeSync(branch);
699
- p5.log.success(`${color5.green("copied to clipboard!")}`);
700
- }
701
- await exit(0);
702
- },
703
- { enabled: false }
704
- )
651
+ execute: withRepository(async (options) => {
652
+ if (!options.isRepo) {
653
+ p5.log.error(dedent5`${color5.red("no git repository found in cwd.")}
654
+ ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`);
655
+ return await exit(1);
656
+ }
657
+ const branch = await getCurrentBranch();
658
+ if (!branch) {
659
+ p5.log.error("failed to fetch current branch");
660
+ return await exit(1);
661
+ }
662
+ p5.log.success(`current branch: ${color5.bold(branch)}`);
663
+ if (options["--copy"]) {
664
+ clipboard3.writeSync(branch);
665
+ p5.log.success(`${color5.green("copied to clipboard!")}`);
666
+ }
667
+ await exit(0);
668
+ }, { enabled: false })
705
669
  };
706
670
  var del = {
707
671
  name: "delete",
@@ -721,53 +685,48 @@ var del = {
721
685
  description: "select all branches except the current one"
722
686
  }
723
687
  ],
724
- execute: withRepository(
725
- async (options) => {
726
- if (!options.isRepo) {
727
- p5.log.error(
728
- dedent5`${color5.red("no git repository found in cwd.")}
729
- ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`
730
- );
731
- return await exit(1);
732
- }
733
- const currentBranch = await getCurrentBranch();
734
- const branches = await getBranches();
735
- if (!currentBranch || !branches) {
736
- p5.log.error("failed to fetch branches");
737
- return await exit(1);
738
- }
739
- const selectedBranches = await p5.multiselect({
740
- message: "select branches to delete",
741
- initialValues: options["--all"] ? branches.filter((b) => b !== currentBranch) : [],
742
- options: branches.map((branch) => ({
743
- value: branch,
744
- label: color5.bold(branch),
745
- hint: branch === options["--current"] ? "current branch" : void 0
746
- }))
747
- });
748
- if (p5.isCancel(selectedBranches)) {
749
- p5.log.error("nothing selected!");
750
- return await exit(1);
751
- }
752
- if (!selectedBranches) {
753
- p5.log.error("no branch selected");
754
- return await exit(1);
755
- }
756
- const force = options["--force"];
757
- if (currentBranch && selectedBranches.includes(currentBranch)) {
758
- p5.log.error("cannot delete current branch");
759
- return await exit(1);
760
- }
761
- const deletedBranches = await deleteBranches(selectedBranches, force);
762
- if (!deletedBranches) {
763
- p5.log.error("failed to delete branches");
764
- return await exit(1);
765
- }
766
- p5.log.success("branches deleted successfully");
767
- await exit(0);
768
- },
769
- { enabled: false }
770
- )
688
+ execute: withRepository(async (options) => {
689
+ if (!options.isRepo) {
690
+ p5.log.error(dedent5`${color5.red("no git repository found in cwd.")}
691
+ ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`);
692
+ return await exit(1);
693
+ }
694
+ const currentBranch = await getCurrentBranch();
695
+ const branches = await getBranches();
696
+ if (!currentBranch || !branches) {
697
+ p5.log.error("failed to fetch branches");
698
+ return await exit(1);
699
+ }
700
+ const selectedBranches = await p5.multiselect({
701
+ message: "select branches to delete",
702
+ initialValues: options["--all"] ? branches.filter((b) => b !== currentBranch) : [],
703
+ options: branches.map((branch) => ({
704
+ value: branch,
705
+ label: color5.bold(branch),
706
+ hint: branch === options["--current"] ? "current branch" : undefined
707
+ }))
708
+ });
709
+ if (p5.isCancel(selectedBranches)) {
710
+ p5.log.error("nothing selected!");
711
+ return await exit(1);
712
+ }
713
+ if (!selectedBranches) {
714
+ p5.log.error("no branch selected");
715
+ return await exit(1);
716
+ }
717
+ const force = options["--force"];
718
+ if (currentBranch && selectedBranches.includes(currentBranch)) {
719
+ p5.log.error("cannot delete current branch");
720
+ return await exit(1);
721
+ }
722
+ const deletedBranches = await deleteBranches(selectedBranches, force);
723
+ if (!deletedBranches) {
724
+ p5.log.error("failed to delete branches");
725
+ return await exit(1);
726
+ }
727
+ p5.log.success("branches deleted successfully");
728
+ await exit(0);
729
+ }, { enabled: false })
771
730
  };
772
731
  var command3 = {
773
732
  name: "branch",
@@ -799,48 +758,42 @@ var command3 = {
799
758
  description: "select all branches except the current one"
800
759
  }
801
760
  ],
802
- execute: withRepository(
803
- async (options) => {
804
- if (!options.isRepo) {
805
- p5.log.error(
806
- dedent5`${color5.red("no git repository found in cwd.")}
807
- ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`
808
- );
809
- return await exit(1);
810
- }
811
- if (options["--delete"]) return del.execute(options);
812
- const remote = options["--remote"];
813
- const branches = await getBranches(remote);
814
- if (!branches) {
815
- p5.log.error("failed to fetch branches");
816
- return await exit(1);
817
- }
818
- const currentBranch = await getCurrentBranch();
819
- const branch = await p5.select({
820
- message: "select a branch",
821
- options: branches.map((branch2) => ({
822
- value: branch2,
823
- label: color5.bold(
824
- branch2 === currentBranch ? color5.green(branch2) : branch2
825
- ),
826
- hint: branch2 === currentBranch ? "current branch" : void 0
827
- })),
828
- initialValue: currentBranch
829
- });
830
- if (p5.isCancel(branch)) {
831
- p5.log.error("nothing selected!");
832
- return await exit(1);
833
- }
834
- if (!branch) {
835
- p5.log.error("no branch selected");
836
- return await exit(1);
837
- }
838
- clipboard3.writeSync(branch);
839
- p5.log.success(`${color5.green("copied to clipboard!")}`);
840
- await exit(0);
841
- },
842
- { enabled: false }
843
- ),
761
+ execute: withRepository(async (options) => {
762
+ if (!options.isRepo) {
763
+ p5.log.error(dedent5`${color5.red("no git repository found in cwd.")}
764
+ ${color5.dim(`run ${color5.cyan("`git init`")} to initialize a new repository.`)}`);
765
+ return await exit(1);
766
+ }
767
+ if (options["--delete"])
768
+ return del.execute(options);
769
+ const remote = options["--remote"];
770
+ const branches = await getBranches(remote);
771
+ if (!branches) {
772
+ p5.log.error("failed to fetch branches");
773
+ return await exit(1);
774
+ }
775
+ const currentBranch = await getCurrentBranch();
776
+ const branch = await p5.select({
777
+ message: "select a branch",
778
+ options: branches.map((branch2) => ({
779
+ value: branch2,
780
+ label: color5.bold(branch2 === currentBranch ? color5.green(branch2) : branch2),
781
+ hint: branch2 === currentBranch ? "current branch" : undefined
782
+ })),
783
+ initialValue: currentBranch
784
+ });
785
+ if (p5.isCancel(branch)) {
786
+ p5.log.error("nothing selected!");
787
+ return await exit(1);
788
+ }
789
+ if (!branch) {
790
+ p5.log.error("no branch selected");
791
+ return await exit(1);
792
+ }
793
+ clipboard3.writeSync(branch);
794
+ p5.log.success(`${color5.green("copied to clipboard!")}`);
795
+ await exit(0);
796
+ }, { enabled: false }),
844
797
  subCommands: [current, del]
845
798
  };
846
799
  var branch_default = command3;
@@ -868,117 +821,100 @@ var command4 = {
868
821
  description: "create a new branch"
869
822
  }
870
823
  ],
871
- execute: withRepository(
872
- async (options) => {
873
- const args = options._.slice(1);
874
- if (!options.isRepo) {
875
- p6.log.error(
876
- dedent6`${color6.red("no git repository found in cwd.")}
877
- ${color6.dim(`run ${color6.cyan("`git init`")} to initialize a new repository.`)}`
878
- );
824
+ execute: withRepository(async (options) => {
825
+ const args = options._.slice(1);
826
+ if (!options.isRepo) {
827
+ p6.log.error(dedent6`${color6.red("no git repository found in cwd.")}
828
+ ${color6.dim(`run ${color6.cyan("`git init`")} to initialize a new repository.`)}`);
829
+ return await exit(1);
830
+ }
831
+ const branches = await getBranches();
832
+ if (!branches) {
833
+ p6.log.error("failed to fetch branches");
834
+ return await exit(1);
835
+ }
836
+ const currentBranch = await getCurrentBranch();
837
+ const branchName = args[0];
838
+ if (options["--create"]) {
839
+ if (branches.includes(branchName)) {
840
+ p6.log.error(`branch ${color6.red(branchName)} already exists in the repository`);
879
841
  return await exit(1);
880
842
  }
881
- const branches = await getBranches();
882
- if (!branches) {
883
- p6.log.error("failed to fetch branches");
843
+ const result2 = await checkoutLocalBranch(branchName);
844
+ if (!result2) {
845
+ p6.log.error(`failed to create and checkout ${color6.bold(branchName)}`);
884
846
  return await exit(1);
885
847
  }
886
- const currentBranch = await getCurrentBranch();
887
- const branchName = args[0];
888
- if (options["--create"]) {
889
- if (branches.includes(branchName)) {
890
- p6.log.error(
891
- `branch ${color6.red(branchName)} already exists in the repository`
892
- );
893
- return await exit(1);
894
- }
895
- const result2 = await checkoutLocalBranch(branchName);
896
- if (!result2) {
897
- p6.log.error(
898
- `failed to create and checkout ${color6.bold(branchName)}`
899
- );
848
+ p6.log.success(`created and checked out ${color6.green(branchName)}`);
849
+ return await exit(0);
850
+ }
851
+ if (branchName) {
852
+ if (!branches.includes(branchName)) {
853
+ p6.log.error(`branch ${color6.red(branchName)} does not exist in the repository`);
854
+ const createBranch = await p6.confirm({
855
+ message: `do you want to create branch ${color6.green(branchName)}?`
856
+ });
857
+ if (p6.isCancel(createBranch)) {
858
+ p6.log.error("aborted");
900
859
  return await exit(1);
901
860
  }
902
- p6.log.success(`created and checked out ${color6.green(branchName)}`);
903
- return await exit(0);
904
- }
905
- if (branchName) {
906
- if (!branches.includes(branchName)) {
907
- p6.log.error(
908
- `branch ${color6.red(branchName)} does not exist in the repository`
909
- );
910
- const createBranch = await p6.confirm({
911
- message: `do you want to create branch ${color6.green(branchName)}?`
912
- });
913
- if (p6.isCancel(createBranch)) {
914
- p6.log.error("aborted");
861
+ if (createBranch) {
862
+ const result3 = await checkoutLocalBranch(branchName);
863
+ if (!result3) {
864
+ p6.log.error(`failed to create and checkout ${color6.bold(branchName)}`);
915
865
  return await exit(1);
916
866
  }
917
- if (createBranch) {
918
- const result3 = await checkoutLocalBranch(branchName);
919
- if (!result3) {
920
- p6.log.error(
921
- `failed to create and checkout ${color6.bold(branchName)}`
922
- );
923
- return await exit(1);
924
- }
925
- p6.log.success(`created and checked out ${color6.green(branchName)}`);
926
- return await exit(0);
927
- }
928
- return await exit(1);
929
- }
930
- if (branchName === currentBranch) {
931
- p6.log.error(
932
- `${color6.red("already on branch")} ${color6.green(branchName)}`
933
- );
934
- return await exit(1);
935
- }
936
- const result2 = await checkout(branchName);
937
- if (!result2) {
938
- p6.log.error(`failed to checkout ${color6.bold(branchName)}`);
939
- return await exit(1);
867
+ p6.log.success(`created and checked out ${color6.green(branchName)}`);
868
+ return await exit(0);
940
869
  }
941
- p6.log.success(`checked out ${color6.green(branchName)}`);
942
- return await exit(0);
943
- }
944
- const branch = await p6.select({
945
- message: "select a branch to checkout",
946
- options: branches.map((branch2) => ({
947
- value: branch2,
948
- label: color6.bold(
949
- branch2 === currentBranch ? color6.green(branch2) : branch2
950
- ),
951
- hint: branch2 === currentBranch ? "current branch" : void 0
952
- })),
953
- initialValue: currentBranch
954
- });
955
- if (p6.isCancel(branch)) {
956
- p6.log.error("nothing selected!");
957
- return await exit(1);
958
- }
959
- if (!branch) {
960
- p6.log.error("no branch selected");
961
870
  return await exit(1);
962
871
  }
963
- if (options["--copy"]) {
964
- clipboard4.writeSync(branch);
965
- p6.log.success(`copied ${color6.green(branch)} to clipboard`);
966
- return await exit(0);
967
- }
968
- if (branch === currentBranch) {
969
- p6.log.error(`${color6.red("already on branch")}`);
872
+ if (branchName === currentBranch) {
873
+ p6.log.error(`${color6.red("already on branch")} ${color6.green(branchName)}`);
970
874
  return await exit(1);
971
875
  }
972
- const result = await checkout(branch);
973
- if (!result) {
974
- p6.log.error(`failed to checkout ${color6.bold(branch)}`);
876
+ const result2 = await checkout(branchName);
877
+ if (!result2) {
878
+ p6.log.error(`failed to checkout ${color6.bold(branchName)}`);
975
879
  return await exit(1);
976
880
  }
977
- p6.log.success(`checked out ${color6.green(branch)}`);
978
- await exit(0);
979
- },
980
- { enabled: false }
981
- )
881
+ p6.log.success(`checked out ${color6.green(branchName)}`);
882
+ return await exit(0);
883
+ }
884
+ const branch = await p6.select({
885
+ message: "select a branch to checkout",
886
+ options: branches.map((branch2) => ({
887
+ value: branch2,
888
+ label: color6.bold(branch2 === currentBranch ? color6.green(branch2) : branch2),
889
+ hint: branch2 === currentBranch ? "current branch" : undefined
890
+ })),
891
+ initialValue: currentBranch
892
+ });
893
+ if (p6.isCancel(branch)) {
894
+ p6.log.error("nothing selected!");
895
+ return await exit(1);
896
+ }
897
+ if (!branch) {
898
+ p6.log.error("no branch selected");
899
+ return await exit(1);
900
+ }
901
+ if (options["--copy"]) {
902
+ clipboard4.writeSync(branch);
903
+ p6.log.success(`copied ${color6.green(branch)} to clipboard`);
904
+ return await exit(0);
905
+ }
906
+ if (branch === currentBranch) {
907
+ p6.log.error(`${color6.red("already on branch")}`);
908
+ return await exit(1);
909
+ }
910
+ const result = await checkout(branch);
911
+ if (!result) {
912
+ p6.log.error(`failed to checkout ${color6.bold(branch)}`);
913
+ return await exit(1);
914
+ }
915
+ p6.log.success(`checked out ${color6.green(branch)}`);
916
+ await exit(0);
917
+ }, { enabled: false })
982
918
  };
983
919
  var checkout_default = command4;
984
920
 
@@ -1120,16 +1056,14 @@ var help = {
1120
1056
  console.log(` ${command6.description}`);
1121
1057
  console.log();
1122
1058
  } else {
1123
- const commands2 = listCommand();
1059
+ const commands = listCommand();
1124
1060
  console.log();
1125
1061
  console.log(color8.bold("usage"));
1126
1062
  console.log(` noto [command] [options]`);
1127
1063
  console.log();
1128
1064
  console.log(color8.bold("commands"));
1129
- commands2.forEach((command7) => {
1130
- console.log(
1131
- ` ${color8.bold(command7.name)} ${color8.dim(command7.description)}`
1132
- );
1065
+ commands.forEach((command7) => {
1066
+ console.log(` ${color8.bold(command7.name)} ${color8.dim(command7.description)}`);
1133
1067
  });
1134
1068
  await exit(0);
1135
1069
  }
@@ -1145,9 +1079,8 @@ var getCommand = (name, cmds = commands) => {
1145
1079
  var listCommand = () => {
1146
1080
  return commands;
1147
1081
  };
1148
-
1149
1082
  // package.json
1150
- var version = "1.2.8";
1083
+ var version = "1.2.9";
1151
1084
 
1152
1085
  // src/index.ts
1153
1086
  var globalSpec = {
@@ -1161,20 +1094,20 @@ function main() {
1161
1094
  const { command: command6, options: globalOptions } = parse(globalSpec, args);
1162
1095
  console.log();
1163
1096
  p8.intro(`${color9.bgCyan(color9.black(" @snelusha/noto "))}`);
1164
- if (globalOptions["--version"]) return p8.outro(version);
1097
+ if (globalOptions["--version"])
1098
+ return p8.outro(version);
1165
1099
  if (globalOptions["--help"]) {
1166
1100
  getCommand("help")?.execute(globalOptions);
1167
1101
  return;
1168
1102
  }
1169
1103
  const cmd = getCommand(command6) ?? getCommand("noto");
1170
- if (!cmd) return getCommand("noto")?.execute(globalOptions);
1104
+ if (!cmd)
1105
+ return getCommand("noto")?.execute(globalOptions);
1171
1106
  let commandArgs = args;
1172
1107
  let selectedCommand = cmd;
1173
1108
  if (cmd.subCommands && commandArgs.length) {
1174
1109
  const possibleCommand = commandArgs[1];
1175
- const subCommand = cmd.subCommands.find(
1176
- (cmd2) => cmd2.name === possibleCommand || cmd2.aliases && cmd2.aliases.includes(possibleCommand)
1177
- );
1110
+ const subCommand = cmd.subCommands.find((cmd2) => cmd2.name === possibleCommand || cmd2.aliases && cmd2.aliases.includes(possibleCommand));
1178
1111
  if (subCommand) {
1179
1112
  selectedCommand = subCommand;
1180
1113
  commandArgs = commandArgs.slice(2);
@@ -1184,7 +1117,8 @@ function main() {
1184
1117
  acc[opt.flag] = opt.type ?? Boolean;
1185
1118
  if (Array.isArray(opt.alias))
1186
1119
  opt.alias.forEach((alias) => acc[alias] = opt.flag);
1187
- else if (opt.alias) acc[opt.alias] = opt.flag;
1120
+ else if (opt.alias)
1121
+ acc[opt.alias] = opt.flag;
1188
1122
  return acc;
1189
1123
  }, {});
1190
1124
  const { options: commandOptions } = safeParse(commandSpec, commandArgs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snelusha/noto",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "Generate clean commit messages in a snap! ✨",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "noto": "./bin/noto.mjs"
26
26
  },
27
27
  "scripts": {
28
- "build": "tsup --clean",
29
- "test": "tsup --clean && vitest",
28
+ "build": "bunup --clean",
29
+ "test": "bunup --clean && vitest",
30
30
  "clean": "git clean -xdf .cache .turbo node_modules"
31
31
  },
32
32
  "files": [
@@ -42,7 +42,6 @@
42
42
  ],
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.15.23",
45
- "tsup": "^8.5.0",
46
45
  "typescript": "^5.8.3",
47
46
  "vitest": "^3.2.4"
48
47
  },
@@ -51,6 +50,7 @@
51
50
  "@clack/prompts": "^0.10.1",
52
51
  "ai": "^4.3.19",
53
52
  "arg": "^5.0.2",
53
+ "bunup": "^0.9.0",
54
54
  "clipboardy": "^4.0.0",
55
55
  "dedent": "^1.6.0",
56
56
  "picocolors": "^1.1.1",