@snelusha/noto 0.2.2 → 0.3.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/README.md +18 -11
- package/dist/cli.cjs +103 -12
- package/dist/cli.mjs +103 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<h1 align="center"
|
|
1
|
+
<h1 align="center">noto ✨</h1>
|
|
2
2
|
<p align="center"><sup>(/nōto/, <em>notebook</em> in Japanese)</sup></p>
|
|
3
|
-
<
|
|
3
|
+
<img src="https://github.com/snelusha/static/blob/main/noto/banner.png?raw=true" align="center"></img>
|
|
4
4
|
|
|
5
5
|
<pre align="center">
|
|
6
6
|
<p>npm install -g <b>@snelusha/noto</b></p>
|
|
@@ -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
|
|
35
|
-
noto --apply
|
|
36
|
-
#
|
|
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
|
|
40
|
-
noto --copy
|
|
41
|
-
#
|
|
42
|
-
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -148,7 +156,14 @@ async function generateCommitMessage(diff) {
|
|
|
148
156
|
messages: [
|
|
149
157
|
{
|
|
150
158
|
role: "system",
|
|
151
|
-
content:
|
|
159
|
+
content: `You are tasked with generating a Git commit message for the following staged changes across multiple files. Strictly follow the instructions given below to generate the commit message. The instructions are given according to order of importance, as such, make sure each instruction is followed before moving on to the next. Likewise, make sure all instructions are followed successfully.
|
|
160
|
+
- Ensure the description is written in the present-tense(start with a present tense verb such as add, fix, update, remove, improve, implement, etc...) (IMPORTANT! follow this for java repositories as well).
|
|
161
|
+
- Identify the key changes only and generate a detailed but brief commit message in the format "<type>: <description>".
|
|
162
|
+
- Use one of these types: feat, fix, refactor, docs, test, or chore.
|
|
163
|
+
- The commit message must be a single line, in all lowercase, without a scope or body, and no full stops at the end.
|
|
164
|
+
- Ensure the message does not exceed 72 characters.
|
|
165
|
+
- Do not mention file names unless a file was renamed or is essential for understanding the changes.
|
|
166
|
+
- Focus on the most important changes.`
|
|
152
167
|
},
|
|
153
168
|
{
|
|
154
169
|
role: "user",
|
|
@@ -160,6 +175,8 @@ ${diff}`
|
|
|
160
175
|
return message.text.trim();
|
|
161
176
|
}
|
|
162
177
|
|
|
178
|
+
const version = "0.2.4";
|
|
179
|
+
|
|
163
180
|
yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
164
181
|
"config",
|
|
165
182
|
"setup you API key to enable noto.",
|
|
@@ -204,6 +221,75 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
204
221
|
);
|
|
205
222
|
}
|
|
206
223
|
}
|
|
224
|
+
).command(
|
|
225
|
+
"prev",
|
|
226
|
+
"access previous commit message",
|
|
227
|
+
(args) => {
|
|
228
|
+
args.option("copy", {
|
|
229
|
+
alias: "c",
|
|
230
|
+
type: "boolean",
|
|
231
|
+
description: "Copy the previous commit message to the clipboard."
|
|
232
|
+
});
|
|
233
|
+
args.option("apply", {
|
|
234
|
+
alias: "a",
|
|
235
|
+
type: "boolean",
|
|
236
|
+
description: "Commit the staged changes with the previous message."
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
async (args) => {
|
|
240
|
+
const spin = spinner();
|
|
241
|
+
const storage = await load();
|
|
242
|
+
if (!storage.lastGeneratedMessage) {
|
|
243
|
+
console.log(c__default.red("No previous commit message found."));
|
|
244
|
+
console.log(
|
|
245
|
+
c__default.dim(
|
|
246
|
+
`Generate a new message with ${c__default.cyan(c__default.bold("`noto`"))} command.`
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
const message = storage.lastGeneratedMessage;
|
|
252
|
+
const copy = args.copy;
|
|
253
|
+
const apply = args.apply;
|
|
254
|
+
spin.success(`Previous Commit Message: ${c__default.dim(c__default.bold(message))}`);
|
|
255
|
+
if (copy) {
|
|
256
|
+
clipboardy__default.writeSync(message);
|
|
257
|
+
spin.success("Message copied to clipboard!");
|
|
258
|
+
}
|
|
259
|
+
if (apply) {
|
|
260
|
+
const cwd = process.cwd();
|
|
261
|
+
if (!isGitRepository(cwd)) {
|
|
262
|
+
console.log(
|
|
263
|
+
c__default.red("Oops! No Git repository found in the current directory.")
|
|
264
|
+
);
|
|
265
|
+
console.log(
|
|
266
|
+
c__default.dim(
|
|
267
|
+
`You can initialize one by running ${c__default.cyan(
|
|
268
|
+
c__default.bold("`git init`")
|
|
269
|
+
)}`
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
const diff = await getStagedDiff();
|
|
275
|
+
if (!diff) {
|
|
276
|
+
console.log(c__default.red("Oops! No staged changes found to commit."));
|
|
277
|
+
console.log(
|
|
278
|
+
c__default.dim(
|
|
279
|
+
`Stage changes with ${c__default.cyan(
|
|
280
|
+
c__default.bold("`git add <file>`")
|
|
281
|
+
)} or ${c__default.cyan(c__default.bold("`git add .`"))} for stage all files.`
|
|
282
|
+
)
|
|
283
|
+
);
|
|
284
|
+
process.exit(1);
|
|
285
|
+
}
|
|
286
|
+
if (!await commit(message)) {
|
|
287
|
+
spin.fail("Failed to commit staged changes.");
|
|
288
|
+
process.exit(1);
|
|
289
|
+
}
|
|
290
|
+
spin.success("Staged changes committed successfully!");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
207
293
|
).command(
|
|
208
294
|
"*",
|
|
209
295
|
"generate commit message",
|
|
@@ -233,7 +319,9 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
233
319
|
c__default.red("Oops! No Git repository found in the current directory.")
|
|
234
320
|
);
|
|
235
321
|
console.log(
|
|
236
|
-
|
|
322
|
+
c__default.dim(
|
|
323
|
+
`You can initialize one by running ${c__default.cyan(c__default.bold("`git init`"))}`
|
|
324
|
+
)
|
|
237
325
|
);
|
|
238
326
|
process.exit(1);
|
|
239
327
|
}
|
|
@@ -241,9 +329,11 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
241
329
|
if (!diff) {
|
|
242
330
|
console.log(c__default.red("Oops! No staged changes found to commit."));
|
|
243
331
|
console.log(
|
|
244
|
-
|
|
245
|
-
c__default.
|
|
246
|
-
|
|
332
|
+
c__default.dim(
|
|
333
|
+
`Stage changes with ${c__default.cyan(
|
|
334
|
+
c__default.bold("`git add <file>`")
|
|
335
|
+
)} or ${c__default.cyan(c__default.bold("`git add .`"))} for stage all files.`
|
|
336
|
+
)
|
|
247
337
|
);
|
|
248
338
|
process.exit(1);
|
|
249
339
|
}
|
|
@@ -251,6 +341,8 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
251
341
|
try {
|
|
252
342
|
spin.start("Generating commit message...");
|
|
253
343
|
const message = await generateCommitMessage(diff);
|
|
344
|
+
storage.lastGeneratedMessage = message;
|
|
345
|
+
await dump();
|
|
254
346
|
const copy = args.copy;
|
|
255
347
|
const apply = args.apply;
|
|
256
348
|
spin.success(`Commit Message: ${c__default.dim(c__default.bold(message))}`);
|
|
@@ -259,7 +351,6 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
259
351
|
spin.success("Message copied to clipboard!");
|
|
260
352
|
}
|
|
261
353
|
if (apply) {
|
|
262
|
-
spin.start("Committing staged changes...");
|
|
263
354
|
if (!await commit(message)) {
|
|
264
355
|
spin.fail("Failed to commit staged changes.");
|
|
265
356
|
process.exit(1);
|
|
@@ -271,4 +362,4 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("noto").usage("$0 [args
|
|
|
271
362
|
process.exit(1);
|
|
272
363
|
}
|
|
273
364
|
}
|
|
274
|
-
).version().alias("-v", "--version").alias("-h", "--help").argv;
|
|
365
|
+
).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
|
|
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
|
|
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
|
}
|
|
@@ -136,7 +144,14 @@ async function generateCommitMessage(diff) {
|
|
|
136
144
|
messages: [
|
|
137
145
|
{
|
|
138
146
|
role: "system",
|
|
139
|
-
content:
|
|
147
|
+
content: `You are tasked with generating a Git commit message for the following staged changes across multiple files. Strictly follow the instructions given below to generate the commit message. The instructions are given according to order of importance, as such, make sure each instruction is followed before moving on to the next. Likewise, make sure all instructions are followed successfully.
|
|
148
|
+
- Ensure the description is written in the present-tense(start with a present tense verb such as add, fix, update, remove, improve, implement, etc...) (IMPORTANT! follow this for java repositories as well).
|
|
149
|
+
- Identify the key changes only and generate a detailed but brief commit message in the format "<type>: <description>".
|
|
150
|
+
- Use one of these types: feat, fix, refactor, docs, test, or chore.
|
|
151
|
+
- The commit message must be a single line, in all lowercase, without a scope or body, and no full stops at the end.
|
|
152
|
+
- Ensure the message does not exceed 72 characters.
|
|
153
|
+
- Do not mention file names unless a file was renamed or is essential for understanding the changes.
|
|
154
|
+
- Focus on the most important changes.`
|
|
140
155
|
},
|
|
141
156
|
{
|
|
142
157
|
role: "user",
|
|
@@ -148,6 +163,8 @@ ${diff}`
|
|
|
148
163
|
return message.text.trim();
|
|
149
164
|
}
|
|
150
165
|
|
|
166
|
+
const version = "0.2.4";
|
|
167
|
+
|
|
151
168
|
yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
152
169
|
"config",
|
|
153
170
|
"setup you API key to enable noto.",
|
|
@@ -192,6 +209,75 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
192
209
|
);
|
|
193
210
|
}
|
|
194
211
|
}
|
|
212
|
+
).command(
|
|
213
|
+
"prev",
|
|
214
|
+
"access previous commit message",
|
|
215
|
+
(args) => {
|
|
216
|
+
args.option("copy", {
|
|
217
|
+
alias: "c",
|
|
218
|
+
type: "boolean",
|
|
219
|
+
description: "Copy the previous commit message to the clipboard."
|
|
220
|
+
});
|
|
221
|
+
args.option("apply", {
|
|
222
|
+
alias: "a",
|
|
223
|
+
type: "boolean",
|
|
224
|
+
description: "Commit the staged changes with the previous message."
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
async (args) => {
|
|
228
|
+
const spin = spinner();
|
|
229
|
+
const storage = await load();
|
|
230
|
+
if (!storage.lastGeneratedMessage) {
|
|
231
|
+
console.log(c.red("No previous commit message found."));
|
|
232
|
+
console.log(
|
|
233
|
+
c.dim(
|
|
234
|
+
`Generate a new message with ${c.cyan(c.bold("`noto`"))} command.`
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
const message = storage.lastGeneratedMessage;
|
|
240
|
+
const copy = args.copy;
|
|
241
|
+
const apply = args.apply;
|
|
242
|
+
spin.success(`Previous Commit Message: ${c.dim(c.bold(message))}`);
|
|
243
|
+
if (copy) {
|
|
244
|
+
clipboardy.writeSync(message);
|
|
245
|
+
spin.success("Message copied to clipboard!");
|
|
246
|
+
}
|
|
247
|
+
if (apply) {
|
|
248
|
+
const cwd = process.cwd();
|
|
249
|
+
if (!isGitRepository(cwd)) {
|
|
250
|
+
console.log(
|
|
251
|
+
c.red("Oops! No Git repository found in the current directory.")
|
|
252
|
+
);
|
|
253
|
+
console.log(
|
|
254
|
+
c.dim(
|
|
255
|
+
`You can initialize one by running ${c.cyan(
|
|
256
|
+
c.bold("`git init`")
|
|
257
|
+
)}`
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
process.exit(1);
|
|
261
|
+
}
|
|
262
|
+
const diff = await getStagedDiff();
|
|
263
|
+
if (!diff) {
|
|
264
|
+
console.log(c.red("Oops! No staged changes found to commit."));
|
|
265
|
+
console.log(
|
|
266
|
+
c.dim(
|
|
267
|
+
`Stage changes with ${c.cyan(
|
|
268
|
+
c.bold("`git add <file>`")
|
|
269
|
+
)} or ${c.cyan(c.bold("`git add .`"))} for stage all files.`
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
if (!await commit(message)) {
|
|
275
|
+
spin.fail("Failed to commit staged changes.");
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
278
|
+
spin.success("Staged changes committed successfully!");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
195
281
|
).command(
|
|
196
282
|
"*",
|
|
197
283
|
"generate commit message",
|
|
@@ -221,7 +307,9 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
221
307
|
c.red("Oops! No Git repository found in the current directory.")
|
|
222
308
|
);
|
|
223
309
|
console.log(
|
|
224
|
-
|
|
310
|
+
c.dim(
|
|
311
|
+
`You can initialize one by running ${c.cyan(c.bold("`git init`"))}`
|
|
312
|
+
)
|
|
225
313
|
);
|
|
226
314
|
process.exit(1);
|
|
227
315
|
}
|
|
@@ -229,9 +317,11 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
229
317
|
if (!diff) {
|
|
230
318
|
console.log(c.red("Oops! No staged changes found to commit."));
|
|
231
319
|
console.log(
|
|
232
|
-
|
|
233
|
-
c.
|
|
234
|
-
|
|
320
|
+
c.dim(
|
|
321
|
+
`Stage changes with ${c.cyan(
|
|
322
|
+
c.bold("`git add <file>`")
|
|
323
|
+
)} or ${c.cyan(c.bold("`git add .`"))} for stage all files.`
|
|
324
|
+
)
|
|
235
325
|
);
|
|
236
326
|
process.exit(1);
|
|
237
327
|
}
|
|
@@ -239,6 +329,8 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
239
329
|
try {
|
|
240
330
|
spin.start("Generating commit message...");
|
|
241
331
|
const message = await generateCommitMessage(diff);
|
|
332
|
+
storage.lastGeneratedMessage = message;
|
|
333
|
+
await dump();
|
|
242
334
|
const copy = args.copy;
|
|
243
335
|
const apply = args.apply;
|
|
244
336
|
spin.success(`Commit Message: ${c.dim(c.bold(message))}`);
|
|
@@ -247,7 +339,6 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
247
339
|
spin.success("Message copied to clipboard!");
|
|
248
340
|
}
|
|
249
341
|
if (apply) {
|
|
250
|
-
spin.start("Committing staged changes...");
|
|
251
342
|
if (!await commit(message)) {
|
|
252
343
|
spin.fail("Failed to commit staged changes.");
|
|
253
344
|
process.exit(1);
|
|
@@ -259,4 +350,4 @@ yargs(hideBin(process.argv)).scriptName("noto").usage("$0 [args]").command(
|
|
|
259
350
|
process.exit(1);
|
|
260
351
|
}
|
|
261
352
|
}
|
|
262
|
-
).version().alias("-v", "--version").alias("-h", "--help").argv;
|
|
353
|
+
).version("version", version).alias("-v", "--version").alias("-h", "--help").argv;
|