genbumppush 0.0.2 → 0.0.4

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/dist/index.d.mts CHANGED
@@ -1,71 +1,519 @@
1
1
  //#region src/types.d.ts
2
+ /**
3
+ * Every release type genbumppush can apply.
4
+ *
5
+ * The first seven values match Semantic Versioning. The `pre*` variants
6
+ * enter a prerelease channel (`beta` by default); `prerelease` continues
7
+ * an existing one.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { ReleaseType } from 'genbumppush';
12
+ *
13
+ * const forced: ReleaseType = 'minor';
14
+ * ```
15
+ */
2
16
  declare const RELEASE_TYPES: readonly ["major", "premajor", "minor", "preminor", "patch", "prepatch", "prerelease"];
17
+ /** One of {@link RELEASE_TYPES}. */
3
18
  type ReleaseType = (typeof RELEASE_TYPES)[number];
19
+ /**
20
+ * How genbumppush talks to Git: remote name, commit/tag templates,
21
+ * and the safety checks run before anything is written.
22
+ */
4
23
  type GitOptions = {
24
+ /** Remote used for tag collision checks and `git push`. Default: `'origin'`. */
5
25
  remote?: string;
26
+ /**
27
+ * Push the release commit and tag together with `git push --atomic`.
28
+ * Set to `false` for a local-only rehearsal.
29
+ * @defaultValue true
30
+ */
6
31
  push?: boolean;
32
+ /**
33
+ * Sign the release commit (`git commit -S`) and annotated tag (`git tag -s`).
34
+ * @defaultValue false
35
+ */
7
36
  sign?: boolean;
37
+ /**
38
+ * Refuse to release when the worktree has uncommitted changes.
39
+ * @defaultValue true
40
+ */
8
41
  requireClean?: boolean;
42
+ /**
43
+ * Require the current branch to have an upstream before pushing.
44
+ * Ignored when {@link GitOptions.push} is `false`.
45
+ * @defaultValue true
46
+ */
9
47
  requireUpstream?: boolean;
48
+ /**
49
+ * Release commit subject. `{{version}}` is replaced with the new version
50
+ * (without a leading `v` unless the template adds one).
51
+ * @defaultValue `'chore(release): v{{version}}'`
52
+ * @example `'release: v{{version}}'`
53
+ */
10
54
  commitMessage?: string;
55
+ /**
56
+ * Tag name template. `{{version}}` is replaced with the new version.
57
+ * @defaultValue `'v{{version}}'`
58
+ */
11
59
  tagName?: string;
60
+ /**
61
+ * Annotated tag message template. `{{version}}` is replaced with the new version.
62
+ * @defaultValue `'v{{version}}'`
63
+ */
12
64
  tagMessage?: string;
13
65
  };
66
+ /**
67
+ * Shell commands run around the release.
68
+ *
69
+ * Commands run in the repository root with a shell. Use them for gates you
70
+ * want on every release (checks, tests), not for storing secrets.
71
+ */
14
72
  type HookOptions = {
73
+ /**
74
+ * Runs after validation and before version files or the changelog change.
75
+ * A failing hook aborts the release with nothing written.
76
+ * @example
77
+ * ```ts
78
+ * hooks: {
79
+ * before: ['npm run check', 'npm test'],
80
+ * }
81
+ * ```
82
+ */
15
83
  before?: string | string[];
84
+ /**
85
+ * Runs after the commit, tag, and optional provider release succeed.
86
+ * @example
87
+ * ```ts
88
+ * hooks: {
89
+ * after: 'echo "Shipped {{version}}"',
90
+ * }
91
+ * ```
92
+ */
16
93
  after?: string | string[];
17
94
  };
95
+ /**
96
+ * Optional GitLab release creation after a successful Git push.
97
+ *
98
+ * Credentials come from the environment (`GENBUMPPUSH_GITLAB_TOKEN` or
99
+ * `GITLAB_TOKEN`). Never put the token itself in this object.
100
+ */
18
101
  type GitLabOptions = {
102
+ /**
103
+ * Create a GitLab release for the new tag.
104
+ * Requires {@link GitOptions.push} to stay enabled and a token in the environment.
105
+ * @defaultValue false
106
+ */
19
107
  enabled?: boolean;
108
+ /**
109
+ * GitLab base URL, including protocol when not on gitlab.com.
110
+ * @defaultValue `'https://gitlab.com'`
111
+ * @example `'https://gitlab.example.com'`
112
+ */
20
113
  host?: string;
114
+ /**
115
+ * Project path or numeric ID, as used by the GitLab API.
116
+ * Falls back to `GENBUMPPUSH_GITLAB_PROJECT` or `GITLAB_PROJECT`.
117
+ * @example `'group/subgroup/project'`
118
+ */
21
119
  project?: string;
120
+ /**
121
+ * Exact environment variable name to read the token from.
122
+ * When set, the usual fallback chain is skipped.
123
+ * @example `'CI_JOB_TOKEN'`
124
+ */
22
125
  tokenEnv?: string;
126
+ /**
127
+ * Release title template. `{{version}}` is replaced with the new version.
128
+ * @defaultValue the tag name (for example `v1.2.3`)
129
+ */
23
130
  releaseName?: string;
24
131
  };
