mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-06-16 10:52:20 +00:00
Add build step to infer and convert pngs to icns
This commit is contained in:
parent
8eaa3a39e0
commit
5475c6e968
|
@ -27,8 +27,6 @@ fi
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
SOURCE=$1
|
SOURCE=$1
|
||||||
echo $1
|
|
||||||
echo $2
|
|
||||||
|
|
||||||
# Get source image
|
# Get source image
|
||||||
if [ -z "${SOURCE}" ]; then
|
if [ -z "${SOURCE}" ]; then
|
||||||
|
|
|
@ -3,8 +3,8 @@ import path from 'path';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
|
|
||||||
import optionsFactory from './options';
|
import optionsFactory from './options';
|
||||||
import pngToIcns from './getIcon';
|
import pngToIcns from './pngToIcns';
|
||||||
import helpers from './helpers';
|
import iconBuild from './iconBuild';
|
||||||
import packager from 'electron-packager';
|
import packager from 'electron-packager';
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
import ncp from 'ncp';
|
import ncp from 'ncp';
|
||||||
|
@ -14,7 +14,6 @@ import _ from 'lodash';
|
||||||
import packageJson from './../package.json';
|
import packageJson from './../package.json';
|
||||||
|
|
||||||
const copy = ncp.ncp;
|
const copy = ncp.ncp;
|
||||||
const isOSX = helpers.isOSX;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback buildAppCallback
|
* @callback buildAppCallback
|
||||||
|
@ -60,14 +59,8 @@ function buildApp(options, callback) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(tempDir, options, callback) => {
|
(tempDir, options, callback) => {
|
||||||
if (options.platform !== 'darwin' || !isOSX()) {
|
iconBuild(options, (error, optionsWithIcon) => {
|
||||||
callback(null, tempDir, options);
|
callback(null, tempDir, optionsWithIcon);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pngToIcns(options.icon, (error, icnsPath) => {
|
|
||||||
options.icon = icnsPath;
|
|
||||||
callback(error, tempDir, options);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
(tempDir, options, callback) => {
|
(tempDir, options, callback) => {
|
||||||
|
@ -81,7 +74,6 @@ function buildApp(options, callback) {
|
||||||
// somehow appPathArray is a 1 element array
|
// somehow appPathArray is a 1 element array
|
||||||
if (appPathArray.length === 0) {
|
if (appPathArray.length === 0) {
|
||||||
// directory already exists, --overwrite is not set
|
// directory already exists, --overwrite is not set
|
||||||
|
|
||||||
// exit here
|
// exit here
|
||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
|
|
73
src/iconBuild.js
Normal file
73
src/iconBuild.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import path from 'path';
|
||||||
|
import helpers from './helpers';
|
||||||
|
import pngToIcns from './pngToIcns';
|
||||||
|
const isOSX = helpers.isOSX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback augmentIconsCallback
|
||||||
|
* @param error
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will check and convert a `.png` to `.icns` if necessary and augment
|
||||||
|
* options.icon with the result
|
||||||
|
*
|
||||||
|
* @param options will need options.platform and options.icon
|
||||||
|
* @param {augmentIconsCallback} callback
|
||||||
|
*/
|
||||||
|
function iconBuild(options, callback) {
|
||||||
|
|
||||||
|
const returnCallback = () => {
|
||||||
|
callback(null, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!options.icon) {
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.platform !== 'darwin') {
|
||||||
|
if (!iconIsPng(options.icon)) {
|
||||||
|
console.warn('Icon should be a png for Linux and Windows apps');
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconIsIcns(options.icon)) {
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconIsPng(options.icon)) {
|
||||||
|
|
||||||
|
if (!isOSX()) {
|
||||||
|
console.warn('Conversion of `.png` to `.icns` for OSX app is only supported on OSX');
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pngToIcns(options.icon, (error, icnsPath) => {
|
||||||
|
options.icon = icnsPath;
|
||||||
|
if (error) {
|
||||||
|
console.warn('Skipping icon conversion from `.png` to `.icns`: ', error);
|
||||||
|
}
|
||||||
|
returnCallback();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function iconIsPng(iconPath) {
|
||||||
|
return path.extname(iconPath) === '.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
function iconIsIcns(iconPath) {
|
||||||
|
return path.extname(iconPath) === '.icns';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default iconBuild;
|
|
@ -1,17 +1,16 @@
|
||||||
import shell from 'shelljs';
|
import shell from 'shelljs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
|
import helpers from './helpers';
|
||||||
|
const isOSX = helpers.isOSX;
|
||||||
tmp.setGracefulCleanup();
|
tmp.setGracefulCleanup();
|
||||||
|
|
||||||
const PNG_TO_ICNS_BIN_PATH = path.join(__dirname, '..', 'bin/pngToIcns');
|
const PNG_TO_ICNS_BIN_PATH = path.join(__dirname, '..', 'bin/pngToIcns');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback pngToIcnsCallback
|
* @callback pngToIcnsCallback
|
||||||
* @param {{}} error
|
* @param error
|
||||||
* @param {string} error.stdOut
|
* @param {string} icnsDest If error, will return the original png src
|
||||||
* @param {string} error.stdError
|
|
||||||
* @param {string} icnsDest
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,12 +20,17 @@ const PNG_TO_ICNS_BIN_PATH = path.join(__dirname, '..', 'bin/pngToIcns');
|
||||||
* @param {pngToIcnsCallback} callback
|
* @param {pngToIcnsCallback} callback
|
||||||
*/
|
*/
|
||||||
function pngToIcns(pngSrc, icnsDest, callback) {
|
function pngToIcns(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) => {
|
shell.exec(`${PNG_TO_ICNS_BIN_PATH} ${pngSrc} ${icnsDest}`, {silent: true}, (exitCode, stdOut, stdError) => {
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
callback({
|
callback({
|
||||||
stdOut: stdOut,
|
stdOut: stdOut,
|
||||||
stdError: stdError
|
stdError: stdError
|
||||||
});
|
}, pngSrc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import tmp from 'tmp';
|
||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import pngToIcns from './../../lib/getIcon';
|
import pngToIcns from './../../lib/pngToIcns';
|
||||||
|
|
||||||
let assert = chai.assert;
|
let assert = chai.assert;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user