-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathapply-canary-version.ts
94 lines (81 loc) · 2.63 KB
/
apply-canary-version.ts
1
2
3
4
5
6
7
8
9
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
import { workspaceRoot } from '@nx/devkit';
import execa from 'execa';
import semver from 'semver';
// We are either releasing a canary version of the latest major version, or one for the next major.
const overrideMajorVersion = process.env.OVERRIDE_MAJOR_VERSION;
const preid = 'alpha';
let distTag = 'canary';
if (overrideMajorVersion) {
console.log(
`Overriding canary major version base to v${overrideMajorVersion}`,
);
distTag = `prerelease-v${overrideMajorVersion}`;
}
(async function main() {
const currentLatestVersion = execa
.sync('npm', ['view', '@angular-eslint/eslint-plugin@latest', 'version'])
.stdout.trim();
let currentCanaryVersion = null;
try {
currentCanaryVersion = execa
.sync('npm', [
'view',
`@angular-eslint/eslint-plugin@${distTag}`,
'version',
])
.stdout.trim();
} catch {
// (ignored - currentCanaryVersion can be null)
}
console.log('\nResolved current versions: ', {
currentLatestVersion,
currentCanaryVersion,
});
let nextCanaryVersion: string | null;
if (overrideMajorVersion) {
nextCanaryVersion = currentCanaryVersion
? semver.inc(currentCanaryVersion, 'prerelease', undefined, preid)
: semver.inc(currentLatestVersion, 'premajor', undefined, preid);
} else {
if (!currentCanaryVersion) {
throw new Error(
'An unexpected error occurred, no current canary version could be read from the npm registry',
);
}
if (semver.gte(currentLatestVersion, currentCanaryVersion)) {
console.log(
'\nLatest version is greater than or equal to the current canary version, starting new prerelease base...',
);
// Determine next minor version above the currentLatestVersion
nextCanaryVersion = semver.inc(
currentLatestVersion,
'prerelease',
undefined,
preid,
);
} else {
console.log(
'\nLatest version is less than the current canary version, incrementing the existing prerelease base...',
);
// Determine next prerelease version above the currentCanaryVersion
nextCanaryVersion = semver.inc(
currentCanaryVersion,
'prerelease',
undefined,
preid,
);
}
}
if (!nextCanaryVersion) {
console.log(`Error: Unable to determine next canary version`);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
console.log(`\nApplying next canary version with Nx`);
const command = `nx release version ${nextCanaryVersion}`;
console.log(`\n> ${command}\n`);
execa.sync('npx', command.split(' '), {
stdio: 'inherit',
cwd: workspaceRoot,
});
})();