1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-mobile/tools/buildReactNativeInjectedJs.js

24 lines
844 B
JavaScript
Raw Normal View History

// React Native WebView cannot load external JS files, however it can load
// arbitrary 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.
const fs = require('fs-extra');
const rnDir = `${__dirname}/..`;
const outputDir = `${rnDir}/lib/rnInjectedJs`;
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`;
await fs.writeFile(outputPath, json);
}
async function main() {
await fs.mkdirp(outputDir);
2020-11-05 18:58:23 +02:00
await copyJs('webviewLib', `${rnDir}/node_modules/@joplinapp/lib/renderers/webviewLib.js`);
}
module.exports = main;