2019-11-16 22:45:22 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2019-07-11 04:54:34 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const semver = require("semver");
|
|
|
|
const { resolve } = require("path");
|
2019-11-16 22:45:22 +00:00
|
|
|
const { execSync } = require("child_process");
|
2019-07-11 04:54:34 +00:00
|
|
|
|
2020-01-20 04:40:12 +00:00
|
|
|
const tsVersion = execSync("npm show tone@next version").toString();
|
2024-04-25 18:06:55 +00:00
|
|
|
const mainVersion = execSync("npm show tone version").toString();
|
2019-07-11 04:54:34 +00:00
|
|
|
|
2019-11-16 22:45:22 +00:00
|
|
|
// go with whichever is the latest version
|
2024-04-25 18:06:55 +00:00
|
|
|
let version = mainVersion;
|
|
|
|
if (tsVersion && semver.gt(tsVersion, mainVersion)) {
|
2019-07-11 04:54:34 +00:00
|
|
|
version = tsVersion;
|
|
|
|
}
|
|
|
|
|
2019-11-16 22:45:22 +00:00
|
|
|
// increment the patch
|
2019-07-11 04:54:34 +00:00
|
|
|
version = semver.inc(version, "patch");
|
|
|
|
|
2019-11-16 22:45:22 +00:00
|
|
|
// write it to the package.json
|
2019-07-11 04:54:34 +00:00
|
|
|
const packageFile = resolve(__dirname, "../package.json");
|
|
|
|
const packageObj = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
|
|
|
|
|
2019-11-16 22:45:22 +00:00
|
|
|
// if the package version if the latest, go with that one
|
|
|
|
if (semver.gt(packageObj.version, version)) {
|
2019-07-11 04:54:34 +00:00
|
|
|
version = packageObj.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`incrementing to version ${version}`);
|
|
|
|
packageObj.version = version;
|
2019-11-16 22:45:22 +00:00
|
|
|
// only if it's travis, update the package.json
|
2024-04-25 18:06:55 +00:00
|
|
|
if (process.env.GITHUB_CI) {
|
2019-07-11 04:54:34 +00:00
|
|
|
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
|
2019-08-02 14:34:09 +00:00
|
|
|
|
2019-11-16 22:45:22 +00:00
|
|
|
// write a version file
|
2020-01-20 04:40:12 +00:00
|
|
|
const versionFile = `export const version: string = ${JSON.stringify(version)};\n`;
|
2019-08-02 14:34:09 +00:00
|
|
|
fs.writeFileSync(resolve(__dirname, "../Tone/version.ts"), versionFile);
|
2019-07-11 04:54:34 +00:00
|
|
|
}
|
|
|
|
|