Skip to content

Commit

Permalink
fix(cz-git): fix emoji and checkbox subcmd usage
Browse files Browse the repository at this point in the history
change usage like `emoji=1 cz` `checkbox=1 cz`
  • Loading branch information
Zhengqbbb committed May 13, 2022
1 parent ac2a241 commit 9efe275
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
12 changes: 5 additions & 7 deletions packages/cz-git/src/generator/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
*/

import { commitizenConfigLoader } from "@cz-git/loader";
import type { Config, CommitizenGitOptions, UserConfig } from "../shared";
import {
defaultConfig,
enumRuleIsActive,
emptyRuleIsActive,
getCommandHaveArgs,
getEnumList,
getValueByCallBack,
getMaxLength,
getMinLength
} from "../shared";
import type { Config, CommitizenGitOptions, UserConfig } from "../shared";

const { emoji, checkbox } = process.env;

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

Expand All @@ -27,17 +28,14 @@ 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: CZ_EMOJI ?? pkgConfig.useEmoji ?? clPromptConfig.useEmoji ?? defaultConfig.useEmoji,
useEmoji: Boolean(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: CZ_CHECKBOX ?? pkgConfig.enableMultipleScopes ?? clPromptConfig.enableMultipleScopes ?? defaultConfig.enableMultipleScopes,
enableMultipleScopes: Boolean(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 Down
2 changes: 1 addition & 1 deletion packages/cz-git/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { SearchCheckbox } from "@cz-git/inquirer";
import { commitilintConfigLoader } from "@cz-git/loader";
// @ts-ignore
import autocompletePrompt from "inquirer-autocomplete-prompt";
import type { CommitizenType, QualifiedConfig, UserConfig } from "./shared";
import { editCommit, log } from "./shared";
import type { CommitizenType, QualifiedConfig, UserConfig } from "./shared";
import { generateOptions, generateQuestions, generateMessage } from "./generator";

export * from "./shared/types";
Expand Down
15 changes: 0 additions & 15 deletions packages/cz-git/src/shared/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,3 @@ 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 9efe275

Please sign in to comment.