Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
217 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const meow = require('meow'); | ||
|
||
const cli = meow(` | ||
Usage | ||
$ g [input] | ||
const meow = require('meow'); | ||
const gx = require('./lib/belly'); | ||
const {cliHelp} = require('./lib/texts'); | ||
|
||
Options | ||
--foo Lorem ipsum [Default: false] | ||
const config = { | ||
flags: { | ||
commitMessage: { | ||
type: 'string', | ||
default: `gx auto-commit`, | ||
alias: 'm' | ||
} | ||
} | ||
}; | ||
|
||
Examples | ||
$ g | ||
unicorns & rainbows | ||
$ g ponies | ||
ponies & rainbows | ||
`); | ||
const cli = meow(cliHelp, config); | ||
|
||
console.log(cli.input[0] || 'unicorns'); | ||
gx(cli); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const ora = require('ora'); | ||
const git = require('./git'); | ||
const texts = require('./texts'); | ||
const handleGitError = require('./handleGitError'); | ||
|
||
const commitSpinner = ora(`Staging and committing all latest changes`); | ||
const pushSpinner = ora(`Pushing latest changes to origin`); | ||
|
||
async function addAllCommitAndPush(commitMessage) { | ||
commitSpinner.start(); | ||
try { | ||
const branchSummary = await git.branchLocal(); | ||
const currentBranch = branchSummary.current; | ||
await git.add('.'); | ||
await git.commit(commitMessage); | ||
commitSpinner.succeed(texts.commitSuccess); | ||
pushSpinner.start(); | ||
await git.push('origin', currentBranch); | ||
pushSpinner.succeed(); | ||
} catch (err) { | ||
handleGitError(err); | ||
} | ||
} | ||
|
||
module.exports = addAllCommitAndPush; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const addAllCommitAndPush = require('./addAllCommitAndPush'); | ||
const switchToBranch = require('./switchToBranch'); | ||
const tagAndPushTags = require('./tagAndPushTags'); | ||
const handleGitError = require('./handleGitError'); | ||
|
||
module.exports = async cli => { | ||
const {commitMessage} = cli.flags; | ||
if (cli.input[0] === 'c') { | ||
try { | ||
await addAllCommitAndPush(commitMessage); | ||
} catch (error) { | ||
handleGitError(error); | ||
} | ||
} else if (cli.input[0] === 's') { | ||
try { | ||
await switchToBranch(cli.input[1]); | ||
} catch (error) { | ||
handleGitError(error); | ||
} | ||
} else if (cli.input[0] === 't') { | ||
if (cli.input[1]) { | ||
tagAndPushTags(cli.input[1]); | ||
} else { | ||
console.error('\nNo version specified'); | ||
process.exit(1); | ||
} | ||
} | ||
process.exit(0); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const git = require('simple-git/promise')(); | ||
|
||
git.silent(true); | ||
|
||
module.exports = git; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function handleGitError(err) { | ||
console.log('\n\n' + err); | ||
process.exit(1); | ||
} | ||
|
||
module.exports = handleGitError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
isEmptyArray(arr) { | ||
if (Array.isArray(arr)) { | ||
return arr.length === 0; | ||
} | ||
throw new TypeError('Input must be of type Array'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const ora = require('ora'); | ||
const git = require('./git'); | ||
const texts = require('./texts'); | ||
const handleGitError = require('./handleGitError'); | ||
|
||
const switchSpinner = ora(`Checking out branch`); | ||
|
||
async function switchToBranch(branchName = '-') { | ||
switchSpinner.start(); | ||
const branchSummary = await git.branchLocal(); | ||
try { | ||
if (branchSummary.all.includes(branchName)) { | ||
await git.checkout(branchName); | ||
switchSpinner.succeed('Switched to branch: ' + branchName); | ||
} else if (branchName === '-') { | ||
await git.checkout(branchName); | ||
switchSpinner.succeed(texts.switchSuccess); | ||
} else { | ||
await git.checkoutLocalBranch(branchName); | ||
switchSpinner.succeed('Checked out new branch: ' + branchName); | ||
} | ||
} catch (err) { | ||
handleGitError(err); | ||
} | ||
} | ||
|
||
module.exports = switchToBranch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const ora = require('ora'); | ||
const git = require('./git'); | ||
const handleGitError = require('./handleGitError'); | ||
|
||
async function tagAndPushTags(tag) { | ||
const tagSpinner = ora('Tagging and annotating latest commit with ' + tag); | ||
const pushTagsSpinner = ora('Push tags to origin'); | ||
tagSpinner.start(); | ||
try { | ||
await git.addAnnotatedTag(tag, tag); | ||
tagSpinner.succeed('Tagged and annotated latest commit wiith ' + tag); | ||
pushTagsSpinner.start(); | ||
await git.pushTags('origin'); | ||
pushTagsSpinner.succeed('Pushed tags to origin'); | ||
} catch (err) { | ||
handleGitError(err); | ||
} | ||
} | ||
|
||
module.exports = tagAndPushTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = { | ||
genericError: `💥 Something went wrong.`, | ||
commitSuccess: `Everything was committed`, | ||
pushSuccess: `Latest commit was pushed to origin`, | ||
switchSuccess: `Switched to last branch`, | ||
cliHelp: ` | ||
Usage | ||
$ belly [c | s | t | r | n | q] | ||
Options | ||
--help Display this message | ||
--message -m "<commit message>" Add a custom commit message | ||
Examples | ||
Commit all staged and unstaged changes with a generic | ||
commit message and push the commit to origin | ||
$ belly c | ||
Commit all staged and unstaged changes with a custom | ||
commit message and push the commit to origin | ||
$ belly c -m "Made some awesome changes" | ||
Switch to last branch or switch to / create a branch with a specific name | ||
$ belly s [<branch-name>] | ||
Tag and annotate the current commit with a version number | ||
and push the tag to origin | ||
$ belly t <version-number> | ||
Rename the current branch locally and on origin | ||
$ belly n <new-branch-name> | ||
Squash all commits since master | ||
$ belly q -m "<commit-message>" | ||
` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import test from 'ava'; | ||
import execa from 'execa'; | ||
// import test from 'ava'; | ||
// import execa from 'execa'; | ||
|
||
test('title', async t => { | ||
t.is(await execa.stdout('./cli.js', ['ponies']), 'ponies & rainbows'); | ||
}); | ||
// test('title', async t => { | ||
// t.is(await execa.stdout('./cli.js', ['ponies']), 'ponies & rainbows'); | ||
// }); |