132
+ /**
133
+ * Optional GitHub (or GitHub Enterprise Server) release after a successful Git push.
134
+ *
135
+ * Credentials come from the environment (`GENBUMPPUSH_GITHUB_TOKEN`,
136
+ * `GITHUB_TOKEN`, or `GH_TOKEN`). Never put the token itself in this object.
137
+ */
138
+ type GitHubOptions = {
139
+ /**
140
+ * Create a GitHub release for the new tag.
141
+ * Requires {@link GitOptions.push} to stay enabled and a token in the environment.
142
+ * @defaultValue false
143
+ */
144
+ enabled?: boolean;
145
+ /**
146
+ * GitHub host. `github.com` uses the public API; any other host is treated
147
+ * as GitHub Enterprise Server (`https://<host>/api/v3`).
148
+ * @defaultValue `'github.com'`
149
+ */
150
+ host?: string;
151
+ /**
152
+ * Repository as `owner/name`. Usually inferred from the Git remote.
153
+ * Override when inference is wrong or unavailable.
154
+ * @example `'xcvzmoon/genbumppush'`
155
+ */
156
+ repo?: string;
157
+ /**
158
+ * Exact environment variable name to read the token from.
159
+ * When set, the usual fallback chain is skipped.
160
+ */
161
+ tokenEnv?: string;
162
+ /**
163
+ * Release title template. `{{version}}` is replaced with the new version.
164
+ * @defaultValue the tag name (for example `v1.2.3`)
165
+ */
166
+ releaseName?: string;
167
+ };
168
+ /**
169
+ * Full genbumppush configuration.
170
+ *
171
+ * Every field is optional. Missing values fall back to the built-in defaults
172
+ * documented on each property. Prefer {@link defineConfig} in a config file
173
+ * so your editor can check the shape.
174
+ *
175
+ * @example Minimal config in `genbumppush.config.ts`
176
+ * ```ts
177
+ * import { defineConfig } from 'genbumppush';
178
+ *
179
+ * export default defineConfig({
180
+ * files: ['package.json', 'package-lock.json'],
181
+ * git: { tagName: 'v{{version}}' },
182
+ * });
183
+ * ```
184
+ *
185
+ * @example Same object under `"genbumppush"` in `package.json`
186
+ * ```json
187
+ * {
188
+ * "genbumppush": {
189
+ * "changelog": false,
190
+ * "git": { "push": false }
191
+ * }
192
+ * }
193
+ * ```
194
+ */
25
195
  type GenBumpPushConfig = {
196
+ /**
197
+ * Force a release type instead of detecting it from Conventional Commits.
198
+ * Leave unset for automatic detection.
199
+ * @example `'patch'`
200
+ */
26
201
  release?: ReleaseType;
202
+ /**
203
+ * Prerelease identifier used by `premajor`, `preminor`, `prepatch`,
204
+ * and `prerelease`.
205
+ * @defaultValue `'beta'`
206
+ * @example `'rc'` produces `1.2.4-rc.0` from `1.2.3`
207
+ */
27
208
  preid?: string;
209
+ /**
210
+ * Files whose version strings are updated for the release.
211
+ * Each path is relative to the repository root and must stay inside it.
212
+ * @defaultValue `['package.json']`
213
+ * @example
214
+ * ```ts
215
+ * files: [
216
+ * 'package.json',
217
+ * 'src-tauri/tauri.conf.json',
218
+ * 'src-tauri/Cargo.toml',
219
+ * ]
220
+ * ```
221
+ */
28
222
  files?: string[];
223
+ /**
224
+ * Also update every nested `package.json` under the repository.
225
+ * Meant for fixed-version monorepos that share one version number.
226
+ * @defaultValue false
227
+ */
29
228
  recursive?: boolean;
229
+ /**
230
+ * Changelog behavior:
231
+ * - `false` — do not write a changelog
232
+ * - `true` — write `CHANGELOG.md`
233
+ * - `string` — write that path
234
+ * @defaultValue `'CHANGELOG.md'`
235
+ * @example `'docs/RELEASES.md'`
236
+ */
30
237
  changelog?: boolean | string;
238
+ /**
239
+ * Ignore non-breaking `chore(deps): …` commits when detecting the next
240
+ * version and building the changelog.
241
+ * @defaultValue true
242
+ */
31
243
  excludeDependencyCommits?: boolean;
244
+ /** Git commit, tag, and push behavior. See {@link GitOptions}. */
32
245
  git?: GitOptions;
246
+ /** Optional GitLab release after push. See {@link GitLabOptions}. */
33
247
  gitlab?: GitLabOptions;
248
+ /** Optional GitHub release after push. See {@link GitHubOptions}. */
249
+ github?: GitHubOptions;
250
+ /** Shell commands run before and after the release. See {@link HookOptions}. */
34
251
  hooks?: HookOptions;
35
252
  };
