2016-01-27 02:36:30 +00:00
|
|
|
import os from 'os';
|
2016-03-11 04:40:08 +00:00
|
|
|
import axios from 'axios';
|
2016-03-12 07:17:03 +00:00
|
|
|
import hasBinary from 'hasbin';
|
|
|
|
import path from 'path';
|
2016-01-27 02:36:30 +00:00
|
|
|
|
|
|
|
function isOSX() {
|
2017-04-29 14:52:12 +00:00
|
|
|
return os.platform() === 'darwin';
|
2016-01-27 02:36:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-28 15:02:42 +00:00
|
|
|
function isWindows() {
|
2017-04-29 14:52:12 +00:00
|
|
|
return os.platform() === 'win32';
|
2016-01-28 15:02:42 +00:00
|
|
|
}
|
2016-01-29 03:37:54 +00:00
|
|
|
|
2016-03-11 04:40:08 +00:00
|
|
|
function downloadFile(fileUrl) {
|
2017-11-14 13:05:01 +00:00
|
|
|
return axios.get(fileUrl, {
|
|
|
|
responseType: 'arraybuffer',
|
|
|
|
})
|
2017-04-29 14:52:12 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (!response.data) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
data: response.data,
|
|
|
|
ext: path.extname(fileUrl),
|
|
|
|
};
|
|
|
|
});
|
2016-03-11 04:40:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-12 07:17:03 +00:00
|
|
|
function allowedIconFormats(platform) {
|
2017-04-29 14:52:12 +00:00
|
|
|
const hasIdentify = hasBinary.sync('identify');
|
|
|
|
const hasConvert = hasBinary.sync('convert');
|
|
|
|
const hasIconUtil = hasBinary.sync('iconutil');
|
2016-03-12 07:17:03 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
const pngToIcns = hasConvert && hasIconUtil;
|
|
|
|
const pngToIco = hasConvert;
|
|
|
|
const icoToIcns = pngToIcns && hasIdentify;
|
|
|
|
const icoToPng = hasConvert;
|
2016-03-12 07:17:03 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
// todo scripts for the following
|
|
|
|
const icnsToPng = false;
|
|
|
|
const icnsToIco = false;
|
2016-03-12 07:17:03 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
const formats = [];
|
2016-03-12 07:17:03 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
// todo shell scripting is not supported on windows, temporary override
|
|
|
|
if (isWindows()) {
|
2016-03-12 07:17:03 +00:00
|
|
|
switch (platform) {
|
2017-04-29 14:52:12 +00:00
|
|
|
case 'darwin':
|
|
|
|
formats.push('.icns');
|
|
|
|
break;
|
|
|
|
case 'linux':
|
|
|
|
formats.push('.png');
|
|
|
|
break;
|
|
|
|
case 'win32':
|
|
|
|
formats.push('.ico');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error(`function allowedIconFormats error: Unknown platform ${platform}`);
|
2016-03-12 07:17:03 +00:00
|
|
|
}
|
|
|
|
return formats;
|
2017-04-29 14:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
|
|
|
formats.push('.icns');
|
|
|
|
if (pngToIcns) {
|
|
|
|
formats.push('.png');
|
|
|
|
}
|
|
|
|
if (icoToIcns) {
|
|
|
|
formats.push('.ico');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'linux':
|
|
|
|
formats.push('.png');
|
|
|
|
if (icoToPng) {
|
|
|
|
formats.push('.ico');
|
|
|
|
}
|
|
|
|
if (icnsToPng) {
|
|
|
|
formats.push('.icns');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'win32':
|
|
|
|
formats.push('.ico');
|
|
|
|
if (pngToIco) {
|
|
|
|
formats.push('.png');
|
|
|
|
}
|
|
|
|
if (icnsToIco) {
|
|
|
|
formats.push('.icns');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error(`function allowedIconFormats error: Unknown platform ${platform}`);
|
|
|
|
}
|
|
|
|
return formats;
|
2016-03-12 07:17:03 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 02:36:30 +00:00
|
|
|
export default {
|
2017-04-29 14:52:12 +00:00
|
|
|
isOSX,
|
|
|
|
isWindows,
|
|
|
|
downloadFile,
|
|
|
|
allowedIconFormats,
|
2016-01-27 02:36:30 +00:00
|
|
|
};
|