-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli):
czg
cli add core commit msg
link #37
- Loading branch information
Showing
12 changed files
with
154 additions
and
12 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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,40 @@ | ||
// import path from "path"; | ||
import cacheDir from "cachedir"; | ||
import { ensureDir } from "fs-extra"; | ||
import { gitCommit } from "../shared"; | ||
import type { CommitizenType } from "cz-git"; | ||
import type { CallBackFn, CzGitPrompter, CommitOptions } from "../shared"; | ||
|
||
/** | ||
* generate cz-git prompt get commit message | ||
*/ | ||
export const commit = ( | ||
inquirer: CommitizenType, | ||
rootPath: string, | ||
prompter: CzGitPrompter, | ||
options: CommitOptions, | ||
done: CallBackFn | ||
) => { | ||
const cacheDirectory = cacheDir("cz-git"); | ||
// const cachePath = path.join(cacheDirectory, "commit.json"); | ||
|
||
ensureDir(cacheDirectory, (err: any) => { | ||
if (err) { | ||
console.error("Couldn't create commitizen cache directory: ", err); | ||
} else { | ||
if (options.retryLastCommit) { | ||
console.log("Retrying last commit attempt."); | ||
// TODO: get cache data | ||
// TODO: retry last commit | ||
} else { | ||
prompter(inquirer, (commitMsg: string | Error) => { | ||
if (commitMsg instanceof Error) { | ||
return done(commitMsg); | ||
} | ||
// TODO: add cache | ||
gitCommit(rootPath, commitMsg, options, done); | ||
}); | ||
} | ||
} | ||
}); | ||
}; |
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,52 @@ | ||
import { CommitizenType, prompter, style } from "cz-git"; | ||
import inquirer from "inquirer"; | ||
import { commit } from "./commit"; | ||
import { isGitClean, getGitRootPath } from "../shared"; | ||
|
||
/** | ||
* start inquirer prompts to commit message | ||
*/ | ||
export const czg = (version: string, commandArgs: string[], environment: any = {}) => { | ||
// TODO: parse commandArgs | ||
// console.log(commandArgs); | ||
// console.log(environment); | ||
// parse git hook and git -a | ||
// isClean | ||
isGitClean( | ||
process.cwd(), | ||
(error, isClean) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
if (isClean) { | ||
throw new Error( | ||
`No files added to staging! Did you forget to run ${style.cyan("git add")} ?` | ||
); | ||
} | ||
|
||
console.log(`czg@${version}\n`); | ||
// commit | ||
commit( | ||
inquirer as CommitizenType, | ||
getGitRootPath(), | ||
prompter, | ||
{ | ||
args: [], | ||
disableAppendPaths: true, | ||
emitData: true, | ||
quiet: false, | ||
retryLastCommit: false, | ||
hookMode: false | ||
}, | ||
(error) => { | ||
if (error) { | ||
console.log(environment); | ||
throw error; | ||
} | ||
} | ||
); | ||
}, | ||
false | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from "./commit"; | ||
export * from "./czg"; | ||
export * from "./help"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./types"; | ||
export * from "./utils"; |
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,14 @@ | ||
import { prompter } from "cz-git"; | ||
|
||
export type CallBackFn = (err: Error | null, data?: any) => void; | ||
|
||
export type CzGitPrompter = typeof prompter; | ||
|
||
export type CommitOptions = { | ||
args: any[]; | ||
disableAppendPaths: boolean; | ||
emitData: boolean; | ||
quiet: boolean; | ||
retryLastCommit: boolean; | ||
hookMode: boolean; | ||
}; |
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 @@ | ||
export * from "./common"; |
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,17 @@ | ||
declare module "dedent" { | ||
/** | ||
* ES6 string tag that strips indentation from multi-line strings. | ||
* @see: https://github.com/dmnd/dedent | ||
*/ | ||
export default function dedent(str: string): string; | ||
} | ||
|
||
declare module "cachedir" { | ||
/** | ||
* Get a directory for your caching needs | ||
* @see: https://github.com/LinusU/node-cachedir | ||
* @param {string} name | ||
* @return {string} cacheDir | ||
*/ | ||
export default function cachedir(name: string): string; | ||
} |
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 @@ | ||
export * from "./git"; |