@codluv/versionguard 0.1.0

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.
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Semantic version parsing, validation, comparison, and increment helpers.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { SemVer, ValidationResult } from './types';
7
+ /**
8
+ * Parses a semantic version string.
9
+ *
10
+ * @remarks
11
+ * This helper enforces the standard SemVer structure and returns `null` when the input does not
12
+ * match. It preserves prerelease and build identifiers as ordered string segments.
13
+ *
14
+ * @param version - Version string to parse.
15
+ * @returns Parsed semantic version components, or `null` when the input is invalid.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { parse } from 'versionguard';
20
+ *
21
+ * parse('1.2.3-alpha.1+build.5')?.prerelease;
22
+ * // => ['alpha', '1']
23
+ * ```
24
+ *
25
+ * @public
26
+ * @since 0.1.0
27
+ */
28
+ export declare function parse(version: string): SemVer | null;
29
+ /**
30
+ * Validates that a string is a supported semantic version.
31
+ *
32
+ * @remarks
33
+ * When validation fails, the result includes targeted structural errors for common cases such as
34
+ * leading `v` prefixes and numeric segments with leading zeroes.
35
+ *
36
+ * @param version - Version string to validate.
37
+ * @returns A validation result containing any detected errors and the parsed version on success.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { validate } from 'versionguard';
42
+ *
43
+ * validate('1.2.3').valid;
44
+ * // => true
45
+ * ```
46
+ *
47
+ * @public
48
+ * @since 0.1.0
49
+ */
50
+ export declare function validate(version: string): ValidationResult;
51
+ /**
52
+ * Compares two semantic version strings.
53
+ *
54
+ * @remarks
55
+ * Comparison follows SemVer precedence rules, including special handling for prerelease
56
+ * identifiers and ignoring build metadata.
57
+ *
58
+ * @param a - Left-hand version string.
59
+ * @param b - Right-hand version string.
60
+ * @returns `1` when `a` is greater, `-1` when `b` is greater, or `0` when they are equal.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { compare } from 'versionguard';
65
+ *
66
+ * compare('1.2.3', '1.2.3-alpha.1');
67
+ * // => 1
68
+ * ```
69
+ *
70
+ * @public
71
+ * @since 0.1.0
72
+ */
73
+ export declare function compare(a: string, b: string): number;
74
+ /**
75
+ * Checks whether one semantic version is greater than another.
76
+ *
77
+ * @remarks
78
+ * This is a convenience wrapper around {@link compare} for callers that only need a boolean.
79
+ *
80
+ * @param a - Left-hand version string.
81
+ * @param b - Right-hand version string.
82
+ * @returns `true` when `a` has higher precedence than `b`.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * import { gt } from 'versionguard';
87
+ *
88
+ * gt('1.2.4', '1.2.3');
89
+ * // => true
90
+ * ```
91
+ *
92
+ * @see {@link compare} for full precedence ordering.
93
+ * @public
94
+ * @since 0.1.0
95
+ */
96
+ export declare function gt(a: string, b: string): boolean;
97
+ /**
98
+ * Checks whether one semantic version is less than another.
99
+ *
100
+ * @remarks
101
+ * This is a convenience wrapper around {@link compare} for callers that only need a boolean.
102
+ *
103
+ * @param a - Left-hand version string.
104
+ * @param b - Right-hand version string.
105
+ * @returns `true` when `a` has lower precedence than `b`.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import { lt } from 'versionguard';
110
+ *
111
+ * lt('1.2.3-alpha.1', '1.2.3');
112
+ * // => true
113
+ * ```
114
+ *
115
+ * @see {@link compare} for full precedence ordering.
116
+ * @public
117
+ * @since 0.1.0
118
+ */
119
+ export declare function lt(a: string, b: string): boolean;
120
+ /**
121
+ * Checks whether two semantic versions are equal in precedence.
122
+ *
123
+ * @remarks
124
+ * This is a convenience wrapper around {@link compare}. Build metadata is ignored because
125
+ * precedence comparisons in SemVer do not consider it.
126
+ *
127
+ * @param a - Left-hand version string.
128
+ * @param b - Right-hand version string.
129
+ * @returns `true` when both versions compare as equal.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { eq } from 'versionguard';
134
+ *
135
+ * eq('1.2.3', '1.2.3');
136
+ * // => true
137
+ * ```
138
+ *
139
+ * @see {@link compare} for full precedence ordering.
140
+ * @public
141
+ * @since 0.1.0
142
+ */
143
+ export declare function eq(a: string, b: string): boolean;
144
+ /**
145
+ * Increments a semantic version string by release type.
146
+ *
147
+ * @remarks
148
+ * Incrementing `major` or `minor` resets lower-order numeric segments. When a prerelease label is
149
+ * provided, it is appended to the newly generated version.
150
+ *
151
+ * @param version - Current semantic version string.
152
+ * @param release - Segment to increment.
153
+ * @param prerelease - Optional prerelease suffix to append to the next version.
154
+ * @returns The incremented semantic version string.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { increment } from 'versionguard';
159
+ *
160
+ * increment('1.2.3', 'minor', 'beta.1');
161
+ * // => '1.3.0-beta.1'
162
+ * ```
163
+ *
164
+ * @public
165
+ * @since 0.1.0
166
+ */
167
+ export declare function increment(version: string, release: 'major' | 'minor' | 'patch', prerelease?: string): string;
168
+ /**
169
+ * Formats a parsed semantic version object.
170
+ *
171
+ * @remarks
172
+ * Prerelease and build metadata segments are only included when their arrays contain values.
173
+ *
174
+ * @param version - Parsed semantic version to serialize.
175
+ * @returns The normalized semantic version string.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { format } from 'versionguard';
180
+ *
181
+ * const version = { major: 1, minor: 2, patch: 3, prerelease: ['rc', '1'], build: ['build', '5'], raw: '1.2.3-rc.1+build.5' };
182
+ *
183
+ * format(version);
184
+ * // => '1.2.3-rc.1+build.5'
185
+ * ```
186
+ *
187
+ * @public
188
+ * @since 0.1.0
189
+ */
190
+ export declare function format(version: SemVer): string;
191
+ //# sourceMappingURL=semver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../src/semver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAmB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAKzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAepD;AA6CD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAe1D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CA8DpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAgBR;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAY9C"}
package/dist/sync.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ import type { SyncConfig, SyncPattern, SyncResult, VersionMismatch } from './types';
2
+ /**
3
+ * Synchronizes configured files to a single version string.
4
+ *
5
+ * @public
6
+ * @since 0.1.0
7
+ * @remarks
8
+ * File globs are resolved relative to `cwd`, then each matched file is updated
9
+ * with the configured replacement patterns.
10
+ *
11
+ * @param version - Version string to write into matching files.
12
+ * @param config - Sync configuration describing files and replacement patterns.
13
+ * @param cwd - Project directory used to resolve file globs.
14
+ * @returns A sync result for each resolved file.
15
+ * @example
16
+ * ```ts
17
+ * import { getDefaultConfig, syncVersion } from 'versionguard';
18
+ *
19
+ * const results = syncVersion('1.2.3', getDefaultConfig().sync, process.cwd());
20
+ * ```
21
+ */
22
+ export declare function syncVersion(version: string, config: SyncConfig, cwd?: string): SyncResult[];
23
+ /**
24
+ * Synchronizes a single file to a target version.
25
+ *
26
+ * @public
27
+ * @since 0.1.0
28
+ * @remarks
29
+ * Each configured regex is applied globally, and `{{version}}` placeholders in
30
+ * templates are replaced with the supplied version.
31
+ *
32
+ * @param filePath - Absolute or relative path to the file to update.
33
+ * @param version - Version string to write.
34
+ * @param patterns - Replacement patterns to apply.
35
+ * @returns A result describing whether the file changed and what changed.
36
+ * @example
37
+ * ```ts
38
+ * import { getDefaultConfig, syncFile } from 'versionguard';
39
+ *
40
+ * const result = syncFile('README.md', '1.2.3', getDefaultConfig().sync.patterns);
41
+ * ```
42
+ */
43
+ export declare function syncFile(filePath: string, version: string, patterns: SyncPattern[]): SyncResult;
44
+ /**
45
+ * Checks configured files for hardcoded version mismatches.
46
+ *
47
+ * @public
48
+ * @since 0.1.0
49
+ * @remarks
50
+ * Files matching the sync config are scanned without modification, and every
51
+ * captured version that differs from `expectedVersion` is returned.
52
+ *
53
+ * @param expectedVersion - Version all matching entries should use.
54
+ * @param config - Sync configuration describing files and replacement patterns.
55
+ * @param ignorePatterns - Glob patterns to exclude while scanning.
56
+ * @param cwd - Project directory used to resolve file globs.
57
+ * @returns A list of detected version mismatches.
58
+ * @example
59
+ * ```ts
60
+ * import { checkHardcodedVersions, getDefaultConfig } from 'versionguard';
61
+ *
62
+ * const mismatches = checkHardcodedVersions(
63
+ * '1.2.3',
64
+ * getDefaultConfig().sync,
65
+ * getDefaultConfig().ignore,
66
+ * process.cwd(),
67
+ * );
68
+ * ```
69
+ */
70
+ export declare function checkHardcodedVersions(expectedVersion: string, config: SyncConfig, ignorePatterns: string[], cwd?: string): VersionMismatch[];
71
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA8BpF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,MAAsB,GAC1B,UAAU,EAAE,CAId;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,UAAU,CAyC/F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,sBAAsB,CACpC,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,UAAU,EAClB,cAAc,EAAE,MAAM,EAAE,EACxB,GAAG,GAAE,MAAsB,GAC1B,eAAe,EAAE,CA0BnB"}
@@ -0,0 +1,180 @@
1
+ import type { VersionGuardConfig } from '../types';
2
+ /**
3
+ * Tag management helpers for reading, validating, and creating release tags.
4
+ *
5
+ * @packageDocumentation
6
+ * @public
7
+ */
8
+ /**
9
+ * Tag entry point exports for release-tag management helpers.
10
+ *
11
+ * @packageDocumentation
12
+ * @public
13
+ * @since 0.1.0
14
+ * @forgeIgnore E020
15
+ */
16
+ export interface TagInfo {
17
+ /**
18
+ * Full git tag name, including any prefix such as `v`.
19
+ */
20
+ name: string;
21
+ /**
22
+ * Normalized version string derived from the tag name.
23
+ */
24
+ version: string;
25
+ /**
26
+ * Annotated tag message when one is available.
27
+ *
28
+ * @defaultValue `undefined`
29
+ */
30
+ message?: string;
31
+ /**
32
+ * Timestamp associated with the tag lookup result.
33
+ */
34
+ date: Date;
35
+ }
36
+ /**
37
+ * Returns the most recent reachable git tag for a repository.
38
+ *
39
+ * @public
40
+ * @since 0.1.0
41
+ * @remarks
42
+ * This helper reads the most recent annotated or lightweight tag that `git describe`
43
+ * can resolve from the current HEAD. It returns `null` when no tags are available
44
+ * or when git metadata cannot be read.
45
+ *
46
+ * @param cwd - Repository directory to inspect.
47
+ * @returns The latest tag details, or `null` when no tag can be resolved.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const latestTag = getLatestTag(process.cwd());
52
+ *
53
+ * if (latestTag) {
54
+ * console.log(latestTag.version);
55
+ * }
56
+ * ```
57
+ */
58
+ export declare function getLatestTag(cwd?: string): TagInfo | null;
59
+ /**
60
+ * Lists all tags in a repository.
61
+ *
62
+ * @public
63
+ * @since 0.1.0
64
+ * @remarks
65
+ * This helper returns tag names in the order provided by `git tag --list`. The
66
+ * `date` field is populated with the current time because the implementation does
67
+ * not perform per-tag date lookups.
68
+ *
69
+ * @param cwd - Repository directory to inspect.
70
+ * @returns A list of discovered tags, or an empty array when tags cannot be read.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const tags = getAllTags(process.cwd());
75
+ * console.log(tags.map((tag) => tag.name));
76
+ * ```
77
+ */
78
+ export declare function getAllTags(cwd?: string): TagInfo[];
79
+ /**
80
+ * Creates a release tag and optionally fixes version state first.
81
+ *
82
+ * @public
83
+ * @since 0.1.0
84
+ * @remarks
85
+ * When `autoFix` is enabled, this helper updates versioned files, stages the
86
+ * changes, and creates a release commit before creating the annotated tag. It
87
+ * returns a structured result instead of throwing for most expected failures.
88
+ *
89
+ * @param version - Version to embed in the new tag name.
90
+ * @param message - Custom annotated tag message.
91
+ * @param autoFix - Whether to auto-fix version mismatches before tagging.
92
+ * @param config - Loaded VersionGuard configuration used for validation and fixes.
93
+ * @param cwd - Repository directory where git commands should run.
94
+ * @returns The tagging outcome and any actions performed along the way.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const result = createTag('1.2.3', 'Release 1.2.3', true, config, process.cwd());
99
+ *
100
+ * if (!result.success) {
101
+ * console.error(result.message);
102
+ * }
103
+ * ```
104
+ */
105
+ export declare function createTag(version: string, message?: string, autoFix?: boolean, config?: VersionGuardConfig, cwd?: string): {
106
+ success: boolean;
107
+ message: string;
108
+ actions: string[];
109
+ };
110
+ /**
111
+ * Runs post-tag validation and sync checks.
112
+ *
113
+ * @public
114
+ * @since 0.1.0
115
+ * @remarks
116
+ * This helper is intended for the `post-tag` git hook flow. It validates the
117
+ * latest tag against the configured versioning rules and reports any required
118
+ * follow-up actions without mutating git history.
119
+ *
120
+ * @param config - Loaded VersionGuard configuration used during validation.
121
+ * @param cwd - Repository directory where validation should run.
122
+ * @returns The post-tag workflow result and any follow-up actions.
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const result = handlePostTag(config, process.cwd());
127
+ * console.log(result.success);
128
+ * ```
129
+ */
130
+ export declare function handlePostTag(config: VersionGuardConfig, cwd?: string): {
131
+ success: boolean;
132
+ message: string;
133
+ actions: string[];
134
+ };
135
+ /**
136
+ * Validates that a local tag is safe to push to the default remote.
137
+ *
138
+ * @public
139
+ * @since 0.1.0
140
+ * @remarks
141
+ * This helper checks that the tag exists locally and, when the tag also exists on
142
+ * `origin`, verifies that both references point to the same commit.
143
+ *
144
+ * @param tagName - Name of the tag to validate.
145
+ * @param cwd - Repository directory where git commands should run.
146
+ * @returns A validation result with an optional suggested fix command.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const result = validateTagForPush('v1.2.3', process.cwd());
151
+ * console.log(result.valid);
152
+ * ```
153
+ */
154
+ export declare function validateTagForPush(tagName: string, cwd?: string): {
155
+ valid: boolean;
156
+ message: string;
157
+ fix?: string;
158
+ };
159
+ /**
160
+ * Suggests an annotated tag message from changelog content.
161
+ *
162
+ * @public
163
+ * @since 0.1.0
164
+ * @remarks
165
+ * When a matching changelog entry exists, this helper uses the first bullet point
166
+ * as a concise release summary. It falls back to a generic `Release {version}`
167
+ * message when no changelog context is available.
168
+ *
169
+ * @param version - Version that the tag will represent.
170
+ * @param cwd - Repository directory containing the changelog file.
171
+ * @returns A suggested annotated tag message.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * const message = suggestTagMessage('1.2.3', process.cwd());
176
+ * console.log(message);
177
+ * ```
178
+ */
179
+ export declare function suggestTagMessage(version: string, cwd?: string): string;
180
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tag/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;GAKG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AAcD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,GAAG,IAAI,CAoBxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,EAAE,CAgBjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,GAAE,OAAc,EACvB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,GAAG,GAAE,MAAsB,GAC1B;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CA0E1D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,kBAAkB,EAC1B,GAAG,GAAE,MAAsB,GAC1B;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAwD1D;AA6DD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,MAAsB,GAC1B;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CA6BnD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,MAAM,CAwBtF"}