Skip to content

Commit

Permalink
feat(cz-git): add breaklineChar option to make new line for body and …
Browse files Browse the repository at this point in the history
…BreakingChanges

BREAKING CHANGE :
add option `breaklineChar`

link #1
  • Loading branch information
Zhengqbbb committed Feb 21, 2022
1 parent 3b7c830 commit 6691c26
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
scopes: [{ value: "cz-git", name: "cz-git: core control" }, { name: "guide" } , 'config'],
allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix'],
breaklineChar: "|",
skipQuestions: ['body'],
issuePrefixs: [
{ value: "link", name: "link: processing to ISSUES" },
Expand Down
11 changes: 5 additions & 6 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* @description: generate commitizen config option(generateOptions) | generate commitizen questions(generateQuestions)
* @author: @Zhengqbbb (zhengqbbb@gmail.com)
* @license: MIT
* TODO: fix getMaxSubjectLength add header max length
* TODO: add custom skip option to higher custom
* TODO: add breaklineChar option
* TODO: add end prompt color option
*/

Expand Down Expand Up @@ -51,6 +49,7 @@ export const generateOptions = (clConfig: any): CommitizenGitOptions => {
allowCustomScopes: pkgConfig.allowCustomScopes ?? clPromptConfig.allowCustomScopes ?? defaultConfig.allowCustomScopes,
upperCaseSubject: pkgConfig.upperCaseSubject ?? clPromptConfig.upperCaseSubject ?? defaultConfig.upperCaseSubject,
allowBreakingChanges: pkgConfig.allowBreakingChanges ?? clPromptConfig.allowBreakingChanges ?? defaultConfig.allowBreakingChanges,
breaklineChar: pkgConfig.breaklineChar ?? clPromptConfig.breaklineChar ?? defaultConfig.breaklineChar,
skipQuestions: pkgConfig.skipQuestions ?? clPromptConfig.skipQuestions ?? defaultConfig.skipQuestions,
issuePrefixs: pkgConfig.issuePrefixs ?? clPromptConfig.issuePrefixs ?? defaultConfig.issuePrefixs,
confirmNoColor: pkgConfig.confirmNoColor ?? clPromptConfig.confirmNoColor ?? defaultConfig.confirmNoColor,
Expand Down Expand Up @@ -186,7 +185,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
},
{
type: "autocomplete",
name: "footerPrefixsSelect",
name: "footerPrefix",
message: options.messages?.footerPrefixsSelect,
source: (_: Answers, input: string) => {
let issues: Array<{ name: string; value: string }> = [
Expand All @@ -202,18 +201,18 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
},
{
type: "input",
name: "footerPrefixsSelect",
name: "footerPrefixs",
message: options.messages?.customFooterPrefixs,
default: options.defaultIssues || undefined,
when(answers: Answers) {
return answers.footerPrefixsSelect === "custom";
return answers.footerPrefix === "custom";
}
},
{
type: "input",
name: "footer",
when(answers: Answers) {
return (answers.footerPrefixsSelect as string | boolean) !== false;
return (answers.footerPrefix as string | boolean) !== false;
},
message: options.messages?.footer
},
Expand Down
8 changes: 8 additions & 0 deletions src/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type Answers = {
* @default: Select the ISSUES type of changeList by this change (optional):
*/
footerPrefixsSelect?: string;
footerPrefix?: string;
/**
* @default: Input ISSUES Prefix:
*/
Expand Down Expand Up @@ -140,6 +141,12 @@ export interface CommitizenGitOptions {
*/
allowBreakingChanges?: string[];

/**
* @description: body and BREAKINGCHANGES new line char
* @default: "|"
*/
breaklineChar?: string;

/**
* @description: List of questions you want to skip
* @example: ['body']
Expand Down Expand Up @@ -236,6 +243,7 @@ export const defaultConfig = Object.freeze({
allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix'],
upperCaseSubject: false,
breaklineChar: "|",
skipQuestions: [],
issuePrefixs: [{ value: "closed", name: "closed: ISSUES has been processed" }],
confirmNoColor: false,
Expand Down
15 changes: 7 additions & 8 deletions src/until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ const addSubject = (subject?: string, color?: boolean) => {
const addBreaklinesIfNeeded = (value: string, breaklineChar = "|") =>
value.split(breaklineChar).join("\n").valueOf();

const addFooter = (footer: string, footerPrefixsSelect = "", color?: boolean) => {
if (footerPrefixsSelect === "") {
const addFooter = (footer: string, footerPrefix = "", color?: boolean) => {
if (footerPrefix === "") {
return color ? `\n\n\u001B[32m${footer}\u001B[0m` : `\n\n${footer}`;
}
return color
? `\n\n\u001B[32m${footerPrefixsSelect} ${footer}\u001B[0m`
: `\n\n${footerPrefixsSelect} ${footer}`;
? `\n\n\u001B[32m${footerPrefix} ${footer}\u001B[0m`
: `\n\n${footerPrefix} ${footer}`;
};

export const buildCommit = (answers: Answers, options: CommitizenGitOptions, color = false) => {
Expand All @@ -238,14 +238,13 @@ export const buildCommit = (answers: Answers, options: CommitizenGitOptions, col

let result = head;
if (body) {
// TODO: options.breaklineChar => prams
result += `\n\n${addBreaklinesIfNeeded(body)}`;
result += `\n\n${addBreaklinesIfNeeded(body, options.breaklineChar)}`;
}
if (breaking) {
result += `\n\nBREAKING CHANGE :\n${addBreaklinesIfNeeded(breaking)}`;
result += `\n\nBREAKING CHANGE :\n${addBreaklinesIfNeeded(breaking, options.breaklineChar)}`;
}
if (footer) {
result += addFooter(footer, answers.footerPrefixsSelect, color);
result += addFooter(footer, answers.footerPrefix, color);
}
return result;
};
Expand Down

0 comments on commit 6691c26

Please sign in to comment.