rs-diff/scripts/publish.js

32 lines
992 B
JavaScript
Raw Normal View History

2020-09-11 05:18:42 +00:00
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
2020-08-14 08:11:58 +00:00
2020-09-11 05:18:42 +00:00
const platforms = require("./platforms");
const updatePackageJson = require("./update-package");
2020-08-14 08:11:58 +00:00
2020-09-11 05:18:42 +00:00
const { version } = require("../package.json");
2020-08-14 08:11:58 +00:00
2020-09-11 05:18:42 +00:00
updatePackageJson(path.join(__dirname, "..", "package.json"), {
2020-08-14 08:11:58 +00:00
optionalDependencies: platforms.reduce((acc, cur) => {
2020-09-11 05:18:42 +00:00
acc[`@mtfos/rs-diff-${cur}`] = `^${version}`;
return acc;
2020-08-14 08:11:58 +00:00
}, {}),
2020-09-11 05:18:42 +00:00
});
const envPlatform = process.env.PLATFORM || "";
2020-08-14 08:11:58 +00:00
for (const name of platforms) {
2020-09-11 05:18:42 +00:00
if (envPlatform && name !== envPlatform) continue;
const pkgDir = path.join(__dirname, "..", "npm", name);
const filename = `index.${name}.node`;
if (!fs.existsSync(path.join(__dirname, "..", filename))) continue;
const bindingFile = fs.readFileSync(path.join(__dirname, "..", filename));
fs.writeFileSync(path.join(pkgDir, filename), bindingFile);
execSync("npm publish", {
2020-08-14 08:11:58 +00:00
cwd: pkgDir,
env: process.env,
2020-09-11 05:18:42 +00:00
stdio: "inherit",
});
2020-08-14 08:11:58 +00:00
}