1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/Tools/buildReactNativeInjectedJs.js
luzpaz d3ba6798d7 Doc: Fix documentation and source comment typos (#2037)
* Misc. typo and whitespace fixes

Found via `codespell -q 3 -S *.po,*.pot,./ElectronClient/app/locales,./ReactNativeClient/locales,./CliClient/locales -L adresse,ba,fonction,te,whet`

* Revert a previous change
2019-10-29 09:02:42 +00:00

28 lines
923 B
JavaScript

// 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 cwd = process.cwd();
const outputDir = `${cwd}/lib/rnInjectedJs`;
const rnDir = `${__dirname}/../ReactNativeClient`;
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() {
await fs.mkdirp(outputDir);
await copyJs('webviewLib', `${rnDir}/lib/renderers/webviewLib.js`);
}
main(process.argv).catch((error) => {
console.error(error);
process.exit(1);
});