mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Chore: Windows: Fix mobile plugin assets change when rebuilding the mobile app (#10886)
This commit is contained in:
parent
7bc81880e1
commit
9cb13af7b0
@ -1,4 +1,5 @@
|
|||||||
const utils = require('@joplin/tools/gulp/utils');
|
const utils = require('@joplin/tools/gulp/utils');
|
||||||
|
const { toForwardSlashes } = require('@joplin/utils/path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
@ -22,20 +23,34 @@ const walk = function(dir) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function encodeFile(sourcePath, destPath) {
|
const readAsBase64 = async (path, mime) => {
|
||||||
const buffer = await fs.readFile(sourcePath);
|
let buffer;
|
||||||
const hash = md5(buffer.toString('base64'));
|
// Normalize line endings to prevent hashes from changing when recompiling on
|
||||||
const js = `module.exports = \`${buffer.toString('base64')}\`;`;
|
// Windows (if originally compiled on Unix).
|
||||||
const outputPath = `${outputDir}/${destPath}.base64.js`;
|
if (mime === 'application/javascript' || mime.startsWith('text/')) {
|
||||||
console.info(`Encoding "${sourcePath}" => "${outputPath}"`);
|
const file = await fs.readFile(path, 'utf-8');
|
||||||
await utils.mkdirp(utils.dirname(outputPath));
|
buffer = Buffer.from(file.replace(/\r\n/g, '\n'), 'utf-8');
|
||||||
await fs.writeFile(outputPath, js);
|
} else {
|
||||||
|
buffer = await fs.readFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString('base64');
|
||||||
|
};
|
||||||
|
|
||||||
|
async function encodeFile(sourcePath, destPath) {
|
||||||
const ext = utils.fileExtension(sourcePath).toLowerCase();
|
const ext = utils.fileExtension(sourcePath).toLowerCase();
|
||||||
let mime = 'application/octet-stream';
|
let mime = 'application/octet-stream';
|
||||||
if (ext === 'js') mime = 'application/javascript';
|
if (ext === 'js') mime = 'application/javascript';
|
||||||
if (ext === 'css') mime = 'text/css';
|
if (ext === 'css') mime = 'text/css';
|
||||||
|
|
||||||
|
const base64Data = await readAsBase64(sourcePath, mime);
|
||||||
|
const hash = md5(base64Data);
|
||||||
|
const js = `module.exports = \`${base64Data}\`;`;
|
||||||
|
const outputPath = `${outputDir}/${destPath}.base64.js`;
|
||||||
|
console.info(`Encoding "${sourcePath}" => "${outputPath}"`);
|
||||||
|
await utils.mkdirp(utils.dirname(outputPath));
|
||||||
|
await fs.writeFile(outputPath, js);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
encoding: 'base64',
|
encoding: 'base64',
|
||||||
name: destPath,
|
name: destPath,
|
||||||
@ -72,7 +87,7 @@ async function main() {
|
|||||||
await fs.writeFile(`${outputDir}/index.js`, `module.exports = {\nhash:"${hash}", files: {\n${indexJs.join('\n')}\n}\n};`);
|
await fs.writeFile(`${outputDir}/index.js`, `module.exports = {\nhash:"${hash}", files: {\n${indexJs.join('\n')}\n}\n};`);
|
||||||
await fs.writeFile(`${outputDir}/index.web.js`, `module.exports = ${JSON.stringify({
|
await fs.writeFile(`${outputDir}/index.web.js`, `module.exports = ${JSON.stringify({
|
||||||
hash,
|
hash,
|
||||||
files: files.map(file => path.relative(sourceAssetDir, file)),
|
files: files.map(file => toForwardSlashes(path.relative(sourceAssetDir, file))),
|
||||||
})}`);
|
})}`);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user