Skip to content

Commit

Permalink
✨ cli: Add cli commands for config and startup
Browse files Browse the repository at this point in the history
Convert the project into a module that can be installed globally using npm
Add configuration for the module to be used as a cli app using the command gg
Add fuctionality for gg start and gg config
  • Loading branch information
yashk2000 authored and Preet Shah committed Nov 22, 2020
1 parent 7fa66a1 commit 3dc39c7
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 39 deletions.
58 changes: 58 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node

const clear = require('clear');
const figlet = require('figlet');
const cowsay = require('cowsay');
const files = require('../lib/files.js');
const program = require('commander');
const { getQuestions, getConfigQuestions } = require('../lib/inquirer.js');

clear();

program
.command('start')
.alias('s')
.action(function () {
// displays Gitg0 on start
if (files.directoryExists('.git')) {
console.log(figlet.textSync('Gitg0', {
horizontalLayout: 'default',
verticalLayout: 'default',
}), '\n');
// asks task based questions
getQuestions();
} else {
// checks if the directory is a git based repo or not
console.log(cowsay.say({
text: 'Not a git repository!',
T: 'U '
}
));
process.exit();
}
});

program
.command('config')
.alias('c')
.action(function () {
// displays Gitg0 on start
if (files.directoryExists('.git')) {
console.log(figlet.textSync('Gitg0', {
horizontalLayout: 'default',
verticalLayout: 'default',
}), '\n');
// asks task based questions
getConfigQuestions();
} else {
// checks if the directory is a git based repo or not
console.log(cowsay.say({
text: 'Not a git repository!',
T: 'U '
}
));
process.exit();
}
});

program.parse(process.argv);
25 changes: 0 additions & 25 deletions index.js

This file was deleted.

12 changes: 0 additions & 12 deletions lib/funcs/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,3 @@ function remove_stopwords(str) {
}
return (res.join(' '))
}


branchName();
suggestCommitMsg();
suggestCommitMsg();
suggestCommitMsg();






113 changes: 112 additions & 1 deletion lib/inquirer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var inquirer = require('inquirer');
var emoji = require('node-emoji')
var emoji = require('node-emoji');
const fs = require('fs');
const { getIssue } = require('./issue.js');
const { jsonReader } = require('./funcs/jsonReader.js');

module.exports = {
getQuestions: async () => {
Expand Down Expand Up @@ -49,5 +51,114 @@ module.exports = {
// Something else went wrong
}
});
},

getConfigQuestions: async () => {

inquirer.prompt([{
type: 'list',
message: 'What commit guidelines do you follow?',
name: 'guidelines',
choices: [
`fix:, feat:, chore:`,
`fix #`,
`...(fix #)`,
`Type your own, if multiple, separate with commas`,
]
}]).then(
ans => {
if (ans['guidelines'] === "Type your own, if multiple, separate with commas") {
inquirer.prompt([
{
// expects issue number as response
type: 'string', message: 'Type your own guidelines, if multiple, separate with commas\n', name: 'commit'
}
]).then(
ans1 => {
jsonReader('./.gitgo', (err, conf) => {
if (err) {
console.log('Error reading file:', err)
return
}
conf.commit_guidelines = ans1['commit'].split(',');
fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => {
if (err) console.log('Error writing file:', err)
})
})
inquirer.prompt([
{
// expects issue number as response
type: 'string', message: 'Would you be using emojis in your commit messages?(y/n)', name: 'emojis'
}
]).then(
ans2 => {
var emo = true;
if (ans2['emojis'] === "y") {
console.log("\nWe have an awesome set of emojis in the .gitgo file which will be suggested to you in the commit messages.\n")
} else {
emo = false;
}
jsonReader('./.gitgo', (err, conf) => {
if (err) {
console.log('Error reading file:', err)
return
}
conf.use_emojis = emo;
fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => {
if (err) console.log('Error writing file:', err)
})
})
console.log("\nSettings for your repo have been stored. Run gg start before working on an issue to get the branch name and commit title automatically. If you would like to change any settings manually, please edit the .gitgo file.\n")
}
)
}
)
} else {
jsonReader('./.gitgo', (err, conf) => {
if (err) {
console.log('Error reading file:', err)
return
}
conf.commit_guidelines = ans['guidelines'].split(',');
fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => {
if (err) console.log('Error writing file:', err)
})
})
inquirer.prompt([
{
// expects issue number as response
type: 'string', message: 'Would you be using emojis in your commit messages?(y/n)', name: 'emojis'
}
]).then(
ans2 => {
var emo = true;
if (ans2['emojis'] === "y") {
console.log("\nWe have an awesome set of emojis in the .gitgo file which will be suggested to you in the commit messages.\n")
} else {
emo = false;
}
jsonReader('./.gitgo', (err, conf) => {
if (err) {
console.log('Error reading file:', err)
return
}
conf.use_emojis = emo;
fs.writeFile('./.gitgo', JSON.stringify(conf), (err) => {
if (err) console.log('Error writing file:', err)
})
})
console.log("\nSettings for your repo have been stored. Run gg start before working on an issue to get the branch name and commit title automatically. If you would like to change any settings manually, please edit the .gitgo file.\n")
}
)
}
}
)
.catch(error => {
if (error.isTtyError) {
// Prompt couldn't render in the current environment
} else {
// Something else went wrong
}
});
}
};
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "gitg0",
"version": "1.0.0",
"description": "a magnificent tool to auto-suggest everything you need before pushing a git commit.",
"main": "index.js",
"bin": {
"gg": "./bin/index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -24,6 +26,7 @@
"axios": "^0.21.0",
"chalk": "^4.1.0",
"clear": "^0.1.0",
"commander": "^6.2.0",
"cowsay": "^1.4.0",
"figlet": "^1.5.0",
"git-remote-origin-url": "^3.1.0",
Expand Down

0 comments on commit 3dc39c7

Please sign in to comment.