253
+ /**
254
+ * Parsed CLI arguments for {@link runRelease}.
255
+ *
256
+ * You usually receive this from the binary rather than building it by hand.
257
+ * When embedding genbumppush, the minimum object is `{ cwd, dryRun: false, yes: true }`
258
+ * (plus `help: false` if you want a complete {@link CliOptions}).
259
+ *
260
+ * @example Non-interactive patch release in another directory
261
+ * ```ts
262
+ * import { runRelease } from 'genbumppush';
263
+ *
264
+ * await runRelease({
265
+ * cwd: '/path/to/repo',
266
+ * dryRun: false,
267
+ * yes: true,
268
+ * help: false,
269
+ * release: 'patch',
270
+ * });
271
+ * ```
272
+ */
36
273
  type CliOptions = {
274
+ /** Absolute path to the Git repository to release. Defaults to `process.cwd()` in the CLI. */
37
275
  cwd: string;
276
+ /** Explicit C12 config file path. Overrides discovery and the `package.json` key. */
38
277
  configFile?: string;
278
+ /** Retry only GitLab release creation for a tag that already exists on the remote. */
39
279
  gitlabRetryTag?: string;
280
+ /** Retry only GitHub release creation for a tag that already exists on the remote. */
281
+ githubRetryTag?: string;
282
+ /** Force a release type; otherwise it is detected from commits (or config). */
40
283
  release?: ReleaseType;
284
+ /** Prerelease identifier; overrides the value from config when set. */
41
285
  preid?: string;
286
+ /** Preview the release without changing files, Git, or remotes. */
42
287
  dryRun: boolean;
288
+ /** `false` keeps the commit and tag local. Unset means “use config”. */
43
289
  push?: boolean;
290
+ /** Skip the interactive `Create a … release?` confirmation. */
44
291
  yes: boolean;
292
+ /** Print CLI help and exit without running a release. */
45
293
  help: boolean;
46
294
  };
295
+ /**
296
+ * What {@link runRelease} did (or would do, for a dry run).
297
+ *
298
+ * When there are no releasable commits, `releaseType`, `newVersion`, and
299
+ * `tag` stay `undefined` and `pushed` is `false`. That is a successful no-op.
300
+ *
301
+ * @example Inspect a dry run
302
+ * ```ts
303
+ * import { runRelease } from 'genbumppush';
304
+ *
305
+ * const result = await runRelease({ cwd: process.cwd(), dryRun: true, yes: true, help: false });
306
+ * if (result.releaseType === undefined) {
307
+ * console.log('Nothing to release');
308
+ * } else {
309
+ * console.log(`${result.currentVersion} → ${result.newVersion} as ${result.tag}`);
310
+ * }
311
+ * ```
312
+ */
47
313
  type ReleaseResult = {
314
+ /** Version before this run (from the root `package.json`). */
48
315
  currentVersion: string;
316
+ /** Version after the bump. Absent on dry-run skips and “no releasable commits”. */
49
317
  newVersion?: string;
318
+ /** Release type that was applied (or planned, for a dry run). */
50
319
  releaseType?: ReleaseType;
320
+ /** Tag name created or planned, after `{{version}}` substitution. */
51
321
  tag?: string;
322
+ /** `true` only when the branch and tag were pushed to the remote. */
52
323
  pushed: boolean;
324
+ /** `true` when the run was a dry run and nothing was written. */
53
325
  dryRun: boolean;
326
+ /** Number of Conventional Commits that fed the release decision. */
54
327
  commitCount: number;
328
+ /** `true` when a GitLab release was created after the Git push. */
55
329
  gitlabReleaseCreated?: boolean;
330
+ /** `true` when a GitHub release was created after the Git push. */
331
+ githubReleaseCreated?: boolean;
56
332
  };
