From eb13543e95052b2d1a0c6cd3376c9655579527bc Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 22 Dec 2018 13:19:30 -0400 Subject: Make mtui work in webpack --- general-util.js | 62 ++------------------------------------------------------- 1 file changed, 2 insertions(+), 60 deletions(-) (limited to 'general-util.js') diff --git a/general-util.js b/general-util.js index 0b9f081..abe2399 100644 --- a/general-util.js +++ b/general-util.js @@ -1,72 +1,14 @@ -const { spawn } = require('child_process') -const { promisify } = require('util') -const fetch = require('node-fetch') -const fs = require('fs') -const npmCommandExists = require('command-exists') - -const readFile = promisify(fs.readFile) - -module.exports.promisifyProcess = function(proc, showLogging = true) { - // Takes a process (from the child_process module) and returns a promise - // that resolves when the process exits (or rejects, if the exit code is - // non-zero). - - return new Promise((resolve, reject) => { - if (showLogging) { - proc.stdout.pipe(process.stdout) - proc.stderr.pipe(process.stderr) - } - - proc.on('exit', code => { - if (code === 0) { - resolve() - } else { - reject(code) - } - }) - }) -} - module.exports.commandExists = async function(command) { - // When the command-exists module sees that a given command doesn't exist, it - // throws an error instead of returning false, which is not what we want. - - try { - return await npmCommandExists(command) - } catch(err) { - return false - } -} - -module.exports.killProcess = async function(proc) { - // Windows is stupid and doesn't like it when we try to kill processes. - // So instead we use taskkill! https://stackoverflow.com/a/28163919/4633828 - - if (await module.exports.commandExists('taskkill')) { - await module.exports.promisifyProcess( - spawn('taskkill', ['/pid', proc.pid, '/f', '/t']), - false - ) - } else { - proc.kill() - } + return false } function downloadPlaylistFromURL(url) { return fetch(url).then(res => res.text()) } -function downloadPlaylistFromLocalPath(path) { - return readFile(path).then(buf => buf.toString()) -} - module.exports.downloadPlaylistFromOptionValue = function(arg) { // TODO: Verify things! - if (arg.startsWith('http://') || arg.startsWith('https://')) { - return downloadPlaylistFromURL(arg) - } else { - return downloadPlaylistFromLocalPath(arg) - } + return downloadPlaylistFromURL(arg) } module.exports.shuffleArray = function(array) { -- cgit 1.3.0-6-gf8a5