Skip to content

Commit

Permalink
feat(cz-git): add get command arg to set useEmoji and enableMultipleS…
Browse files Browse the repository at this point in the history
…copes

No need to change configuration items
just like `cz emoji` or `cz checkbox` will turn on config
  • Loading branch information
Zhengqbbb committed May 12, 2022
1 parent 2fc82da commit 2cebeea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
46 changes: 15 additions & 31 deletions packages/cz-git/src/generator/option.ts
Expand Up @@ -8,27 +8,15 @@ import { commitizenConfigLoader } from "@cz-git/loader";
import type { Config, CommitizenGitOptions, UserConfig } from "../shared";
import {
defaultConfig,
getMaxLength,
getMinLength,
enumRuleIsActive,
emptyRuleIsActive,
getCommandHaveArgs,
getEnumList,
getValueByCallBack
getValueByCallBack,
getMaxLength,
getMinLength
} from "../shared";

/**
* @description: Compatibility support for cz-conventional-changelog
*/
const {
CZ_SCOPE,
CZ_SUBJECT,
CZ_BODY,
CZ_ISSUES,
CZ_MAN_HEADER_LENGTH,
CZ_MAN_SUBJECT_LENGTH,
CZ_MIN_SUBJECT_LENGTH
} = process.env;

const pkgConfig: Config = commitizenConfigLoader() ?? {};

/* eslint-disable prettier/prettier */
Expand All @@ -39,15 +27,17 @@ export const generateOptions = (clConfig: UserConfig): CommitizenGitOptions => {
clPromptConfig,
["defaultScope", "defaultSubject", "defaultBody", "defaultFooterPrefix", "defaultIssues"]
)
const CZ_EMOJI = getCommandHaveArgs("emoji");
const CZ_CHECKBOX = getCommandHaveArgs("checkbox");

return {
messages: pkgConfig.messages ?? clPromptConfig.messages ?? defaultConfig.messages,
types: pkgConfig.types ?? clPromptConfig.types ?? defaultConfig.types,
typesAppend: pkgConfig.typesAppend ?? clPromptConfig.typesAppend ?? defaultConfig.typesAppend,
useEmoji: pkgConfig.useEmoji ?? clPromptConfig.useEmoji ?? defaultConfig.useEmoji,
useEmoji: CZ_EMOJI ?? pkgConfig.useEmoji ?? clPromptConfig.useEmoji ?? defaultConfig.useEmoji,
scopes: pkgConfig.scopes ?? clPromptConfig.scopes ?? getEnumList(clConfig?.rules?.["scope-enum"] as any),
scopeOverrides: pkgConfig.scopeOverrides ?? clPromptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
enableMultipleScopes: pkgConfig.enableMultipleScopes ?? clPromptConfig.enableMultipleScopes ?? defaultConfig.enableMultipleScopes,
enableMultipleScopes: CZ_CHECKBOX ?? pkgConfig.enableMultipleScopes ?? clPromptConfig.enableMultipleScopes ?? defaultConfig.enableMultipleScopes,
scopeEnumSeparator: pkgConfig.scopeEnumSeparator ?? clPromptConfig.scopeEnumSeparator ?? defaultConfig.scopeEnumSeparator,
allowCustomScopes: pkgConfig.allowCustomScopes ?? clPromptConfig.allowCustomScopes ?? !enumRuleIsActive(clConfig?.rules?.["scope-enum"] as any),
allowEmptyScopes: pkgConfig.allowEmptyScopes ?? clPromptConfig.allowEmptyScopes ?? !emptyRuleIsActive(clConfig?.rules?.["scope-empty"] as any),
Expand All @@ -68,19 +58,13 @@ export const generateOptions = (clConfig: UserConfig): CommitizenGitOptions => {
allowCustomIssuePrefixs: pkgConfig.allowCustomIssuePrefixs ?? clPromptConfig.allowCustomIssuePrefixs ?? defaultConfig.allowCustomIssuePrefixs,
allowEmptyIssuePrefixs: pkgConfig.allowEmptyIssuePrefixs ?? clPromptConfig.allowEmptyIssuePrefixs ?? defaultConfig.allowEmptyIssuePrefixs,
confirmColorize: pkgConfig.confirmColorize ?? clPromptConfig.confirmColorize ?? defaultConfig.confirmColorize,
maxHeaderLength: CZ_MAN_HEADER_LENGTH
? parseInt(CZ_MAN_HEADER_LENGTH)
: clPromptConfig.maxHeaderLength ?? getMaxLength(clConfig?.rules?.["header-max-length"] as any),
maxSubjectLength: CZ_MAN_SUBJECT_LENGTH
? parseInt(CZ_MAN_SUBJECT_LENGTH)
: clPromptConfig.maxSubjectLength ?? getMaxLength(clConfig?.rules?.["subject-max-length"] as any),
minSubjectLength: CZ_MIN_SUBJECT_LENGTH
? parseInt(CZ_MIN_SUBJECT_LENGTH)
: clPromptConfig.minSubjectLength ?? getMinLength(clConfig?.rules?.["subject-min-length"] as any),
defaultScope: CZ_SCOPE ?? clPromptConfig.defaultScope ?? defaultConfig.defaultScope,
defaultSubject: CZ_SUBJECT ?? clPromptConfig.defaultSubject ?? defaultConfig.defaultSubject,
defaultBody: CZ_BODY ?? clPromptConfig.defaultBody ?? defaultConfig.defaultBody,
maxHeaderLength: clPromptConfig.maxHeaderLength ?? getMaxLength(clConfig?.rules?.["header-max-length"] as any),
maxSubjectLength: clPromptConfig.maxSubjectLength ?? getMaxLength(clConfig?.rules?.["subject-max-length"] as any),
minSubjectLength: clPromptConfig.minSubjectLength ?? getMinLength(clConfig?.rules?.["subject-min-length"] as any),
defaultScope: clPromptConfig.defaultScope ?? defaultConfig.defaultScope,
defaultSubject: clPromptConfig.defaultSubject ?? defaultConfig.defaultSubject,
defaultBody: clPromptConfig.defaultBody ?? defaultConfig.defaultBody,
defaultFooterPrefix: clPromptConfig.defaultFooterPrefix ?? defaultConfig.defaultFooterPrefix,
defaultIssues: CZ_ISSUES ?? clPromptConfig.defaultIssues ?? defaultConfig.defaultIssues
defaultIssues: clPromptConfig.defaultIssues ?? defaultConfig.defaultIssues
}
}
15 changes: 15 additions & 0 deletions packages/cz-git/src/shared/utils/util.ts
Expand Up @@ -174,3 +174,18 @@ export const getValueByCallBack = (
});
return target;
};

/**
* @description: get command options
*/
export const getCommandHaveArgs = (target: string) => {
let res = false;
if (!process.argv || process.argv.length === 0) return false;
for (let index = 0; index < process.argv.length; index++) {
if (process.argv[index] === target) {
res = true;
break;
}
}
return res;
};

0 comments on commit 2cebeea

Please sign in to comment.