make publish script parallel
This commit is contained in:
@@ -6,6 +6,10 @@ var chalk = require("chalk");
|
||||
var child = require("child_process");
|
||||
var fs = require("fs");
|
||||
|
||||
var NPM_OWNERS = fs.readFileSync(__dirname + "/../NPM_OWNERS", "utf8").trim().split("\n");
|
||||
|
||||
//
|
||||
|
||||
var PACKAGE_LOC = __dirname + "/../packages";
|
||||
var VERSION_LOC = __dirname + "/../VERSION";
|
||||
|
||||
@@ -15,8 +19,33 @@ console.log("Current version:", CURRENT_VERSION);
|
||||
var FORCE_VERSION = process.env.FORCE_VERSION;
|
||||
FORCE_VERSION = FORCE_VERSION ? FORCE_VERSION.split(",") : [];
|
||||
|
||||
var NEW_VERSION = getVersion();
|
||||
fs.writeFileSync(VERSION_LOC, NEW_VERSION, "utf8");
|
||||
|
||||
//
|
||||
|
||||
try {
|
||||
checkUpdatedPackages();
|
||||
updateChangedPackages();
|
||||
updateTag();
|
||||
build();
|
||||
publish();
|
||||
} catch (err) {
|
||||
onError(err);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function updateTag() {
|
||||
var NEW_TAG_NAME = "v" + NEW_VERSION;
|
||||
execSync("git commit -m " + NEW_TAG_NAME, true);
|
||||
execSync("git tag " + NEW_TAG_NAME, true);
|
||||
}
|
||||
|
||||
function build() {
|
||||
execSync("make build-dist");
|
||||
}
|
||||
|
||||
function getVersion() {
|
||||
var input = readline.question("New version (Leave blank for new patch): ");
|
||||
|
||||
@@ -33,18 +62,13 @@ function getVersion() {
|
||||
}
|
||||
}
|
||||
|
||||
var NEW_VERSION = getVersion();
|
||||
fs.writeFileSync(VERSION_LOC, NEW_VERSION, "utf8");
|
||||
|
||||
//
|
||||
|
||||
function exec(cmd, log) {
|
||||
console.log("$", cmd);
|
||||
|
||||
function execSync(cmd, log) {
|
||||
var out = child.execSync(cmd, {
|
||||
encoding: "utf8"
|
||||
}).trim();
|
||||
|
||||
console.log("$ " + cmd);
|
||||
|
||||
if (log) {
|
||||
if (out) console.log(out);
|
||||
} else {
|
||||
@@ -60,8 +84,6 @@ function getPackageConfig(name) {
|
||||
return require(getPackageLocation(name) + "/package.json");
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function updateDepsObject(changedPackages, deps) {
|
||||
for (var depName in deps) {
|
||||
// ensure this was generated and we're on the same major
|
||||
@@ -73,13 +95,13 @@ function updateDepsObject(changedPackages, deps) {
|
||||
}
|
||||
}
|
||||
|
||||
function publish() {
|
||||
function checkUpdatedPackages() {
|
||||
var packageNames = fs.readdirSync(PACKAGE_LOC).filter(function (name) {
|
||||
return name[0] !== "." && fs.statSync(PACKAGE_LOC + "/" + name).isDirectory();
|
||||
});
|
||||
|
||||
var lastTagCommit = exec("git rev-list --tags --max-count=1");
|
||||
var lastTag = exec("git describe " + lastTagCommit);
|
||||
var lastTagCommit = execSync("git rev-list --tags --max-count=1");
|
||||
var lastTag = execSync("git describe " + lastTagCommit);
|
||||
|
||||
var changedPackages = [];
|
||||
var changedFiles = [VERSION_LOC];
|
||||
@@ -89,7 +111,7 @@ function publish() {
|
||||
if (config.private) return;
|
||||
|
||||
// check if package has changed since last release
|
||||
var diff = exec("git diff " + lastTag + " -- " + getPackageLocation(name));
|
||||
var diff = execSync("git diff " + lastTag + " -- " + getPackageLocation(name));
|
||||
if (diff || FORCE_VERSION.indexOf("*") >= 0 || FORCE_VERSION.indexOf(name) >= 0) {
|
||||
console.log(chalk.green("Changes detected to package", name));
|
||||
changedPackages.push(name);
|
||||
@@ -103,9 +125,9 @@ function publish() {
|
||||
if (changedPackages.indexOf("babel-browser") < 0) {
|
||||
changedPackages.push("babel-browser");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
function updateChangedPackages() {
|
||||
changedPackages.forEach(function (name) {
|
||||
var pkgLoc = getPackageLocation(name) + "/package.json";
|
||||
var pkg = require(pkgLoc);
|
||||
@@ -125,68 +147,54 @@ function publish() {
|
||||
});
|
||||
|
||||
changedFiles.forEach(function (loc) {
|
||||
exec("git add " + loc, true);
|
||||
execSync("git add " + loc, true);
|
||||
});
|
||||
}
|
||||
|
||||
var NEW_TAG_NAME = "v" + NEW_VERSION;
|
||||
exec("git commit -m " + NEW_TAG_NAME, true);
|
||||
exec("git tag " + NEW_TAG_NAME, true);
|
||||
|
||||
exec("make build-dist");
|
||||
|
||||
function publish() {
|
||||
changedPackages.forEach(function (name) {
|
||||
// prepublish script
|
||||
var prePub = getPackageLocation(name) + "/scripts/prepublish.js";
|
||||
if (fs.existsSync(prePub)) require(prePub);
|
||||
});
|
||||
|
||||
changedPackages.forEach(function (name) {
|
||||
async.parallelLimit(changedPackages, function (name, done) {
|
||||
var loc = getPackageLocation(name);
|
||||
exec("cd " + loc + " && npm publish --tag prerelease", true);
|
||||
|
||||
// postpublish script
|
||||
var postPub = loc + "/scripts/postpublish.js";
|
||||
if (fs.existsSync(postPub)) require(postPub);
|
||||
publishedPackages.push(name);
|
||||
child.exec("cd " + loc + " && npm publish --tag prerelease", function (err, stdout, stderr) {
|
||||
if (err || stderr) return done(err || stderr);
|
||||
|
||||
console.log(stdout);
|
||||
|
||||
// postpublish script
|
||||
var postPub = loc + "/scripts/postpublish.js";
|
||||
if (fs.existsSync(postPub)) require(postPub);
|
||||
|
||||
done();
|
||||
});
|
||||
}, function (err) {
|
||||
onError(err);
|
||||
ship();
|
||||
});
|
||||
}
|
||||
|
||||
var publishedPackages = [];
|
||||
var originalCommit = exec("git rev-list --all --max-count=1");
|
||||
|
||||
try {
|
||||
publish();
|
||||
} catch (err) {
|
||||
function onError(err) {
|
||||
if (!err) return;
|
||||
console.log(chalk.red("There was a problem publishing."));
|
||||
console.log(err.stack);
|
||||
return;
|
||||
|
||||
if (publishedPackages.length) {
|
||||
console.log(chalk.warning("Unpublishing published packages..."));
|
||||
|
||||
publishedPackages.forEach(function () {
|
||||
var verInfo = name + "@" + NEW_VERSION;
|
||||
try {
|
||||
console.log(chalk.warning("Unpublishing " + verInfo + "..."));
|
||||
//exec("npm unpublish --force " + verInfo);
|
||||
} catch (err) {
|
||||
console.log(chalk.red("Failed to unpublish " + verInfo));
|
||||
console.log(err.stack);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(chalk.warning("Rolling back to commit", originalCommit, "..."));
|
||||
//exec("git checkout --hard " + originalCommit, true);
|
||||
}
|
||||
|
||||
return;
|
||||
console.log(err.stack || err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
changedPackages.forEach(function (name) {
|
||||
var loc = getPackageLocation(name);
|
||||
exec("npm dist-tag rm " + name + " prerelease", true);
|
||||
exec("npm dist-tag add " + name + "@" + NEW_VERSION + " stable");
|
||||
});
|
||||
|
||||
exec("git push", true);
|
||||
exec("git push --tags", true);
|
||||
function ship() {
|
||||
async.parallelLimit(changedPackages, 4, function (name, done) {
|
||||
var loc = getPackageLocation(name);
|
||||
execSync("npm dist-tag rm " + name + " prerelease", true);
|
||||
execSync("npm dist-tag add " + name + "@" + NEW_VERSION + " stable");
|
||||
}, function (err) {
|
||||
onError(err);
|
||||
execSync("git push", true);
|
||||
execSync("git push --tags", true);
|
||||
console.log(chalk.green("Successfully shipped " + NEW_VERSION));
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user