Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(prompt): migrate prompt to typescript (#2371)
* refactor(prompt): port prompt to typescript * chore(prompt): correct docs * fix(prompt): correct typeguard of ruleIsActive * chore(prompt): fix spacing * fix: cleanup package.json from no longer used lerna calls * chore: fix watch command * refactor(prompt): refactor prompt cli to use utils
- Loading branch information
Showing
28 changed files
with
695 additions
and
481 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 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,17 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import vorpal from 'vorpal'; | ||
import input from './input'; | ||
|
||
type Commit = (input: string) => void; | ||
|
||
/** | ||
* Entry point for commitizen | ||
* @param _ inquirer instance passed by commitizen, unused | ||
* @param commit callback to execute with complete commit message | ||
* @return generated commit message | ||
*/ | ||
export async function prompter(_: unknown, commit: Commit): Promise<void> { | ||
const message = await input(vorpal); | ||
commit(message); | ||
} |
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,63 @@ | ||
import load from '@commitlint/load'; | ||
import throat from 'throat'; | ||
|
||
import format from './library/format'; | ||
import getPrompt from './library/get-prompt'; | ||
import settings from './settings'; | ||
import {InputSetting, Prompter, Result} from './library/types'; | ||
import {getHasName, getMaxLength, getRules} from './library/utils'; | ||
|
||
export default input; | ||
|
||
/** | ||
* Get user input by interactive prompt based on | ||
* conventional-changelog-lint rules. | ||
* @param prompter | ||
* @return commit message | ||
*/ | ||
async function input(prompter: () => Prompter): Promise<string> { | ||
const results: Result = { | ||
type: null, | ||
scope: null, | ||
subject: null, | ||
body: null, | ||
footer: null, | ||
}; | ||
|
||
const {rules} = await load(); | ||
const parts = ['type', 'scope', 'subject', 'body', 'footer'] as const; | ||
const headerParts = ['type', 'scope', 'subject']; | ||
|
||
const headerLengthRule = getRules('header', rules).find( | ||
getHasName('max-length') | ||
); | ||
const maxLength = getMaxLength(headerLengthRule); | ||
|
||
await Promise.all( | ||
parts.map( | ||
throat(1, async (input) => { | ||
const inputRules = getRules(input, rules); | ||
const inputSettings: InputSetting = settings[input]; | ||
|
||
if (headerParts.includes(input) && maxLength < Infinity) { | ||
inputSettings.header = { | ||
length: maxLength, | ||
}; | ||
} | ||
|
||
results[input] = await getPrompt(input, { | ||
rules: inputRules, | ||
settings: inputSettings, | ||
results, | ||
prompter, | ||
}); | ||
}) | ||
) | ||
).catch((err) => { | ||
console.error(err); | ||
return ''; | ||
}); | ||
|
||
// Return the results | ||
return format(results); | ||
} |
This file was deleted.
Oops, something went wrong.
14 changes: 7 additions & 7 deletions
14
@commitlint/prompt/src/library/format.js → @commitlint/prompt/src/library/format.ts
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.
Oops, something went wrong.