-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
set-version.js
75 lines (63 loc) · 1.99 KB
/
set-version.js
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
let argv = require("yargs")
.options({
"artifact-name": {
type: "string",
describe:
"name of the artifact to be set (e.g. azure-keyvault-secrets), will be translated to @azure/(package) format",
demandOption: true
},
"new-version": {
type: "string",
describe: "package version string",
demandOption: true
},
"repo-root": {
type: "string",
default: "../../../",
describe: "root of the repository (e.g. ../../../)",
demandOption: true
},
"dry-run": {
type: "boolean"
}
})
.help().argv;
const path = require("path");
const versionUtils = require("./VersionUtils");
const packageUtils = require("eng-package-utils");
async function main(argv) {
const artifactName = argv["artifact-name"];
const newVersion = argv["new-version"];
const repoRoot = argv["repo-root"];
const dryRun = argv["dry-run"];
const rushSpec = await packageUtils.getRushSpec(repoRoot);
const targetPackage = rushSpec.projects.find(
packageSpec => packageSpec.packageName.replace("@", "").replace("/", "-") == artifactName
);
const targetPackagePath = path.join(repoRoot, targetPackage.projectFolder);
const packageJsonLocation = path.join(targetPackagePath, "package.json");
const packageJsonContents = await packageUtils.readFileJson(
packageJsonLocation
);
const oldVersion = packageJsonContents.version;
console.log(`${packageJsonContents.name}: ${oldVersion} -> ${newVersion}`);
if (dryRun) {
console.log("Dry run only, no changes");
return;
}
const updatedPackageJson = {
...packageJsonContents,
version: newVersion
};
await packageUtils.writePackageJson(packageJsonLocation, updatedPackageJson);
await versionUtils.updatePackageConstants(
targetPackagePath,
packageJsonContents,
newVersion
);
const updateStatus = versionUtils.updateChangelog(targetPackagePath, repoRoot, newVersion, false, true);
if (!updateStatus) {
process.exit(1);
}
}
main(argv);