2019-02-28 02:21:40 +02:00
|
|
|
// React Native WebView cannot load external JS files, however it can load
|
|
|
|
// arbitraty JS via the injectedJavaScript property. So we use this to load external
|
|
|
|
// 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');
|
|
|
|
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const outputDir = cwd + '/lib/rnInjectedJs';
|
2019-03-08 19:14:17 +02:00
|
|
|
const rnDir = __dirname + '/../ReactNativeClient';
|
2019-02-28 01:38:50 +02:00
|
|
|
|
|
|
|
async function copyJs(name, filePath) {
|
|
|
|
const js = await fs.readFile(filePath, 'utf-8');
|
|
|
|
const json = 'module.exports = ' + JSON.stringify(js) + ';';
|
|
|
|
const outputPath = outputDir + '/' + name + '.js';
|
|
|
|
await fs.writeFile(outputPath, json);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main(argv) {
|
|
|
|
await fs.mkdirp(outputDir);
|
2019-03-08 19:14:17 +02:00
|
|
|
await copyJs('webviewLib', rnDir + '/lib/MdToHtml/webviewLib.js');
|
2019-02-28 01:38:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main(process.argv).catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|