Tone.js/scripts/increment_version.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-05-18 16:07:39 +00:00
const fs = require("fs");
const semver = require("semver");
const { resolve } = require("path");
const child_process = require("child_process");
2018-05-18 16:07:39 +00:00
const devVersion = child_process.execSync("npm show tone@next version").toString();
const masterVersion = child_process.execSync("npm show tone version").toString();
//go with whichever is the latest version
2018-05-18 16:07:39 +00:00
let version = masterVersion;
if (semver.gt(devVersion, masterVersion)){
2018-05-18 16:07:39 +00:00
version = devVersion;
}
//increment the patch
2019-07-11 04:54:11 +00:00
version = semver.inc(version, "patch");
//write it to the package.json
2018-05-18 16:07:39 +00:00
const packageFile = resolve(__dirname, "../package.json");
2018-05-18 16:44:00 +00:00
const packageObj = JSON.parse(fs.readFileSync(packageFile, "utf-8"));
//if the package version if the latest, go with that one
2018-05-18 16:44:00 +00:00
if (semver.gt(packageObj.version, version)){
version = packageObj.version;
}
2018-05-18 16:07:39 +00:00
console.log(`incrementing to version ${version}`);
2018-05-18 16:44:00 +00:00
packageObj.version = version;
//only if it's travis, update the package.json
if (process.env.TRAVIS){
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
//write a version file
var versionFile = `export default ${JSON.stringify(version)};\n`;
fs.writeFileSync(resolve(__dirname, "../Tone/version.js"), versionFile);
}