From f995c46388d7aaca79d76c81ba78a595a1d16f8f Mon Sep 17 00:00:00 2001 From: Ash McBride Date: Wed, 9 Dec 2020 20:45:42 +0000 Subject: [PATCH 1/3] cli: add typescript support --- .gitignore | 3 +- package-lock.json | 79 ++++++++ package.json | 22 ++- src/bin/index.js | 262 +++++++++++++++++++++++++ bin/index.js => src/bin/index.ts | 44 ++--- {lib => src/lib}/files.js | 0 {lib => src/lib}/funcs/commit-gen.js | 0 {lib => src/lib}/funcs/generate.js | 0 {lib => src/lib}/funcs/jsonReader.js | 0 {lib => src/lib}/funcs/rec-iss-type.js | 0 {lib => src/lib}/inquirer.js | 0 {lib => src/lib}/issue.js | 0 tsconfig.json | 67 +++++++ 13 files changed, 445 insertions(+), 32 deletions(-) create mode 100644 src/bin/index.js rename bin/index.js => src/bin/index.ts (90%) mode change 100755 => 100644 rename {lib => src/lib}/files.js (100%) rename {lib => src/lib}/funcs/commit-gen.js (100%) rename {lib => src/lib}/funcs/generate.js (100%) rename {lib => src/lib}/funcs/jsonReader.js (100%) rename {lib => src/lib}/funcs/rec-iss-type.js (100%) rename {lib => src/lib}/inquirer.js (100%) rename {lib => src/lib}/issue.js (100%) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 9590fbe..300ca35 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules/ lib/dist lib/funcs/dist/ -bin/dist \ No newline at end of file +bin/dist +dist/ diff --git a/package-lock.json b/package-lock.json index 781af66..bdc26ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -655,6 +655,15 @@ "@sinonjs/commons": "^1.7.0" } }, + "@types/axios": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz", + "integrity": "sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=", + "dev": true, + "requires": { + "axios": "*" + } + }, "@types/babel__core": { "version": "7.1.12", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.12.tgz", @@ -696,6 +705,45 @@ "@babel/types": "^7.3.0" } }, + "@types/chalk": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "dev": true, + "requires": { + "chalk": "*" + } + }, + "@types/clear": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@types/clear/-/clear-0.1.1.tgz", + "integrity": "sha512-Wu6DxCnSjFiqymbTeyb63VdU1oKYW0qCnmOSBjpMyuvcuvI9keXfS6RbEcKYqUY0dPOLa34qV+XHAdgiRzPBtg==", + "dev": true + }, + "@types/commander": { + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/@types/commander/-/commander-2.12.2.tgz", + "integrity": "sha512-0QEFiR8ljcHp9bAbWxecjVRuAMr16ivPiGOw6KFQBVrVd0RQIcM3xKdRisH2EDWgVWujiYtHwhSkSUoAAGzH7Q==", + "dev": true, + "requires": { + "commander": "*" + } + }, + "@types/figlet": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@types/figlet/-/figlet-1.2.1.tgz", + "integrity": "sha512-uw+Xmam7sMFHYyVGq5CGH/6Lu0T792bf4T6+jPFtPkWnJ9YVjLKqOLzF7DHuSo/LEHtLWleUO7Zi7EKkg6rSIg==", + "dev": true + }, + "@types/git-remote-origin-url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/git-remote-origin-url/-/git-remote-origin-url-3.0.1.tgz", + "integrity": "sha512-qSeYls542yijI/p6ejDW3QS8eLjJjIQvfTEbPD5xaRvvKlq8hCtiP6nXCTyfPnK3zrsbLSA9RLyyPxT80Ri20g==", + "dev": true, + "requires": { + "git-remote-origin-url": "*" + } + }, "@types/graceful-fs": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.4.tgz", @@ -705,6 +753,16 @@ "@types/node": "*" } }, + "@types/inquirer": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-7.3.1.tgz", + "integrity": "sha512-osD38QVIfcdgsPCT0V3lD7eH0OFurX71Jft18bZrsVQWVRt6TuxRzlr0GJLrxoHZR2V5ph7/qP8se/dcnI7o0g==", + "dev": true, + "requires": { + "@types/through": "*", + "rxjs": "^6.4.0" + } + }, "@types/istanbul-lib-coverage": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", @@ -735,6 +793,12 @@ "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==", "dev": true }, + "@types/node-emoji": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/@types/node-emoji/-/node-emoji-1.8.1.tgz", + "integrity": "sha512-0fRfA90FWm6KJfw6P9QGyo0HDTCmthZ7cWaBQndITlaWLTZ6njRyKwrwpzpg+n6kBXBIGKeUHEQuBx7bphGJkA==", + "dev": true + }, "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -753,6 +817,15 @@ "integrity": "sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==", "dev": true }, + "@types/through": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/@types/through/-/through-0.0.30.tgz", + "integrity": "sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/unist": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz", @@ -4816,6 +4889,12 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz", + "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==", + "dev": true + }, "unherit": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.3.tgz", diff --git a/package.json b/package.json index c9dbea4..f37e6a3 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,18 @@ "name": "gitg0", "version": "1.0.1", "description": "a magnificent tool to auto-suggest everything you need before pushing a git commit.", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", + "files": [ + "dist" + ], + "types": "dist/index.d.ts", "bin": { - "gtg": "./bin/index.js" + "gtg": "./dist/index.cjs.js" }, "scripts": { - "test": "jest" + "test": "jest", + "build": "tsc" }, "repository": { "type": "git", @@ -41,6 +48,15 @@ "simple-git": "^2.23.0" }, "devDependencies": { - "jest": "^26.6.3" + "@types/axios": "^0.14.0", + "@types/chalk": "^2.2.0", + "@types/clear": "^0.1.1", + "@types/commander": "^2.12.2", + "@types/figlet": "^1.2.1", + "@types/git-remote-origin-url": "^3.0.1", + "@types/inquirer": "^7.3.1", + "@types/node-emoji": "^1.8.1", + "jest": "^26.6.3", + "typescript": "^4.1.2" } } diff --git a/src/bin/index.js b/src/bin/index.js new file mode 100644 index 0000000..ee169e5 --- /dev/null +++ b/src/bin/index.js @@ -0,0 +1,262 @@ +"use strict"; +var clear = require("clear"); +var figlet = require("figlet"); +var cowsay = require("cowsay"); +var files = require("../lib/files.js"); +var program = require("commander"); +var _a = require("../lib/inquirer.js"), getQuestions = _a.getQuestions, getConfigQuestions = _a.getConfigQuestions, displaySuggestions = _a.displaySuggestions; +var simpleGit = require("simple-git"); +var git = simpleGit(); +var jsonReader = require("../lib/funcs/jsonReader.js").jsonReader; +var version = require("../../package.json"); +var chalk = require("chalk"); +var exec = require("child_process").exec; +var fs = require("fs"); +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"); + 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"); + fs.stat("./.gitgo", function (err, stat) { + if (err == null) { + // asks task based questions + getConfigQuestions(); + } + else if (err.code === "ENOENT") { + // file does not exist + var conf = { + current_issue: { + number: "", + labels: [""], + title: "", + }, + commit_guidelines: [""], + custom_guidelines: false, + selected_commit_type: "", + emojis: { + initial_commit: "tada", + feature: "sparkles", + ui: "art", + code_quality: "package", + performance: "racehorse", + security: "lock", + config: "wrench", + accessibility: "wheelchair", + dev_tools: "rocket", + docs: "pencil", + release: "gem", + bug_fix: "bug", + crash: "boom", + cleanup: "fire", + wip: "construction", + }, + existing_branches: [], + current_branch: [""], + current_commit_message: "", + use_emojis: false, + commit_config: false, + }; + fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), function (err) { + if (err) + console.log("Error writing file:", err); + }); + getConfigQuestions(); + } + else { + console.log("Some other error: ", err.code); + } + }); + } + 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("display") + .alias("d") + .action(function () { + // displays Gitg0 on start + if (files.directoryExists(".git")) { + console.log(figlet.textSync("Gitg0", { + horizontalLayout: "default", + verticalLayout: "default", + }), "\n"); + // asks task based questions + displaySuggestions(); + } + 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("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", function (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", function (err, conf) { + if (err) { + console.log("Error reading file:", err); + return; + } + cMsg = conf.current_commit_message; + if (conf.commit_config) { + conf.commit_config = false; + conf.current_commit_message = ""; + conf.current_branch = [""]; + conf.existing_branches = [""]; + conf.selected_commit_type = ""; + conf.current_issue.number = ""; + conf.current_issue.labels = [""]; + conf.current_issue.title = ""; + fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), function (err) { + if (err) + console.log("Error writing file:", err); + }); + setTimeout(function () { + exec("git add ./.gitgo", function (error, stdout, stderr) { + if (error) { + console.log("error: " + error.message); + return; + } + if (stderr) { + console.log("stderr: " + stderr); + return; + } + }); + git.commit(cMsg); + console.log("Files have be commited!\nRecent commit message: " + cMsg); + }, 1000); + } + else { + exec("git reset -- ./.gitgo", function (error, stdout, stderr) { + if (error) { + console.log("error: " + error.message); + return; + } + if (stderr) { + console.log("stderr: " + stderr); + return; + } + }); + git.commit(cMsg); + console.log("Files have be commited!\nRecent commit message: " + 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 + .command("version") + .alias("v") + .action(function () { + // displays Gitg0 on start + console.log(figlet.textSync("Gitg0", { + horizontalLayout: "default", + verticalLayout: "default", + }), "\n"); + console.log("v" + version.version + "-stable"); +}); +program + .command("whoami") + .alias("w") + .action(function () { + // displays Gitg0 on start + console.log(figlet.textSync("Gitg0", { + horizontalLayout: "default", + verticalLayout: "default", + }), "\n"); + console.log("You just need to know 7 simple commands you and then you're " + chalk.bold.cyan("gtg") + " : " + chalk.magenta("Good to Go")); + console.log(chalk.green("\ngtg config:\n")); + console.log("Use this to set up your project's gitgo configuration. You will be asked certain questions regarding your commit and emoji preferences.\n"); + console.log(chalk.green("\ngtg version:\n")); + console.log("Use this to check the version of your installed gitg0 package."); + console.log(chalk.green("\ngtg whoami:\n")); + console.log("I mean,,, you just used me."); + console.log(chalk.green("\ngtg start:\n")); + console.log("Use this before you you start working on a new issue so that we can suggest the branch names and commit messages automatically.\n"); + console.log(chalk.green("\ngtg display:\n")); + console.log("Use this to view the suggested branch name and commit title. You can also edit the suggested text based on your preference. This command should be run after " + chalk.yellow("gtg start") + ".\n"); + console.log(chalk.green("\ngtg checkout:\n")); + console.log("This is a replacement for " + chalk.yellow("git checkout -b") + " and will simply checkout with gitgo's suggested branch name.\n"); + console.log(chalk.green("\ngtg checkout:\n")); + console.log("This is a replacement for " + chalk.yellow("git checkout -m") + " and will commit your files once added with gitgo's suggested commit message.\n"); +}); +program.parse(process.argv); diff --git a/bin/index.js b/src/bin/index.ts old mode 100755 new mode 100644 similarity index 90% rename from bin/index.js rename to src/bin/index.ts index d787836..f9a4383 --- a/bin/index.js +++ b/src/bin/index.ts @@ -1,19 +1,13 @@ -#!/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, - displaySuggestions, -} = require("../lib/inquirer.js"); +const { getQuestions, getConfigQuestions, displaySuggestions } = require("../lib/inquirer.js"); const simpleGit = require("simple-git"); const git = simpleGit(); const { jsonReader } = require("../lib/funcs/jsonReader.js"); -const version = require("../package.json"); +const version = require("../../package.json"); const chalk = require("chalk"); const { exec } = require("child_process"); const fs = require("fs"); @@ -23,7 +17,7 @@ clear(); program .command("start") .alias("s") - .action(function () { + .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { console.log( @@ -49,7 +43,7 @@ program program .command("config") .alias("c") - .action(function () { + .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { console.log( @@ -59,7 +53,7 @@ program }), "\n" ); - fs.stat("./.gitgo", function (err, stat) { + fs.stat("./.gitgo", function(err, stat) { if (err == null) { // asks task based questions getConfigQuestions(); @@ -120,7 +114,7 @@ program program .command("display") .alias("d") - .action(function () { + .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { console.log( @@ -147,7 +141,7 @@ program program .command("checkout") .alias("cout") - .action(function () { + .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { console.log( @@ -162,7 +156,7 @@ program console.log("Error reading file:", err); return; } - bName = conf.current_branch; + const bName = conf.current_branch; git.checkoutLocalBranch(bName); console.log("Checked out to new branch: " + bName); }); @@ -181,7 +175,7 @@ program program .command("commit") .alias("cmt") - .action(function () { + .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { console.log( @@ -196,7 +190,7 @@ program console.log("Error reading file:", err); return; } - cMsg = conf.current_commit_message; + const cMsg = conf.current_commit_message; if (conf.commit_config) { conf.commit_config = false; conf.current_commit_message = ""; @@ -209,7 +203,7 @@ program fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), (err) => { if (err) console.log("Error writing file:", err); }); - setTimeout(function () { + setTimeout(function() { exec("git add ./.gitgo", (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); @@ -221,9 +215,7 @@ program } }); git.commit(cMsg); - console.log( - "Files have be commited!\nRecent commit message: " + cMsg - ); + console.log("Files have be commited!\nRecent commit message: " + cMsg); }, 1000); } else { exec("git reset -- ./.gitgo", (error, stdout, stderr) => { @@ -237,9 +229,7 @@ program } }); git.commit(cMsg); - console.log( - "Files have be commited!\nRecent commit message: " + cMsg - ); + console.log("Files have be commited!\nRecent commit message: " + cMsg); } }); } else { @@ -257,7 +247,7 @@ program program .command("version") .alias("v") - .action(function () { + .action(function() { // displays Gitg0 on start console.log( figlet.textSync("Gitg0", { @@ -272,7 +262,7 @@ program program .command("whoami") .alias("w") - .action(function () { + .action(function() { // displays Gitg0 on start console.log( figlet.textSync("Gitg0", { @@ -291,9 +281,7 @@ program "Use this to set up your project's gitgo configuration. You will be asked certain questions regarding your commit and emoji preferences.\n" ); console.log(chalk.green("\ngtg version:\n")); - console.log( - "Use this to check the version of your installed gitg0 package." - ); + console.log("Use this to check the version of your installed gitg0 package."); console.log(chalk.green("\ngtg whoami:\n")); console.log("I mean,,, you just used me."); console.log(chalk.green("\ngtg start:\n")); diff --git a/lib/files.js b/src/lib/files.js similarity index 100% rename from lib/files.js rename to src/lib/files.js diff --git a/lib/funcs/commit-gen.js b/src/lib/funcs/commit-gen.js similarity index 100% rename from lib/funcs/commit-gen.js rename to src/lib/funcs/commit-gen.js diff --git a/lib/funcs/generate.js b/src/lib/funcs/generate.js similarity index 100% rename from lib/funcs/generate.js rename to src/lib/funcs/generate.js diff --git a/lib/funcs/jsonReader.js b/src/lib/funcs/jsonReader.js similarity index 100% rename from lib/funcs/jsonReader.js rename to src/lib/funcs/jsonReader.js diff --git a/lib/funcs/rec-iss-type.js b/src/lib/funcs/rec-iss-type.js similarity index 100% rename from lib/funcs/rec-iss-type.js rename to src/lib/funcs/rec-iss-type.js diff --git a/lib/inquirer.js b/src/lib/inquirer.js similarity index 100% rename from lib/inquirer.js rename to src/lib/inquirer.js diff --git a/lib/issue.js b/src/lib/issue.js similarity index 100% rename from lib/issue.js rename to src/lib/issue.js diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b093eb5 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,67 @@ +{ + "include": ["src/**/*"], + "compilerOptions": { + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + // "lib": [], /* Specify library files to be included in the compilation. */ + "allowJs": true /* Allow javascript files to be compiled. */, + "checkJs": false /* Report errors in .js files. */, + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist" /* Redirect output structure to the directory. */, + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": false /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} From 7d4847eb635add99f743eac284b11e6ed56328c1 Mon Sep 17 00:00:00 2001 From: Ash McBride Date: Wed, 9 Dec 2020 21:12:40 +0000 Subject: [PATCH 2/3] cli: refactor logo log and typed file --- package.json | 5 +- src/bin/index.js | 262 --------------------------------------- src/bin/index.ts | 111 ++++++----------- src/lib/funcs/logLogo.js | 13 ++ src/types.d.ts | 32 +++++ tsconfig.json | 2 +- 6 files changed, 84 insertions(+), 341 deletions(-) delete mode 100644 src/bin/index.js create mode 100644 src/lib/funcs/logLogo.js create mode 100644 src/types.d.ts diff --git a/package.json b/package.json index f37e6a3..e7250f7 100644 --- a/package.json +++ b/package.json @@ -2,14 +2,13 @@ "name": "gitg0", "version": "1.0.1", "description": "a magnificent tool to auto-suggest everything you need before pushing a git commit.", - "main": "dist/index.cjs.js", - "module": "dist/index.esm.js", + "main": "dist/bin/index.js", "files": [ "dist" ], "types": "dist/index.d.ts", "bin": { - "gtg": "./dist/index.cjs.js" + "gtg": "./dist/bin/index.js" }, "scripts": { "test": "jest", diff --git a/src/bin/index.js b/src/bin/index.js deleted file mode 100644 index ee169e5..0000000 --- a/src/bin/index.js +++ /dev/null @@ -1,262 +0,0 @@ -"use strict"; -var clear = require("clear"); -var figlet = require("figlet"); -var cowsay = require("cowsay"); -var files = require("../lib/files.js"); -var program = require("commander"); -var _a = require("../lib/inquirer.js"), getQuestions = _a.getQuestions, getConfigQuestions = _a.getConfigQuestions, displaySuggestions = _a.displaySuggestions; -var simpleGit = require("simple-git"); -var git = simpleGit(); -var jsonReader = require("../lib/funcs/jsonReader.js").jsonReader; -var version = require("../../package.json"); -var chalk = require("chalk"); -var exec = require("child_process").exec; -var fs = require("fs"); -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"); - 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"); - fs.stat("./.gitgo", function (err, stat) { - if (err == null) { - // asks task based questions - getConfigQuestions(); - } - else if (err.code === "ENOENT") { - // file does not exist - var conf = { - current_issue: { - number: "", - labels: [""], - title: "", - }, - commit_guidelines: [""], - custom_guidelines: false, - selected_commit_type: "", - emojis: { - initial_commit: "tada", - feature: "sparkles", - ui: "art", - code_quality: "package", - performance: "racehorse", - security: "lock", - config: "wrench", - accessibility: "wheelchair", - dev_tools: "rocket", - docs: "pencil", - release: "gem", - bug_fix: "bug", - crash: "boom", - cleanup: "fire", - wip: "construction", - }, - existing_branches: [], - current_branch: [""], - current_commit_message: "", - use_emojis: false, - commit_config: false, - }; - fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), function (err) { - if (err) - console.log("Error writing file:", err); - }); - getConfigQuestions(); - } - else { - console.log("Some other error: ", err.code); - } - }); - } - 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("display") - .alias("d") - .action(function () { - // displays Gitg0 on start - if (files.directoryExists(".git")) { - console.log(figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), "\n"); - // asks task based questions - displaySuggestions(); - } - 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("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", function (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", function (err, conf) { - if (err) { - console.log("Error reading file:", err); - return; - } - cMsg = conf.current_commit_message; - if (conf.commit_config) { - conf.commit_config = false; - conf.current_commit_message = ""; - conf.current_branch = [""]; - conf.existing_branches = [""]; - conf.selected_commit_type = ""; - conf.current_issue.number = ""; - conf.current_issue.labels = [""]; - conf.current_issue.title = ""; - fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), function (err) { - if (err) - console.log("Error writing file:", err); - }); - setTimeout(function () { - exec("git add ./.gitgo", function (error, stdout, stderr) { - if (error) { - console.log("error: " + error.message); - return; - } - if (stderr) { - console.log("stderr: " + stderr); - return; - } - }); - git.commit(cMsg); - console.log("Files have be commited!\nRecent commit message: " + cMsg); - }, 1000); - } - else { - exec("git reset -- ./.gitgo", function (error, stdout, stderr) { - if (error) { - console.log("error: " + error.message); - return; - } - if (stderr) { - console.log("stderr: " + stderr); - return; - } - }); - git.commit(cMsg); - console.log("Files have be commited!\nRecent commit message: " + 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 - .command("version") - .alias("v") - .action(function () { - // displays Gitg0 on start - console.log(figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), "\n"); - console.log("v" + version.version + "-stable"); -}); -program - .command("whoami") - .alias("w") - .action(function () { - // displays Gitg0 on start - console.log(figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), "\n"); - console.log("You just need to know 7 simple commands you and then you're " + chalk.bold.cyan("gtg") + " : " + chalk.magenta("Good to Go")); - console.log(chalk.green("\ngtg config:\n")); - console.log("Use this to set up your project's gitgo configuration. You will be asked certain questions regarding your commit and emoji preferences.\n"); - console.log(chalk.green("\ngtg version:\n")); - console.log("Use this to check the version of your installed gitg0 package."); - console.log(chalk.green("\ngtg whoami:\n")); - console.log("I mean,,, you just used me."); - console.log(chalk.green("\ngtg start:\n")); - console.log("Use this before you you start working on a new issue so that we can suggest the branch names and commit messages automatically.\n"); - console.log(chalk.green("\ngtg display:\n")); - console.log("Use this to view the suggested branch name and commit title. You can also edit the suggested text based on your preference. This command should be run after " + chalk.yellow("gtg start") + ".\n"); - console.log(chalk.green("\ngtg checkout:\n")); - console.log("This is a replacement for " + chalk.yellow("git checkout -b") + " and will simply checkout with gitgo's suggested branch name.\n"); - console.log(chalk.green("\ngtg checkout:\n")); - console.log("This is a replacement for " + chalk.yellow("git checkout -m") + " and will commit your files once added with gitgo's suggested commit message.\n"); -}); -program.parse(process.argv); diff --git a/src/bin/index.ts b/src/bin/index.ts index f9a4383..ac2a6c1 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -1,32 +1,26 @@ 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, displaySuggestions } = require("../lib/inquirer.js"); -const simpleGit = require("simple-git"); -const git = simpleGit(); +const logLogo = require("../lib/funcs/logLogo"); +const git = require("simple-git")(); const { jsonReader } = require("../lib/funcs/jsonReader.js"); const version = require("../../package.json"); const chalk = require("chalk"); const { exec } = require("child_process"); const fs = require("fs"); +import { GitGoConf } from "../types"; clear(); program .command("start") .alias("s") - .action(function() { + .action(() => { // displays Gitg0 on start if (files.directoryExists(".git")) { - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); + logLogo(); getQuestions(); } else { // checks if the directory is a git based repo or not @@ -43,21 +37,15 @@ program program .command("config") .alias("c") - .action(function() { + .action(async () => { // displays Gitg0 on start if (files.directoryExists(".git")) { - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); - fs.stat("./.gitgo", function(err, stat) { - if (err == null) { - // asks task based questions - getConfigQuestions(); - } else if (err.code === "ENOENT") { + try { + logLogo(); + await fs.stat("./.gitgo"); + getConfigQuestions(); + } catch (err) { + if (err.code === "ENOENT") { // file does not exist var conf = { current_issue: { @@ -91,16 +79,17 @@ program use_emojis: false, commit_config: false, }; - fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), (err) => { - if (err) console.log("Error writing file:", err); - }); - getConfigQuestions(); + try { + await fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2)); + getConfigQuestions(); + } catch (e) { + console.log("Error writing file: ", e); + } } else { console.log("Some other error: ", err.code); } - }); + } } else { - // checks if the directory is a git based repo or not console.log( cowsay.say({ text: "Not a git repository!", @@ -114,16 +103,10 @@ program program .command("display") .alias("d") - .action(function() { + .action(() => { // displays Gitg0 on start if (files.directoryExists(".git")) { - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); + logLogo(); // asks task based questions displaySuggestions(); } else { @@ -144,14 +127,8 @@ program .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); - jsonReader("./.gitgo", (err, conf) => { + logLogo(); + jsonReader("./.gitgo", (err: Error, conf: GitGoConf) => { if (err) { console.log("Error reading file:", err); return; @@ -178,14 +155,8 @@ program .action(function() { // displays Gitg0 on start if (files.directoryExists(".git")) { - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); - jsonReader("./.gitgo", (err, conf) => { + logLogo(); + jsonReader("./.gitgo", (err: Error, conf: GitGoConf) => { if (err) { console.log("Error reading file:", err); return; @@ -194,17 +165,19 @@ program if (conf.commit_config) { conf.commit_config = false; conf.current_commit_message = ""; - conf.current_branch = [""]; + conf.current_branch = ""; conf.existing_branches = [""]; conf.selected_commit_type = ""; - conf.current_issue.number = ""; - conf.current_issue.labels = [""]; - conf.current_issue.title = ""; - fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), (err) => { + conf.current_issue = { + number: undefined, + labels: [""], + title: "", + }; + fs.writeFile("./.gitgo", JSON.stringify(conf, null, 2), (err: Error) => { if (err) console.log("Error writing file:", err); }); setTimeout(function() { - exec("git add ./.gitgo", (error, stdout, stderr) => { + exec("git add ./.gitgo", (error: Error, stdout: any, stderr: Error) => { if (error) { console.log(`error: ${error.message}`); return; @@ -218,7 +191,7 @@ program console.log("Files have be commited!\nRecent commit message: " + cMsg); }, 1000); } else { - exec("git reset -- ./.gitgo", (error, stdout, stderr) => { + exec("git reset -- ./.gitgo", (error: Error, stdout: any, stderr: Error) => { if (error) { console.log(`error: ${error.message}`); return; @@ -249,13 +222,7 @@ program .alias("v") .action(function() { // displays Gitg0 on start - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); + logLogo(); console.log("v" + version.version + "-stable"); }); @@ -264,13 +231,7 @@ program .alias("w") .action(function() { // displays Gitg0 on start - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); + logLogo(); console.log( `You just need to know 7 simple commands you and then you're ${chalk.bold.cyan( "gtg" diff --git a/src/lib/funcs/logLogo.js b/src/lib/funcs/logLogo.js new file mode 100644 index 0000000..b92ba17 --- /dev/null +++ b/src/lib/funcs/logLogo.js @@ -0,0 +1,13 @@ +import figlet from 'figlet' + +const logLogo = () => { + console.log( + figlet.textSync('Gitg0', { + horizontalLayout: 'default', + verticalLayout: 'default' + }), + "\n" + ) +} + +export default logLogo diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..e88afd8 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,32 @@ +export interface GitGoConf { + current_issue?: { + number?: number; + labels?: string[]; + title?: string; + } + commit_guidelines: string[]; + custom_guidelines: boolean; + selected_commit_type: string; + emojis: { + initial_commit: string; + feature: string; + ui: string; + code_quality: string; + performance: string; + security: string; + config: string; + accessibility: string; + dev_tools: string; + docs: string; + release: string; + bug_fix: string; + crash: string; + cleanup: string; + wip: string; + } + existing_branches: string[]; + current_branch: string; + current_commit_message: string; + use_emojis: boolean; + commit_config: boolean; +} diff --git a/tsconfig.json b/tsconfig.json index b093eb5..d95012b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,7 +24,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": false /* Enable all strict type-checking options. */, + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ From ccd4a8db3b81f429e119ff1b420a0a38f0bf4679 Mon Sep 17 00:00:00 2001 From: Ash McBride Date: Wed, 9 Dec 2020 21:26:30 +0000 Subject: [PATCH 3/3] cli: fix missing variable declaration --- src/bin/index.ts | 2 +- src/lib/funcs/commit-gen.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/index.ts b/src/bin/index.ts index ac2a6c1..eaea8bb 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -3,7 +3,7 @@ const cowsay = require("cowsay"); const files = require("../lib/files.js"); const program = require("commander"); const { getQuestions, getConfigQuestions, displaySuggestions } = require("../lib/inquirer.js"); -const logLogo = require("../lib/funcs/logLogo"); +import logLogo from "../lib/funcs/logLogo"; const git = require("simple-git")(); const { jsonReader } = require("../lib/funcs/jsonReader.js"); const version = require("../../package.json"); diff --git a/src/lib/funcs/commit-gen.js b/src/lib/funcs/commit-gen.js index 34ecf2c..5132173 100644 --- a/src/lib/funcs/commit-gen.js +++ b/src/lib/funcs/commit-gen.js @@ -3,7 +3,7 @@ const fs = require("fs"); const reader = require("./jsonReader"); const { Console } = require("console"); -stopwords = ["a", "the"]; +const stopwords = ["a", "the"]; const suggestCommitMsgCb = (conf) => { const issue_labels = conf.current_issue.labels;