2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-03 05:10:47 +00:00
nativefier/src/helpers/helpers.js
Ronan Jouchet 6fb3b92eb8
Upgrade dependencies and default to latest Electron 1.7.9 (PR #483)
* Update deps except eslint
* Update eslint and lint:fix (WIP, needs manual fixing for remaining 44 problems)
* Manually fix remaining eslint errors
* Document deprecation of `version-string` as of electron-packager 9.0.0
* Upgrade to Electron 1.7.9 (chrome-58, node-7.9.0, v8-5.8)
* npm: Disable generation of package-lock.json and gitignore it
  --Trying this, package-lock is a pain in PRs. May not be a good idea
  (obviously we lose deps pinning), will revert if necessary.--
* npm tasks: add dev-up-win for Windows developers,
  and e2e for end-to-end tests. Update docs.
* Move normalizeUrl test to a jest unit test, makes no sense to be in the mocha e2e tests
* Switch from babel-preset-es2015 to babel-preset-env,
  with target.node=4.0. Seem like it's today's most convenient
  way to support the latest ES and let babel transpile to what
  makes sense for our currently minimal node version
2017-11-14 08:05:01 -05:00

103 lines
2.1 KiB
JavaScript

import os from 'os';
import axios from 'axios';
import hasBinary from 'hasbin';
import path from 'path';
function isOSX() {
return os.platform() === 'darwin';
}
function isWindows() {
return os.platform() === 'win32';
}
function downloadFile(fileUrl) {
return axios.get(fileUrl, {
responseType: 'arraybuffer',
})
.then((response) => {
if (!response.data) {
return null;
}
return {
data: response.data,
ext: path.extname(fileUrl),
};
});
}
function allowedIconFormats(platform) {
const hasIdentify = hasBinary.sync('identify');
const hasConvert = hasBinary.sync('convert');
const hasIconUtil = hasBinary.sync('iconutil');
const pngToIcns = hasConvert && hasIconUtil;
const pngToIco = hasConvert;
const icoToIcns = pngToIcns && hasIdentify;
const icoToPng = hasConvert;
// todo scripts for the following
const icnsToPng = false;
const icnsToIco = false;
const formats = [];
// todo shell scripting is not supported on windows, temporary override
if (isWindows()) {
switch (platform) {
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}`);
}
return formats;
}
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;
}
export default {
isOSX,
isWindows,
downloadFile,
allowedIconFormats,
};