Merge pull request #1913 from thelounge/astorije/changelog-script

Allow keywords as changelog script version argument, e.g. `node scripts/changelog pre`
This commit is contained in:
Jérémie Astori 2017-12-28 15:26:38 -05:00 committed by GitHub
commit dd40011967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,8 +28,10 @@ it is very likely you will have to run all those each time:
node scripts/changelog <version>
```
`<version>` must *not* be prefixed with `v`. It is formatted either:
`<version>` must be either:
- A keyword among: major, minor, patch, prerelease, pre
- An explicit version of either format:
- `MAJOR.MINOR.PATCH` for a stable release, for example `2.5.0`
- `MAJOR.MINOR.PATCH-(pre|rc).N` for a pre-release, for example `2.5.0-rc.1`
@ -48,6 +50,7 @@ const colors = require("colors/safe");
const fs = require("fs");
const GraphQLClient = require("graphql-request").GraphQLClient;
const moment = require("moment");
const semver = require("semver");
const util = require("util");
const log = require("../src/log");
const packageJson = require("../package.json");
@ -68,11 +71,17 @@ if (process.argv[2] === undefined) {
process.exit(1);
}
const version = process.argv[2];
// If version is not a valid X.Y.Z, it may be something like "pre".
let version = semver.valid(process.argv[2]);
if (!version) {
version = semver.inc(packageJson.version, process.argv[2]);
}
if (!/^[0-9]+\.[0-9]+\.[0-9]+(-(pre|rc)+\.[0-9]+)?$/.test(version)) {
log.error(`Argument ${colors.bold("version")} is incorrect.`);
log.error(`It must match format ${colors.green("x.y.z")} (stable) or ${colors.green("x.y.z-(pre|rc).n")} (pre-release).`);
log.error(`Argument ${colors.bold("version")} is incorrect It must be either:`);
log.error(`- A keyword among: ${colors.green("major")}, ${colors.green("minor")}, ${colors.green("patch")}, ${colors.green("prerelease")}, ${colors.green("pre")}`);
log.error(`- An explicit version of format ${colors.green("x.y.z")} (stable) or ${colors.green("x.y.z-(pre|rc).n")} (pre-release).`);
process.exit(1);
}