const { execSync } = require("child_process"); const fs = require("fs"); const path = require("path"); const platforms = require("./platforms"); const updatePackageJson = require("./update-package"); const { version } = require("../package.json"); updatePackageJson(path.join(__dirname, "..", "package.json"), { optionalDependencies: platforms.reduce((acc, cur) => { acc[`@mtfos/rs-diff-${cur}`] = `^${version}`; return acc; }, {}), }); const envPlatform = process.env.PLATFORM || ""; for (const name of platforms) { 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", { cwd: pkgDir, env: process.env, stdio: "inherit", }); }