Skip to content

Commit

Permalink
🎉 Feat(default.ts): add additioan stage/question about breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
INeedJobToStartWork committed Feb 7, 2024
1 parent 5e7d1db commit 37ec41a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# commitsmile

## 0.5.0

### Minor Changes

- FEAT: Add Breaking Changes stage in commiting.

## 0.4.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commitsmile",
"version": "0.4.0",
"version": "0.5.0",
"description": "Make smile on your commits",
"keywords": [],
"homepage": "",
Expand Down
6 changes: 4 additions & 2 deletions src/cli/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ program
{
changes: async () => select(config.CHANGES),
scopes: async () => select(config.SCOPES),
breakingChanges: async () => prompter.confirm(config.BREAKING_CHANGES),
commitShort: async () => prompter.text(config.COMMIT_SHORT),
commitDescription: async () => prompter.text(config.COMMIT_DESCRIPTION),
commit: async ({ results }) => {
const { changes, scopes, commitShort } = results;
const { changes, scopes, commitShort, breakingChanges } = results;
const commit = (): string => {
const scopesFormat = scopes ? `(${scopes})` : "";
return `${changes}${scopesFormat}: ${commitShort}`;
const breakingChangesFormat = breakingChanges ? "!" : "";
return `${changes}${scopesFormat}${breakingChangesFormat}: ${commitShort}`;
};
prompter.note(commit());
let agree = await prompter.confirm({ message: "Commit message is correct?" });
Expand Down
6 changes: 6 additions & 0 deletions src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export const defaultConfig: z.infer<typeof configSchema> = {
{ label: "🍃 API", value: "api" }
]
},
BREAKING_CHANGES: {
message: "Are there any breaking changes?",
active: "Yes",
inactive: "No",
initialValue: false
},
COMMIT_SHORT: {
message: "Write short description of commit",
validate(input: string) {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import defaultConfig from "@/defaultConfig";
import type { multiselect, text } from "@clack/prompts";
import type { multiselect, text, confirm } from "@clack/prompts";
import z from "zod";

export type flatMultipleClack = FlatArray<Parameters<typeof multiselect>, 0>;

const flatMultipleClackZod = z.custom<flatMultipleClack>(() => true);

export type TConfirmFlat = FlatArray<Parameters<typeof confirm>, 0>;
export const TConfirmScheme = z.custom<TConfirmFlat>(() => true);

export const TSelectScheme = z
.object({
custom: z.object({
Expand All @@ -30,13 +33,15 @@ export type TStages = "CHANGES" | "COMMIT_DESCRIPTION" | "COMMIT_SHORT" | "SCOPE
export const configSchema = z.object({
CHANGES: TSelectScheme,
SCOPES: TSelectScheme,
BREAKING_CHANGES: TConfirmScheme,
COMMIT_SHORT: TOptionTextZod,
COMMIT_DESCRIPTION: TOptionTextZod
}) satisfies TStagesZod;

export const UserConfigSchema = z.object({
CHANGES: TSelectScheme.default(defaultConfig.CHANGES),
SCOPES: TSelectScheme.default(defaultConfig.SCOPES),
BREAKING_CHANGES: TConfirmScheme.default(defaultConfig.BREAKING_CHANGES),
COMMIT_SHORT: TOptionTextZod.default(defaultConfig.COMMIT_SHORT),
COMMIT_DESCRIPTION: TOptionTextZod.default(defaultConfig.COMMIT_DESCRIPTION)
});
Expand Down

0 comments on commit 37ec41a

Please sign in to comment.