Tone.js/gulp/increment_version.js

42 lines
1.3 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;
let isDev = false;
if (semver.gt(devVersion, masterVersion)){
2018-05-18 16:07:39 +00:00
isDev = true;
version = devVersion;
}
2018-05-18 16:07:39 +00:00
version = version.split(".");
//increment the patch
2018-05-18 16:07:39 +00:00
version[2] = parseInt(version[2]) + 1;
//put it back in semver
2018-05-18 16:07:39 +00:00
version = version.join(".");
//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, " "));
}
2018-05-18 16:07:39 +00:00
//write a version file
var versionFile = `module.exports = ${JSON.stringify({ version, dev : isDev }, undefined, "\t")};\n`;
fs.writeFileSync(resolve(__dirname, "../Tone/version.js"), versionFile);