cross-bump 0.0.1-alpha.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/index.cjs +208 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.mjs +164 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 rainbowatcher
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Cross Bump
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var semver = require('semver');
|
|
6
|
+
var fs = require('node:fs/promises');
|
|
7
|
+
var path = require('node:path');
|
|
8
|
+
var cheerio = require('cheerio');
|
|
9
|
+
var detectIndent = require('detect-indent');
|
|
10
|
+
var TOML = require('@iarna/toml');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n["default"] = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
|
|
33
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
34
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
35
|
+
var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
|
|
36
|
+
var detectIndent__default = /*#__PURE__*/_interopDefaultLegacy(detectIndent);
|
|
37
|
+
var TOML__namespace = /*#__PURE__*/_interopNamespace(TOML);
|
|
38
|
+
|
|
39
|
+
function isJsonMap(obj) {
|
|
40
|
+
return typeof obj === "object" && obj !== null && !(obj instanceof Array) && !(obj instanceof Date);
|
|
41
|
+
}
|
|
42
|
+
function isBlankPath(path) {
|
|
43
|
+
return typeof path === "undefined" || path.toString().trim().length === 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const supportedProjectFiles = ["package.json", "pom.xml", "Cargo.toml"];
|
|
47
|
+
const projectCategoryMap = {
|
|
48
|
+
"pom.xml": "java",
|
|
49
|
+
"package.json": "javascript",
|
|
50
|
+
"Cargo.toml": "rust"
|
|
51
|
+
// go: "go.mod",
|
|
52
|
+
};
|
|
53
|
+
async function findProjectFiles(dir, excludes, recursive = false) {
|
|
54
|
+
const files = [];
|
|
55
|
+
if (isBlankPath(dir)) {
|
|
56
|
+
return files;
|
|
57
|
+
}
|
|
58
|
+
const dirEntries = await fs__namespace.readdir(dir, { withFileTypes: true });
|
|
59
|
+
for await (const dirEntry of dirEntries) {
|
|
60
|
+
const { name: filename } = dirEntry;
|
|
61
|
+
if (excludes == null ? void 0 : excludes.includes(filename))
|
|
62
|
+
continue;
|
|
63
|
+
const filePath = path__default["default"].resolve(process.cwd(), dir.toString(), filename);
|
|
64
|
+
if (recursive && dirEntry.isDirectory()) {
|
|
65
|
+
files.push(...await findProjectFiles(filePath, excludes, recursive));
|
|
66
|
+
} else if (supportedProjectFiles.includes(filename)) {
|
|
67
|
+
files.push({
|
|
68
|
+
category: projectCategoryMap[filename],
|
|
69
|
+
path: filePath
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return files;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const FALLBACK_VERSION = "undefined";
|
|
77
|
+
function getNextVersions(version, coerce = false) {
|
|
78
|
+
var _a, _b, _c, _d, _e;
|
|
79
|
+
let versionNum;
|
|
80
|
+
let id;
|
|
81
|
+
const defaultId = "alpha";
|
|
82
|
+
if (version instanceof semver__default["default"].SemVer) {
|
|
83
|
+
versionNum = version.version;
|
|
84
|
+
id = `${(_a = version.prerelease[0]) != null ? _a : ""}`;
|
|
85
|
+
} else if (typeof version === "string") {
|
|
86
|
+
versionNum = coerce ? (_c = (_b = semver__default["default"].coerce(version)) == null ? void 0 : _b.version) != null ? _c : version : version;
|
|
87
|
+
id = `${(_e = (_d = semver__default["default"].prerelease(version)) == null ? void 0 : _d[0]) != null ? _e : ""}`;
|
|
88
|
+
} else {
|
|
89
|
+
versionNum = "0.0.0";
|
|
90
|
+
id = defaultId;
|
|
91
|
+
}
|
|
92
|
+
const nextMajor = semver__default["default"].inc(versionNum, "major") || FALLBACK_VERSION;
|
|
93
|
+
const nextMinor = semver__default["default"].inc(versionNum, "minor") || FALLBACK_VERSION;
|
|
94
|
+
const nextPatch = semver__default["default"].inc(versionNum, "patch") || FALLBACK_VERSION;
|
|
95
|
+
const nextRelease = (id ? semver__default["default"].inc(versionNum, "prerelease", id, "1") : semver__default["default"].inc(versionNum, "patch")) || FALLBACK_VERSION;
|
|
96
|
+
const nextPreMajor = semver__default["default"].inc(versionNum, "premajor", defaultId, "1") || FALLBACK_VERSION;
|
|
97
|
+
const nextPreMinor = semver__default["default"].inc(versionNum, "preminor", defaultId, "1") || FALLBACK_VERSION;
|
|
98
|
+
const nextPrePatch = semver__default["default"].inc(versionNum, "prepatch", defaultId, "1") || FALLBACK_VERSION;
|
|
99
|
+
return {
|
|
100
|
+
nextMajor,
|
|
101
|
+
nextMinor,
|
|
102
|
+
nextPatch,
|
|
103
|
+
nextRelease,
|
|
104
|
+
nextPreMajor,
|
|
105
|
+
nextPreMinor,
|
|
106
|
+
nextPrePatch
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function upgradePomVersion(filePath, version, dry = process.env.DRY) {
|
|
110
|
+
const content = await fs__namespace.readFile(filePath, "utf-8");
|
|
111
|
+
const $ = cheerio__namespace.load(content, {
|
|
112
|
+
xml: { decodeEntities: false }
|
|
113
|
+
});
|
|
114
|
+
const projectVersion = $("project>version");
|
|
115
|
+
const parentVersion = $("project>parent>version");
|
|
116
|
+
projectVersion == null ? void 0 : projectVersion.text(version);
|
|
117
|
+
parentVersion == null ? void 0 : parentVersion.text(version);
|
|
118
|
+
if (!dry) {
|
|
119
|
+
await fs__namespace.writeFile(filePath, $.xml());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function getJavaProjectVersion(filePath) {
|
|
123
|
+
const pom = await fs__namespace.readFile(filePath, "utf-8");
|
|
124
|
+
const $ = cheerio__namespace.load(pom);
|
|
125
|
+
const currVersion = $("project>version").text();
|
|
126
|
+
return currVersion;
|
|
127
|
+
}
|
|
128
|
+
async function upgradePackageVersion(filePath, version, dry = process.env.DRY) {
|
|
129
|
+
const file = await fs__namespace.readFile(filePath, "utf-8");
|
|
130
|
+
const { amount } = detectIndent__default["default"](file);
|
|
131
|
+
const packageJson = JSON.parse(file);
|
|
132
|
+
if (!dry) {
|
|
133
|
+
packageJson.version = version;
|
|
134
|
+
await fs__namespace.writeFile(filePath, JSON.stringify(packageJson, null, amount != null ? amount : 2));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function getJSProjectVersion(filePath) {
|
|
138
|
+
const packageJson = await fs__namespace.readFile(filePath, "utf-8");
|
|
139
|
+
const { version } = JSON.parse(packageJson);
|
|
140
|
+
return version;
|
|
141
|
+
}
|
|
142
|
+
async function getRustProjectVersion(filePath) {
|
|
143
|
+
const file = await fs__namespace.readFile(filePath, "utf-8");
|
|
144
|
+
const { package: cargoPackage } = TOML__namespace.parse(file);
|
|
145
|
+
if (isJsonMap(cargoPackage)) {
|
|
146
|
+
if (cargoPackage.version) {
|
|
147
|
+
return cargoPackage.version;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function upgradeCargoVersion(filePath, version, dry = process.env.DRY) {
|
|
152
|
+
const file = await fs__namespace.readFile(filePath, "utf-8");
|
|
153
|
+
const cargoToml = TOML__namespace.parse(file);
|
|
154
|
+
if (!dry) {
|
|
155
|
+
if (isJsonMap(cargoToml.package)) {
|
|
156
|
+
if (cargoToml.package.version) {
|
|
157
|
+
cargoToml.package.version = version;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
await fs__namespace.writeFile(filePath, TOML__namespace.stringify(cargoToml));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function upgradeProjectVersion(nextVersion, projectFile, dry = process.env.DRY) {
|
|
164
|
+
switch (projectFile == null ? void 0 : projectFile.category) {
|
|
165
|
+
case "java":
|
|
166
|
+
await upgradePomVersion(projectFile.path, nextVersion, dry);
|
|
167
|
+
break;
|
|
168
|
+
case "javascript":
|
|
169
|
+
await upgradePackageVersion(projectFile.path, nextVersion, dry);
|
|
170
|
+
break;
|
|
171
|
+
case "rust":
|
|
172
|
+
await upgradeCargoVersion(projectFile.path, nextVersion, dry);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function getProjectVersion(projectFile) {
|
|
177
|
+
let projectVersion;
|
|
178
|
+
switch (projectFile == null ? void 0 : projectFile.category) {
|
|
179
|
+
case "java":
|
|
180
|
+
projectVersion = await getJavaProjectVersion(projectFile.path);
|
|
181
|
+
break;
|
|
182
|
+
case "javascript":
|
|
183
|
+
projectVersion = await getJSProjectVersion(projectFile.path);
|
|
184
|
+
break;
|
|
185
|
+
case "rust":
|
|
186
|
+
projectVersion = await getRustProjectVersion(projectFile.path);
|
|
187
|
+
}
|
|
188
|
+
return projectVersion;
|
|
189
|
+
}
|
|
190
|
+
function isVersionValid(version) {
|
|
191
|
+
return !!semver__default["default"].valid(version);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Object.defineProperty(exports, 'parseVersion', {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function () { return semver.parse; }
|
|
197
|
+
});
|
|
198
|
+
exports.findProjectFiles = findProjectFiles;
|
|
199
|
+
exports.getJSProjectVersion = getJSProjectVersion;
|
|
200
|
+
exports.getJavaProjectVersion = getJavaProjectVersion;
|
|
201
|
+
exports.getNextVersions = getNextVersions;
|
|
202
|
+
exports.getProjectVersion = getProjectVersion;
|
|
203
|
+
exports.getRustProjectVersion = getRustProjectVersion;
|
|
204
|
+
exports.isVersionValid = isVersionValid;
|
|
205
|
+
exports.upgradeCargoVersion = upgradeCargoVersion;
|
|
206
|
+
exports.upgradePackageVersion = upgradePackageVersion;
|
|
207
|
+
exports.upgradePomVersion = upgradePomVersion;
|
|
208
|
+
exports.upgradeProjectVersion = upgradeProjectVersion;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
export { parse as parseVersion } from 'semver';
|
|
3
|
+
import { PathLike } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
declare const supportedProjectCategory: readonly ["java", "javascript", "rust"];
|
|
6
|
+
declare const supportedProjectFiles: readonly ["package.json", "pom.xml", "Cargo.toml"];
|
|
7
|
+
type ProjectCategory = typeof supportedProjectCategory[number];
|
|
8
|
+
type ProjectFileName = typeof supportedProjectFiles[number];
|
|
9
|
+
type ProjectFile = {
|
|
10
|
+
/**
|
|
11
|
+
* project category
|
|
12
|
+
*/
|
|
13
|
+
category: ProjectCategory;
|
|
14
|
+
/**
|
|
15
|
+
* project file path
|
|
16
|
+
*/
|
|
17
|
+
path: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Searches for all project files in the specified directory and its subdirectories.
|
|
21
|
+
*
|
|
22
|
+
* @param dir - The directory to search in.
|
|
23
|
+
* @param excludes - The directories to exclude from the search.
|
|
24
|
+
* @return An array of file paths that match the search criteria.
|
|
25
|
+
*/
|
|
26
|
+
declare function findProjectFiles(dir?: PathLike, excludes?: string[], recursive?: boolean): Promise<ProjectFile[]>;
|
|
27
|
+
|
|
28
|
+
type VersionNumbers = {
|
|
29
|
+
nextMajor: string;
|
|
30
|
+
nextMinor: string;
|
|
31
|
+
nextPatch: string;
|
|
32
|
+
nextRelease: string;
|
|
33
|
+
nextPreMajor: string;
|
|
34
|
+
nextPreMinor: string;
|
|
35
|
+
nextPrePatch: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Generates the next versions based on the given version.
|
|
39
|
+
*
|
|
40
|
+
* @param version - Optional. The version to generate the next versions from.
|
|
41
|
+
* @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
|
|
42
|
+
* @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
|
|
43
|
+
*/
|
|
44
|
+
declare function getNextVersions(version?: string | semver.SemVer, coerce?: boolean): VersionNumbers;
|
|
45
|
+
/**
|
|
46
|
+
* Upgrades the version of the POM file.
|
|
47
|
+
*
|
|
48
|
+
* @param filePath - The path to the POM file.
|
|
49
|
+
* @param version - The new version to set.
|
|
50
|
+
* @param dry - Whether to perform a dry run or not. @default process.env.DRY
|
|
51
|
+
* @return A promise that resolves when the version upgrade is complete.
|
|
52
|
+
*/
|
|
53
|
+
declare function upgradePomVersion(filePath: PathLike, version: string, dry?: string | undefined): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the version of the Java project.
|
|
56
|
+
*
|
|
57
|
+
* @return The version of the Java project.
|
|
58
|
+
*/
|
|
59
|
+
declare function getJavaProjectVersion(filePath: PathLike): Promise<string | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Updates the version of a package in a specified file.
|
|
62
|
+
*
|
|
63
|
+
* @param filePath - The path to the file.
|
|
64
|
+
* @param version - The new version to set.
|
|
65
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
66
|
+
* @return A promise that resolves when the version is upgraded.
|
|
67
|
+
*/
|
|
68
|
+
declare function upgradePackageVersion(filePath: PathLike, version: string, dry?: string | undefined): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Reads the package.json file at the specified file path and returns the version number.
|
|
71
|
+
*
|
|
72
|
+
* @param filePath - The path to the package.json file.
|
|
73
|
+
* @return The version number as a string, or undefined if the file cannot be read or parsed.
|
|
74
|
+
*/
|
|
75
|
+
declare function getJSProjectVersion(filePath: PathLike): Promise<string | undefined>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves the version of a Rust project based on the contents of a specified file.
|
|
78
|
+
*
|
|
79
|
+
* @param filePath - The path to the file containing the Rust project details.
|
|
80
|
+
* @return The version of the Rust project, or undefined if the version is not available.
|
|
81
|
+
*/
|
|
82
|
+
declare function getRustProjectVersion(filePath: PathLike): Promise<string | undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* Upgrade the cargo version in the specified file.
|
|
85
|
+
*
|
|
86
|
+
* @param filePath - The path to the file.
|
|
87
|
+
* @param version - The version to upgrade to.
|
|
88
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
89
|
+
* @return A promise that resolves when the upgrade is complete.
|
|
90
|
+
*/
|
|
91
|
+
declare function upgradeCargoVersion(filePath: PathLike, version: string, dry?: string | undefined): Promise<void>;
|
|
92
|
+
declare function upgradeProjectVersion(nextVersion: string, projectFile?: ProjectFile, dry?: string | undefined): Promise<void>;
|
|
93
|
+
declare function getProjectVersion(projectFile: ProjectFile): Promise<string | undefined>;
|
|
94
|
+
declare function isVersionValid(version?: string): boolean;
|
|
95
|
+
|
|
96
|
+
export { ProjectCategory, ProjectFile, ProjectFileName, findProjectFiles, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isVersionValid, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
export { parse as parseVersion } from 'semver';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import * as cheerio from 'cheerio';
|
|
6
|
+
import detectIndent from 'detect-indent';
|
|
7
|
+
import * as TOML from '@iarna/toml';
|
|
8
|
+
|
|
9
|
+
function isJsonMap(obj) {
|
|
10
|
+
return typeof obj === "object" && obj !== null && !(obj instanceof Array) && !(obj instanceof Date);
|
|
11
|
+
}
|
|
12
|
+
function isBlankPath(path) {
|
|
13
|
+
return typeof path === "undefined" || path.toString().trim().length === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const supportedProjectFiles = ["package.json", "pom.xml", "Cargo.toml"];
|
|
17
|
+
const projectCategoryMap = {
|
|
18
|
+
"pom.xml": "java",
|
|
19
|
+
"package.json": "javascript",
|
|
20
|
+
"Cargo.toml": "rust"
|
|
21
|
+
// go: "go.mod",
|
|
22
|
+
};
|
|
23
|
+
async function findProjectFiles(dir, excludes, recursive = false) {
|
|
24
|
+
const files = [];
|
|
25
|
+
if (isBlankPath(dir)) {
|
|
26
|
+
return files;
|
|
27
|
+
}
|
|
28
|
+
const dirEntries = await fs.readdir(dir, { withFileTypes: true });
|
|
29
|
+
for await (const dirEntry of dirEntries) {
|
|
30
|
+
const { name: filename } = dirEntry;
|
|
31
|
+
if (excludes == null ? void 0 : excludes.includes(filename))
|
|
32
|
+
continue;
|
|
33
|
+
const filePath = path.resolve(process.cwd(), dir.toString(), filename);
|
|
34
|
+
if (recursive && dirEntry.isDirectory()) {
|
|
35
|
+
files.push(...await findProjectFiles(filePath, excludes, recursive));
|
|
36
|
+
} else if (supportedProjectFiles.includes(filename)) {
|
|
37
|
+
files.push({
|
|
38
|
+
category: projectCategoryMap[filename],
|
|
39
|
+
path: filePath
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const FALLBACK_VERSION = "undefined";
|
|
47
|
+
function getNextVersions(version, coerce = false) {
|
|
48
|
+
var _a, _b, _c, _d, _e;
|
|
49
|
+
let versionNum;
|
|
50
|
+
let id;
|
|
51
|
+
const defaultId = "alpha";
|
|
52
|
+
if (version instanceof semver.SemVer) {
|
|
53
|
+
versionNum = version.version;
|
|
54
|
+
id = `${(_a = version.prerelease[0]) != null ? _a : ""}`;
|
|
55
|
+
} else if (typeof version === "string") {
|
|
56
|
+
versionNum = coerce ? (_c = (_b = semver.coerce(version)) == null ? void 0 : _b.version) != null ? _c : version : version;
|
|
57
|
+
id = `${(_e = (_d = semver.prerelease(version)) == null ? void 0 : _d[0]) != null ? _e : ""}`;
|
|
58
|
+
} else {
|
|
59
|
+
versionNum = "0.0.0";
|
|
60
|
+
id = defaultId;
|
|
61
|
+
}
|
|
62
|
+
const nextMajor = semver.inc(versionNum, "major") || FALLBACK_VERSION;
|
|
63
|
+
const nextMinor = semver.inc(versionNum, "minor") || FALLBACK_VERSION;
|
|
64
|
+
const nextPatch = semver.inc(versionNum, "patch") || FALLBACK_VERSION;
|
|
65
|
+
const nextRelease = (id ? semver.inc(versionNum, "prerelease", id, "1") : semver.inc(versionNum, "patch")) || FALLBACK_VERSION;
|
|
66
|
+
const nextPreMajor = semver.inc(versionNum, "premajor", defaultId, "1") || FALLBACK_VERSION;
|
|
67
|
+
const nextPreMinor = semver.inc(versionNum, "preminor", defaultId, "1") || FALLBACK_VERSION;
|
|
68
|
+
const nextPrePatch = semver.inc(versionNum, "prepatch", defaultId, "1") || FALLBACK_VERSION;
|
|
69
|
+
return {
|
|
70
|
+
nextMajor,
|
|
71
|
+
nextMinor,
|
|
72
|
+
nextPatch,
|
|
73
|
+
nextRelease,
|
|
74
|
+
nextPreMajor,
|
|
75
|
+
nextPreMinor,
|
|
76
|
+
nextPrePatch
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
async function upgradePomVersion(filePath, version, dry = process.env.DRY) {
|
|
80
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
81
|
+
const $ = cheerio.load(content, {
|
|
82
|
+
xml: { decodeEntities: false }
|
|
83
|
+
});
|
|
84
|
+
const projectVersion = $("project>version");
|
|
85
|
+
const parentVersion = $("project>parent>version");
|
|
86
|
+
projectVersion == null ? void 0 : projectVersion.text(version);
|
|
87
|
+
parentVersion == null ? void 0 : parentVersion.text(version);
|
|
88
|
+
if (!dry) {
|
|
89
|
+
await fs.writeFile(filePath, $.xml());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function getJavaProjectVersion(filePath) {
|
|
93
|
+
const pom = await fs.readFile(filePath, "utf-8");
|
|
94
|
+
const $ = cheerio.load(pom);
|
|
95
|
+
const currVersion = $("project>version").text();
|
|
96
|
+
return currVersion;
|
|
97
|
+
}
|
|
98
|
+
async function upgradePackageVersion(filePath, version, dry = process.env.DRY) {
|
|
99
|
+
const file = await fs.readFile(filePath, "utf-8");
|
|
100
|
+
const { amount } = detectIndent(file);
|
|
101
|
+
const packageJson = JSON.parse(file);
|
|
102
|
+
if (!dry) {
|
|
103
|
+
packageJson.version = version;
|
|
104
|
+
await fs.writeFile(filePath, JSON.stringify(packageJson, null, amount != null ? amount : 2));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function getJSProjectVersion(filePath) {
|
|
108
|
+
const packageJson = await fs.readFile(filePath, "utf-8");
|
|
109
|
+
const { version } = JSON.parse(packageJson);
|
|
110
|
+
return version;
|
|
111
|
+
}
|
|
112
|
+
async function getRustProjectVersion(filePath) {
|
|
113
|
+
const file = await fs.readFile(filePath, "utf-8");
|
|
114
|
+
const { package: cargoPackage } = TOML.parse(file);
|
|
115
|
+
if (isJsonMap(cargoPackage)) {
|
|
116
|
+
if (cargoPackage.version) {
|
|
117
|
+
return cargoPackage.version;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function upgradeCargoVersion(filePath, version, dry = process.env.DRY) {
|
|
122
|
+
const file = await fs.readFile(filePath, "utf-8");
|
|
123
|
+
const cargoToml = TOML.parse(file);
|
|
124
|
+
if (!dry) {
|
|
125
|
+
if (isJsonMap(cargoToml.package)) {
|
|
126
|
+
if (cargoToml.package.version) {
|
|
127
|
+
cargoToml.package.version = version;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
await fs.writeFile(filePath, TOML.stringify(cargoToml));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function upgradeProjectVersion(nextVersion, projectFile, dry = process.env.DRY) {
|
|
134
|
+
switch (projectFile == null ? void 0 : projectFile.category) {
|
|
135
|
+
case "java":
|
|
136
|
+
await upgradePomVersion(projectFile.path, nextVersion, dry);
|
|
137
|
+
break;
|
|
138
|
+
case "javascript":
|
|
139
|
+
await upgradePackageVersion(projectFile.path, nextVersion, dry);
|
|
140
|
+
break;
|
|
141
|
+
case "rust":
|
|
142
|
+
await upgradeCargoVersion(projectFile.path, nextVersion, dry);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function getProjectVersion(projectFile) {
|
|
147
|
+
let projectVersion;
|
|
148
|
+
switch (projectFile == null ? void 0 : projectFile.category) {
|
|
149
|
+
case "java":
|
|
150
|
+
projectVersion = await getJavaProjectVersion(projectFile.path);
|
|
151
|
+
break;
|
|
152
|
+
case "javascript":
|
|
153
|
+
projectVersion = await getJSProjectVersion(projectFile.path);
|
|
154
|
+
break;
|
|
155
|
+
case "rust":
|
|
156
|
+
projectVersion = await getRustProjectVersion(projectFile.path);
|
|
157
|
+
}
|
|
158
|
+
return projectVersion;
|
|
159
|
+
}
|
|
160
|
+
function isVersionValid(version) {
|
|
161
|
+
return !!semver.valid(version);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { findProjectFiles, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isVersionValid, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cross-bump",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1-alpha.1",
|
|
5
|
+
"description": "cross language bump utility",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "rainbowatcher",
|
|
8
|
+
"email": "rainbow-w@qq.com",
|
|
9
|
+
"url": "https://github.com/rainbowatcher"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/rainbowatcher/cross-release/blob/main/packages/cross-bump/README.md",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/rainbowatcher/cross-release.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": "https://github.com/rainbowatcher/cross-release/issues",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"cross",
|
|
20
|
+
"bump",
|
|
21
|
+
"cross-bump",
|
|
22
|
+
"release"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"require": "./dist/index.cjs",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.mjs",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"./dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@iarna/toml": "^2.2.5",
|
|
39
|
+
"cheerio": "1.0.0-rc.12",
|
|
40
|
+
"detect-indent": "^7.0.1",
|
|
41
|
+
"semver": "^7.5.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "pkgroll"
|
|
45
|
+
}
|
|
46
|
+
}
|