57
333
  //#endregion
58
334
  //#region src/config.d.ts
335
+ /**
336
+ * Identity helper that types a release config for your editor.
337
+ *
338
+ * It does not change the object at runtime — it only enables autocomplete
339
+ * and catches typos inside `defineConfig({ … })`.
340
+ *
341
+ * @typeParam Config - Config object shape; defaults to {@link GenBumpPushConfig}.
342
+ * @returns The same object you passed in.
343
+ *
344
+ * @example `genbumppush.config.ts`
345
+ * ```ts
346
+ * import { defineConfig } from 'genbumppush';
347
+ *
348
+ * export default defineConfig({
349
+ * preid: 'beta',
350
+ * files: ['package.json'],
351
+ * git: {
352
+ * commitMessage: 'chore(release): v{{version}}',
353
+ * },
354
+ * hooks: {
355
+ * before: ['npm run check', 'npm test'],
356
+ * },
357
+ * });
358
+ * ```
359
+ */
59
360
  export declare const defineConfig: import("c12").DefineConfig<GenBumpPushConfig, import("c12").ConfigLayerMeta>;
361
+ /**
362
+ * Load the effective release config for a repository.
363
+ *
364
+ * Resolution order (later wins):
365
+ * 1. {@link defaults}
366
+ * 2. `"genbumppush"` key in that directory’s `package.json`
367
+ * 3. C12 config file (`genbumppush.config.ts` / `.js`, or `configFile` when given)
368
+ * 4. `overrides` you pass here (CLI flags in the binary go through this)
369
+ *
370
+ * Also loads `.env` from `cwd` into `process.env` without overwriting
371
+ * variables that are already set. Secrets still belong in the environment —
372
+ * not in config files.
373
+ *
374
+ * @param cwd - Repository root to load config from.
375
+ * @param configFile - Optional explicit path to a C12 config file.
376
+ * @param overrides - Highest-priority values (for example CLI flags).
377
+ * @returns The fully merged config object.
378
+ * @throws May reject if the config file throws or cannot be loaded.
379
+ *
380
+ * @example Read what a repo already configured
381
+ * ```ts
382
+ * import { loadReleaseConfig } from 'genbumppush';
383
+ *
384
+ * const config = await loadReleaseConfig(process.cwd());
385
+ * console.log(config.git?.remote ?? 'origin');
386
+ * ```
387
+ *
388
+ * @example Force a dry-run-style push disable from a script
389
+ * ```ts
390
+ * import { loadReleaseConfig } from 'genbumppush';
391
+ *
392
+ * const config = await loadReleaseConfig(process.cwd(), undefined, {
393
+ * git: { push: false },
394
+ * });
395
+ * // config.git.push === false even if the file enabled push
396
+ * ```
397
+ */
60
398
  export declare function loadReleaseConfig(cwd: string, configFile?: string, overrides?: GenBumpPushConfig): Promise<GenBumpPushConfig>;
61
399
  //#endregion
62
400
  //#region src/error.d.ts
401
+ /**
402
+ * Error thrown by genbumppush for expected release failures.
403
+ *
404
+ * Unlike a generic `Error`, every {@link ReleaseError} carries a stable
405
+ * {@link ReleaseError.code} so scripts and the CLI can branch on the reason
406
+ * (`DIRTY_WORKTREE`, `TAG_EXISTS`, `CANCELLED`, …) without parsing messages.
407
+ *
408
+ * @example Branch on the failure reason
409
+ * ```ts
410
+ * import { runRelease, ReleaseError } from 'genbumppush';
411
+ *
412
+ * try {
413
+ * await runRelease({ cwd: process.cwd(), dryRun: false, yes: true, help: false });
414
+ * } catch (error) {
415
+ * if (error instanceof ReleaseError && error.code === 'CANCELLED') {
416
+ * process.exit(0);
417
+ * }
418
+ * throw error;
419
+ * }
420
+ * ```
421
+ *
422
+ * @example Print code and message the same way the CLI does
423
+ * ```ts
424
+ * if (error instanceof ReleaseError) {
425
+ * console.error(`[${error.code}] ${error.message}`);
426
+ * }
427
+ * ```
428
+ */
63
429
  export declare class ReleaseError extends Error {
430
+ /** Machine-readable reason, for example `'DIRTY_WORKTREE'` or `'TAG_EXISTS'`. */
64
431
  readonly code: string;
432
+ /**
433
+ * @param code - Stable machine-readable reason.
434
+ * @param message - Human-readable explanation shown to the user.
435
+ * @param options - Optional `cause` when wrapping an underlying error.
436
+ */
65
437
  constructor(code: string, message: string, options?: ErrorOptions);
66
438
  }
