-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (39 loc) · 1.4 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
#!/usr/bin/env node
//Import commander, execa and listr modules
const commander = require('commander');
//Helper function to add, commit and push changes to git
function triggerGitPush(message){
const execa = require('execa');
const listr = require('listr');
new listr([
{
title: "Adding changes to git",
task: (ctx, task) => execa('git', ['add', '.']).catch(() => task.skip())
},
{
title: "Commit changes to repo",
task: (ctx, task) => execa('git', ['commit', '-m', message]).catch(() => task.skip())
},
{
title: "Push to remote repo",
task: (ctx, task) => execa('git', ['push', 'origin', 'master']).catch(() => task.skip())
}
]).run();
}
//Init commander with name and version
commander
.version('0.1.0')
.description('Git made easy');
//Command to commit changes with message "Regular Sync"
commander
.command('regularsync')
.alias('r')
.description("Pushes to remote 'origin' repo with commit message as 'Regular Sync'")
.action(() => triggerGitPush('Regular Sync'));
//Command to commit changes with message <msg>
commander
.command('syncwithmessage <msg>')
.alias('m')
.description("Pushes to remote 'origin' repo and takes in a argument 'message' to commit to the repo")
.action(msg => triggerGitPush(msg));
commander.parse(process.argv);