@snelusha/noto 1.0.0-beta.5 → 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.
- package/dist/index.js +49 -37
- 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";
|
|
@@ -259,13 +284,26 @@ var generateCommitMessage = async (diff, type) => {
|
|
|
259
284
|
};
|
|
260
285
|
|
|
261
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
|
+
}));
|
|
262
300
|
var command = {
|
|
263
301
|
name: "noto",
|
|
264
302
|
description: "generate commit message",
|
|
265
303
|
usage: "noto [options]",
|
|
266
304
|
options: [
|
|
267
305
|
{
|
|
268
|
-
type:
|
|
306
|
+
type: String,
|
|
269
307
|
flag: "--type",
|
|
270
308
|
alias: "-t",
|
|
271
309
|
description: "generate commit message based on type"
|
|
@@ -295,44 +333,18 @@ var command = {
|
|
|
295
333
|
try {
|
|
296
334
|
const { diff } = options;
|
|
297
335
|
const isEditMode = options["--edit"];
|
|
298
|
-
|
|
299
|
-
|
|
336
|
+
const type = options["--type"];
|
|
337
|
+
if (typeof type === "string" && !availableTypes.includes(type) || typeof type === "boolean") {
|
|
338
|
+
const type2 = await p3.select({
|
|
300
339
|
message: "select the type of commit message",
|
|
301
|
-
options:
|
|
302
|
-
{
|
|
303
|
-
label: "chore",
|
|
304
|
-
value: "chore"
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
label: "feat",
|
|
308
|
-
value: "feat"
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
label: "fix",
|
|
312
|
-
value: "fix"
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
label: "docs",
|
|
316
|
-
value: "docs"
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
label: "refactor",
|
|
320
|
-
value: "refactor"
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
label: "perf",
|
|
324
|
-
value: "perf"
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
label: "test",
|
|
328
|
-
value: "test"
|
|
329
|
-
}
|
|
330
|
-
]
|
|
340
|
+
options: commitTypeOptions
|
|
331
341
|
});
|
|
332
|
-
if (p3.isCancel(
|
|
342
|
+
if (p3.isCancel(type2)) {
|
|
333
343
|
p3.log.error(color3.red("nothing selected!"));
|
|
334
344
|
return await exit(1);
|
|
335
345
|
}
|
|
346
|
+
options.type = type2;
|
|
347
|
+
} else if (typeof type === "string") {
|
|
336
348
|
options.type = type;
|
|
337
349
|
}
|
|
338
350
|
spin.start("generating commit message");
|
|
@@ -367,7 +379,7 @@ var command = {
|
|
|
367
379
|
p3.log.error(color3.red("failed to commit changes"));
|
|
368
380
|
}
|
|
369
381
|
}
|
|
370
|
-
|
|
382
|
+
return await exit(0);
|
|
371
383
|
} catch {
|
|
372
384
|
spin.stop(color3.red("failed to generate commit message"), 1);
|
|
373
385
|
return await exit(1);
|
|
@@ -573,7 +585,7 @@ var getCommand = (name, cmds = commands) => {
|
|
|
573
585
|
};
|
|
574
586
|
|
|
575
587
|
// package.json
|
|
576
|
-
var version = "1.0.0-beta.
|
|
588
|
+
var version = "1.0.0-beta.6";
|
|
577
589
|
|
|
578
590
|
// src/index.ts
|
|
579
591
|
var globalSpec = {
|
|
@@ -609,7 +621,7 @@ function main() {
|
|
|
609
621
|
else if (opt.alias) acc[opt.alias] = opt.flag;
|
|
610
622
|
return acc;
|
|
611
623
|
}, {});
|
|
612
|
-
const { options: commandOptions } =
|
|
624
|
+
const { options: commandOptions } = safeParse(commandSpec, commandArgs);
|
|
613
625
|
const options = { ...globalOptions, ...commandOptions };
|
|
614
626
|
selectedCommand.execute(options);
|
|
615
627
|
}
|