package: reduce number of prebuilt binaries (keep 64bit linux/windows/osx + node)

This commit is contained in:
bordun 2020-11-10 09:24:54 +01:00
parent df215612c5
commit b8173294aa
4 changed files with 38 additions and 27 deletions

View file

@ -1,4 +1,6 @@
var {PythonShell} = require('python-shell'),
fs = require('fs'),
path = require('path'),
settings = require('./settings'),
midiVersion = '1.7.0'
@ -7,18 +9,29 @@ var pythonOptions = {
mode:'text',
}
var midiBinaries = {
linux: 'osc-midi-linux',
darwin: 'osc-midi-osx',
win32: 'osc-midi-windows.exe'
}
var pythonPathOverride
if (process.arch === 'x64' && midiBinaries[process.platform]) {
if (fs.existsSync(path.resolve(__dirname, midiBinaries[process.platform]))) {
pythonPathOverride = midiBinaries[process.platform]
}
}
class MidiConverter {
constructor() {
var pythonPath = settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0]
this.py = new PythonShell('python/midi.py', Object.assign({
args: [
settings.read('debug') ? 'debug' : '',
...settings.read('midi')
],
pythonPath
pythonPath: MidiConverter.getPythonPath()
}, pythonOptions))
this.py.childProcess.on('error', (e)=>{
@ -85,9 +98,7 @@ class MidiConverter {
static list() {
var pythonPath = settings.read('midi') ? settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0] : undefined
PythonShell.run('python/midi.py', Object.assign({pythonPath: pythonPath, args: ['list-only']}, pythonOptions), function(e, results) {
PythonShell.run('python/midi.py', Object.assign({pythonPath: MidiConverter.getPythonPath(), args: ['list-only']}, pythonOptions), function(e, results) {
if (e) {
if (e.code === 'ENOENT') {
console.error(`(ERROR, MIDI) Could not find python binary: ${e.message.replace(/spawn (.*) ENOENT/, '$1')}`)
@ -103,6 +114,16 @@ class MidiConverter {
}
static getPythonPath() {
var pythonPath = settings.read('midi') ? settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0] : undefined
if (!pythonPath && pythonPathOverride) pythonPath = pythonPathOverride
return pythonPath
}
}
module.exports = MidiConverter