|
| 1 | +// https://github.com/patrikx3/redis-ui/blob/b772176fc71f5cccbe1dbe31c8f7bd0fdb75f52e/src/build/after-pack.js |
| 2 | + |
| 3 | +const fs = require('fs-extra'); |
| 4 | +const pkg = require('../package'); |
| 5 | +const { spawn } = require('child_process'); |
| 6 | +const { chdir } = require('process'); |
| 7 | + |
| 8 | +const exec = async function exec(cmd, args = []) { |
| 9 | + const child = spawn(cmd, args, { shell: true }); |
| 10 | + redirectOutputFor(child); |
| 11 | + await waitFor(child); |
| 12 | +}; |
| 13 | + |
| 14 | +const redirectOutputFor = (child) => { |
| 15 | + const printStdout = (data) => { |
| 16 | + process.stdout.write(data.toString()); |
| 17 | + }; |
| 18 | + const printStderr = (data) => { |
| 19 | + process.stderr.write(data.toString()); |
| 20 | + }; |
| 21 | + child.stdout.on('data', printStdout); |
| 22 | + child.stderr.on('data', printStderr); |
| 23 | + |
| 24 | + child.once('close', () => { |
| 25 | + child.stdout.off('data', printStdout); |
| 26 | + child.stderr.off('data', printStderr); |
| 27 | + }); |
| 28 | +}; |
| 29 | + |
| 30 | +const waitFor = async function(child) { |
| 31 | + return new Promise((resolve) => { |
| 32 | + child.once('close', () => resolve()); |
| 33 | + }); |
| 34 | +}; |
| 35 | + |
| 36 | +module.exports = async function(context) { |
| 37 | + // eslint-disable-next-line no-console |
| 38 | + console.warn('after build; disable sandbox'); |
| 39 | + const isLinux = context.targets.find(target => target.name === 'appImage' || target.name === 'snap'); |
| 40 | + if (!isLinux) { |
| 41 | + return; |
| 42 | + } |
| 43 | + const originalDir = process.cwd(); |
| 44 | + const dirname = context.appOutDir; |
| 45 | + chdir(dirname); |
| 46 | + |
| 47 | + await exec('mv', [pkg.name, pkg.name + '.bin']); |
| 48 | + const wrapperScript = `#!/bin/bash |
| 49 | + "\${BASH_SOURCE%/*}"/${pkg.name}.bin "$@" --no-sandbox |
| 50 | + `; |
| 51 | + fs.writeFileSync(pkg.name, wrapperScript); |
| 52 | + await exec('chmod', ['+x', pkg.name]); |
| 53 | + |
| 54 | + chdir(originalDir); |
| 55 | +}; |
0 commit comments