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");
|
2017-09-09 22:30:36 +00:00
|
|
|
|
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();
|
2017-09-09 22:56:03 +00:00
|
|
|
|
|
|
|
//go with whichever is the latest version
|
2018-05-18 16:07:39 +00:00
|
|
|
let version = masterVersion;
|
2017-09-09 22:56:03 +00:00
|
|
|
if (semver.gt(devVersion, masterVersion)){
|
2018-05-18 16:07:39 +00:00
|
|
|
version = devVersion;
|
2017-09-09 22:56:03 +00:00
|
|
|
}
|
2017-09-09 22:30:36 +00:00
|
|
|
|
2018-05-18 16:07:39 +00:00
|
|
|
version = version.split(".");
|
2017-09-09 22:30:36 +00:00
|
|
|
//increment the patch
|
2018-05-18 16:07:39 +00:00
|
|
|
version[2] = parseInt(version[2]) + 1;
|
2017-09-09 22:30:36 +00:00
|
|
|
//put it back in semver
|
2018-05-18 16:07:39 +00:00
|
|
|
version = version.join(".");
|
2017-09-09 22:30:36 +00:00
|
|
|
|
|
|
|
//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"));
|
2017-09-17 16:51:33 +00:00
|
|
|
|
|
|
|
//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;
|
2017-09-17 16:51:33 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2018-05-18 16:58:15 +00:00
|
|
|
//only if it's travis, update the package.json
|
|
|
|
if (process.env.TRAVIS){
|
|
|
|
fs.writeFileSync(packageFile, JSON.stringify(packageObj, undefined, " "));
|
|
|
|
}
|
2018-05-18 16:07:39 +00:00
|
|
|
|
|
|
|
//write a version file
|
2019-01-27 18:05:20 +00:00
|
|
|
var versionFile = `export default ${JSON.stringify(version)};\n`;
|
2018-05-18 16:07:39 +00:00
|
|
|
fs.writeFileSync(resolve(__dirname, "../Tone/version.js"), versionFile);
|