@snelusha/noto 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,17 +29,24 @@ Here, you’ll need to input your Google GenAI API Key.
29
29
  To generate a commit message, simply run:
30
30
 
31
31
  ```bash
32
- noto
32
+ noto # generate a commit message
33
33
 
34
- # apply the generated message:
35
- noto --apply
36
- # or
37
- noto -a
34
+ # apply generated message
35
+ noto --apply # apply the message to current commit
36
+ noto -a # alias for apply
38
37
 
39
- # copy the generated message:
40
- noto --copy
41
- # or
42
- noto -c
38
+ # copy generated message
39
+ noto --copy # copy the message to clipboard
40
+ noto -c # alias for copy
41
+
42
+ # access the previously generated message
43
+ noto prev # view the last message
44
+
45
+ noto prev --apply # apply the last message to current commit
46
+ noto prev -a # alias for apply
47
+
48
+ noto prev --copy # copy the last message to clipboard
49
+ noto prev -c # alias for copy
43
50
  ```
44
51
 
45
52
  ## Pro Tips
package/dist/cli.cjs CHANGED
@@ -78,16 +78,24 @@ function spinner() {
78
78
  s.start();
79
79
  },
80
80
  fail(text) {
81
- if (s)
82
- s.fail(text);
81
+ if (!s) {
82
+ s = ora__default();
83
+ }
84
+ s.fail(text);
85
+ s = void 0;
83
86
  },
84
87
  success(text) {
85
- if (s)
86
- s.succeed(text);
88
+ if (!s) {
89
+ s = ora__default();
90
+ }
91
+ s.succeed(text);
92
+ s = void 0;
87
93
  },
88
94
  stop() {
89
- if (s)
95
+ if (s) {
90
96
  s.stop();
97
+ s = void 0;
98
+ }
91
99
  }
92
100
  };
93
101
  }
