2019-02-28 02:21:40 +02:00
|
|
|
// React Native WebView cannot load external JS files, however it can load
|
2019-10-29 11:02:42 +02:00
|
|
|
// arbitrary JS via the injectedJavaScript property. So we use this to load external
|
2019-02-28 02:21:40 +02:00
|
|
|
// files: First here we convert the JS file to a plain string, and that string
|
|
|
|
// is then loaded by eg. the Mermaid plugin, and finally injected in the WebView.
|
|
|
|
|
2019-02-28 01:38:50 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
const rnDir = `${__dirname}/..`;
|
|
|
|
const outputDir = `${rnDir}/lib/rnInjectedJs`;
|
2019-02-28 01:38:50 +02:00
|
|
|
|
|
|
|
async function copyJs(name, filePath) {
|
|
|
|
const js = await fs.readFile(filePath, 'utf-8');
|
2019-09-19 23:51:18 +02:00
|
|
|
const json = `module.exports = ${JSON.stringify(js)};`;
|
|
|
|
const outputPath = `${outputDir}/${name}.js`;
|
2019-02-28 01:38:50 +02:00
|
|
|
await fs.writeFile(outputPath, json);
|
|
|
|
}
|
|
|
|
|
2019-09-13 00:16:42 +02:00
|
|
|
async function main() {
|
2019-02-28 01:38:50 +02:00
|
|
|
await fs.mkdirp(outputDir);
|
2019-09-19 23:51:18 +02:00
|
|
|
await copyJs('webviewLib', `${rnDir}/lib/renderers/webviewLib.js`);
|
2019-02-28 01:38:50 +02:00
|
|
|
}
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
module.exports = main;
|