Skip to content

Commit

Permalink
Fixes #27, where /usr/bin/type was not found on windows (#28)
Browse files Browse the repository at this point in the history
Should fix [this
issue](#27) where
/usr/bin/type was not found in order to check for `convert` and `gm`
binaries in $PATH.
  • Loading branch information
alexanderscott committed Aug 9, 2023
1 parent 0edb1b1 commit f803c5f
Show file tree
Hide file tree
Showing 4 changed files with 516 additions and 223 deletions.
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ commander
.option('--only-web', 'Only generate Web icons')
.parse(process.argv);

var inputImage = path.resolve(process.cwd(), commander.args[0]);
var outputPath = (commander.args[1] &&
const inputImage = path.resolve(process.cwd(), commander.args[0]);
let outputPath = (commander.args[1] &&
fs.statSync(path.resolve(process.cwd(), commander.args[1])).isDirectory()) ?
path.resolve(process.cwd(), commander.args[1]) :
process.cwd();
Expand Down
30 changes: 15 additions & 15 deletions lib/iconerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ var fs = require('fs'),
gm = require('gm'),
im = require('imagemagick'),
async = require('async'),
commandExists = require('command-exists'),
_ = require('underscore'),
child_process = require('child_process'),
config = require(__dirname+'/config');


function createWebIconFolders(outputPath) {
if(!fs.existsSync(path.join(outputPath, config.output.webDir))) {
fs.mkdirSync(path.join(outputPath, config.output.webDir));
}
};
}

function createAndroidIconFolders(outputPath) {
var baseDir = path.join(outputPath, config.output.androidDir);
var dirs = [
const baseDir = path.join(outputPath, config.output.androidDir);
const dirs = [
'',
'/res',
'/res/drawable-ldpi',
Expand All @@ -35,29 +35,29 @@ function createAndroidIconFolders(outputPath) {
'/res/mipmap-xxxhdpi'
];

for(var i = 0; i < dirs.length; i++){
for(let i = 0; i < dirs.length; i++){
if(!fs.existsSync(path.join(baseDir, dirs[i]))) fs.mkdirSync(baseDir + dirs[i]);
}
};
}

function createIOSIconFolders(outputPath) {
if(!fs.existsSync(path.join(outputPath, config.output.iosDir))) {
fs.mkdirSync(path.join(outputPath, config.output.iosDir));
}
};
}

exports.checkDependencies = function(cb) {
child_process.exec("/usr/bin/type convert", function(err, stdout){
if(err || stdout === "") return cb("ImageMagick binary not found");
child_process.exec("/usr/bin/type gm", function(err, stdout){
if(err || stdout === "") return cb("GraphicsMagick binary not found");
commandExists('convert', function(err, convertExists){
if(!convertExists) return cb("ImageMagick binary not found");
commandExists('gm', function(err, gmExists){
if(!gmExists) return cb("GraphicsMagick binary not found");
cb(null);
});
});
})
};

exports.generateIcons = function(inputImg, outputPath, platform, device, cb) {
var iconMeta = config.icons,
let iconMeta = config.icons,
error;

if(!fs.statSync(inputImg).isFile()){
Expand Down Expand Up @@ -86,7 +86,7 @@ exports.generateIcons = function(inputImg, outputPath, platform, device, cb) {


async.each(iconMeta, function(meta, cb){
var outputFile;
let outputFile;
if(meta.platform === 'iOS'){
outputFile = path.join(outputPath, config.output.iosDir, meta.file_name);
} else if(meta.platform === 'Android'){
Expand All @@ -97,7 +97,7 @@ exports.generateIcons = function(inputImg, outputPath, platform, device, cb) {
outputFile = path.join(outputPath, config.output.webDir, meta.file_name);
}

if(meta.platform == 'Web') {
if(meta.platform === 'Web') {
im.convert([inputImg, '-bordercolor', 'white', '-border', '0', '-alpha', 'off', '-colors', '256', '-resize', meta.width+'x'+meta.height, outputFile], function(err){
if(err) {
console.error("Error generating %s (res: %s) icon: %s:: %s", meta.platform, (meta.resolution || ''), meta.file_name, err);
Expand Down
Loading

0 comments on commit f803c5f

Please sign in to comment.