@snelusha/noto 1.0.4 → 1.0.5
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 +67 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import * as p6 from "@clack/prompts";
|
|
3
|
-
import
|
|
3
|
+
import color7 from "picocolors";
|
|
4
4
|
|
|
5
5
|
// src/utils/parser.ts
|
|
6
6
|
import arg from "arg";
|
|
@@ -153,10 +153,26 @@ import dedent2 from "dedent";
|
|
|
153
153
|
|
|
154
154
|
// src/utils/git.ts
|
|
155
155
|
import simpleGit from "simple-git";
|
|
156
|
+
var INIT_COMMIT_MESSAGE = "chore: init repo";
|
|
156
157
|
var git = simpleGit();
|
|
157
158
|
var isGitRepository = async () => {
|
|
158
159
|
return git.checkIsRepo();
|
|
159
160
|
};
|
|
161
|
+
var getCommitCount = async () => {
|
|
162
|
+
try {
|
|
163
|
+
const count = await git.raw(["rev-list", "--all", "--count"]);
|
|
164
|
+
return parseInt(count);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
const message = error.message;
|
|
167
|
+
const regex = /(ambiguous argument.*HEAD|unknown revision or path.*HEAD)/;
|
|
168
|
+
if (regex.test(message)) return 0;
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var isFirstCommit = async () => {
|
|
173
|
+
const count = await getCommitCount();
|
|
174
|
+
return count === 0;
|
|
175
|
+
};
|
|
160
176
|
var getStagedDiff = async () => {
|
|
161
177
|
try {
|
|
162
178
|
return git.diff(["--cached"]);
|
|
@@ -362,7 +378,12 @@ var command = {
|
|
|
362
378
|
options.type = type;
|
|
363
379
|
}
|
|
364
380
|
spin.start("generating commit message");
|
|
365
|
-
let message =
|
|
381
|
+
let message = null;
|
|
382
|
+
if (!await isFirstCommit()) {
|
|
383
|
+
message = await generateCommitMessage(diff, options.type);
|
|
384
|
+
} else {
|
|
385
|
+
message = INIT_COMMIT_MESSAGE;
|
|
386
|
+
}
|
|
366
387
|
spin.stop(isEditMode ? color3.white(message) : color3.green(message));
|
|
367
388
|
if (isEditMode) {
|
|
368
389
|
const editedMessage = await p3.text({
|
|
@@ -609,14 +630,51 @@ var command3 = {
|
|
|
609
630
|
};
|
|
610
631
|
var config_default = command3;
|
|
611
632
|
|
|
633
|
+
// src/commands/help.ts
|
|
634
|
+
import color6 from "picocolors";
|
|
635
|
+
var help = {
|
|
636
|
+
name: "help",
|
|
637
|
+
description: "show help",
|
|
638
|
+
usage: "noto help [command]",
|
|
639
|
+
execute: async (options) => {
|
|
640
|
+
const command4 = getCommand(options._[0]);
|
|
641
|
+
if (command4) {
|
|
642
|
+
console.log();
|
|
643
|
+
console.log(color6.bold("Usage"));
|
|
644
|
+
console.log(` ${command4.usage}`);
|
|
645
|
+
console.log();
|
|
646
|
+
console.log(color6.bold("Description"));
|
|
647
|
+
console.log(` ${command4.description}`);
|
|
648
|
+
console.log();
|
|
649
|
+
} else {
|
|
650
|
+
const commands2 = listCommand();
|
|
651
|
+
console.log();
|
|
652
|
+
console.log(color6.bold("Usage"));
|
|
653
|
+
console.log(` noto [command] [options]`);
|
|
654
|
+
console.log();
|
|
655
|
+
console.log(color6.bold("Commands"));
|
|
656
|
+
commands2.forEach((command5) => {
|
|
657
|
+
console.log(
|
|
658
|
+
` ${color6.bold(command5.name)} ${color6.dim(command5.description)}`
|
|
659
|
+
);
|
|
660
|
+
});
|
|
661
|
+
console.log();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
var help_default = help;
|
|
666
|
+
|
|
612
667
|
// src/commands/index.ts
|
|
613
|
-
var commands = [noto_default, prev_default, config_default];
|
|
668
|
+
var commands = [noto_default, prev_default, config_default, help_default];
|
|
614
669
|
var getCommand = (name, cmds = commands) => {
|
|
615
670
|
return cmds.find((cmd) => cmd.name === name);
|
|
616
671
|
};
|
|
672
|
+
var listCommand = () => {
|
|
673
|
+
return commands;
|
|
674
|
+
};
|
|
617
675
|
|
|
618
676
|
// package.json
|
|
619
|
-
var version = "1.0.
|
|
677
|
+
var version = "1.0.5";
|
|
620
678
|
|
|
621
679
|
// src/index.ts
|
|
622
680
|
var globalSpec = {
|
|
@@ -629,8 +687,12 @@ function main() {
|
|
|
629
687
|
const args = process.argv.slice(2);
|
|
630
688
|
const { command: command4, options: globalOptions } = parse(globalSpec, args);
|
|
631
689
|
console.log();
|
|
632
|
-
p6.intro(`${
|
|
690
|
+
p6.intro(`${color7.bgCyan(color7.black(" @snelusha/noto "))}`);
|
|
633
691
|
if (globalOptions["--version"]) return p6.outro(version);
|
|
692
|
+
if (globalOptions["--help"]) {
|
|
693
|
+
getCommand("help")?.execute(globalOptions);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
634
696
|
const cmd = getCommand(command4) ?? getCommand("noto");
|
|
635
697
|
if (!cmd) return getCommand("noto")?.execute(globalOptions);
|
|
636
698
|
let commandArgs = args;
|