You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Tools: Improve and simplify how to build the apps (#2538)
* Improving CLI build * Improving CLI build * Remove requirement to build the tools * Moved Electron app one level down * Clean up Electron build * Moved tools to sub-dir * Updated root script * update root * update root * update root * update root * update root * update root * Updated build * Added doc * Update CI config * Should not lint index.js * Fixing jetify * Fixed linter errors * Fixed pod build * Fixed Windows build
This commit is contained in:
23
ReactNativeClient/tools/buildReactNativeInjectedJs.js
Normal file
23
ReactNativeClient/tools/buildReactNativeInjectedJs.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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');
|
||||
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`);
|
||||
}
|
||||
|
||||
module.exports = main;
|
||||
70
ReactNativeClient/tools/encodeAssets.js
Normal file
70
ReactNativeClient/tools/encodeAssets.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const utils = require('../../Tools/gulp/utils');
|
||||
const fs = require('fs-extra');
|
||||
const md5 = require('md5');
|
||||
|
||||
const rootDir = `${__dirname}/..`;
|
||||
const outputDir = `${rootDir}/pluginAssets`;
|
||||
|
||||
var walk = function(dir) {
|
||||
var results = [];
|
||||
var list = fs.readdirSync(dir);
|
||||
list.forEach(function(file) {
|
||||
file = `${dir}/${file}`;
|
||||
var stat = fs.statSync(file);
|
||||
if (stat && stat.isDirectory()) {
|
||||
results = results.concat(walk(file));
|
||||
} else {
|
||||
results.push(file);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
async function encodeFile(sourcePath, destPath) {
|
||||
const buffer = await fs.readFile(sourcePath);
|
||||
const hash = md5(buffer.toString('base64'));
|
||||
const js = `module.exports = \`${buffer.toString('base64')}\`;`;
|
||||
const outputPath = `${outputDir}/${destPath}.base64.js`;
|
||||
await fs.mkdirp(utils.dirname(outputPath));
|
||||
await fs.writeFile(outputPath, js);
|
||||
|
||||
const ext = utils.fileExtension(sourcePath).toLowerCase();
|
||||
let mime = 'application/octet-stream';
|
||||
if (ext === 'js') mime = 'application/javascript';
|
||||
if (ext === 'css') mime = 'text/css';
|
||||
|
||||
return {
|
||||
encoding: 'base64',
|
||||
name: destPath,
|
||||
encodedName: `${destPath}.base64.js`,
|
||||
mime: mime,
|
||||
hash: hash,
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await fs.remove(outputDir);
|
||||
await fs.mkdirp(outputDir);
|
||||
|
||||
const encodedFiles = [];
|
||||
const sourceAssetDir = `${rootDir}/lib/joplin-renderer/assets`;
|
||||
const files = walk(sourceAssetDir);
|
||||
|
||||
for (const file of files) {
|
||||
const destFile = file.substr(sourceAssetDir.length + 1);
|
||||
encodedFiles.push(await encodeFile(file, destFile));
|
||||
}
|
||||
|
||||
const hashes = [];
|
||||
const indexJs = [];
|
||||
for (const file of encodedFiles) {
|
||||
indexJs.push(`'${file.name}': { data: require('./${file.encodedName}'), mime: '${file.mime}', encoding: '${file.encoding}' },`);
|
||||
hashes.push(file.hash);
|
||||
}
|
||||
|
||||
const hash = md5(hashes.join(''));
|
||||
|
||||
await fs.writeFile(`${outputDir}/index.js`, `module.exports = {\nhash:"${hash}", files: {\n${indexJs.join('\n')}\n}\n};`);
|
||||
}
|
||||
|
||||
module.exports = main;
|
||||
15
ReactNativeClient/tools/podInstall.js
Normal file
15
ReactNativeClient/tools/podInstall.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const execa = require('execa');
|
||||
|
||||
module.exports = async function() {
|
||||
if (process.platform !== 'darwin') return Promise.resolve();
|
||||
|
||||
try {
|
||||
const promise = execa('pod', ['install'], { cwd: `${__dirname}/../ios` });
|
||||
promise.stdout.pipe(process.stdout);
|
||||
await promise;
|
||||
} catch (error) {
|
||||
console.warn('Could not run pod install', error);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
};
|
||||
Reference in New Issue
Block a user