-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
154 lines (114 loc) · 5.65 KB
/
index.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env node
const childProcess = require('child_process');
const { match } = require('matchlight');
const package = require('./package.json');
const { configureBranchPrefixes, configureCollaborators, configureCommitPrefixes, clearConfig } = require('./modules/setup/configure-gittey');
const aliasConfig = require('./modules/setup/alias-config');
const { addCollaborator, removeCollaborators } = require('./modules/setup/collaborator-config');
const branchPrefixes = require('./modules/help/branch-prefixes');
const branchService = require('./modules/branch/branch-service');
const cloneService = require('./modules/clone/clone-service');
const commitPrefixes = require('./modules/help/commit-prefixes');
const commitService = require('./modules/commit/commit-service');
const helpOutput = require('./modules/help/help-output');
const { checkForUpdate } = require("./modules/runtime/version-service");
const { registerUserCommands } = require('./modules/user-commands/user-commands-service');
var { revertCommits } = require('./modules/revert/revert-service');
const { setRemoteUri, removeRemote, listRemotes } = require('./modules/remote/manage-remotes');
const { renameCurrentBranch } = require('./modules/branch/rename-current-branch');
const { initRepo } = require('./modules/init/init-repo');
const { loadCliOptions } = require('./modules/config/cli-options-service');
const { setVerboseMode } = require('./modules/init/configure-verbose-mode');
const { aliases, cliOptions, args } = loadCliOptions();
new Promise(function (resolve) {
resolve(true);
})
.then(function () {
match(cliOptions, function (onCase, onDefault) {
onCase({ ['set-verbose-mode']: true },
() => setVerboseMode())
onCase({ ['init-repo']: true },
() => initRepo())
onCase({ ['rename-branch']: true },
() => renameCurrentBranch())
onCase({ ['set-remote-uri']: true },
() => setRemoteUri());
onCase({ ['remove-remote']: true },
() => removeRemote());
onCase({ ['list-remotes']: true },
() => listRemotes());
onCase({ ['add-alias']: true },
() => aliasConfig.addAlias());
onCase({ ['delete-alias']: true },
() => aliasConfig.deleteAlias());
onCase({ ['new-branch']: true },
() => branchService.createBranch(args));
onCase({ ['checkout']: true },
() => branchService.checkoutBranch(args, cliOptions));
onCase({ ['commit']: true },
() => commitService.createCommit(args));
onCase({ ['init']: true },
() => configureBranchPrefixes()
.then(() => configureCommitPrefixes())
.then(() => configureCollaborators())
.then(() => console.log('Gittey has been configured for this project.')));
onCase({ ['add-collaborator']: true },
() => addCollaborator());
onCase({ ['remove-collaborators']: true },
() => removeCollaborators());
onCase({ ['clone']: true },
() => cloneService.clone());
onCase({ ['configure-branch-annotations']: true },
() => configureBranchPrefixes()
.then(() => console.log('Branch prefixes configured.')));
onCase({ ['configure-commit-annotations']: true },
() => configureCommitPrefixes()
.then(() => console.log('Commit message prefixes configured.')));
onCase({ ['reset-configuration']: true },
() => clearConfig());
onCase({ ['revert-commits']: true },
() => revertCommits());
onCase({ ['update-current-branch']: true },
() => branchService.updateCurrentBranch());
onCase({ ['merge-from-branch']: true },
() => branchService.mergeFromBranch());
onCase({ ['merge-to-branch']: true },
() => branchService.mergeToBranch());
onCase({ ['merge-to-temp']: true },
() => branchService.mergeToTemp());
onCase({ ['delete-branch']: true },
() => branchService.deleteBranch());
onCase({ ['prune-branches']: true },
() => branchService.pruneBranches());
onCase({ ['branch-prefixes']: true },
() => branchPrefixes.displayBranchPrefixes());
onCase({ ['commit-prefixes']: true },
() => commitPrefixes.displayBranchPrefixes());
onCase({ ['commit-prefixes']: true },
() => commitPrefixes.displayBranchPrefixes());
onCase({ ['help']: true },
() => helpOutput.display());
onCase({ ['version']: true },
() => console.log(`v${package.version}`));
onCase({ ['update']: true },
() =>
childProcess.execSync(`npm install gittey@latest -g`, { stdio: 'inherit' }));
onCase({ ['passthrough']: true },
() =>
childProcess.execSync(`git ${args.join(' ')}`, { stdio: 'inherit' }));
registerUserCommands(aliases, cliOptions, onCase);
onDefault(() => {
console.log('Gittey: unknown command, sorry.');
helpOutput.display();
process.exit(1);
});
});
})
.then(function () {
if (!cliOptions.update) {
checkForUpdate(package.version);
}
})
.catch(function (error) {
process.exit(1);
});