Update inject script for new release format

This commit is contained in:
Samuel Elliott 2019-03-17 12:59:58 +00:00
parent 0c361ce33f
commit 5681cf2045
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 40 additions and 15 deletions

View File

@ -37,7 +37,6 @@ const TEST_ARGS = () => {
'data': path.resolve(_baseDataPath, 'data'),
'editor': path.resolve(_basePath, 'editor', 'dist'),
// tmp: path.join(_basePath, 'tmp')
tmp: path.join(os.tmpdir(), 'betterdiscord', `${process.getuid()}`)
}
}
}
@ -337,6 +336,7 @@ export class BetterDiscord {
this.config.addPath('userfiles', userfiles);
this.config.addPath('snippets', snippets);
if (!this.config.getPath('editor')) this.config.addPath('editor', path.resolve(base, 'editor'));
if (!this.config.getPath('tmp')) this.config.addPath('tmp', path.join(os.tmpdir(), 'betterdiscord', `${process.getuid()}`));
}
/**

View File

@ -1,7 +1,9 @@
const args = process.argv;
const process = require('process');
const fs = require('fs');
const path = require('path');
const args = process.argv;
const useBdRelease = args[2] && args[2].toLowerCase() === 'release';
const releaseInput = useBdRelease ? args[3] && args[3].toLowerCase() : args[2] && args[2].toLowerCase();
const release = releaseInput === 'canary' ? 'Discord Canary' : releaseInput === 'ptb' ? 'Discord PTB' : 'Discord';
@ -31,30 +33,53 @@ console.log(`Found ${release} in ${discordPath}`);
const appPath = path.join(discordPath, 'app');
const packageJson = path.join(appPath, 'package.json');
const indexJs = path.join(appPath, 'index.js');
const bdJson = path.join(appPath, 'bd.json');
if (!fs.existsSync(appPath)) fs.mkdirSync(appPath);
if (fs.existsSync(packageJson)) fs.unlinkSync(packageJson);
if (fs.existsSync(indexJs)) fs.unlinkSync(indexJs);
const bdPath = useBdRelease ? path.resolve(__dirname, '..', 'release') : path.resolve(__dirname, '..');
if (fs.existsSync(bdJson)) fs.unlinkSync(bdJson);
console.log(`Writing package.json`);
fs.writeFileSync(packageJson, JSON.stringify({
fs.writeFileSync(path.join(appPath, 'package.json'), JSON.stringify({
name: 'betterdiscord',
description: 'BetterDiscord',
main: 'index.js',
private: true
}, null, 4));
console.log(`Writing index.js`);
fs.writeFileSync(indexJs, `const path = require('path');
const fs = require('fs');
const Module = require('module');
const electron = require('electron');
const basePath = path.join(__dirname, '..', 'app.asar');
electron.app.getAppPath = () => basePath;
Module._load(basePath, null, true);
electron.app.on('ready', () => new (require('${bdPath.replace(/\\/g, '\\\\').replace(/'/g, '\\\'')}').BetterDiscord)());
`);
if (useBdRelease) {
console.log(`Writing index.js`);
fs.writeFileSync(path.join(appPath, 'index.js'), fs.readFileSync(path.resolve(__dirname, '..', 'installer', 'stub.js')));
console.log(`Writing bd.json`);
fs.writeFileSync(path.join(appPath, 'bd.json'), JSON.stringify({
options: {
autoInject: true,
commonCore: true,
commonData: true
},
paths: {
core: path.resolve(__dirname, '..', 'release', 'core'),
client: path.resolve(__dirname, '..', 'release', 'client'),
editor: path.resolve(__dirname, '..', 'release', 'editor'),
data: path.resolve(__dirname, '..', 'release', 'data'),
// tmp: path.resolve(os.tmpdir(), 'betterdiscord', `${process.getuid()}`)
}
}, null, 4));
} else {
const bdPath = path.resolve(__dirname, '..');
console.log(`Writing index.js`);
fs.writeFileSync(path.join(appPath, 'index.js'), `const path = require('path');
const fs = require('fs');
const Module = require('module');
const electron = require('electron');
const basePath = path.join(__dirname, '..', 'app.asar');
electron.app.getAppPath = () => basePath;
Module._load(basePath, null, true);
electron.app.on('ready', () => new (require('${bdPath.replace(/\\/g, '\\\\').replace(/'/g, '\\\'')}').BetterDiscord)());
`);
}
console.log(`Injection successful, please restart ${release}.`);