@snelusha/noto 1.0.0-beta.4 → 1.0.0-beta.6

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 (2) hide show
  1. package/dist/index.js +69 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,6 +11,31 @@ var parse = (schema, raw) => {
11
11
  options: args
12
12
  };
13
13
  };
14
+ var safeParse = (schema, raw) => {
15
+ let current = { ...schema };
16
+ let iterations = 0;
17
+ const maxIterations = Object.keys(current).filter(
18
+ (key2) => current[key2] === String
19
+ ).length;
20
+ while (iterations++ < maxIterations) {
21
+ try {
22
+ return parse(current, raw);
23
+ } catch (error) {
24
+ if (error.code === "ARG_MISSING_REQUIRED_LONGARG") {
25
+ const match = error.message.match(/(--\w[\w-]*)/);
26
+ if (match) {
27
+ const missingFlag = match[0];
28
+ if (current[missingFlag] === String) {
29
+ current[missingFlag] = Boolean;
30
+ continue;
31
+ }
32
+ }
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+ return parse(current, raw);
38
+ };
14
39
 
15
40
  // src/commands/noto.ts
16
41
  import * as p3 from "@clack/prompts";
@@ -220,7 +245,7 @@ var getModel = async () => {
220
245
  };
221
246
 
222
247
  // src/ai/index.ts
223
- var generateCommitMessage = async (diff) => {
248
+ var generateCommitMessage = async (diff, type) => {
224
249
  const model2 = await getModel();
225
250
  const { object } = await generateObject({
226
251
  model: model2,
@@ -242,7 +267,11 @@ var generateCommitMessage = async (diff) => {
242
267
  6. Avoid mentioning file names unless a file was renamed or is critical for understanding the changes.
243
268
  7. Prioritize clarity and focus on the most impactful changes for the commit.
244
269
 
245
- You are expected to generate structured outputs that align with the provided guidelines and produce a message optimized for readability and accuracy. Strictly follow all constraints to ensure high-quality results.`
270
+ You are expected to generate structured outputs that align with the provided guidelines and produce a message optimized for readability and accuracy. Strictly follow all constraints to ensure high-quality results.
271
+
272
+ ${type ? `if a type is provided (e.g., feat, fix), include it in the commit message in the format "type: message"
273
+
274
+ type: ${type}` : ""}`
246
275
  },
247
276
  {
248
277
  role: "user",
@@ -255,11 +284,30 @@ var generateCommitMessage = async (diff) => {
255
284
  };
256
285
 
257
286
  // src/commands/noto.ts
287
+ var availableTypes = [
288
+ "chore",
289
+ "feat",
290
+ "fix",
291
+ "docs",
292
+ "refactor",
293
+ "perf",
294
+ "test"
295
+ ];
296
+ var commitTypeOptions = availableTypes.map((type) => ({
297
+ label: type,
298
+ value: type
299
+ }));
258
300
  var command = {
259
301
  name: "noto",
260
302
  description: "generate commit message",
261
303
  usage: "noto [options]",
262
304
  options: [
305
+ {
306
+ type: String,
307
+ flag: "--type",
308
+ alias: "-t",
309
+ description: "generate commit message based on type"
310
+ },
263
311
  {
264
312
  type: Boolean,
265
313
  flag: "--copy",
@@ -285,8 +333,22 @@ var command = {
285
333
  try {
286
334
  const { diff } = options;
287
335
  const isEditMode = options["--edit"];
336
+ const type = options["--type"];
337
+ if (typeof type === "string" && !availableTypes.includes(type) || typeof type === "boolean") {
338
+ const type2 = await p3.select({
339
+ message: "select the type of commit message",
340
+ options: commitTypeOptions
341
+ });
342
+ if (p3.isCancel(type2)) {
343
+ p3.log.error(color3.red("nothing selected!"));
344
+ return await exit(1);
345
+ }
346
+ options.type = type2;
347
+ } else if (typeof type === "string") {
348
+ options.type = type;
349
+ }
288
350
  spin.start("generating commit message");
289
- let message = await generateCommitMessage(diff);
351
+ let message = await generateCommitMessage(diff, options.type);
290
352
  spin.stop(isEditMode ? color3.white(message) : color3.green(message));
291
353
  if (isEditMode) {
292
354
  const editedMessage = await p3.text({
@@ -317,7 +379,7 @@ var command = {
317
379
  p3.log.error(color3.red("failed to commit changes"));
318
380
  }
319
381
  }
320
- process.stdout.write("\n");
382
+ return await exit(0);
321
383
  } catch {
322
384
  spin.stop(color3.red("failed to generate commit message"), 1);
323
385
  return await exit(1);
@@ -523,7 +585,7 @@ var getCommand = (name, cmds = commands) => {
523
585
  };
524
586
 
525
587
  // package.json
526
- var version = "1.0.0-beta.4";
588
+ var version = "1.0.0-beta.6";
527
589
 
528
590
  // src/index.ts
529
591
  var globalSpec = {
@@ -543,7 +605,7 @@ function main() {
543
605
  let commandArgs = args;
544
606
  let selectedCommand = cmd;
545
607
  if (cmd.subCommands && commandArgs.length) {
546
- const possibleCommand = commandArgs[0];
608
+ const possibleCommand = commandArgs[1];
547
609
  const subCommand = cmd.subCommands.find(
548
610
  (cmd2) => cmd2.name === possibleCommand || cmd2.aliases && cmd2.aliases.includes(possibleCommand)
549
611
  );
@@ -559,7 +621,7 @@ function main() {
559
621
  else if (opt.alias) acc[opt.alias] = opt.flag;
560
622
  return acc;
561
623
  }, {});
562
- const { options: commandOptions } = parse(commandSpec, commandArgs);
624
+ const { options: commandOptions } = safeParse(commandSpec, commandArgs);
563
625
  const options = { ...globalOptions, ...commandOptions };
564
626
  selectedCommand.execute(options);
565
627
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snelusha/noto",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Generate clean commit messages in a snap! ✨",
5
5
  "license": "MIT",
6
6
  "type": "module",