2020-09-21 08:14:06 +03:00
|
|
|
import fs from "fs";
|
|
|
|
|
|
|
|
import semver from "semver";
|
|
|
|
|
|
|
|
import { dirnames, getPackageJsonPath, getPackagePath, resolve } from "../path";
|
|
|
|
import * as local from "../local";
|
|
|
|
import { colorify, getProgressBar } from "../log";
|
|
|
|
import * as npm from "../npm";
|
|
|
|
import { loadJson, repeat, saveJson } from "../utils";
|
|
|
|
|
|
|
|
(async function() {
|
|
|
|
const progress = getProgressBar(colorify.bold("Bumping package.json versions"));
|
|
|
|
|
|
|
|
const latestVersions: Record<string, string> = { };
|
|
|
|
let updated = false;
|
|
|
|
|
|
|
|
const output: Array<string> = [ ];
|
|
|
|
|
|
|
|
// For each package, detect diff between tarball and remote
|
|
|
|
for (let i = 0; i < dirnames.length; i++) {
|
|
|
|
progress(i / dirnames.length);
|
|
|
|
|
|
|
|
const dirname = dirnames[i];
|
|
|
|
|
|
|
|
const pLocal = local.getPackage(dirname);
|
|
|
|
const pNpm = await npm.getPackage(dirname);
|
|
|
|
|
|
|
|
const tarballHash = local.computeTarballHash(dirname);
|
|
|
|
|
|
|
|
let version = pNpm.version;
|
|
|
|
|
|
|
|
if (tarballHash !== pNpm.tarballHash) {
|
|
|
|
version = semver.inc(version, "patch");
|
|
|
|
|
|
|
|
output.push([
|
|
|
|
" ",
|
|
|
|
colorify.blue(pLocal.name),
|
|
|
|
repeat(" ", 47 - pLocal.name.length - pNpm.version.length),
|
|
|
|
pNpm.version,
|
|
|
|
colorify.bold(" => "),
|
|
|
|
colorify.green(version)
|
|
|
|
].join(""));
|
|
|
|
|
2020-09-23 06:18:45 +03:00
|
|
|
local.updateJson(getPackageJsonPath(dirname), { gitHead: undefined, tarballHash, version }, true);
|
2020-09-21 08:14:06 +03:00
|
|
|
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
latestVersions[pLocal.name] = version;
|
|
|
|
|
|
|
|
// Write out the _version.ts
|
|
|
|
if (!pLocal._ethers_nobuild) {
|
2020-10-07 07:11:47 +03:00
|
|
|
const code = "export const version = " + JSON.stringify(dirname + "/" + version) + ";\n";
|
2020-09-21 08:14:06 +03:00
|
|
|
fs.writeFileSync(resolve(getPackagePath(dirname), "src.ts/_version.ts"), code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
progress(1);
|
|
|
|
|
|
|
|
if (updated) {
|
|
|
|
const filename = resolve("packages/ethers/package.json")
|
|
|
|
const info = loadJson(filename);
|
|
|
|
Object.keys(info.dependencies).forEach((name) => {
|
|
|
|
const version = latestVersions[name];
|
|
|
|
if (name == null) { return; }
|
|
|
|
info.dependencies[name] = version;
|
|
|
|
});
|
|
|
|
saveJson(filename, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
output.forEach((line) => { console.log(line); });
|
|
|
|
|
|
|
|
})().catch((error) => {
|
|
|
|
console.log(`Error running ${ process.argv[0] }: ${ error.message }`);
|
|
|
|
process.exit(1);
|
|
|
|
});
|