-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ize-302/develop
feat: add amend commit command
- Loading branch information
Showing
14 changed files
with
227 additions
and
182 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,83 @@ | ||
import { Command } from "commander"; | ||
import shell from "shelljs"; | ||
|
||
import hasStagedChanges from "@/utils/hasStagedChanges.js"; | ||
import isConventionalCommit from "@/utils/isConventionalCommit.js"; | ||
import onCancel from "@/utils/onCancel.js"; | ||
import promptContinue from "@/utils/promptContinue.js"; | ||
import showCommitMessagePrompt from "@/utils/showCommitMessagePrompt.js"; | ||
import packageJson from "../package.json"; | ||
|
||
shell.config.silent = false; | ||
|
||
const program = new Command(); | ||
|
||
export const init = () => { | ||
try { | ||
program | ||
.name("gitmo") | ||
.description( | ||
"A cli tool that adds appropriate emoji to your commit message based on conventional commits specification", | ||
) | ||
.version(packageJson.version); | ||
|
||
program | ||
.command("cm [message]") | ||
.description("Submit commit") | ||
.action(async (message) => { | ||
if (!message) { | ||
if (hasStagedChanges()) { | ||
const modifiedMessage = await showCommitMessagePrompt(); | ||
shell.exec(`git commit -m '${modifiedMessage}'`); | ||
} | ||
} else { | ||
const isValidCommit = await isConventionalCommit(message); | ||
if (isValidCommit) { | ||
shell.exec(`git commit -m '${message}'`); | ||
} else { | ||
const response = await promptContinue(); | ||
if (response.continue === "yes") { | ||
shell.exec(`git commit -m '${message}'`); | ||
} else { | ||
onCancel(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
program | ||
.command("ac [message]") | ||
.description("Ament last commit") | ||
.action(async (message) => { | ||
if (!message) { | ||
const modifiedMessage = await showCommitMessagePrompt(); | ||
shell.exec(`git commit -m '${modifiedMessage}'`); | ||
} else { | ||
const isValidCommit = await isConventionalCommit(message); | ||
if (isValidCommit) { | ||
shell.exec(`git commit --amend -m '${message}'`); | ||
} else { | ||
const response = await promptContinue(); | ||
if (response.continue === "yes") { | ||
shell.exec(`git commit --amend -m '${message}'`); | ||
} else { | ||
onCancel(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
program | ||
.command("update") | ||
.description("Update gitmo cli") | ||
.action(() => { | ||
shell.exec("npm i -g gitmo"); | ||
}); | ||
|
||
// Parse the command-line arguments | ||
program.parse(process.argv); | ||
} catch (error) { | ||
console.log(error); | ||
process.exit(1); | ||
} | ||
}; |
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,4 @@ | ||
#!/usr/bin/env node | ||
import { init } from "./gitmo.js"; | ||
|
||
init(); |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import shell from "shelljs"; | ||
|
||
// check if there is exisiting staged commit | ||
const hasStagedChanges = () => { | ||
// check if there are staged changes | ||
const gitStatus = shell.exec("git status --porcelain", { | ||
silent: true, | ||
}).stdout; | ||
// Parse the status output | ||
const stagedChanges = gitStatus | ||
.split("\n") | ||
.filter((line) => line.startsWith("A ") || line.startsWith("M ")); | ||
if (stagedChanges.length === 0) { | ||
console.log( | ||
"You have no changes staged for commit. Please stage you commit before continuing!", | ||
); | ||
} else { | ||
return true; | ||
} | ||
}; | ||
|
||
export default hasStagedChanges; |
Oops, something went wrong.