raiton 3.1.0 → 3.1.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/build/bin/index.mjs +1 -1
- package/package.json +1 -1
- package/scripts/update-version.ts +41 -4
package/build/bin/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -10,6 +10,14 @@ function getLatestTag() {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
function getCurrentBranch() {
|
|
14
|
+
try {
|
|
15
|
+
return execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
|
|
16
|
+
} catch {
|
|
17
|
+
return "main";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
function getCommitsSince(tag: string | null) {
|
|
14
22
|
const range = tag ? `${tag}..HEAD` : "HEAD";
|
|
15
23
|
try {
|
|
@@ -51,11 +59,21 @@ function determineIncrement(commits: string[]) {
|
|
|
51
59
|
return increment;
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
function updateVersion(increment: "major" | "minor" | "patch") {
|
|
62
|
+
function updateVersion(increment: "major" | "minor" | "patch", branch: string) {
|
|
55
63
|
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
56
64
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
57
65
|
const currentVersion = packageJson.version;
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
// Identification du suffixe de branche (alpha, beta, rc)
|
|
68
|
+
let preReleaseType: string | null = null;
|
|
69
|
+
if (branch.startsWith("alpha")) preReleaseType = "alpha";
|
|
70
|
+
else if (branch.startsWith("beta")) preReleaseType = "beta";
|
|
71
|
+
else if (branch.startsWith("rc")) preReleaseType = "rc";
|
|
72
|
+
|
|
73
|
+
// Extraction de la version de base et de la pre-release
|
|
74
|
+
// Format: major.minor.patch-type.num
|
|
75
|
+
const [versionPart, preReleasePart] = currentVersion.split("-");
|
|
76
|
+
const [major, minor, patch] = versionPart.split(".").map(Number);
|
|
59
77
|
|
|
60
78
|
let nextVersion = "";
|
|
61
79
|
if (increment === "major") {
|
|
@@ -66,9 +84,27 @@ function updateVersion(increment: "major" | "minor" | "patch") {
|
|
|
66
84
|
nextVersion = `${major}.${minor}.${patch + 1}`;
|
|
67
85
|
}
|
|
68
86
|
|
|
87
|
+
// Si nous sommes sur une branche de pre-release
|
|
88
|
+
if (preReleaseType) {
|
|
89
|
+
let preReleaseCount = 0;
|
|
90
|
+
if (preReleasePart && preReleasePart.startsWith(preReleaseType)) {
|
|
91
|
+
// Si on était déjà sur le même type de pre-release, on incrémente le compteur
|
|
92
|
+
// Si la version de base a changé suite à l'incrément, on repart à 0 ?
|
|
93
|
+
// Généralement si on fait un "feat" sur une branche alpha, on incrémente le patch ou le minor
|
|
94
|
+
// MAIS on garde le suffixe alpha.
|
|
95
|
+
const match = preReleasePart.match(/\d+$/);
|
|
96
|
+
preReleaseCount = match ? parseInt(match[0], 10) + 1 : 0;
|
|
97
|
+
|
|
98
|
+
// Si la version de base a été incrémentée, on pourrait vouloir repartir de 0,
|
|
99
|
+
// mais ici on suit la logique demandée : ajouter le nom de la branche.
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
nextVersion = `${nextVersion}-${preReleaseType}.${preReleaseCount}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
69
105
|
packageJson.version = nextVersion;
|
|
70
106
|
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
71
|
-
console.log(`Version updated from ${currentVersion} to ${nextVersion}`);
|
|
107
|
+
console.log(`Version updated from ${currentVersion} to ${nextVersion} (branch: ${branch})`);
|
|
72
108
|
return nextVersion;
|
|
73
109
|
}
|
|
74
110
|
|
|
@@ -91,7 +127,8 @@ function main() {
|
|
|
91
127
|
}
|
|
92
128
|
|
|
93
129
|
console.log(`Determined increment: ${increment}`);
|
|
94
|
-
|
|
130
|
+
const branch = getCurrentBranch();
|
|
131
|
+
updateVersion(increment, branch);
|
|
95
132
|
}
|
|
96
133
|
|
|
97
134
|
main();
|