-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (72 loc) · 1.93 KB
/
Copy pathindex.js
File metadata and controls
84 lines (72 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* git-commit-helper
* helps you commit your code in one line rather than three
*
* @author shikhar13012001 <https://portfolio-shikhar13012001.vercel.app/>
*/
const init = require("./utils/init");
const cli = require("./utils/cli");
const log = require("./utils/log");
const alert = require("cli-alerts");
const TableView = require("./utils/table");
const input = cli.input;
const flags = cli.flags;
const { clear, debug } = flags;
const GET_BRANCH = require("./utils/branch");
const commit = require("./utils/commit");
process.on("unhandledRejection", (err) => {
alert({
type: `error`,
name: `ERROR`,
msg: `${err.output}`,
});
// exit process
process.exit(1);
});
(async () => {
init({ clear });
input.includes(`help`) && cli.showHelp(0);
input.includes(`version`) && cli.showVersion(0);
// get branch
const Presentbranch=GET_BRANCH();
const { message, branch } = flags;
if (message) {
log({ msg: `\nCommit message: ${flags.message}\n`, type: `green` });
log({
msg: `\nBranch name: ${flags.branch || Presentbranch.toString()}\n`,
type: flags.branch ? `green` : `yellow`,
});
log({ msg: `\nCommitting...\n`, type: `blue` });
}
try {
const add = require("child_process").execSync(commit(flags));
// if log is true then print log of commits in table format
if (flags.log) {
TableView(add.toString());
}
} catch (err) {
if (err.output?.toString()?.includes("nothing to commit")) {
alert({
type: `warning`,
name: `WARNING`,
msg: `${"Nothing to commit"}`,
});
} else {
// remove leading commas from message
alert({
type: `error`,
name: `ERROR`,
msg: `${err.output?.toString()}`,
});
}
return;
}
// check if there is any error
alert({
type: `success`,
name: `SUCCESS`,
msg: `Commit successful.`,
});
debug && console.log(flags);
})();