fork-version 3.0.2 → 3.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.
- package/CHANGELOG.md +8 -0
- package/README.md +29 -6
- package/dist/{chunk-YSWJMT7B.cjs → chunk-BPV4HZ7U.cjs} +134 -57
- package/dist/chunk-BPV4HZ7U.cjs.map +1 -0
- package/dist/{chunk-AZZVHG2X.js → chunk-FRII64VR.js} +131 -58
- package/dist/chunk-FRII64VR.js.map +1 -0
- package/dist/cli.cjs +66 -54
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +63 -51
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +31 -15
- package/dist/index.d.cts +473 -343
- package/dist/index.d.ts +473 -343
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-AZZVHG2X.js.map +0 -1
- package/dist/chunk-YSWJMT7B.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Fork Version
|
|
2
2
|
|
|
3
|
+
## [3.1.0](https://github.com/eglavin/fork-version/compare/v3.0.2...v3.1.0) (2025-10-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* implement new command flow for inspect-* commands ([d89e4e0](https://github.com/eglavin/fork-version/commit/d89e4e07803180c7b79847ed4a5e1241ee19074b))
|
|
9
|
+
|
|
10
|
+
|
|
3
11
|
## [3.0.2](https://github.com/eglavin/fork-version/compare/v3.0.1...v3.0.2) (2025-10-02)
|
|
4
12
|
|
|
5
13
|
|
package/README.md
CHANGED
|
@@ -87,6 +87,17 @@ You can then add the following entry to your package.json scripts section and us
|
|
|
87
87
|
|
|
88
88
|
For example if you use npm you can now use `npm run release` to run Fork-Version.
|
|
89
89
|
|
|
90
|
+
### Commands
|
|
91
|
+
|
|
92
|
+
Fork-Version has a number of command modes which will make the program behave differently. The default "command" is the `main` mode, this mode will be used when no other command is defined.
|
|
93
|
+
|
|
94
|
+
| Command | Description |
|
|
95
|
+
| ------------------- | ---------------------------------------------------------------------- |
|
|
96
|
+
| `main` | Bumps the version, update files, generate changelog, commits, and tag. |
|
|
97
|
+
| `inspect-version` | Prints the current version and exit. |
|
|
98
|
+
| `inspect-tag` | Prints the current git tag and exit. |
|
|
99
|
+
| `validate-config` | Validates the configuration and exit. |
|
|
100
|
+
|
|
90
101
|
### Exit Codes
|
|
91
102
|
|
|
92
103
|
When ran as a cli tool Fork-Version will exit with one of the following exit codes:
|
|
@@ -95,6 +106,7 @@ When ran as a cli tool Fork-Version will exit with one of the following exit cod
|
|
|
95
106
|
| --------- | ---------------------------- |
|
|
96
107
|
| 0 | Success |
|
|
97
108
|
| 1 | General Error |
|
|
109
|
+
| 2 | Unknown Command |
|
|
98
110
|
| 3 | Config File Validation Error |
|
|
99
111
|
|
|
100
112
|
### Command Line Options
|
|
@@ -105,17 +117,24 @@ The following help text can be viewed by running the following command: `npx for
|
|
|
105
117
|
|
|
106
118
|
```text
|
|
107
119
|
Usage:
|
|
108
|
-
$ fork-version [options]
|
|
120
|
+
$ fork-version [command?] [options?]
|
|
109
121
|
|
|
110
122
|
Commands:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
main Bumps the version, update files, generate changelog, commit, and tag. [Default when no command is provided]
|
|
124
|
+
inspect-version Prints the current version and exits.
|
|
125
|
+
inspect-tag Prints the current git tag and exits.
|
|
126
|
+
validate-config Validates the configuration and exits.
|
|
114
127
|
|
|
115
|
-
Options:
|
|
128
|
+
General Options:
|
|
129
|
+
--version Show the current version of Fork-Version and exit.
|
|
130
|
+
--help Show this help message and exit.
|
|
131
|
+
|
|
132
|
+
Location Options:
|
|
116
133
|
--file, -F List of the files to be updated. [Default: ["bower.json", "deno.json", "deno.jsonc", "jsr.json", "jsr.jsonc", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]]
|
|
117
134
|
--glob, -G Glob pattern to match files to be updated.
|
|
118
135
|
--path, -P The path Fork-Version will run from. [Default: process.cwd()]
|
|
136
|
+
|
|
137
|
+
Options:
|
|
119
138
|
--changelog Name of the changelog file. [Default: "CHANGELOG.md"]
|
|
120
139
|
--header The header text for the changelog.
|
|
121
140
|
--tag-prefix Specify a prefix for the created tag. [Default: "v"]
|
|
@@ -155,6 +174,7 @@ Conventional Changelog Overrides:
|
|
|
155
174
|
Exit Codes:
|
|
156
175
|
0: Success
|
|
157
176
|
1: General Error
|
|
177
|
+
2: Unknown Command
|
|
158
178
|
3: Config File Validation Error
|
|
159
179
|
|
|
160
180
|
Examples:
|
|
@@ -169,6 +189,9 @@ Examples:
|
|
|
169
189
|
|
|
170
190
|
$ fork-version --glob "*/package.json"
|
|
171
191
|
Run fork-version and update all "package.json" files in subdirectories.
|
|
192
|
+
|
|
193
|
+
$ fork-version inspect-version
|
|
194
|
+
Prints the current version and exits.
|
|
172
195
|
```
|
|
173
196
|
|
|
174
197
|
<!-- END COMMAND LINE OPTIONS -->
|
|
@@ -268,7 +291,7 @@ Alternatively you can define your config using a key in your `package.json` file
|
|
|
268
291
|
|
|
269
292
|
| Property | Type | Default | Description |
|
|
270
293
|
| :---------------------------------------------------- | :--------------- | :---------------------- | :------------------------------------------------------------------------------------------------------------------ |
|
|
271
|
-
|
|
|
294
|
+
| command | string | `main` | The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main. |
|
|
272
295
|
| [files](#configfiles) | Array\<string> | `["package.json", ...]` | List of the files to be updated |
|
|
273
296
|
| [glob](#configglob) | string | - | Glob pattern to match files to be updated |
|
|
274
297
|
| path | string | `process.cwd()` | The path Fork-Version will run from |
|
|
@@ -101,11 +101,26 @@ var ChangelogPresetConfigSchema = zod.z.object({
|
|
|
101
101
|
var ForkConfigSchema = zod.z.object({
|
|
102
102
|
// Commands
|
|
103
103
|
//
|
|
104
|
+
/**
|
|
105
|
+
* The command to run, can be one of the following:
|
|
106
|
+
*
|
|
107
|
+
* - `main` - Bumps the version, update files, generate changelog, commit, and tag.
|
|
108
|
+
* - `inspect-version` - Prints the current version and exits.
|
|
109
|
+
* - `inspect-tag` - Prints the current git tag and exits.
|
|
110
|
+
* - `validate-config` - Validates the configuration and exits.
|
|
111
|
+
*
|
|
112
|
+
* @default "main"
|
|
113
|
+
*/
|
|
114
|
+
command: zod.z.literal(["main", "inspect-version", "inspect-tag", "validate-config"]).describe(
|
|
115
|
+
"The command to run. Can be one of: main, inspect-version, inspect-tag, validate-config. Defaults to main."
|
|
116
|
+
),
|
|
104
117
|
/**
|
|
105
118
|
* If set, Fork-Version will print the current version and exit.
|
|
106
119
|
* @default false
|
|
120
|
+
*
|
|
121
|
+
* @deprecated Set the `inspect-version` command instead.
|
|
107
122
|
*/
|
|
108
|
-
inspectVersion: zod.z.boolean().describe("If set, Fork-Version will print the current version and exit."),
|
|
123
|
+
inspectVersion: zod.z.boolean().optional().describe("If set, Fork-Version will print the current version and exit."),
|
|
109
124
|
// Options
|
|
110
125
|
//
|
|
111
126
|
/**
|
|
@@ -656,7 +671,7 @@ function getChangelogPresetConfig(mergedConfig, cliArguments, detectedGitHost) {
|
|
|
656
671
|
// src/config/defaults.ts
|
|
657
672
|
var DEFAULT_CONFIG = {
|
|
658
673
|
// Commands
|
|
659
|
-
|
|
674
|
+
command: "main",
|
|
660
675
|
// Options
|
|
661
676
|
files: [
|
|
662
677
|
"package.json",
|
|
@@ -792,12 +807,12 @@ function mergeFiles(configFiles, cliFiles, globResults) {
|
|
|
792
807
|
|
|
793
808
|
// src/config/user-config.ts
|
|
794
809
|
async function getUserConfig(cliArguments) {
|
|
795
|
-
const cwd = cliArguments.path ? path.resolve(cliArguments.path) : process.cwd();
|
|
810
|
+
const cwd = cliArguments.flags.path ? path.resolve(cliArguments.flags.path) : process.cwd();
|
|
796
811
|
const configFile = await loadConfigFile(cwd);
|
|
797
812
|
const mergedConfig = {
|
|
798
813
|
...DEFAULT_CONFIG,
|
|
799
814
|
...configFile,
|
|
800
|
-
...cliArguments
|
|
815
|
+
...cliArguments.flags
|
|
801
816
|
};
|
|
802
817
|
let globResults = [];
|
|
803
818
|
if (mergedConfig.glob) {
|
|
@@ -807,21 +822,33 @@ async function getUserConfig(cliArguments) {
|
|
|
807
822
|
nodir: true
|
|
808
823
|
});
|
|
809
824
|
}
|
|
810
|
-
const files = mergeFiles(configFile?.files, cliArguments
|
|
825
|
+
const files = mergeFiles(configFile?.files, cliArguments.flags.files, globResults);
|
|
811
826
|
const detectedGitHost = await detectGitHost(cwd);
|
|
812
827
|
const changelogPresetConfig = getChangelogPresetConfig(
|
|
813
828
|
mergedConfig,
|
|
814
|
-
cliArguments,
|
|
829
|
+
cliArguments.flags,
|
|
815
830
|
detectedGitHost
|
|
816
831
|
);
|
|
832
|
+
let command = DEFAULT_CONFIG.command;
|
|
833
|
+
if (cliArguments.input.length > 0 && cliArguments.input[0].trim()) {
|
|
834
|
+
command = cliArguments.input[0].trim().toLowerCase();
|
|
835
|
+
} else if (mergedConfig.command.trim()) {
|
|
836
|
+
command = mergedConfig.command.trim().toLowerCase();
|
|
837
|
+
}
|
|
838
|
+
if (mergedConfig.inspectVersion) {
|
|
839
|
+
command = "inspect-version";
|
|
840
|
+
}
|
|
841
|
+
const shouldBeSilent = ![DEFAULT_CONFIG.command].includes(command);
|
|
817
842
|
return {
|
|
818
843
|
...mergedConfig,
|
|
844
|
+
command,
|
|
819
845
|
files,
|
|
820
846
|
path: cwd,
|
|
821
847
|
preRelease: (
|
|
822
848
|
// Meow doesn't support multiple flags with the same name, so we need to check both.
|
|
823
|
-
cliArguments.preReleaseTag ?? cliArguments.preRelease ?? configFile.preRelease
|
|
849
|
+
cliArguments.flags.preReleaseTag ?? cliArguments.flags.preRelease ?? configFile.preRelease
|
|
824
850
|
),
|
|
851
|
+
silent: shouldBeSilent || mergedConfig.silent,
|
|
825
852
|
changelogPresetConfig
|
|
826
853
|
};
|
|
827
854
|
}
|
|
@@ -834,7 +861,7 @@ var Logger = class {
|
|
|
834
861
|
this.warn = this.warn.bind(this);
|
|
835
862
|
this.error = this.error.bind(this);
|
|
836
863
|
this.debug = this.debug.bind(this);
|
|
837
|
-
this.disableLogs = this.config.silent
|
|
864
|
+
this.disableLogs = this.config.silent;
|
|
838
865
|
}
|
|
839
866
|
disableLogs = false;
|
|
840
867
|
log(...messages) {
|
|
@@ -1170,6 +1197,76 @@ var FileManager = class {
|
|
|
1170
1197
|
}
|
|
1171
1198
|
};
|
|
1172
1199
|
|
|
1200
|
+
// src/commands/validate-config.ts
|
|
1201
|
+
function validateConfig(config) {
|
|
1202
|
+
console.log(`
|
|
1203
|
+
\u2699\uFE0F Configuration:
|
|
1204
|
+
${JSON.stringify(config, null, 2)}
|
|
1205
|
+
|
|
1206
|
+
\u2705 Configuration is valid.
|
|
1207
|
+
`);
|
|
1208
|
+
}
|
|
1209
|
+
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1210
|
+
const files = [];
|
|
1211
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1212
|
+
for (const file of filesToUpdate) {
|
|
1213
|
+
if (await git.isIgnored(file)) {
|
|
1214
|
+
logger.debug(`[Git Ignored] ${file}`);
|
|
1215
|
+
continue;
|
|
1216
|
+
}
|
|
1217
|
+
const fileState = fileManager.read(file);
|
|
1218
|
+
if (fileState) {
|
|
1219
|
+
files.push(fileState);
|
|
1220
|
+
if (!config.currentVersion) {
|
|
1221
|
+
versions.add(fileState.version);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (config.currentVersion) {
|
|
1226
|
+
versions.add(config.currentVersion);
|
|
1227
|
+
}
|
|
1228
|
+
if (versions.size === 0 && config.gitTagFallback) {
|
|
1229
|
+
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1230
|
+
if (version) {
|
|
1231
|
+
logger.warn(`Using latest git tag as fallback`);
|
|
1232
|
+
versions.add(version);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
if (versions.size === 0) {
|
|
1236
|
+
throw new Error("Unable to find current version");
|
|
1237
|
+
} else if (versions.size > 1) {
|
|
1238
|
+
if (!config.allowMultipleVersions) {
|
|
1239
|
+
throw new Error("Found multiple versions");
|
|
1240
|
+
}
|
|
1241
|
+
logger.warn(
|
|
1242
|
+
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
const currentVersion = semver__default.default.rsort(Array.from(versions))[0];
|
|
1246
|
+
logger.log(`Current version: ${currentVersion}`);
|
|
1247
|
+
return {
|
|
1248
|
+
files,
|
|
1249
|
+
version: currentVersion
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// src/commands/inspect-version.ts
|
|
1254
|
+
async function inspectVersion(config, logger, fileManager, git) {
|
|
1255
|
+
let foundVersion = "";
|
|
1256
|
+
try {
|
|
1257
|
+
const currentVersion = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1258
|
+
if (currentVersion) foundVersion = currentVersion.version;
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
console.log(foundVersion);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// src/commands/inspect-tag.ts
|
|
1265
|
+
async function inspectTag(config, git) {
|
|
1266
|
+
const tag = await git.getMostRecentTag(config.tagPrefix);
|
|
1267
|
+
console.log(tag ?? "");
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1173
1270
|
// src/utils/trim-string-array.ts
|
|
1174
1271
|
function trimStringArray(array) {
|
|
1175
1272
|
const items = [];
|
|
@@ -1644,53 +1741,6 @@ async function getCommitsSinceTag(config, logger, git) {
|
|
|
1644
1741
|
commits: filteredCommits
|
|
1645
1742
|
};
|
|
1646
1743
|
}
|
|
1647
|
-
async function getCurrentVersion(config, logger, git, fileManager, filesToUpdate) {
|
|
1648
|
-
const files = [];
|
|
1649
|
-
const versions = /* @__PURE__ */ new Set();
|
|
1650
|
-
for (const file of filesToUpdate) {
|
|
1651
|
-
if (await git.isIgnored(file)) {
|
|
1652
|
-
logger.debug(`[Git Ignored] ${file}`);
|
|
1653
|
-
continue;
|
|
1654
|
-
}
|
|
1655
|
-
const fileState = fileManager.read(file);
|
|
1656
|
-
if (fileState) {
|
|
1657
|
-
files.push(fileState);
|
|
1658
|
-
if (!config.currentVersion) {
|
|
1659
|
-
versions.add(fileState.version);
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
if (config.currentVersion) {
|
|
1664
|
-
versions.add(config.currentVersion);
|
|
1665
|
-
}
|
|
1666
|
-
if (versions.size === 0 && config.gitTagFallback) {
|
|
1667
|
-
const version = await git.getHighestSemverVersionFromTags(config.tagPrefix);
|
|
1668
|
-
if (version) {
|
|
1669
|
-
logger.warn(`Using latest git tag as fallback`);
|
|
1670
|
-
versions.add(version);
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
if (versions.size === 0) {
|
|
1674
|
-
throw new Error("Unable to find current version");
|
|
1675
|
-
} else if (versions.size > 1) {
|
|
1676
|
-
if (!config.allowMultipleVersions) {
|
|
1677
|
-
throw new Error("Found multiple versions");
|
|
1678
|
-
}
|
|
1679
|
-
logger.warn(
|
|
1680
|
-
`Found multiple versions (${Array.from(versions).join(", ")}), using the higher semver version`
|
|
1681
|
-
);
|
|
1682
|
-
}
|
|
1683
|
-
const currentVersion = semver__default.default.rsort(Array.from(versions))[0];
|
|
1684
|
-
if (config.inspectVersion) {
|
|
1685
|
-
console.log(currentVersion);
|
|
1686
|
-
process.exit(0);
|
|
1687
|
-
}
|
|
1688
|
-
logger.log(`Current version: ${currentVersion}`);
|
|
1689
|
-
return {
|
|
1690
|
-
files,
|
|
1691
|
-
version: currentVersion
|
|
1692
|
-
};
|
|
1693
|
-
}
|
|
1694
1744
|
function getPriority(type) {
|
|
1695
1745
|
return ["patch", "minor", "major"].indexOf(type ?? "");
|
|
1696
1746
|
}
|
|
@@ -1922,6 +1972,29 @@ async function tagChanges(config, logger, git, nextVersion) {
|
|
|
1922
1972
|
);
|
|
1923
1973
|
}
|
|
1924
1974
|
|
|
1975
|
+
// src/commands/main.ts
|
|
1976
|
+
async function main(config, logger, fileManager, git) {
|
|
1977
|
+
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
1978
|
+
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
1979
|
+
const commits = await getCommitsSinceTag(config, logger, git);
|
|
1980
|
+
const current = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
1981
|
+
const next = await getNextVersion(config, logger, commits.commits, current.version);
|
|
1982
|
+
logger.log("Updating files: ");
|
|
1983
|
+
for (const outFile of current.files) {
|
|
1984
|
+
logger.log(` - ${outFile.path}`);
|
|
1985
|
+
fileManager.write(outFile, next.version);
|
|
1986
|
+
}
|
|
1987
|
+
await updateChangelog(config, logger, next.version);
|
|
1988
|
+
await commitChanges(config, logger, git, current.files, next.version);
|
|
1989
|
+
await tagChanges(config, logger, git, next.version);
|
|
1990
|
+
return {
|
|
1991
|
+
config,
|
|
1992
|
+
commits,
|
|
1993
|
+
current,
|
|
1994
|
+
next
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1925
1998
|
exports.CommitParser = CommitParser;
|
|
1926
1999
|
exports.FileManager = FileManager;
|
|
1927
2000
|
exports.ForkConfigSchema = ForkConfigSchema;
|
|
@@ -1934,7 +2007,11 @@ exports.getCommitsSinceTag = getCommitsSinceTag;
|
|
|
1934
2007
|
exports.getCurrentVersion = getCurrentVersion;
|
|
1935
2008
|
exports.getNextVersion = getNextVersion;
|
|
1936
2009
|
exports.getUserConfig = getUserConfig;
|
|
2010
|
+
exports.inspectTag = inspectTag;
|
|
2011
|
+
exports.inspectVersion = inspectVersion;
|
|
2012
|
+
exports.main = main;
|
|
1937
2013
|
exports.tagChanges = tagChanges;
|
|
1938
2014
|
exports.updateChangelog = updateChangelog;
|
|
1939
|
-
|
|
1940
|
-
//# sourceMappingURL=chunk-
|
|
2015
|
+
exports.validateConfig = validateConfig;
|
|
2016
|
+
//# sourceMappingURL=chunk-BPV4HZ7U.cjs.map
|
|
2017
|
+
//# sourceMappingURL=chunk-BPV4HZ7U.cjs.map
|