beez-rp 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE.md +21 -0
- package/README.md +82 -0
- package/bin/beez-rp.js +36 -0
- package/package.json +77 -0
- package/src/build-gate.js +93 -0
- package/src/changelog-ai.js +52 -0
- package/src/changelog.js +109 -0
- package/src/constants/build-gate.js +24 -0
- package/src/constants/changelog-ai.js +14 -0
- package/src/constants/changelog.js +32 -0
- package/src/constants/cli.js +10 -0
- package/src/constants/index.js +12 -0
- package/src/constants/terminal-ui.js +93 -0
- package/src/constants/versions.js +39 -0
- package/src/index.js +37 -0
- package/src/terminal-ui.js +517 -0
- package/src/testing.js +70 -0
- package/src/versions.js +211 -0
- package/types/build-gate.d.ts +34 -0
- package/types/changelog-ai.d.ts +27 -0
- package/types/changelog.d.ts +52 -0
- package/types/constants/build-gate.d.ts +19 -0
- package/types/constants/changelog-ai.d.ts +11 -0
- package/types/constants/changelog.d.ts +23 -0
- package/types/constants/cli.d.ts +9 -0
- package/types/constants/index.d.ts +11 -0
- package/types/constants/terminal-ui.d.ts +73 -0
- package/types/constants/versions.d.ts +29 -0
- package/types/index.d.ts +18 -0
- package/types/terminal-ui.d.ts +180 -0
- package/types/testing.d.ts +31 -0
- package/types/versions.d.ts +102 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-free terminal UI for release commands: colors, banner, rounded
|
|
3
|
+
* boxes, step headers, spinners and the interactive select prompt.
|
|
4
|
+
*
|
|
5
|
+
* Colors go through `util.styleText`, which drops ANSI codes automatically
|
|
6
|
+
* when stdout is not a TTY or `NO_COLOR` is set. Interactive prompts fall
|
|
7
|
+
* back to their default answer when stdin is not a TTY, so a command never
|
|
8
|
+
* hangs in a pipe.
|
|
9
|
+
*
|
|
10
|
+
* @module terminal-ui
|
|
11
|
+
*/
|
|
12
|
+
import { styleText } from "node:util";
|
|
13
|
+
import { BOX_TONE, INTERRUPTED_EXIT_CODE } from "./constants/terminal-ui.js";
|
|
14
|
+
export type TextFormat = Parameters<typeof styleText>[0];
|
|
15
|
+
export type SelectOption = {
|
|
16
|
+
label: string;
|
|
17
|
+
hint?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Icons shared by status lines, colored once at import. They use Nerd Font
|
|
23
|
+
* glyphs, so the terminal needs a Nerd Font.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ICON: {
|
|
26
|
+
success: string;
|
|
27
|
+
failure: string;
|
|
28
|
+
warning: string;
|
|
29
|
+
info: string;
|
|
30
|
+
pending: string;
|
|
31
|
+
arrow: string;
|
|
32
|
+
bullet: string;
|
|
33
|
+
star: string;
|
|
34
|
+
rocket: "";
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns how long the command has waited for the user's answers.
|
|
38
|
+
*
|
|
39
|
+
* @returns {number} Milliseconds spent with a prompt open.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPromptWaitMs(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Measures the elapsed time since a start, without the time spent waiting for answers.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} startedAt - `Date.now()` when the measured work started.
|
|
46
|
+
* @param {number} [promptWaitAtStart] - {@link getPromptWaitMs} at that moment.
|
|
47
|
+
* @returns {number} Active milliseconds.
|
|
48
|
+
*/
|
|
49
|
+
export declare function measureActiveMs(startedAt: number, promptWaitAtStart?: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Applies one or more `util.styleText` formats.
|
|
52
|
+
*
|
|
53
|
+
* @param {TextFormat} format - Format names such as `"bold"` or `["cyan", "bold"]`.
|
|
54
|
+
* @param {string} text - Text to style.
|
|
55
|
+
* @returns {string} Styled text (plain when colors are disabled).
|
|
56
|
+
*/
|
|
57
|
+
export declare function paint(format: TextFormat, text: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Measures the visible width of a string, ignoring ANSI codes.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} text - Possibly styled text.
|
|
62
|
+
* @returns {number} Visible column count.
|
|
63
|
+
*/
|
|
64
|
+
export declare function visibleWidth(text: string): number;
|
|
65
|
+
/**
|
|
66
|
+
* Word-wraps a styled line to a visible width without ever cutting it off:
|
|
67
|
+
* words move to the next line, continuation lines align after a leading
|
|
68
|
+
* marker (icon, arrow, bullet or `1.`), styles are closed at each break and
|
|
69
|
+
* reopened on the next line, and a word longer than the width is split.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} text - Possibly styled line.
|
|
72
|
+
* @param {number} width - Maximum visible width.
|
|
73
|
+
* @returns {string[]} Lines that each fit in `width` columns.
|
|
74
|
+
*/
|
|
75
|
+
export declare function wrapStyledLine(text: string, width: number): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Returns the box width for the current terminal.
|
|
78
|
+
*
|
|
79
|
+
* @returns {number} Outer width in columns.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveBoxWidth(): number;
|
|
82
|
+
/**
|
|
83
|
+
* Renders a rounded box with an optional title in its top border. Long lines
|
|
84
|
+
* are word-wrapped, never truncated; a title that does not fit in the border
|
|
85
|
+
* moves inside the box as its first lines.
|
|
86
|
+
*
|
|
87
|
+
* @param {{ title?: string, lines: string[], tone?: TextFormat, width?: number }} options - Box content.
|
|
88
|
+
* @returns {string} Multi-line box.
|
|
89
|
+
*/
|
|
90
|
+
export declare function renderBox({ title, lines, tone, width }: {
|
|
91
|
+
title?: string;
|
|
92
|
+
lines: string[];
|
|
93
|
+
tone?: TextFormat;
|
|
94
|
+
width?: number;
|
|
95
|
+
}): string;
|
|
96
|
+
/**
|
|
97
|
+
* Renders a label/value row aligned for status panels.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} icon - Leading icon.
|
|
100
|
+
* @param {string} label - Left column.
|
|
101
|
+
* @param {string} value - Right column.
|
|
102
|
+
* @param {number} [labelWidth] - Width of the label column.
|
|
103
|
+
* @returns {string} Row.
|
|
104
|
+
*/
|
|
105
|
+
export declare function renderRow(icon: string, label: string, value: string, labelWidth?: number): string;
|
|
106
|
+
/**
|
|
107
|
+
* Renders the one-line header shown when a release command starts: an
|
|
108
|
+
* inverted `RELEASE` label, the project name, the published version aligned
|
|
109
|
+
* to the right and a rule underneath.
|
|
110
|
+
*
|
|
111
|
+
* @param {{ projectName: string, publishedLabel: string | null }} options - Header content.
|
|
112
|
+
* @returns {string} Header.
|
|
113
|
+
*/
|
|
114
|
+
export declare function renderBanner({ projectName, publishedLabel }: {
|
|
115
|
+
projectName: string;
|
|
116
|
+
publishedLabel: string | null;
|
|
117
|
+
}): string;
|
|
118
|
+
/**
|
|
119
|
+
* Renders the header that introduces each executed step.
|
|
120
|
+
*
|
|
121
|
+
* @param {number} stepNumber - 1-based index.
|
|
122
|
+
* @param {number} stepCount - Total steps.
|
|
123
|
+
* @param {string} title - Step title.
|
|
124
|
+
* @returns {string} Header line.
|
|
125
|
+
*/
|
|
126
|
+
export declare function renderStepHeader(stepNumber: number, stepCount: number, title: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Writes a line to stdout.
|
|
129
|
+
*
|
|
130
|
+
* @param {string} [text] - Line content.
|
|
131
|
+
*/
|
|
132
|
+
export declare function print(text?: string): void;
|
|
133
|
+
/**
|
|
134
|
+
* Formats a duration in a compact Spanish form.
|
|
135
|
+
*
|
|
136
|
+
* @param {number} milliseconds - Duration.
|
|
137
|
+
* @returns {string} Such as `3.2 s` or `4 min 05 s`.
|
|
138
|
+
*/
|
|
139
|
+
export declare function formatDuration(milliseconds: number): string;
|
|
140
|
+
/**
|
|
141
|
+
* Starts a spinner; on non-TTY outputs it prints the label once instead.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} label - Initial label.
|
|
144
|
+
* @returns {{ update: (label: string) => void, succeed: (label?: string) => void, fail: (label?: string) => void }} Controls.
|
|
145
|
+
*/
|
|
146
|
+
export declare function startSpinner(label: string): {
|
|
147
|
+
update: (label: string) => void;
|
|
148
|
+
succeed: (label?: string) => void;
|
|
149
|
+
fail: (label?: string) => void;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Counts the terminal rows that lines occupy, including the extra rows of
|
|
153
|
+
* lines wider than the terminal, so a prompt can erase exactly what it drew.
|
|
154
|
+
*
|
|
155
|
+
* @param {string[]} lines - Rendered lines, possibly styled.
|
|
156
|
+
* @param {number} columns - Terminal width in columns.
|
|
157
|
+
* @returns {number} Physical rows.
|
|
158
|
+
*/
|
|
159
|
+
export declare function countTerminalRows(lines: string[], columns: number): number;
|
|
160
|
+
/**
|
|
161
|
+
* Maps a typed character to the option it selects.
|
|
162
|
+
*
|
|
163
|
+
* @param {string | undefined} text - Character typed by the user.
|
|
164
|
+
* @param {number} optionCount - Number of options in the prompt.
|
|
165
|
+
* @returns {number} Zero-based option index, or -1 when the key does not pick an option.
|
|
166
|
+
*/
|
|
167
|
+
export declare function resolveNumberKey(text: string | undefined, optionCount: number): number;
|
|
168
|
+
/**
|
|
169
|
+
* Asks the user to choose one option: its number picks it right away, or the
|
|
170
|
+
* arrow keys move the selection and Enter confirms it.
|
|
171
|
+
*
|
|
172
|
+
* @param {{ message: string, options: SelectOption[], defaultIndex?: number }} prompt - Prompt; `description` renders on its own line below the option.
|
|
173
|
+
* @returns {Promise<string>} Selected value (the default one when stdin is not a TTY).
|
|
174
|
+
*/
|
|
175
|
+
export declare function select({ message, options, defaultIndex }: {
|
|
176
|
+
message: string;
|
|
177
|
+
options: SelectOption[];
|
|
178
|
+
defaultIndex?: number;
|
|
179
|
+
}): Promise<string>;
|
|
180
|
+
export { BOX_TONE, INTERRUPTED_EXIT_CODE };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version bump fixtures for the test suites of every repository that uses
|
|
3
|
+
* `beez-rp`, so `create-version`, the Vercel build gate and any custom release
|
|
4
|
+
* command are checked against the same rule: from a stable version only the
|
|
5
|
+
* next patch, minor or major is allowed.
|
|
6
|
+
*
|
|
7
|
+
* @module testing
|
|
8
|
+
*/
|
|
9
|
+
/** Stable version every fixture bumps from. */
|
|
10
|
+
export declare const CURRENT_STABLE_VERSION = "1.2.3";
|
|
11
|
+
/** The only versions allowed after {@link CURRENT_STABLE_VERSION}: next patch, minor and major. */
|
|
12
|
+
export declare const ALLOWED_NEXT_VERSIONS: readonly string[];
|
|
13
|
+
/** Every rejected kind of bump from {@link CURRENT_STABLE_VERSION}, grouped by why it is rejected. */
|
|
14
|
+
export declare const REJECTED_VERSION_BUMPS: Readonly<{
|
|
15
|
+
unchanged: readonly string[];
|
|
16
|
+
lower: readonly string[];
|
|
17
|
+
"skips patches": readonly string[];
|
|
18
|
+
"skips minors": readonly string[];
|
|
19
|
+
"skips majors": readonly string[];
|
|
20
|
+
"minor bump without resetting the patch": readonly string[];
|
|
21
|
+
"major bump without resetting minor and patch": readonly string[];
|
|
22
|
+
prerelease: readonly string[];
|
|
23
|
+
"build metadata": readonly string[];
|
|
24
|
+
"not a plain X.Y.Z": readonly string[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* All rejected bumps as `[reason, version]` pairs for table-driven tests.
|
|
28
|
+
*
|
|
29
|
+
* @type {ReadonlyArray<readonly [string, string]>}
|
|
30
|
+
*/
|
|
31
|
+
export declare const REJECTED_VERSION_BUMP_CASES: ReadonlyArray<readonly [string, string]>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release version rules: only stable `X.Y.Z` versions exist, and after a
|
|
3
|
+
* version only its next patch, minor or major is allowed (from `1.2.3`:
|
|
4
|
+
* `1.2.4`, `1.3.0` or `2.0.0`). No version can be skipped, repeated or
|
|
5
|
+
* lowered, and prereleases or build metadata are never released.
|
|
6
|
+
*
|
|
7
|
+
* @module versions
|
|
8
|
+
*/
|
|
9
|
+
export type ReleaseType = "patch" | "minor" | "major";
|
|
10
|
+
export type NextVersion = {
|
|
11
|
+
releaseType: ReleaseType;
|
|
12
|
+
version: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {"patch" | "minor" | "major"} ReleaseType
|
|
16
|
+
* @typedef {{ releaseType: ReleaseType, version: string }} NextVersion
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Returns whether a value is a stable `X.Y.Z` release version.
|
|
20
|
+
*
|
|
21
|
+
* @param {unknown} version - Candidate version.
|
|
22
|
+
* @returns {boolean} `true` only for plain `X.Y.Z` without prerelease, metadata, prefix or leading zeros.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isStableReleaseVersion(version: unknown): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Parses a stable `X.Y.Z` version.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} version - Version such as `0.93.0`.
|
|
29
|
+
* @returns {[number, number, number]} Major, minor and patch numbers.
|
|
30
|
+
* @throws {Error} When the version is not a stable release version.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseReleaseVersion(version: string): [number, number, number];
|
|
33
|
+
/**
|
|
34
|
+
* Returns the next version for a semver release type.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} version - Current `X.Y.Z` version.
|
|
37
|
+
* @param {ReleaseType} releaseType - One of {@link RELEASE_TYPE}.
|
|
38
|
+
* @returns {string} Next `X.Y.Z` version.
|
|
39
|
+
* @throws {Error} When the version is not stable or the release type is unknown.
|
|
40
|
+
*/
|
|
41
|
+
export declare function bumpReleaseVersion(version: string, releaseType: ReleaseType): string;
|
|
42
|
+
/**
|
|
43
|
+
* Lists the only versions allowed after the current one: the next patch,
|
|
44
|
+
* minor and major. Anything else would skip versions or go backwards.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} currentVersion - Current `X.Y.Z` version.
|
|
47
|
+
* @returns {NextVersion[]} Allowed next versions, patch first.
|
|
48
|
+
*/
|
|
49
|
+
export declare function listNextVersions(currentVersion: string): NextVersion[];
|
|
50
|
+
/**
|
|
51
|
+
* Lists the versions allowed after any previous semver version. A previous
|
|
52
|
+
* prerelease is also followed by its own stable release (`1.0.0-beta.1` →
|
|
53
|
+
* `1.0.0`).
|
|
54
|
+
*
|
|
55
|
+
* @param {string} previousVersion - Previous version, stable or prerelease.
|
|
56
|
+
* @returns {string[] | null} Allowed versions, or `null` when the previous version is not semver.
|
|
57
|
+
*/
|
|
58
|
+
export declare function listAllowedVersionsAfter(previousVersion: string): string[] | null;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves the version requested through `--bump` or `--set-version`.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} currentVersion - Current `X.Y.Z` version.
|
|
63
|
+
* @param {{ bump: ReleaseType | null, setVersion: string | null }} request - Parsed CLI options.
|
|
64
|
+
* @returns {NextVersion | null} Requested version, or `null` to ask interactively.
|
|
65
|
+
* @throws {Error} With a Spanish message when the request is invalid.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveRequestedVersion(currentVersion: string, { bump, setVersion }: {
|
|
68
|
+
bump: ReleaseType | null;
|
|
69
|
+
setVersion: string | null;
|
|
70
|
+
}): NextVersion | null;
|
|
71
|
+
/**
|
|
72
|
+
* Builds the Git tag name of a release version.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} version - `X.Y.Z` version.
|
|
75
|
+
* @returns {string} Tag such as `v0.94.0`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function toReleaseTag(version: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Returns whether a commit subject is a release bump commit (`0.93.0`).
|
|
80
|
+
*
|
|
81
|
+
* @param {string} subject - Commit subject.
|
|
82
|
+
* @returns {boolean} `true` for version-only subjects.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isReleaseCommitSubject(subject: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Suggests the semver release type for the commits that will ship.
|
|
87
|
+
*
|
|
88
|
+
* Breaking changes suggest `major`; features (conventional `feat` or legacy
|
|
89
|
+
* imperative subjects such as "Add ...") suggest `minor`; a set made only of
|
|
90
|
+
* conventional maintenance commits (`fix`, `chore`, `docs`, ...) suggests
|
|
91
|
+
* `patch`. Unknown legacy subjects suggest `minor`.
|
|
92
|
+
*
|
|
93
|
+
* @param {{ subject: string, body?: string }[]} commits - Commits since the last release.
|
|
94
|
+
* @returns {{ releaseType: ReleaseType, reason: string }} Suggested type and a Spanish explanation.
|
|
95
|
+
*/
|
|
96
|
+
export declare function suggestReleaseType(commits: {
|
|
97
|
+
subject: string;
|
|
98
|
+
body?: string;
|
|
99
|
+
}[]): {
|
|
100
|
+
releaseType: ReleaseType;
|
|
101
|
+
reason: string;
|
|
102
|
+
};
|