2019-05-14 18:25:46 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const config = require("../config");
|
|
|
|
|
2020-05-13 03:54:38 -04:00
|
|
|
const { ChangelogPath, latestChange } = require("../changelog");
|
2019-05-14 18:25:46 -04:00
|
|
|
const { getOrdered, loadPackage } = require("../depgraph");
|
2020-05-13 03:54:38 -04:00
|
|
|
const { getGitTag } = require("../git");
|
2020-02-12 17:18:43 -05:00
|
|
|
const { createRelease } = require("../github");
|
2019-05-14 18:25:46 -04:00
|
|
|
const { getPackageVersion, publish } = require("../npm");
|
|
|
|
const { log } = require("../log");
|
|
|
|
|
|
|
|
const USER_AGENT = "ethers-dist@0.0.0";
|
2020-06-12 23:59:06 -04:00
|
|
|
const TAG = "latest";
|
2019-05-14 18:25:46 -04:00
|
|
|
|
2020-02-12 17:18:43 -05:00
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
let dirnames = getOrdered();
|
|
|
|
|
|
|
|
// Only publish specific packages
|
|
|
|
if (process.argv.length > 2) {
|
|
|
|
let filter = process.argv.slice(2);
|
|
|
|
|
|
|
|
// Verify all named packages exist
|
|
|
|
filter.forEach((dirname) => {
|
|
|
|
try {
|
|
|
|
loadPackage(dirname);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("Package not found: " + dirname);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Filter out pacakges we don't care about
|
|
|
|
dirnames = dirnames.filter((dirname) => (filter.indexOf(dirname) >= 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
let token = null;
|
|
|
|
|
2020-05-13 03:54:38 -04:00
|
|
|
const gitCommit = await getGitTag(ChangelogPath);
|
|
|
|
|
2020-02-12 17:18:43 -05:00
|
|
|
let includeEthers = false;
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
// @TODO: Fail if there are any untracked files or unchecked in files
|
|
|
|
|
|
|
|
// Load the token from the encrypted store
|
|
|
|
try {
|
2019-09-20 22:38:03 -04:00
|
|
|
token = await config.get("npm-token");
|
2019-05-14 18:25:46 -04:00
|
|
|
} catch (error) {
|
|
|
|
switch (error.message) {
|
|
|
|
case "wrong password":
|
|
|
|
log("<bold:Wrong password>");
|
|
|
|
break;
|
|
|
|
case "cancelled":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
log("<red:Aborting.>");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
token = token.trim().split("=");
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
npmVersion: USER_AGENT,
|
|
|
|
tag: TAG
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the authentication token
|
|
|
|
options[token[0]] = token[1];
|
|
|
|
|
|
|
|
for (let i = 0; i < dirnames.length; i++) {
|
|
|
|
let dirname = dirnames[i];
|
|
|
|
|
|
|
|
if (dirname === "ethers") {
|
2020-02-12 17:18:43 -05:00
|
|
|
includeEthers = true;
|
2019-05-14 18:25:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let info = loadPackage(dirname);
|
|
|
|
let npmInfo = await getPackageVersion(info.name);
|
|
|
|
if (!npmInfo) { npmInfo = { version: "NEW" }; }
|
|
|
|
|
|
|
|
if (info.tarballHash === npmInfo.tarballHash) { continue; }
|
|
|
|
|
|
|
|
log(`<bold:Publishing:> ${info.name}...`);
|
|
|
|
log(` <blue:Version:> ${npmInfo.version} <bold:=\\>> ${info.version}`);
|
|
|
|
|
|
|
|
let success = await publish(dirname, options);
|
|
|
|
if (!success) {
|
|
|
|
log(" <red:FAILED! Aborting.>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log(" <green:Done.>");
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:59:06 -04:00
|
|
|
// Publish the GitHub release
|
|
|
|
const beta = false;
|
2020-02-12 17:18:43 -05:00
|
|
|
if (includeEthers) {
|
2020-06-12 23:59:06 -04:00
|
|
|
{
|
|
|
|
// The password above already succeeded
|
|
|
|
const username = await config.get("github-user");
|
|
|
|
const password = await config.get("github-release");
|
2020-02-12 17:18:43 -05:00
|
|
|
|
2020-06-12 23:59:06 -04:00
|
|
|
// Get the latest change from the changelog
|
|
|
|
const change = latestChange();
|
2020-02-12 17:18:43 -05:00
|
|
|
|
2020-06-12 23:59:06 -04:00
|
|
|
// Publish the release
|
|
|
|
const link = await createRelease(username, password, change.version, change.title, change.content, beta, gitCommit);
|
|
|
|
log(`<bold:Published Release:> ${ link }`);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
const accessKey = await config.get("aws-upload-scripts-accesskey");
|
|
|
|
const secretKey = await config.get("aws-upload-scripts-secretkey");
|
|
|
|
const s3 =
|
|
|
|
}
|
|
|
|
*/
|
2020-02-12 17:18:43 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
})();
|