cross-bump 0.1.0 → 0.2.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/dist/index.d.ts +65 -53
- package/dist/index.js +255 -210
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { PathLike } from
|
|
2
|
-
import semver from
|
|
3
|
-
export { parse as parseVersion } from 'semver';
|
|
1
|
+
import { PathLike } from "node:fs";
|
|
2
|
+
import semver, { parse as parseVersion } from "semver";
|
|
4
3
|
|
|
4
|
+
//#region src/ignore.d.ts
|
|
5
5
|
declare const DEFAULT_IGNORED_GLOBS: string[];
|
|
6
6
|
declare const G_GITIGNORE = "**/.gitignore";
|
|
7
|
-
declare function getGitignores(cwd
|
|
7
|
+
declare function getGitignores(cwd?: string, ignoreGlobs?: string[]): Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* parse gitignore to globs
|
|
10
|
+
* @param content gitignore file content
|
|
11
|
+
*/
|
|
12
|
+
declare function parseGitingore(content: string): string[];
|
|
8
13
|
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/project.d.ts
|
|
9
16
|
declare const supportedProjectCategory: readonly ["java", "javascript", "rust"];
|
|
10
17
|
declare const supportedProjectFiles: readonly ["package.json", "pom.xml", "Cargo.toml"];
|
|
11
18
|
declare const supportedProjectGlobs: string[];
|
|
@@ -22,17 +29,21 @@ type ProjectFile = {
|
|
|
22
29
|
path: string;
|
|
23
30
|
};
|
|
24
31
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
* Searches for all project files in the specified directory and its subdirectories.
|
|
33
|
+
*
|
|
34
|
+
* @param dir - The directory to search in.
|
|
35
|
+
* @param ignore - The directories to exclude from the search.
|
|
36
|
+
* @param recursive - Whether to recursively search. @default false
|
|
37
|
+
* @return An array of file paths that match the search criteria.
|
|
38
|
+
*/
|
|
32
39
|
declare function findProjectFiles(cwd?: string, ignore?: string[], recursive?: boolean): ProjectFile[];
|
|
33
40
|
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/util.d.ts
|
|
34
43
|
declare function isBlankPath(path?: PathLike): path is "" | undefined;
|
|
35
44
|
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/version.d.ts
|
|
36
47
|
type VersionNumbers = {
|
|
37
48
|
nextMajor: string;
|
|
38
49
|
nextMinor: string;
|
|
@@ -47,62 +58,63 @@ type UpgradeOptions = {
|
|
|
47
58
|
finalNewline?: boolean;
|
|
48
59
|
};
|
|
49
60
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
* Generates the next versions based on the given version.
|
|
62
|
+
*
|
|
63
|
+
* @param version - Optional. The version to generate the next versions from.
|
|
64
|
+
* @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
|
|
65
|
+
* @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
|
|
66
|
+
*/
|
|
56
67
|
declare function getNextVersions(version?: semver.SemVer | string, coerce?: boolean): VersionNumbers;
|
|
57
68
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
* Upgrades the version of the POM file.
|
|
70
|
+
*
|
|
71
|
+
* @param filePath - The path to the POM file.
|
|
72
|
+
* @param version - The new version to set.
|
|
73
|
+
* @param dry - Whether to perform a dry run or not. @default process.env.DRY
|
|
74
|
+
* @return A promise that resolves when the version upgrade is complete.
|
|
75
|
+
*/
|
|
65
76
|
declare function upgradePomVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
|
|
66
77
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
* Retrieves the version of the Java project.
|
|
79
|
+
*
|
|
80
|
+
* @return The version of the Java project.
|
|
81
|
+
*/
|
|
71
82
|
declare function getJavaProjectVersion(filePath: PathLike): string | undefined;
|
|
72
83
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
* Updates the version of a package in a specified file.
|
|
85
|
+
*
|
|
86
|
+
* @param filePath - The path to the file.
|
|
87
|
+
* @param version - The new version to set.
|
|
88
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
89
|
+
* @return A promise that resolves when the version is upgraded.
|
|
90
|
+
*/
|
|
80
91
|
declare function upgradePackageVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
|
|
81
92
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
* Reads the package.json file at the specified file path and returns the version number.
|
|
94
|
+
*
|
|
95
|
+
* @param filePath - The path to the package.json file.
|
|
96
|
+
* @return The version number as a string, or undefined if the file cannot be read or parsed.
|
|
97
|
+
*/
|
|
87
98
|
declare function getJSProjectVersion(filePath: PathLike): string | undefined;
|
|
88
99
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
100
|
+
* Retrieves the version of a Rust project based on the contents of a specified file.
|
|
101
|
+
*
|
|
102
|
+
* @param filePath - The path to the file containing the Rust project details.
|
|
103
|
+
* @return The version of the Rust project, or undefined if the version is not available.
|
|
104
|
+
*/
|
|
94
105
|
declare function getRustProjectVersion(filePath: PathLike): Promise<string | undefined>;
|
|
95
106
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
* Upgrade the cargo version in the specified file.
|
|
108
|
+
*
|
|
109
|
+
* @param filePath - The path to the file.
|
|
110
|
+
* @param version - The version to upgrade to.
|
|
111
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
112
|
+
* @return A promise that resolves when the upgrade is complete.
|
|
113
|
+
*/
|
|
103
114
|
declare function upgradeCargoVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): Promise<void>;
|
|
104
115
|
declare function upgradeProjectVersion(nextVersion: string, projectFile?: ProjectFile, opts?: UpgradeOptions): Promise<void>;
|
|
105
116
|
declare function getProjectVersion(projectFile: ProjectFile): Promise<string | undefined>;
|
|
106
117
|
declare function isVersionValid(version?: string): boolean;
|
|
107
118
|
|
|
108
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
export { DEFAULT_IGNORED_GLOBS, G_GITIGNORE, ProjectCategory, ProjectFile, ProjectFileName, findProjectFiles, getGitignores, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isBlankPath, isVersionValid, parseGitingore, parseVersion, supportedProjectCategory, supportedProjectFiles, supportedProjectGlobs, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
|
package/dist/index.js
CHANGED
|
@@ -1,242 +1,287 @@
|
|
|
1
|
-
|
|
1
|
+
import * as fs$1 from "node:fs";
|
|
2
|
+
import fs, { readFileSync } from "node:fs";
|
|
2
3
|
import fg from "fast-glob";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import isGlob from "is-glob";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
import initTomlEdit, { edit, parse } from "@rainbowatcher/toml-edit-js";
|
|
8
|
+
import * as cheerio from "cheerio";
|
|
9
|
+
import detectIndent from "detect-indent";
|
|
10
|
+
import semver, { parse as parseVersion } from "semver";
|
|
11
|
+
|
|
12
|
+
//#region src/ignore.ts
|
|
13
|
+
const DEFAULT_IGNORED_GLOBS = [
|
|
14
|
+
"**/node_modules/**",
|
|
15
|
+
"**/.git/**",
|
|
16
|
+
"**/target/**",
|
|
17
|
+
"**/build/**",
|
|
18
|
+
"**/dist/**"
|
|
19
|
+
];
|
|
20
|
+
const G_GITIGNORE = "**/.gitignore";
|
|
6
21
|
function getGitignores(cwd, ignoreGlobs = DEFAULT_IGNORED_GLOBS) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const gitignores = fg.sync(G_GITIGNORE, {
|
|
23
|
+
absolute: true,
|
|
24
|
+
cwd,
|
|
25
|
+
ignore: ignoreGlobs,
|
|
26
|
+
onlyFiles: true
|
|
27
|
+
});
|
|
28
|
+
const set = new Set();
|
|
29
|
+
for (const gi of gitignores) {
|
|
30
|
+
const rules = readFileSync(gi, { encoding: "utf8" });
|
|
31
|
+
const globs = parseGitingore(rules);
|
|
32
|
+
if (globs.length === 0) continue;
|
|
33
|
+
for (const item of globs) set.add(item);
|
|
34
|
+
}
|
|
35
|
+
return set;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* parse gitignore to globs
|
|
39
|
+
* @param content gitignore file content
|
|
40
|
+
*/
|
|
41
|
+
function parseGitingore(content) {
|
|
42
|
+
const globs = [];
|
|
43
|
+
const lines = content.split(/\r\n?|\n/);
|
|
44
|
+
for (const rawLine of lines) {
|
|
45
|
+
const line = rawLine.trim();
|
|
46
|
+
if (line.startsWith("#") || line.length === 0) continue;
|
|
47
|
+
let isNegative = false;
|
|
48
|
+
let pattern = line;
|
|
49
|
+
if (pattern.startsWith("!")) {
|
|
50
|
+
isNegative = true;
|
|
51
|
+
pattern = pattern.slice(1);
|
|
52
|
+
}
|
|
53
|
+
if (isGlob(pattern)) {
|
|
54
|
+
globs.push(isNegative ? `!${pattern}` : pattern);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (pattern.endsWith("/")) {
|
|
58
|
+
const dirPattern = pattern.slice(0, -1);
|
|
59
|
+
globs.push(isNegative ? `!**/${dirPattern}/**` : `**/${dirPattern}/**`);
|
|
60
|
+
} else if (pattern.startsWith("/")) {
|
|
61
|
+
const rootPattern = pattern.slice(1);
|
|
62
|
+
globs.push(isNegative ? `!${rootPattern}` : rootPattern, isNegative ? `!${rootPattern}/**` : `${rootPattern}/**`);
|
|
63
|
+
} else globs.push(isNegative ? `!**/${pattern}` : `**/${pattern}`, isNegative ? `!**/${pattern}/**` : `**/${pattern}/**`);
|
|
64
|
+
}
|
|
65
|
+
return globs;
|
|
22
66
|
}
|
|
23
67
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// src/util.ts
|
|
30
|
-
function isBlankPath(path2) {
|
|
31
|
-
return path2 === void 0 || path2.toString().trim().length === 0;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/util.ts
|
|
70
|
+
function isBlankPath(path$1) {
|
|
71
|
+
return path$1 === void 0 || path$1.toString().trim().length === 0;
|
|
32
72
|
}
|
|
33
73
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/project.ts
|
|
76
|
+
const supportedProjectCategory = [
|
|
77
|
+
"java",
|
|
78
|
+
"javascript",
|
|
79
|
+
"rust"
|
|
40
80
|
];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
const supportedProjectFiles = [
|
|
82
|
+
"package.json",
|
|
83
|
+
"pom.xml",
|
|
84
|
+
"Cargo.toml"
|
|
85
|
+
];
|
|
86
|
+
const supportedProjectGlobs = supportedProjectFiles.map((f) => `**/${f}`);
|
|
87
|
+
const projectCategoryMap = {
|
|
88
|
+
"Cargo.toml": "rust",
|
|
89
|
+
"package.json": "javascript",
|
|
90
|
+
"pom.xml": "java"
|
|
48
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Searches for all project files in the specified directory and its subdirectories.
|
|
94
|
+
*
|
|
95
|
+
* @param dir - The directory to search in.
|
|
96
|
+
* @param ignore - The directories to exclude from the search.
|
|
97
|
+
* @param recursive - Whether to recursively search. @default false
|
|
98
|
+
* @return An array of file paths that match the search criteria.
|
|
99
|
+
*/
|
|
49
100
|
function findProjectFiles(cwd, ignore = [], recursive = false) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
path: f
|
|
64
|
-
}));
|
|
101
|
+
const files = [];
|
|
102
|
+
if (isBlankPath(cwd)) return files;
|
|
103
|
+
const projectFiles = fg.sync(supportedProjectGlobs, {
|
|
104
|
+
absolute: true,
|
|
105
|
+
cwd,
|
|
106
|
+
deep: recursive ? Infinity : 1,
|
|
107
|
+
fs,
|
|
108
|
+
ignore
|
|
109
|
+
});
|
|
110
|
+
return projectFiles.map((f) => ({
|
|
111
|
+
category: projectCategoryMap[path.basename(f)],
|
|
112
|
+
path: f
|
|
113
|
+
}));
|
|
65
114
|
}
|
|
66
115
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/version.ts
|
|
118
|
+
const FALLBACK_VERSION = "undefined";
|
|
119
|
+
/**
|
|
120
|
+
* Generates the next versions based on the given version.
|
|
121
|
+
*
|
|
122
|
+
* @param version - Optional. The version to generate the next versions from.
|
|
123
|
+
* @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
|
|
124
|
+
* @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
|
|
125
|
+
*/
|
|
75
126
|
function getNextVersions(version, coerce = false) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
127
|
+
let versionNum;
|
|
128
|
+
let id;
|
|
129
|
+
const defaultId = "alpha";
|
|
130
|
+
if (version instanceof semver.SemVer) {
|
|
131
|
+
versionNum = version.version;
|
|
132
|
+
id = `${version.prerelease[0] ?? ""}`;
|
|
133
|
+
} else if (typeof version === "string") {
|
|
134
|
+
versionNum = coerce ? semver.coerce(version)?.version ?? version : version;
|
|
135
|
+
id = `${semver.prerelease(version)?.[0] ?? ""}`;
|
|
136
|
+
} else {
|
|
137
|
+
versionNum = "0.0.0";
|
|
138
|
+
id = defaultId;
|
|
139
|
+
}
|
|
140
|
+
const nextMajor = semver.inc(versionNum, "major") ?? FALLBACK_VERSION;
|
|
141
|
+
const nextMinor = semver.inc(versionNum, "minor") ?? FALLBACK_VERSION;
|
|
142
|
+
const nextPatch = semver.inc(versionNum, "patch") ?? FALLBACK_VERSION;
|
|
143
|
+
const nextRelease = (id ? semver.inc(versionNum, "prerelease", id, "1") : semver.inc(versionNum, "patch")) ?? FALLBACK_VERSION;
|
|
144
|
+
const nextPreMajor = semver.inc(versionNum, "premajor", defaultId, "1") ?? FALLBACK_VERSION;
|
|
145
|
+
const nextPreMinor = semver.inc(versionNum, "preminor", defaultId, "1") ?? FALLBACK_VERSION;
|
|
146
|
+
const nextPrePatch = semver.inc(versionNum, "prepatch", defaultId, "1") ?? FALLBACK_VERSION;
|
|
147
|
+
return {
|
|
148
|
+
nextMajor,
|
|
149
|
+
nextMinor,
|
|
150
|
+
nextPatch,
|
|
151
|
+
nextPreMajor,
|
|
152
|
+
nextPreMinor,
|
|
153
|
+
nextPrePatch,
|
|
154
|
+
nextRelease
|
|
155
|
+
};
|
|
105
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Upgrades the version of the POM file.
|
|
159
|
+
*
|
|
160
|
+
* @param filePath - The path to the POM file.
|
|
161
|
+
* @param version - The new version to set.
|
|
162
|
+
* @param dry - Whether to perform a dry run or not. @default process.env.DRY
|
|
163
|
+
* @return A promise that resolves when the version upgrade is complete.
|
|
164
|
+
*/
|
|
106
165
|
function upgradePomVersion(filePath, version, opts = {}) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
projectVersion?.text(version);
|
|
118
|
-
parentVersion?.text(version);
|
|
119
|
-
let newXml = $.xml().trimEnd();
|
|
120
|
-
if (finalNewline) {
|
|
121
|
-
newXml += "\n";
|
|
122
|
-
}
|
|
123
|
-
if (!dry) {
|
|
124
|
-
fs2.writeFileSync(filePath, newXml);
|
|
125
|
-
}
|
|
166
|
+
const { dry = process.env.DRY, finalNewline = true } = opts;
|
|
167
|
+
const content = fs$1.readFileSync(filePath, "utf8");
|
|
168
|
+
const $ = cheerio.load(content, { xml: { decodeEntities: false } });
|
|
169
|
+
const projectVersion = $("project>version");
|
|
170
|
+
const parentVersion = $("project>parent>version");
|
|
171
|
+
projectVersion?.text(version);
|
|
172
|
+
parentVersion?.text(version);
|
|
173
|
+
let newXml = $.xml().trimEnd();
|
|
174
|
+
if (finalNewline) newXml += "\n";
|
|
175
|
+
if (!dry) fs$1.writeFileSync(filePath, newXml);
|
|
126
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Retrieves the version of the Java project.
|
|
179
|
+
*
|
|
180
|
+
* @return The version of the Java project.
|
|
181
|
+
*/
|
|
127
182
|
function getJavaProjectVersion(filePath) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
183
|
+
const pom = fs$1.readFileSync(filePath, "utf8");
|
|
184
|
+
const $ = cheerio.load(pom);
|
|
185
|
+
const currVersion = $("project>version").text();
|
|
186
|
+
return currVersion;
|
|
132
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Updates the version of a package in a specified file.
|
|
190
|
+
*
|
|
191
|
+
* @param filePath - The path to the file.
|
|
192
|
+
* @param version - The new version to set.
|
|
193
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
194
|
+
* @return A promise that resolves when the version is upgraded.
|
|
195
|
+
*/
|
|
133
196
|
function upgradePackageVersion(filePath, version, opts = {}) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
let newPkgJson = JSON.stringify(packageJson, null, indent);
|
|
144
|
-
if (finalNewline) {
|
|
145
|
-
newPkgJson += "\n";
|
|
146
|
-
}
|
|
147
|
-
if (!dry) {
|
|
148
|
-
fs2.writeFileSync(filePath, newPkgJson);
|
|
149
|
-
}
|
|
197
|
+
const { dry = process.env.DRY, finalNewline = true } = opts;
|
|
198
|
+
const file = fs$1.readFileSync(filePath, "utf8");
|
|
199
|
+
const { amount } = detectIndent(file);
|
|
200
|
+
const packageJson = JSON.parse(file);
|
|
201
|
+
const indent = amount ?? 2;
|
|
202
|
+
packageJson.version = version;
|
|
203
|
+
let newPkgJson = JSON.stringify(packageJson, null, indent);
|
|
204
|
+
if (finalNewline) newPkgJson += "\n";
|
|
205
|
+
if (!dry) fs$1.writeFileSync(filePath, newPkgJson);
|
|
150
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Reads the package.json file at the specified file path and returns the version number.
|
|
209
|
+
*
|
|
210
|
+
* @param filePath - The path to the package.json file.
|
|
211
|
+
* @return The version number as a string, or undefined if the file cannot be read or parsed.
|
|
212
|
+
*/
|
|
151
213
|
function getJSProjectVersion(filePath) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
214
|
+
const packageJson = fs$1.readFileSync(filePath, "utf8");
|
|
215
|
+
const { version } = JSON.parse(packageJson);
|
|
216
|
+
return version;
|
|
155
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Retrieves the version of a Rust project based on the contents of a specified file.
|
|
220
|
+
*
|
|
221
|
+
* @param filePath - The path to the file containing the Rust project details.
|
|
222
|
+
* @return The version of the Rust project, or undefined if the version is not available.
|
|
223
|
+
*/
|
|
156
224
|
async function getRustProjectVersion(filePath) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return cargoPackage.version;
|
|
162
|
-
}
|
|
225
|
+
const file = fs$1.readFileSync(filePath, "utf8");
|
|
226
|
+
await initTomlEdit({});
|
|
227
|
+
const { package: cargoPackage } = parse(file);
|
|
228
|
+
if (cargoPackage?.version) return cargoPackage.version;
|
|
163
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Upgrade the cargo version in the specified file.
|
|
232
|
+
*
|
|
233
|
+
* @param filePath - The path to the file.
|
|
234
|
+
* @param version - The version to upgrade to.
|
|
235
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
236
|
+
* @return A promise that resolves when the upgrade is complete.
|
|
237
|
+
*/
|
|
164
238
|
async function upgradeCargoVersion(filePath, version, opts = {}) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
if (workspace?.package?.version && typeof workspace.package.version === "string") {
|
|
178
|
-
newCargoFile = edit(newCargoFile, "workspace.package.version", version);
|
|
179
|
-
}
|
|
180
|
-
fs2.writeFileSync(filePath, newCargoFile);
|
|
181
|
-
}
|
|
239
|
+
const { dry = process.env.DRY } = opts;
|
|
240
|
+
await initTomlEdit({});
|
|
241
|
+
const cargoFile = fs$1.readFileSync(filePath, "utf8");
|
|
242
|
+
const cargoToml = parse(cargoFile);
|
|
243
|
+
let newCargoFile = cargoFile;
|
|
244
|
+
const { package: cargoPackage, workspace } = cargoToml;
|
|
245
|
+
if (!dry) {
|
|
246
|
+
if (cargoPackage?.version && typeof cargoPackage.version === "string") newCargoFile = edit(cargoFile, "package.version", version);
|
|
247
|
+
if (workspace?.package?.version && typeof workspace.package.version === "string") newCargoFile = edit(newCargoFile, "workspace.package.version", version);
|
|
248
|
+
fs$1.writeFileSync(filePath, newCargoFile);
|
|
249
|
+
}
|
|
182
250
|
}
|
|
183
251
|
async function upgradeProjectVersion(nextVersion, projectFile, opts = {}) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
252
|
+
switch (projectFile?.category) {
|
|
253
|
+
case "java": {
|
|
254
|
+
upgradePomVersion(projectFile.path, nextVersion, opts);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
case "javascript": {
|
|
258
|
+
upgradePackageVersion(projectFile.path, nextVersion, opts);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "rust": {
|
|
262
|
+
await upgradeCargoVersion(projectFile.path, nextVersion, opts);
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
198
266
|
}
|
|
199
267
|
async function getProjectVersion(projectFile) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
return projectVersion;
|
|
268
|
+
let projectVersion;
|
|
269
|
+
switch (projectFile?.category) {
|
|
270
|
+
case "java": {
|
|
271
|
+
projectVersion = getJavaProjectVersion(projectFile.path);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "javascript": {
|
|
275
|
+
projectVersion = getJSProjectVersion(projectFile.path);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
case "rust": projectVersion = await getRustProjectVersion(projectFile.path);
|
|
279
|
+
}
|
|
280
|
+
return projectVersion;
|
|
215
281
|
}
|
|
216
282
|
function isVersionValid(version) {
|
|
217
|
-
|
|
283
|
+
return !!semver.valid(version);
|
|
218
284
|
}
|
|
219
285
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
export {
|
|
223
|
-
DEFAULT_IGNORED_GLOBS,
|
|
224
|
-
G_GITIGNORE,
|
|
225
|
-
findProjectFiles,
|
|
226
|
-
getGitignores,
|
|
227
|
-
getJSProjectVersion,
|
|
228
|
-
getJavaProjectVersion,
|
|
229
|
-
getNextVersions,
|
|
230
|
-
getProjectVersion,
|
|
231
|
-
getRustProjectVersion,
|
|
232
|
-
isBlankPath,
|
|
233
|
-
isVersionValid,
|
|
234
|
-
parse2 as parseVersion,
|
|
235
|
-
supportedProjectCategory,
|
|
236
|
-
supportedProjectFiles,
|
|
237
|
-
supportedProjectGlobs,
|
|
238
|
-
upgradeCargoVersion,
|
|
239
|
-
upgradePackageVersion,
|
|
240
|
-
upgradePomVersion,
|
|
241
|
-
upgradeProjectVersion
|
|
242
|
-
};
|
|
286
|
+
//#endregion
|
|
287
|
+
export { DEFAULT_IGNORED_GLOBS, G_GITIGNORE, findProjectFiles, getGitignores, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isBlankPath, isVersionValid, parseGitingore, parseVersion, supportedProjectCategory, supportedProjectFiles, supportedProjectGlobs, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-bump",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "cross language bump utility",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "rainbowatcher",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"@rainbowatcher/toml-edit-js": "^0.2.1",
|
|
38
38
|
"cheerio": "1.0.0",
|
|
39
39
|
"detect-indent": "^7.0.1",
|
|
40
|
-
"fast-glob": "^3.3.
|
|
41
|
-
"
|
|
42
|
-
"semver": "^7.
|
|
40
|
+
"fast-glob": "^3.3.3",
|
|
41
|
+
"is-glob": "^4.0.3",
|
|
42
|
+
"semver": "^7.7.1"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf dist/*",
|
|
46
|
-
"build": "
|
|
46
|
+
"build": "tsdown"
|
|
47
47
|
}
|
|
48
48
|
}
|