@@ -160,6 +168,8 @@ ${diff}`
160
168
  return message.text.trim();
161
169
  }
162
170
 
171
+ const version = "0.2.2";
172
+
163
173
  yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
164
174
  "config",
165
175
  "setup you API key to enable noto.",
@@ -204,6 +214,75 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
204
214
  );
205
215
  }
206
216
  }
217
+ ).command(
218
+ "prev",
219
+ "access previous commit message",
220
+ (args) => {
221
+ args.option("copy", {
222
+ alias: "c",
223
+ type: "boolean",
224
+ description: "Copy the previous commit message to the clipboard."
225
+ });
226
+ args.option("apply", {
227
+ alias: "a",
228
+ type: "boolean",
229
+ description: "Commit the staged changes with the previous message."
230
+ });
231
+ },
232
+ async (args) => {
233
+ const spin = spinner();
234
+ const storage = await load();
235
+ if (!storage.lastGeneratedMessage) {
236
+ console.log(c__default.red("No previous commit message found."));
237
+ console.log(
238
+ c__default.dim(
239
+ `Generate a new message with ${c__default.cyan(c__default.bold("`noto`"))} command.`
240
+ )
241
+ );
242
+ process.exit(1);
243
+ }
244
+ const message = storage.lastGeneratedMessage;
245
+ const copy = args.copy;
246
+ const apply = args.apply;
247
+ spin.success(`Previous Commit Message: ${c__default.dim(c__default.bold(message))}`);
248
+ if (copy) {
249
+ clipboardy__default.writeSync(message);
250
+ spin.success("Message copied to clipboard!");
251
+ }
252
+ if (apply) {
253
+ const cwd = process.cwd();
254
+ if (!isGitRepository(cwd)) {
255
+ console.log(
256
+ c__default.red("Oops! No Git repository found in the current directory.")
257
+ );
258
+ console.log(
259
+ c__default.dim(
260
+ `You can initialize one by running ${c__default.cyan(
261
+ c__default.bold("`git init`")
262
+ )}`
263
+ )
264
+ );
265
+ process.exit(1);
266
+ }
267
+ const diff = await getStagedDiff();
268
+ if (!diff) {
269
+ console.log(c__default.red("Oops! No staged changes found to commit."));
270
+ console.log(
271
+ c__default.dim(
272
+ `Stage changes with ${c__default.cyan(
273
+ c__default.bold("`git add <file>`")
274
+ )} or ${c__default.cyan(c__default.bold("`git add .`"))} for stage all files.`
275
+ )
276
+ );
277
+ process.exit(1);
278
+ }
279
+ if (!await commit(message)) {
280
+ spin.fail("Failed to commit staged changes.");
281
+ process.exit(1);
282
+ }
283
+ spin.success("Staged changes committed successfully!");
284
+ }
285
+ }
207
286
  ).command(
208
287
  "*",
209
288
  "generate commit message",
@@ -233,7 +312,9 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
233
312
  c__default.red("Oops! No Git repository found in the current directory.")
234
313
  );
235
314
  console.log(
236
- `You can initialize one by running ${c__default.cyan(c__default.bold("`git init`"))}`
315
+ c__default.dim(
316
+ `You can initialize one by running ${c__default.cyan(c__default.bold("`git init`"))}`
317
+ )
237
318
  );
238
319
  process.exit(1);
239
320
  }
@@ -241,9 +322,11 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
241
322
  if (!diff) {
242
323
  console.log(c__default.red("Oops! No staged changes found to commit."));
243
324
  console.log(
244
- `Stage changes with ${c__default.cyan(c__default.bold("`git add <file>`"))} or ${c__default.cyan(
245
- c__default.bold("`git add .`")
246
- )} for stage all files.`
325
+ c__default.dim(
326
+ `Stage changes with ${c__default.cyan(
327
+ c__default.bold("`git add <file>`")
328
+ )} or ${c__default.cyan(c__default.bold("`git add .`"))} for stage all files.`
329
+ )
247
330
  );
248
331
  process.exit(1);
249
332
  }
@@ -251,6 +334,8 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
251
334
  try {
252
335
  spin.start("Generating commit message...");
253
336
  const message = await generateCommitMessage(diff);
337
+ storage.lastGeneratedMessage = message;
338
+ await dump();
254
339
  const copy = args.copy;
255
340
  const apply = args.apply;
256
341
  spin.success(`Commit Message: ${c__default.dim(c__default.bold(message))}`);
@@ -259,7 +344,6 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
259
344
  spin.success("Message copied to clipboard!");
260
345
  }
261
346
  if (apply) {
262
- spin.start("Committing staged changes...");
263
347
  if (!await commit(message)) {
264
348
  spin.fail("Failed to commit staged changes.");
265
349
  process.exit(1);
@@ -271,4 +355,4 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
271
355
  process.exit(1);
272
356
  }
273
357
  }
274
- ).version().alias("-v", "--version").alias("-h", "--help").argv;
358
+ ).version("version", version).alias("-v", "--version").alias("-h", "--help").argv;
package/dist/cli.mjs CHANGED
@@ -66,16 +66,24 @@ function spinner() {
66
66
  s.start();
67
67
  },
68
68
  fail(text) {
69
- if (s)
70
- s.fail(text);
69
+ if (!s) {
70
+ s = ora();
71
+ }
72
+ s.fail(text);
73
+ s = void 0;
71
74
  },
72
75
  success(text) {
73
- if (s)
74
- s.succeed(text);
76
+ if (!s) {
77
+ s = ora();
78
+ }
79
+ s.succeed(text);
80
+ s = void 0;
75
81
  },
76
82
  stop() {
77
- if (s)
83
+ if (s) {
78
84
  s.stop();
85
+ s = void 0;
86
+ }
79
87
  }
80
88
  };
81
89
  }
@@ -148,6 +156,8 @@ ${diff}`
148
156
  return message.text.trim();
149
157
  }
150
158
 
159
+ const version = "0.2.2";
160
+
151
161
  yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
152
162
  "config",
153
163
  "setup you API key to enable noto.",
@@ -192,6 +202,75 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
192
202
  );
193
203
  }
194
204
  }
