diff --git a/.gitgo b/.gitgo index 41c9e19..0699c21 100644 --- a/.gitgo +++ b/.gitgo @@ -1,15 +1,16 @@ { "current_issue": { - "number": "", - "labels": [], - "title": "" + "number": "39", + "labels": [ + "cli" + ], + "title": "Create commands for checking out and committing" }, "commit_guidelines": [ - "fix:", - "feat:", - "chore:" + "cli:", + "general:" ], - "custom_guidelines": false, + "custom_guidelines": true, "selected_commit_type": "✨ Adding a new user-facing feature", "emojis": { "initial_commit": "tada", @@ -28,8 +29,13 @@ "cleanup": "fire", "wip": "construction" }, - "existing_branches": [], - "current_branch": "", - "current_commit_message": "", - "use_emojis": false + "existing_branches": [ + "main", + "readme" + ], + "current_branch": [ + "commands" + ], + "current_commit_message": "✨ cli: Create commands for checking out and committing", + "use_emojis": true } \ No newline at end of file diff --git a/bin/index.js b/bin/index.js index 28b7f0b..77470f8 100755 --- a/bin/index.js +++ b/bin/index.js @@ -6,6 +6,9 @@ const cowsay = require('cowsay'); const files = require('../lib/files.js'); const program = require('commander'); const { getQuestions, getConfigQuestions, displaySuggestions } = require('../lib/inquirer.js'); +const simpleGit = require('simple-git'); +const git = simpleGit(); +const { jsonReader } = require('../lib/funcs/jsonReader.js'); clear(); @@ -19,7 +22,6 @@ program horizontalLayout: 'default', verticalLayout: 'default', }), '\n'); - // asks task based questions getQuestions(); } else { // checks if the directory is a git based repo or not @@ -78,4 +80,64 @@ program } }); +program +.command('checkout') +.alias('cout') +.action(function () { + // displays Gitg0 on start + if (files.directoryExists('.git')) { + console.log(figlet.textSync('Gitg0', { + horizontalLayout: 'default', + verticalLayout: 'default', + }), '\n'); + jsonReader('./.gitgo', (err, conf) => { + if (err) { + console.log('Error reading file:', err) + return + } + bName = conf.current_branch; + git.checkoutLocalBranch(bName); + console.log("Checked out to new branch: " + bName); + }); + } 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('commit') +.alias('cmt') +.action(function () { + // displays Gitg0 on start + if (files.directoryExists('.git')) { + console.log(figlet.textSync('Gitg0', { + horizontalLayout: 'default', + verticalLayout: 'default', + }), '\n'); + jsonReader('./.gitgo', (err, conf) => { + if (err) { + console.log('Error reading file:', err) + return + } + cMsg = conf.current_commit_message; + git.commit(cMsg); + console.log("Files have be commited: " + cMsg); + }); + } 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); diff --git a/package-lock.json b/package-lock.json index 7c4e52d..6972ef5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,19 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@kwsites/file-exists": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", + "integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==", + "requires": { + "debug": "^4.1.1" + } + }, + "@kwsites/promise-deferred": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", + "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" + }, "ansi-escapes": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", @@ -123,6 +136,14 @@ } } }, + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", + "requires": { + "ms": "2.1.2" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -245,6 +266,11 @@ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", @@ -333,6 +359,16 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" }, + "simple-git": { + "version": "2.23.0", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-2.23.0.tgz", + "integrity": "sha512-s/gEkxFV2WGTN4kO1uQoA4cE4rq0FRzQPR5Yhgg8JUuA4IhOeccjlKSFhwF3rrpo7797ZvQc7L6hJJNA4szHCw==", + "requires": { + "@kwsites/file-exists": "^1.1.1", + "@kwsites/promise-deferred": "^1.1.1", + "debug": "^4.3.1" + } + }, "string-width": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", diff --git a/package.json b/package.json index 2e42ab2..78b3f42 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "retext": "^7.0.1", "retext-keywords": "^6.0.0", "retext-pos": "^3.0.0", - "sentence-engine": "^0.7.0" + "sentence-engine": "^0.7.0", + "simple-git": "^2.23.0" } }