raiton 6.1.1-beta.5 → 6.3.0-beta.10
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 +24 -0
- package/build/bin/index.mjs +25 -1183
- package/docs/contributors/README.md +8 -1
- package/package.json +2 -2
- package/scripts/postinstall.ts +42 -0
- package/scripts/update-version.ts +532 -123
- package/source/core/injection/injection.ts +1 -1
- package/source/core/router/matcher.ts +16 -4
|
@@ -1,135 +1,544 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {execSync} from "node:child_process";
|
|
3
|
+
import {readFileSync, writeFileSync, existsSync} from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type Increment = "major" | "minor" | "patch";
|
|
7
|
+
|
|
8
|
+
const INCREMENT_PRIORITY: Record<Increment, number> = {
|
|
9
|
+
patch: 1,
|
|
10
|
+
minor: 2,
|
|
11
|
+
major: 3,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface CliOptions {
|
|
15
|
+
dryRun: boolean;
|
|
16
|
+
json: boolean;
|
|
17
|
+
cwd: string;
|
|
18
|
+
allowNonConventional: boolean;
|
|
19
|
+
noTag: boolean;
|
|
20
|
+
base?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parseArgs(argv: string[]): CliOptions {
|
|
24
|
+
const baseIndex = argv.indexOf("--base");
|
|
25
|
+
const base = baseIndex !== -1 ? argv[baseIndex + 1] : undefined;
|
|
26
|
+
return {
|
|
27
|
+
dryRun: argv.includes("--dry-run"),
|
|
28
|
+
json: argv.includes("--json"),
|
|
29
|
+
allowNonConventional: argv.includes("--allow-non-conventional"),
|
|
30
|
+
noTag: argv.includes("--no-tag"),
|
|
31
|
+
base,
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function run(command: string): string {
|
|
37
|
+
return execSync(command, {stdio: ["ignore", "pipe", "ignore"]}).toString().trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getUpstreamRef(): string | null {
|
|
41
|
+
try {
|
|
42
|
+
return run("git rev-parse --abbrev-ref --symbolic-full-name @{u}");
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getCurrentBranch(): string {
|
|
49
|
+
try {
|
|
50
|
+
return (
|
|
51
|
+
process.env.CI_BRANCH ||
|
|
52
|
+
process.env.GITHUB_REF_NAME ||
|
|
53
|
+
run("git rev-parse --abbrev-ref HEAD")
|
|
54
|
+
);
|
|
55
|
+
} catch {
|
|
56
|
+
return "main";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface CommitInfo {
|
|
61
|
+
hash: string;
|
|
62
|
+
subject: string;
|
|
63
|
+
body: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getCommitsInRange(range: string): CommitInfo[] {
|
|
67
|
+
const SEP = "\u0000";
|
|
68
|
+
const END = "\u0001";
|
|
69
|
+
try {
|
|
70
|
+
const output = run(`git log ${range} --format=%H%x00%s%x00%b%x01`);
|
|
71
|
+
if (!output) return [];
|
|
72
|
+
return output
|
|
73
|
+
.split(END)
|
|
74
|
+
.map((entry) => entry.replace(/^\n/, "").trim())
|
|
75
|
+
.filter(Boolean)
|
|
76
|
+
.map((entry) => {
|
|
77
|
+
const [hash, subject, body = ""] = entry.split(SEP);
|
|
78
|
+
return {
|
|
79
|
+
hash: hash?.trim() || "",
|
|
80
|
+
subject: subject?.trim() || "",
|
|
81
|
+
body: body.trim(),
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
} catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface VersionRange {
|
|
90
|
+
base: string | null;
|
|
91
|
+
label: string | null;
|
|
92
|
+
commits: CommitInfo[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Correspond aux tags de release de type "vX.Y.Z..." ou "vX.Y.Z-beta.N"...
|
|
96
|
+
const RELEASE_TAG_RE = /^v?\d+\.\d+\.\d+/;
|
|
97
|
+
|
|
98
|
+
function getLastReleaseTag(): string | null {
|
|
99
|
+
try {
|
|
100
|
+
// Tag le plus récent atteignable depuis HEAD
|
|
101
|
+
const tag = run("git describe --tags --abbrev=0");
|
|
102
|
+
return tag && RELEASE_TAG_RE.test(tag) ? tag : null;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getRepoUrl(): string {
|
|
109
|
+
try {
|
|
110
|
+
const url = run("git config --get remote.origin.url");
|
|
111
|
+
return url.replace(/\.git$/, "").trim();
|
|
112
|
+
} catch {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function commitUrl(repoUrl: string, hash: string): string {
|
|
118
|
+
if (!repoUrl) return `${hash.slice(0, 7)}`;
|
|
119
|
+
return `[${hash.slice(0, 7)}](${repoUrl}/commit/${hash})`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getCommitsSinceTag(tag: string): CommitInfo[] {
|
|
123
|
+
// Commit d'ancêtre commun le plus récent entre le tag et HEAD,
|
|
124
|
+
// pour ne prendre que les commits réellement nouveaux depuis le tag.
|
|
125
|
+
try {
|
|
126
|
+
const mergeBase = run(`git merge-base "${tag}" HEAD`);
|
|
127
|
+
return getCommitsInRange(`${mergeBase}..HEAD`);
|
|
128
|
+
} catch {
|
|
129
|
+
return getCommitsInRange(`${tag}..HEAD`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function getAllCommits(): CommitInfo[] {
|
|
134
|
+
return getCommitsInRange("--root HEAD");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Détection de la base de comparaison, par ordre de pertinence :
|
|
139
|
+
* 1. --base explicite
|
|
140
|
+
* 2. dernier tag de release atteignable (détermine réellement les nouveaux commits)
|
|
141
|
+
* 3. branche amont (commits non poussés)
|
|
142
|
+
* 4. historique complet (aucune base configurée)
|
|
143
|
+
*/
|
|
144
|
+
function getCommitsForVersion(
|
|
145
|
+
baseOverride?: string
|
|
146
|
+
): VersionRange {
|
|
147
|
+
if (baseOverride) {
|
|
148
|
+
return {base: baseOverride, label: "base explicite (--base)", commits: getCommitsInRange(`${baseOverride}..HEAD`)};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const tag = getLastReleaseTag();
|
|
152
|
+
if (tag) {
|
|
153
|
+
return {base: tag, label: "dernier tag de release", commits: getCommitsSinceTag(tag)};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const upstream = getUpstreamRef();
|
|
157
|
+
if (upstream) {
|
|
158
|
+
return {base: upstream, label: "branche amont (commits non poussés)", commits: getCommitsInRange(`${upstream}..HEAD`)};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {base: null, label: "historique complet", commits: getAllCommits()};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
const CONVENTIONAL_COMMIT_RE = /^(?<type>[a-zA-Z]+)(\((?<scope>[^)]+)\))?(?<breaking>!)?:\s*(?<description>.+)$/;
|
|
166
|
+
|
|
167
|
+
const MERGE_COMMIT_RE = /^Merge (pull request|branch|remote-tracking branch)/i;
|
|
168
|
+
const MINOR_TYPES = new Set(["feat", "feature", "deprecate"]);
|
|
169
|
+
const PATCH_TYPES = new Set(["fix", "refactor", "perf", "remove", "revert", "chore", "docs"]);
|
|
170
|
+
|
|
171
|
+
function isConventional(commit: CommitInfo): boolean {
|
|
172
|
+
if (MERGE_COMMIT_RE.test(commit.subject)) return true;
|
|
173
|
+
return CONVENTIONAL_COMMIT_RE.test(commit.subject.trim());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface ValidationResult {
|
|
177
|
+
valid: CommitInfo[];
|
|
178
|
+
invalid: CommitInfo[];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function validateCommits(commits: CommitInfo[]): ValidationResult {
|
|
182
|
+
const valid: CommitInfo[] = [];
|
|
183
|
+
const invalid: CommitInfo[] = [];
|
|
184
|
+
for (const commit of commits) {
|
|
185
|
+
(isConventional(commit) ? valid : invalid).push(commit);
|
|
186
|
+
}
|
|
187
|
+
return {valid, invalid};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function classifyCommit(commit: CommitInfo): Increment | null {
|
|
191
|
+
const subject = commit.subject.trim();
|
|
192
|
+
const body = commit.body.trim();
|
|
193
|
+
const fullText = `${subject}\n${body}`;
|
|
194
|
+
|
|
195
|
+
if (/^BREAKING[ -]CHANGE:/im.test(fullText)) {
|
|
196
|
+
return "major";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const match = subject.match(CONVENTIONAL_COMMIT_RE);
|
|
200
|
+
if (!match?.groups) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const {type, breaking} = match.groups;
|
|
205
|
+
const normalizedType = type?.toLowerCase() || '';
|
|
206
|
+
|
|
207
|
+
if (breaking === "!") return "major";
|
|
208
|
+
if (MINOR_TYPES.has(normalizedType)) return "minor";
|
|
209
|
+
if (PATCH_TYPES.has(normalizedType)) return "patch";
|
|
210
|
+
|
|
9
211
|
return null;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function determineIncrement(commits: CommitInfo[]): Increment | null {
|
|
215
|
+
let result: Increment | null = null;
|
|
216
|
+
|
|
217
|
+
for (const commit of commits) {
|
|
218
|
+
const increment = classifyCommit(commit);
|
|
219
|
+
if (!increment) continue;
|
|
220
|
+
if (increment === "major") return "major";
|
|
221
|
+
if (!result || INCREMENT_PRIORITY[increment] > INCREMENT_PRIORITY[result]) {
|
|
222
|
+
result = increment;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return result;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type ChangelogSection = "breaking" | "features" | "bugfixes" | "others";
|
|
230
|
+
|
|
231
|
+
function sectionForCommit(commit: CommitInfo): ChangelogSection {
|
|
232
|
+
const subject = commit.subject.trim();
|
|
233
|
+
const body = commit.body.trim();
|
|
234
|
+
const fullText = `${subject}\n${body}`;
|
|
235
|
+
|
|
236
|
+
if (/^BREAKING[ -]CHANGE:/im.test(fullText)) return "breaking";
|
|
237
|
+
|
|
238
|
+
const match = subject.match(CONVENTIONAL_COMMIT_RE);
|
|
239
|
+
const type = match?.groups?.type?.toLowerCase() ?? "";
|
|
240
|
+
|
|
241
|
+
// un "!" dans le type (ex. feat!) marque aussi un breaking change
|
|
242
|
+
if (type && subject.includes(`${type}!`)) return "breaking";
|
|
243
|
+
if (MINOR_TYPES.has(type)) return "features";
|
|
244
|
+
if (PATCH_TYPES.has(type)) return "bugfixes";
|
|
245
|
+
|
|
246
|
+
return "others";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function renderCommitLine(commit: CommitInfo, repoUrl: string): string {
|
|
250
|
+
return `* ${commit.subject} (${commitUrl(repoUrl, commit.hash)})`;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const SECTION_TITLES: Record<ChangelogSection, string> = {
|
|
254
|
+
breaking: "Breaking Changes",
|
|
255
|
+
features: "Features",
|
|
256
|
+
bugfixes: "Bug Fixes",
|
|
257
|
+
others: "Other Changes",
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Construit une section de CHANGELOG pour la version `next` à partir des commits
|
|
262
|
+
* analysés, en imitant le format conventional-changelog existant.
|
|
263
|
+
*/
|
|
264
|
+
function renderChangelogSection(
|
|
265
|
+
version: string,
|
|
266
|
+
previousTag: string | null,
|
|
267
|
+
commits: CommitInfo[],
|
|
268
|
+
repoUrl: string
|
|
269
|
+
): string {
|
|
270
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
271
|
+
const title = previousTag
|
|
272
|
+
? `## [${version}](${repoUrl}/compare/${previousTag}...v${version}) (${date})`
|
|
273
|
+
: `# ${version} (${date})`;
|
|
274
|
+
|
|
275
|
+
const sections: ChangelogSection[] = ["breaking", "features", "bugfixes", "others"];
|
|
276
|
+
const lines: string[] = [title, ""];
|
|
277
|
+
|
|
278
|
+
// La section breaking vient en premier et porte tous les commits classés
|
|
279
|
+
// "other" restent en dernier.
|
|
280
|
+
for (const section of sections) {
|
|
281
|
+
const entries = commits.filter((c) => sectionForCommit(c) === section);
|
|
282
|
+
if (entries.length === 0) continue;
|
|
283
|
+
lines.push(`### ${SECTION_TITLES[section]}`, "");
|
|
284
|
+
for (const commit of entries) {
|
|
285
|
+
lines.push(renderCommitLine(commit, repoUrl));
|
|
286
|
+
}
|
|
287
|
+
lines.push("");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
while (lines.length && lines[lines.length - 1] === "") lines.pop();
|
|
291
|
+
return lines.join("\n");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function writeChangelog(
|
|
295
|
+
version: string,
|
|
296
|
+
previousTag: string | null,
|
|
297
|
+
commits: CommitInfo[],
|
|
298
|
+
cwd: string
|
|
299
|
+
): void {
|
|
300
|
+
const repoUrl = getRepoUrl();
|
|
301
|
+
const changelogPath = path.resolve(cwd, "CHANGELOG.md");
|
|
302
|
+
const section = renderChangelogSection(version, previousTag, commits, repoUrl);
|
|
303
|
+
|
|
304
|
+
let existing = "";
|
|
305
|
+
if (existsSync(changelogPath)) {
|
|
306
|
+
existing = readFileSync(changelogPath, "utf-8").trim();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const newContent = existing ? `${section}\n\n${existing}\n` : `${section}\n`;
|
|
310
|
+
writeFileSync(changelogPath, newContent);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
interface SemVer {
|
|
314
|
+
major: number;
|
|
315
|
+
minor: number;
|
|
316
|
+
patch: number;
|
|
317
|
+
preReleaseType: string | null;
|
|
318
|
+
preReleaseNum: number | null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function parseSemVer(version: string): SemVer {
|
|
322
|
+
const [versionPart, ...preReleaseParts] = version.split("-");
|
|
323
|
+
const preReleasePart = preReleaseParts.join("-"); // gère les suffixes contenant des "-"
|
|
324
|
+
const parts = versionPart?.split(".").map((n) => {
|
|
325
|
+
const parsed = Number(n);
|
|
326
|
+
if (Number.isNaN(parsed)) {
|
|
327
|
+
throw new Error(`Version invalide dans package.json : "${version}"`);
|
|
328
|
+
}
|
|
329
|
+
return parsed;
|
|
330
|
+
}) || [];
|
|
331
|
+
const [major = 0, minor = 0, patch = 0] = parts;
|
|
332
|
+
|
|
333
|
+
let preReleaseType: string | null = null;
|
|
334
|
+
let preReleaseNum: number | null = null;
|
|
335
|
+
if (preReleasePart) {
|
|
336
|
+
const m = preReleasePart.match(/^([a-zA-Z]+)\.?(\d+)?$/);
|
|
337
|
+
if (m) {
|
|
338
|
+
preReleaseType = m[1] || null;
|
|
339
|
+
preReleaseNum = m[2] ? Number(m[2]) : 0;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return {major, minor, patch, preReleaseType, preReleaseNum};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function detectBranchPreReleaseType(branch: string): string | null {
|
|
347
|
+
const known = ["alpha", "beta", "rc"];
|
|
348
|
+
return known.find((t) => branch.startsWith(t)) ?? null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function computeNextVersion(current: string, increment: Increment, branch: string): string {
|
|
352
|
+
const currentSemVer = parseSemVer(current);
|
|
353
|
+
const {major, minor, patch} = currentSemVer;
|
|
354
|
+
const branchPreType = detectBranchPreReleaseType(branch);
|
|
355
|
+
|
|
356
|
+
let base: string;
|
|
357
|
+
if (increment === "major") base = `${major + 1}.0.0`;
|
|
358
|
+
else if (increment === "minor") base = `${major}.${minor + 1}.0`;
|
|
359
|
+
else base = `${major}.${minor}.${patch + 1}`;
|
|
360
|
+
|
|
361
|
+
if (!branchPreType) {
|
|
362
|
+
return base;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const isSameCycle = currentSemVer.preReleaseType === branchPreType;
|
|
366
|
+
const nextPreReleaseNum = isSameCycle ? (currentSemVer.preReleaseNum ?? -1) + 1 : 0;
|
|
367
|
+
|
|
368
|
+
return `${base}-${branchPreType}.${nextPreReleaseNum}`;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function createVersionTag(version: string): boolean {
|
|
372
|
+
const tag = `v${version}`;
|
|
373
|
+
try {
|
|
374
|
+
// Déjà présent (re-run) : on le déplace proprement sur HEAD.
|
|
375
|
+
if (run(`git rev-parse -q --verify "refs/tags/${tag}"`)) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
} catch {
|
|
379
|
+
// le tag n'existe pas, on va le créer
|
|
380
|
+
}
|
|
381
|
+
run(`git tag "${tag}"`);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function updateVersion(
|
|
386
|
+
increment: Increment,
|
|
387
|
+
branch: string,
|
|
388
|
+
commits: CommitInfo[],
|
|
389
|
+
previousTag: string | null,
|
|
390
|
+
options: CliOptions
|
|
391
|
+
): { previous: string; next: string; tag: string | null; changelog: boolean } {
|
|
392
|
+
const packageJsonPath = path.resolve(options.cwd, "package.json");
|
|
393
|
+
if (!existsSync(packageJsonPath)) {
|
|
394
|
+
throw new Error(`package.json introuvable à l'emplacement : ${packageJsonPath}`);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const raw = readFileSync(packageJsonPath, "utf-8");
|
|
398
|
+
const packageJson = JSON.parse(raw);
|
|
399
|
+
const currentVersion: string = packageJson.version;
|
|
400
|
+
if (!currentVersion) {
|
|
401
|
+
throw new Error('Le champ "version" est manquant dans package.json');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const nextVersion = computeNextVersion(currentVersion, increment, branch);
|
|
405
|
+
|
|
406
|
+
let tag: string | null = null;
|
|
407
|
+
let changelog = false;
|
|
408
|
+
if (!options.dryRun) {
|
|
409
|
+
packageJson.version = nextVersion;
|
|
410
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
411
|
+
|
|
412
|
+
// Un tag accompagne toute nouvelle version : c'est la source de vérité
|
|
413
|
+
// sur laquelle s'appuie la déduction (base = dernier tag).
|
|
414
|
+
if (!options.noTag) {
|
|
415
|
+
tag = `v${nextVersion}`;
|
|
416
|
+
createVersionTag(nextVersion);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Le CHANGELOG est synchronisé en parallèle avec la version.
|
|
420
|
+
writeChangelog(nextVersion, previousTag, commits, options.cwd);
|
|
421
|
+
changelog = true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return {previous: currentVersion, next: nextVersion, tag, changelog};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function logValidationError(options: CliOptions, invalid: CommitInfo[]) {
|
|
428
|
+
if (options.json) {
|
|
429
|
+
console.error(
|
|
430
|
+
JSON.stringify(
|
|
431
|
+
{
|
|
432
|
+
status: "error",
|
|
433
|
+
reason: "commits non conventionnels détectés",
|
|
434
|
+
invalidCommits: invalid.map((c) => c.subject),
|
|
435
|
+
},
|
|
436
|
+
null,
|
|
437
|
+
2
|
|
438
|
+
)
|
|
439
|
+
);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
console.error("Erreur : certains commits ne respectent pas le format conventional commits.");
|
|
443
|
+
console.error('Format attendu : "type(scope)!: description" (ex: "feat(auth): add login")');
|
|
444
|
+
console.error("");
|
|
445
|
+
for (const commit of invalid) {
|
|
446
|
+
console.error(` - ${commit.subject}`);
|
|
447
|
+
}
|
|
448
|
+
console.error("");
|
|
449
|
+
console.error(
|
|
450
|
+
"Corrige ces messages de commit (rebase interactif) ou relance avec --allow-non-conventional pour les ignorer."
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function log(options: CliOptions, data: Record<string, unknown>) {
|
|
455
|
+
if (options.json) {
|
|
456
|
+
console.log(JSON.stringify(data, null, 2));
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (data.status === "skipped") {
|
|
460
|
+
console.log(`Aucune mise à jour : ${data.reason}`);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
console.log(`Base de comparaison : ${data.base ?? "aucune"}${data.label ? ` (${data.label})` : ""}`);
|
|
464
|
+
console.log(`Commits analysés : ${data.commitCount}`);
|
|
465
|
+
console.log(`Increment déterminé : ${data.increment}`);
|
|
466
|
+
const prefix = data.status === "dry-run" ? "[dry-run] " : "";
|
|
467
|
+
console.log(
|
|
468
|
+
`${prefix}Version : ${data.previousVersion} -> ${data.nextVersion} (branche: ${data.branch})`
|
|
469
|
+
);
|
|
470
|
+
if (data.tag) {
|
|
471
|
+
console.log(`Tag créé : ${data.tag}`);
|
|
472
|
+
}
|
|
473
|
+
if (data.changelog) {
|
|
474
|
+
console.log(`CHANGELOG.md synchronisé`);
|
|
475
|
+
}
|
|
110
476
|
}
|
|
111
477
|
|
|
112
478
|
function main() {
|
|
113
|
-
|
|
114
|
-
|
|
479
|
+
const options = parseArgs(process.argv.slice(2));
|
|
480
|
+
const branch = getCurrentBranch();
|
|
481
|
+
const {base, label, commits} = getCommitsForVersion(options.base);
|
|
482
|
+
|
|
483
|
+
if (commits.length === 0) {
|
|
484
|
+
log(options, {
|
|
485
|
+
base,
|
|
486
|
+
label,
|
|
487
|
+
commitCount: 0,
|
|
488
|
+
branch,
|
|
489
|
+
dryRun: options.dryRun,
|
|
490
|
+
status: "skipped",
|
|
491
|
+
reason: `aucun commit à analyser (base: ${base ?? "historique complet"})`,
|
|
492
|
+
});
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
115
495
|
|
|
116
|
-
|
|
117
|
-
|
|
496
|
+
if (!options.allowNonConventional) {
|
|
497
|
+
const {invalid} = validateCommits(commits);
|
|
498
|
+
if (invalid.length > 0) {
|
|
499
|
+
logValidationError(options, invalid);
|
|
500
|
+
process.exitCode = 1;
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const increment = determineIncrement(commits);
|
|
118
506
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
507
|
+
const summary = {
|
|
508
|
+
base,
|
|
509
|
+
label,
|
|
510
|
+
commitCount: commits.length,
|
|
511
|
+
increment,
|
|
512
|
+
branch,
|
|
513
|
+
dryRun: options.dryRun,
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
if (!increment) {
|
|
517
|
+
log(options, {
|
|
518
|
+
...summary,
|
|
519
|
+
status: "skipped",
|
|
520
|
+
reason: "aucun commit ne déclenche de version (feat, fix, BREAKING CHANGE...)",
|
|
521
|
+
});
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
123
524
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
525
|
+
const previousTag = (base && RELEASE_TAG_RE.test(base)) ? base : null;
|
|
526
|
+
const {previous, next, tag, changelog} = updateVersion(
|
|
527
|
+
increment,
|
|
528
|
+
branch,
|
|
529
|
+
commits,
|
|
530
|
+
previousTag,
|
|
531
|
+
options
|
|
532
|
+
);
|
|
129
533
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
534
|
+
log(options, {
|
|
535
|
+
...summary,
|
|
536
|
+
status: options.dryRun ? "dry-run" : "updated",
|
|
537
|
+
previousVersion: previous,
|
|
538
|
+
nextVersion: next,
|
|
539
|
+
tag,
|
|
540
|
+
changelog,
|
|
541
|
+
});
|
|
133
542
|
}
|
|
134
543
|
|
|
135
|
-
main();
|
|
544
|
+
main();
|