Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/platform-selection' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olivab committed Nov 19, 2017
2 parents f962f61 + deaf181 commit 2874ec5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 21 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cordova-res-generator

Automatic icon and splash screen resizing tool for **Cordova**/**ionic**/**PhoneGap** based applications.
Automatic icon and splash screen resizing tool for **Cordova**/**Ionic**/**PhoneGap** based applications.

It automatically resizes and copies your ```icon.png``` and ```splash.png``` files for mobile platforms.

Expand All @@ -26,6 +26,18 @@ or

$ crgen

### Options

Options:

-V, --version output the version number
-i, --icon [optional] optional icon file path (default: ./resources/icon.png)
-s, --splash [optional] optional splash file path (default: ./resources/splash.png)
-p, --platforms [optional] optional comma separated platform token list without any space (default: all platforms processed)
(available tokens: android, ios, windows, blackberry10)
-o, -outputdir [optional] optional output directory (default: ./resources/)
-h, --help output usage information

---

### Platforms
Expand Down
77 changes: 60 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin / env node

'use strict';

Expand All @@ -10,6 +10,7 @@ var Q = require('bluebird');
var fs = require('fs-extra');
var path = require('path');
var Jimp = require('jimp');
var _ = require('lodash');

// helpers

Expand All @@ -27,27 +28,74 @@ var display = {
},
header: (str) => {
console.log('');
console.log(str.cyan.underline);
console.log(str.underline);
}
};

// app main variables
// app main variables and constants

const PLATFORMS = {
'android': {
definitions: ['./platforms/icons/android', './platforms/splash/android']
},
'ios': {
definitions: ['./platforms/icons/ios', './platforms/splash/ios']
},
'windows': {
definitions: ['./platforms/icons/windows', './platforms/splash/windows']
},
'blackberry10': {
definitions: ['./platforms/icons/blackberry10']
}
};
var g_imageObjects;
var g_selectedPlatforms = [];

// app functions

function check(settings) {
display.header('Checking files and directories');

return getImages(settings)
return checkPlatforms(settings)
.then((selPlatforms) => g_selectedPlatforms = selPlatforms)
.then(() => getImages(settings))
.then((iobjs) => {
g_imageObjects = iobjs;
})
.then(() => checkOutPutDir(settings));

}

function checkPlatforms(settings) {
var platformsKeys = _.keys(PLATFORMS);

if (!settings.platforms || typeof settings.platforms !== 'string') {
display.success('Processing files for all platforms');
return Q.resolve(platformsKeys);
}

var platforms = settings.platforms.split(',');
var platformsToProcess = [];
var platformsUnknown = [];

platforms.forEach(platform => {

if (_.find(platformsKeys, (p) => platform === p)) {
platformsToProcess.push(platform);
} else {
platformsUnknown.push(platform);
}
});

if (platformsUnknown.length > 0) {
display.error('Bad platforms: ' + platformsUnknown);
return Q.reject('Bad platforms: ' + platformsUnknown);
}

display.success('Processing files for: ' + platformsToProcess);
return Q.resolve(platformsToProcess);
}

function getImages(settings) {

var imageObjects = {
Expand Down Expand Up @@ -193,19 +241,12 @@ function generate(imageObj, settings) {

display.header('Generating files');

var configs = [
// android
require('./platforms/icons/android'),
require('./platforms/splash/android'),
// ios
require('./platforms/icons/ios'),
require('./platforms/splash/ios'),
// windows
require('./platforms/icons/windows'),
require('./platforms/splash/windows'),
// blackberry10
require('./platforms/icons/blackberry10'),
];
var configs = [];

g_selectedPlatforms.forEach((platform) => {
PLATFORMS[platform].definitions.forEach((def) => configs.push(require(def)));
});


return Q.mapSeries(configs, (config) => {
return generateForConfig(imageObj, settings, config);
Expand All @@ -228,6 +269,7 @@ program
.description(pjson.description)
.option('-i, --icon [optional]', 'optional icon file path (default: ./resources/icon.png)')
.option('-s, --splash [optional]', 'optional splash file path (default: ./resources/splash.png)')
.option('-p, --platforms [optional]', 'optional platform comma separated list without any space (default: all platforms processed)')
.option('-o, -outputdir [optional]', 'optional output directory (default: ./resources/)')
.parse(process.argv);

Expand All @@ -236,6 +278,7 @@ program
var g_settings = {
iconfile: program.icon || path.join('.', 'resources', 'icon.png'),
splashfile: program.splash || path.join('.', 'resources', 'splash.png'),
platforms: program.platforms || undefined,
outputdirectory: program.outputdir || path.join('.', 'resources')
};

Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-res-generator",
"version": "0.1.3",
"version": "0.2.0",
"description": "Generates icon & splash screen for cordova/ionic projects using javascript only.",
"main": "index.js",
"preferGlobal": false,
Expand Down Expand Up @@ -37,7 +37,8 @@
"commander": "^2.11.0",
"jimp": "^0.2.28",
"fs-extra": "^4.0.2",
"bluebird": "^3.5.1"
"bluebird": "^3.5.1",
"lodash": "^4.17.4"
},
"contributors": [
{
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ load-bmfont@^1.2.3:
xhr "^2.0.1"
xtend "^4.0.0"

lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

mime-db@~1.30.0:
version "1.30.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01"
Expand Down

0 comments on commit 2874ec5

Please sign in to comment.