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..e7250f7 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,17 @@ "name": "gitg0", "version": "1.0.1", "description": "a magnificent tool to auto-suggest everything you need before pushing a git commit.", + "main": "dist/bin/index.js", + "files": [ + "dist" + ], + "types": "dist/index.d.ts", "bin": { - "gtg": "./bin/index.js" + "gtg": "./dist/bin/index.js" }, "scripts": { - "test": "jest" + "test": "jest", + "build": "tsc" }, "repository": { "type": "git", @@ -41,6 +47,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/bin/index.js b/src/bin/index.ts old mode 100755 new mode 100644 similarity index 68% rename from bin/index.js rename to src/bin/index.ts index d787836..eaea8bb --- a/bin/index.js +++ b/src/bin/index.ts @@ -1,38 +1,26 @@ -#!/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 simpleGit = require("simple-git"); -const git = simpleGit(); +const { getQuestions, getConfigQuestions, displaySuggestions } = require("../lib/inquirer.js"); +import logLogo from "../lib/funcs/logLogo"; +const git = require("simple-git")(); 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"); +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 @@ -49,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: { @@ -97,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!", @@ -120,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 { @@ -147,22 +124,16 @@ program program .command("checkout") .alias("cout") - .action(function () { + .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; } - bName = conf.current_branch; + const bName = conf.current_branch; git.checkoutLocalBranch(bName); console.log("Checked out to new branch: " + bName); }); @@ -181,36 +152,32 @@ program program .command("commit") .alias("cmt") - .action(function () { + .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; } - cMsg = conf.current_commit_message; + const cMsg = conf.current_commit_message; 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) => { + setTimeout(function() { + exec("git add ./.gitgo", (error: Error, stdout: any, stderr: Error) => { if (error) { console.log(`error: ${error.message}`); return; @@ -221,12 +188,10 @@ 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) => { + exec("git reset -- ./.gitgo", (error: Error, stdout: any, stderr: Error) => { if (error) { console.log(`error: ${error.message}`); return; @@ -237,9 +202,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,30 +220,18 @@ program program .command("version") .alias("v") - .action(function () { + .action(function() { // displays Gitg0 on start - console.log( - figlet.textSync("Gitg0", { - horizontalLayout: "default", - verticalLayout: "default", - }), - "\n" - ); + logLogo(); console.log("v" + version.version + "-stable"); }); program .command("whoami") .alias("w") - .action(function () { + .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" @@ -291,9 +242,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 99% rename from lib/funcs/commit-gen.js rename to src/lib/funcs/commit-gen.js index 34ecf2c..5132173 100644 --- a/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; 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/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/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/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 new file mode 100644 index 0000000..d95012b --- /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": 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. */ + // "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. */ + } +}