| return new Promise((resolve, reject) => { | return new Promise((resolve, reject) => { | ||||
| fs.access(file, fs.constants.F_OK, (err) => { | fs.access(file, fs.constants.F_OK, (err) => { | ||||
| if (err && err.code === "ENOENT") { | if (err && err.code === "ENOENT") { | ||||
| reject(new Error(`${file} does not exist`)); | |||||
| resolve(false); | |||||
| } else { | } else { | ||||
| resolve(true); | resolve(true); | ||||
| } | } | ||||
| `${outputDir}${outputImg}`, | `${outputDir}${outputImg}`, | ||||
| ]; | ]; | ||||
| const libreOfficeBins = [ | const libreOfficeBins = [ | ||||
| libreofficeBin, | |||||
| ...(libreofficeBin ? [libreofficeBin] : []), | |||||
| ...(Array.isArray(libreofficeBins) ? libreofficeBins : []) | ...(Array.isArray(libreofficeBins) ? libreofficeBins : []) | ||||
| ]; | ]; | ||||
| if (!libreofficeBin) { | if (!libreofficeBin) { | ||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files\\\\LibreOffice\\\\program\\\\soffice.exe")); | |||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files (x86)\\\\LibreOffice\\\\program\\\\soffice.exe")); | |||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files (x86)\\\\LIBREO~1\\\\program\\\\soffice.exe")); | |||||
| libreOfficeBins.push(path.resolve("/usr/bin/libreoffice")); | libreOfficeBins.push(path.resolve("/usr/bin/libreoffice")); | ||||
| libreOfficeBins.push(path.resolve("/usr/bin/soffice")); | libreOfficeBins.push(path.resolve("/usr/bin/soffice")); | ||||
| libreOfficeBins.push(path.resolve("/Applications/LibreOffice.app/Contents/MacOS/soffice")); | libreOfficeBins.push(path.resolve("/Applications/LibreOffice.app/Contents/MacOS/soffice")); | ||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files\\\\LibreOffice\\\\program\\\\soffice.exe")); | |||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files (x86)\\\\LibreOffice\\\\program\\\\soffice.exe")); | |||||
| libreOfficeBins.push(path.resolve("C:\\\\Program Files (x86)\\\\LIBREO~1\\\\program\\\\soffice.exe")); | |||||
| } | } | ||||
| return getFileThatExist(...libreOfficeBins).then((libreofficeBin) => { | return getFileThatExist(...libreOfficeBins).then((libreofficeBin) => { | ||||
| if (libreofficeBin) { | if (libreofficeBin) { | ||||
| //Re arrange the array for more efficient future runs | |||||
| if (libreOfficeBins[0] !== libreofficeBin) { | |||||
| libreOfficeBins.splice(libreOfficeBins.indexOf(libreofficeBin), 1); | |||||
| libreOfficeBins.unshift(libreofficeBin); | |||||
| } | |||||
| return filesExist(sourceFile).then((srcExist) => { | return filesExist(sourceFile).then((srcExist) => { | ||||
| if (srcExist) { | if (srcExist) { | ||||
| if (ext === ".pdf") | if (ext === ".pdf") |