mirror of
https://github.com/TurboWarp/desktop.git
synced 2024-11-25 16:36:20 +08:00
Patch electron-builder to use our custom mime.xml
This commit is contained in:
parent
511282ef18
commit
dd81e44f52
@ -1,3 +1,5 @@
|
||||
require('./patch-electron-builder');
|
||||
|
||||
const pathUtil = require('path');
|
||||
const fs = require('fs');
|
||||
const builder = require('electron-builder');
|
||||
|
26
release-automation/patch-electron-builder.js
Normal file
26
release-automation/patch-electron-builder.js
Normal file
@ -0,0 +1,26 @@
|
||||
// Very bad things happen in here!
|
||||
|
||||
const fsPromises = require('fs/promises');
|
||||
const pathUtil = require('path');
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
// Override https://github.com/electron-userland/electron-builder/blob/14942b70a5da79a5e36e330f64de66ec501b4ac6/packages/app-builder-lib/src/targets/LinuxTargetHelper.ts#L28-L53
|
||||
// The upstream Linux file association support is not great so we'll just replace it with the one
|
||||
// that we wrote by hand until we can send an upstream-ready PR.
|
||||
const LinuxTargetHelper = require('../node_modules/app-builder-lib/out/targets/LinuxTargetHelper.js').LinuxTargetHelper;
|
||||
LinuxTargetHelper.prototype.computeMimeTypeFiles = async function (...args) {
|
||||
const tempFile = await this.packager.getTempFile('.xml');
|
||||
console.log(`${packageJSON.name}: LinuxTargetHelper.prototype.computeMimeTypeFiles has been patched. mime.xml to be saved to ${tempFile}`);
|
||||
|
||||
const xmlPath = pathUtil.join(__dirname, '../linux-files/org.turbowarp.TurboWarp.mime.xml');
|
||||
const rawXml = await fsPromises.readFile(xmlPath, 'utf-8');
|
||||
const newXml = rawXml.replace(/org\.turbowarp\.TurboWarp/g, packageJSON.name);
|
||||
|
||||
// Roughly equivalent to fs-extra's outputFile (creates parent directories as needed)
|
||||
await fsPromises.mkdir(pathUtil.dirname(tempFile), {
|
||||
recursive: true
|
||||
});
|
||||
await fsPromises.writeFile(tempFile, newXml);
|
||||
|
||||
return tempFile;
|
||||
};
|
Loading…
Reference in New Issue
Block a user