forked from vercel/turborepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.js
executable file
·24 lines (18 loc) · 954 Bytes
/
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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const semver = require("semver");
// These values come from the invocation of release.
const increment = process.argv[2];
// Now we get the current version of the package.
const versionFilePath = path.join(__dirname, "..", "version.txt");
const versionFileContents = fs.readFileSync(versionFilePath, "utf-8");
const [currentVersion] = versionFileContents.split("\n");
// Now that we know current state, figure out what the target state is.
// If we're doing a "pre" release, set the identifier to canary
const identifier = increment.startsWith("pre") ? "canary" : "latest";
const newVersion = semver.inc(currentVersion, increment, identifier);
// Parse the output semver identifer to identify which npm tag to publish to.
const parsed = semver.parse(newVersion);
const tag = parsed?.prerelease[0] || "latest";
fs.writeFileSync(versionFilePath, `${newVersion}\n${tag}\n`);