forked from ssb-junkyard/react-native-scuttlebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert-bundle.js
35 lines (33 loc) · 1.37 KB
/
insert-bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const path = require("path");
const execSync = require("child_process").execSync;
const fs = require("fs");
const innerBinsPath = path.join(__dirname, "node_modules/.bin/");
const outerBinsPath = path.join(__dirname, "../.bin/");
let noderifyBinPath = path.join(innerBinsPath, "noderify");
if (!fs.existsSync(noderifyBinPath)) {
noderifyBinPath = path.join(outerBinsPath, "noderify");
}
let rnnodeBinPath = path.join(innerBinsPath, "react-native-node");
if (!fs.existsSync(rnnodeBinPath)) {
rnnodeBinPath = path.join(outerBinsPath, "react-native-node");
}
const projectPath = path.join(__dirname, "../../");
const replacements =
"--replace.chloride=sodium-browserify-tweetnacl " +
"--replace.sodium-chloride=sodium-browserify-tweetnacl " +
"--replace.node-extend=xtend " +
"--replace.leveldown=@staltz/jsondown " +
"--replace.runtimejs=noop2 " +
"--replace.fatfs=noop2 " +
"";
const ssbPeerPath = path.join(__dirname, "ssb-peer.js");
const bundleFilePath = path.join(__dirname, "bundle.js");
const bundleDirPath = path.join(projectPath, "background-bundled");
execSync(
`${noderifyBinPath} ${replacements} ${ssbPeerPath} > ${bundleFilePath}`,
{ cwd: __dirname }
);
execSync(`mkdir -p ${bundleDirPath}`);
execSync(`cp ${bundleFilePath} ${bundleDirPath}/index.js`);
execSync(`${rnnodeBinPath} insert ${bundleDirPath}`, { cwd: projectPath });
execSync(`rm -rf ${bundleDirPath}`);