mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-09-28 20:29:04 +00:00
6fb3b92eb8
* 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
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import shell from 'shelljs';
|
|
import path from 'path';
|
|
import tmp from 'tmp';
|
|
import helpers from './helpers';
|
|
|
|
const { isOSX } = helpers;
|
|
tmp.setGracefulCleanup();
|
|
|
|
const PNG_TO_ICNS_BIN_PATH = path.join(__dirname, '../..', 'bin/convertToIcns');
|
|
|
|
/**
|
|
* @callback pngToIcnsCallback
|
|
* @param error
|
|
* @param {string} icnsDest If error, will return the original png src
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* @param {string} pngSrc
|
|
* @param {string} icnsDest
|
|
* @param {pngToIcnsCallback} callback
|
|
*/
|
|
function convertToIcns(pngSrc, icnsDest, callback) {
|
|
if (!isOSX()) {
|
|
callback('OSX is required to convert .png to .icns icon', pngSrc);
|
|
return;
|
|
}
|
|
|
|
shell.exec(`${PNG_TO_ICNS_BIN_PATH} ${pngSrc} ${icnsDest}`, { silent: true }, (exitCode, stdOut, stdError) => {
|
|
if (stdOut.includes('icon.iconset:error') || exitCode) {
|
|
if (exitCode) {
|
|
callback({
|
|
stdOut,
|
|
stdError,
|
|
}, pngSrc);
|
|
return;
|
|
}
|
|
|
|
callback(stdOut, pngSrc);
|
|
return;
|
|
}
|
|
|
|
callback(null, icnsDest);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Converts the png to a temporary directory which will be cleaned up on process exit
|
|
* @param {string} pngSrc
|
|
* @param {pngToIcnsCallback} callback
|
|
*/
|
|
function convertToIcnsTmp(pngSrc, callback) {
|
|
const tempIconDirObj = tmp.dirSync({ unsafeCleanup: true });
|
|
const tempIconDirPath = tempIconDirObj.name;
|
|
convertToIcns(pngSrc, `${tempIconDirPath}/icon.icns`, callback);
|
|
}
|
|
|
|
export default convertToIcnsTmp;
|