Skip to content

Commit

Permalink
comments, add other types
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 committed Nov 18, 2024
1 parent 55661a6 commit 13d49d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
12 changes: 11 additions & 1 deletion src/changefile/changeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeSet, ChangeType } from '../types/ChangeInfo';
import { ChangeSet, ChangeType, PrereleaseChangeType } from '../types/ChangeInfo';

/**
* List of all change types from least to most significant.
Expand All @@ -14,6 +14,16 @@ export const SortedChangeTypes: ChangeType[] = [
'major',
];

/**
* All the prerelease change types.
*/
export const PrereleaseChangeTypes: ChangeType[] = [
'prerelease',
'prepatch',
'preminor',
'premajor',
] satisfies PrereleaseChangeType[];

/**
* Change type with the smallest weight.
*/
Expand Down
19 changes: 12 additions & 7 deletions src/changefile/getQuestionsForPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { BeachballOptions } from '../types/BeachballOptions';
import { ChangeTypeDescriptions, DefaultPrompt } from '../types/ChangeFilePrompt';
import { getDisallowedChangeTypes } from './getDisallowedChangeTypes';
import { PackageGroups, PackageInfos } from '../types/PackageInfo';
import { PrereleaseChangeTypes } from './changeTypes';

const defaultChangeTypeDescriptions: ChangeTypeDescriptions = {
const defaultChangeTypeDescriptions: Required<ChangeTypeDescriptions> = {
prerelease: 'bump prerelease version',
// TODO: these pre* types are included for completeness but currently won't be shown
prepatch: 'bump to prerelease of the next patch version',
preminor: 'bump to prerelease of the next minor version',
premajor: 'bump to prerelease of the next major version',
patch: {
general: 'bug fixes; no API changes',
v0: 'bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)',
Expand All @@ -21,7 +26,6 @@ const defaultChangeTypeDescriptions: ChangeTypeDescriptions = {
general: 'breaking changes; major feature',
v0: 'official release',
},
// TODO: add an option to show other pre* versions, and add their text
};

/**
Expand Down Expand Up @@ -70,10 +74,11 @@ function getChangeTypePrompt(params: {
return;
}

const omittedChangeTypes = [...disallowedChangeTypes];
// if the current version doesn't include a prerelease part, omit the prerelease option
if (!semver.prerelease(packageInfo.version)) {
omittedChangeTypes.push('prerelease');
// TODO: conditionally add other prerelease types later
const omittedChangeTypes = new Set([...disallowedChangeTypes, ...PrereleaseChangeTypes]);
// if the current version includes a prerelease part, show the prerelease option
if (semver.prerelease(packageInfo.version)) {
omittedChangeTypes.add('prerelease');
}
const isVersion0 = semver.major(packageInfo.version) === 0;
// this is used to determine padding length since it's the longest
Expand All @@ -82,7 +87,7 @@ function getChangeTypePrompt(params: {
const changeTypeChoices: prompts.Choice[] = Object.entries(
packageInfo.combinedOptions.changeFilePrompt?.changeTypeDescriptions || defaultChangeTypeDescriptions
)
.filter(([changeType]) => !omittedChangeTypes.includes(changeType as ChangeType))
.filter(([changeType]) => !omittedChangeTypes.has(changeType as ChangeType))
.map(([changeType, descriptions]): prompts.Choice => {
const label = getChangeTypeLabel(changeType);
// use the appropriate message for 0.x or >= 1.x (if different)
Expand Down
11 changes: 6 additions & 5 deletions src/types/ChangeFilePrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ export type ChangeTypeDescriptions = {

/**
* Options for customizing change file prompt.
* The package name is provided so that the prompt can be customized by package if desired.
*/
export interface ChangeFilePromptOptions {
/**
* Get custom change file prompt questions.
* The questions MUST result in an answers object `{ comment: string; type: ChangeType }`.
* If you just want to customize the descriptions of each change type, use `changeTypeDescriptions`.
* Get custom change file prompt questions. The questions MUST result in an answers object
* `{ comment: string; type: ChangeType }`, though any extra properties returned will be preserved.
*
* (If you just want to customize the descriptions of each change type, use `changeTypeDescriptions`.)
*
* @param defaultPrompt Default prompt questions
* @param pkg Package name, so that changelog customizations can be specified at the package level
*/
changePrompt?(defaultPrompt: DefaultPrompt, pkg: string): prompts.PromptObject[];

/**
* Custom descriptions for each change type. This is good for if you only want to customize the
* descriptions, not the whole prompt.
* descriptions, not the whole prompt. (Any types not included here will use the defaults.)
*
* Each description can either be a single string, or one string for 0.x versions (which follow
* different semver rules) and one string for general use with versions >= 1.
Expand Down
3 changes: 2 additions & 1 deletion src/types/ChangeInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type ChangeType = 'prerelease' | 'prepatch' | 'patch' | 'preminor' | 'minor' | 'premajor' | 'major' | 'none';
export type PrereleaseChangeType = 'prerelease' | 'prepatch' | 'preminor' | 'premajor';
export type ChangeType = PrereleaseChangeType | 'patch' | 'minor' | 'major' | 'none';

/**
* Info saved in each change file.
Expand Down

0 comments on commit 13d49d9

Please sign in to comment.