205
+ ).command(
206
+ "prev",
207
+ "access previous commit message",
208
+ (args) => {
209
+ args.option("copy", {
210
+ alias: "c",
211
+ type: "boolean",
212
+ description: "Copy the previous commit message to the clipboard."
213
+ });
214
+ args.option("apply", {
215
+ alias: "a",
216
+ type: "boolean",
217
+ description: "Commit the staged changes with the previous message."
218
+ });
219
+ },
220
+ async (args) => {
221
+ const spin = spinner();
222
+ const storage = await load();
223
+ if (!storage.lastGeneratedMessage) {
224
+ console.log(c.red("No previous commit message found."));
225
+ console.log(
226
+ c.dim(
227
+ `Generate a new message with ${c.cyan(c.bold("`noto`"))} command.`
228
+ )
229
+ );
230
+ process.exit(1);
231
+ }
232
+ const message = storage.lastGeneratedMessage;
233
+ const copy = args.copy;
234
+ const apply = args.apply;
235
+ spin.success(`Previous Commit Message: ${c.dim(c.bold(message))}`);
236
+ if (copy) {
237
+ clipboardy.writeSync(message);
238
+ spin.success("Message copied to clipboard!");
239
+ }
240
+ if (apply) {
241
+ const cwd = process.cwd();
242
+ if (!isGitRepository(cwd)) {
243
+ console.log(
244
+ c.red("Oops! No Git repository found in the current directory.")
245
+ );
246
+ console.log(
247
+ c.dim(
248
+ `You can initialize one by running ${c.cyan(
249
+ c.bold("`git init`")
250
+ )}`
251
+ )
252
+ );
253
+ process.exit(1);
254
+ }
255
+ const diff = await getStagedDiff();
256
+ if (!diff) {
257
+ console.log(c.red("Oops! No staged changes found to commit."));
258
+ console.log(
259
+ c.dim(
260
+ `Stage changes with ${c.cyan(
261
+ c.bold("`git add <file>`")
262
+ )} or ${c.cyan(c.bold("`git add .`"))} for stage all files.`
263
+ )
264
+ );
265
+ process.exit(1);
266
+ }
267
+ if (!await commit(message)) {
268
+ spin.fail("Failed to commit staged changes.");
269
+ process.exit(1);
270
+ }
271
+ spin.success("Staged changes committed successfully!");
272
+ }
273
+ }
195
274
  ).command(
196
275
  "*",
197
276
  "generate commit message",
@@ -221,7 +300,9 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
221
300
  c.red("Oops! No Git repository found in the current directory.")
222
301
  );
223
302
  console.log(
224
- `You can initialize one by running ${c.cyan(c.bold("`git init`"))}`
303
+ c.dim(
304
+ `You can initialize one by running ${c.cyan(c.bold("`git init`"))}`
305
+ )
225
306
  );
226
307
  process.exit(1);
227
308
  }
@@ -229,9 +310,11 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
229
310
  if (!diff) {
230
311
  console.log(c.red("Oops! No staged changes found to commit."));
231
312
  console.log(
232
- `Stage changes with ${c.cyan(c.bold("`git add <file>`"))} or ${c.cyan(
233
- c.bold("`git add .`")
234
- )} for stage all files.`
313
+ c.dim(
314
+ `Stage changes with ${c.cyan(
315
+ c.bold("`git add <file>`")
316
+ )} or ${c.cyan(c.bold("`git add .`"))} for stage all files.`
317
+ )
235
318
  );
236
319
  process.exit(1);
237
320
  }
@@ -239,6 +322,8 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
239
322
  try {
240
323
  spin.start("Generating commit message...");
241
324
  const message = await generateCommitMessage(diff);
325
+ storage.lastGeneratedMessage = message;
326
+ await dump();
242
327
  const copy = args.copy;
243
328
  const apply = args.apply;
244
329
  spin.success(`Commit Message: ${c.dim(c.bold(message))}`);
@@ -247,7 +332,6 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
247
332
  spin.success("Message copied to clipboard!");
248
333
  }
249
334
  if (apply) {
250
- spin.start("Committing staged changes...");
251
335
  if (!await commit(message)) {
252
336
  spin.fail("Failed to commit staged changes.");
253
337
  process.exit(1);
@@ -259,4 +343,4 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
259
343
  process.exit(1);
260
344
  }
261
345
  }
262
- ).version().alias("-v", "--version").alias("-h", "--help").argv;
346
+ ).version("version", version).alias("-v", "--version").alias("-h", "--help").argv;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snelusha/noto",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "description": "generate clean commit messages in a snap! ✨",
6
6
  "license": "MIT",
7
7
  "author": {