fix(cli): show an error on startup if one of the binary dependencies is missing

Closes #95
pull/99/head
Romain 6 years ago
parent 424d2c8b8b
commit a5a75b81ad

@ -0,0 +1,31 @@
const chalk = require('chalk')
const commandExists = require('command-exists')
const COMMANDS = {
'gm': 'http://www.graphicsmagick.org',
'exiftool': 'https://www.sno.phy.queensu.ca/~phil/exiftool',
'ffmpeg': 'https://www.ffmpeg.org'
}
exports.verify = function () {
const missing = Object.keys(COMMANDS).reduce(addToArrayIfMissing, [])
if (missing.length > 0) {
const list = missing.map(nameAndURL).join('\n')
return `The following programs are required to run thumbsup:\n
${list}\n
Please make sure they are installed and available in the system path.`
}
return null
}
function addToArrayIfMissing (acc, cmd) {
if (!commandExists.sync(cmd)) {
acc.push(cmd)
}
return acc
}
function nameAndURL (cmd) {
const url = chalk.green(COMMANDS[cmd])
return `- ${cmd} (${url})`
}

@ -5,6 +5,7 @@ const fs = require('fs')
const messages = require('./messages')
const path = require('path')
const options = require('./options')
const checks = require('./checks')
const tty = require('tty')
console.log('')
@ -37,6 +38,13 @@ analytics.start()
// Catch all exceptions and exit gracefully
process.on('uncaughtException', handleError)
// Check that all binary dependencies are present
const missingErrors = checks.verify()
if (missingErrors) {
console.log(`${missingErrors}\n`)
exit(1)
}
// Build the gallery!
index.build(opts, (err, album) => {
if (err) {

5
package-lock.json generated

@ -603,6 +603,11 @@
"delayed-stream": "1.0.0"
}
},
"command-exists": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.6.tgz",
"integrity": "sha512-Qst/zUUNmS/z3WziPxyqjrcz09pm+2Knbs5mAZL4VAE0sSrNY1/w8+/YxeHcoBTsO6iojA6BW7eFf27Eg2MRuw=="
},
"commander": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",

@ -32,6 +32,7 @@
"async": "^2.5.0",
"better-sqlite3": "^4.0.3",
"chalk": "^2.3.0",
"command-exists": "^1.2.6",
"debug": "^3.1.0",
"event-stream": "^3.3.4",
"fs-extra": "^4.0.1",

Loading…
Cancel
Save