67
439
  //#endregion
68
440
  //#region src/release.d.ts
441
+ /**
442
+ * Run a full release (or a dry run / provider retry) for one repository.
443
+ *
444
+ * Typical flow:
445
+ * 1. Load config and `.env`
446
+ * 2. Verify the worktree is a clean Git repo on a branch
447
+ * 3. Detect (or force) a release type from Conventional Commits
448
+ * 4. Confirm, run `before` hooks, update version files and the changelog
449
+ * 5. Commit, tag, and atomically push branch + tag
450
+ * 6. Optionally create a GitHub/GitLab release, then run `after` hooks
451
+ *
452
+ * Version-file or commit failures restore files and the index. A failed tag
453
+ * or network push can leave the release commit locally so you can inspect
454
+ * and retry — see the returned {@link ReleaseResult} and any thrown
455
+ * {@link ReleaseError}.
456
+ *
457
+ * Prefer the `genbumppush` CLI for day-to-day use. Call this directly when
458
+ * embedding releases in a Node script or CI job that already builds
459
+ * {@link CliOptions}.
460
+ *
461
+ * @param options - Parsed CLI options. `cwd`, `dryRun`, `yes`, and `help` are required;
462
+ * the rest override config when set.
463
+ * @returns A summary of what happened. Never mutates when `dryRun` is `true`.
464
+ * @throws {@link ReleaseError} for expected failures (dirty worktree, existing tag,
465
+ * cancelled confirmation, Git/provider errors). Unexpected errors may also throw.
466
+ *
467
+ * @example Dry run in the current directory
468
+ * ```ts
469
+ * import { runRelease } from 'genbumppush';
470
+ *
471
+ * const result = await runRelease({
472
+ * cwd: process.cwd(),
473
+ * dryRun: true,
474
+ * yes: true,
475
+ * help: false,
476
+ * });
477
+ *
478
+ * console.log(result);
479
+ * // {
480
+ * // currentVersion: '1.2.3',
481
+ * // newVersion: '1.3.0',
482
+ * // releaseType: 'minor',
483
+ * // tag: 'v1.3.0',
484
+ * // pushed: false,
485
+ * // dryRun: true,
486
+ * // commitCount: 4
487
+ * // }
488
+ * ```
489
+ *
490
+ * @example Non-interactive patch release that stays local
491
+ * ```ts
492
+ * import { runRelease } from 'genbumppush';
493
+ *
494
+ * await runRelease({
495
+ * cwd: process.cwd(),
496
+ * dryRun: false,
497
+ * yes: true,
498
+ * help: false,
499
+ * release: 'patch',
500
+ * push: false,
501
+ * });
502
+ * ```
503
+ *
504
+ * @example Retry only the GitLab release after Git already succeeded
505
+ * ```ts
506
+ * import { runRelease } from 'genbumppush';
507
+ *
508
+ * await runRelease({
509
+ * cwd: process.cwd(),
510
+ * dryRun: false,
511
+ * yes: true,
512
+ * help: false,
513
+ * gitlabRetryTag: 'v1.3.0',
514
+ * });
515
+ * ```
516
+ */
69
517
  export declare function runRelease(options: CliOptions): Promise<ReleaseResult>;
70
518
  //#endregion
71
- export type { CliOptions, GenBumpPushConfig, GitLabOptions, GitOptions, HookOptions, ReleaseResult, ReleaseType };
519
+ export type { CliOptions, GenBumpPushConfig, GitHubOptions, GitLabOptions, GitOptions, HookOptions, ReleaseResult, ReleaseType };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { i as loadReleaseConfig, n as ReleaseError, r as defineConfig, t as runRelease } from "./release-cb3ZULZM.mjs";
1
+ import { i as loadReleaseConfig, n as ReleaseError, r as defineConfig, t as runRelease } from "./release-gwyqzR0C.mjs";
2
2
  export { ReleaseError, defineConfig, loadReleaseConfig, runRelease };