Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ trim_trailing_whitespace = true
charset = utf-8

[*.js]
indent_size = 4
indent_size = 2
indent_style = space
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes to this project [will be documented](http://keepachangelog.com/) in this file.
This project *tries to* adhere to [Semantic Versioning](http://semver.org/).

## [0.7.0] - 2016-04-17

- Use wrench to prevent issues with directory creation (e150cc1)
- uses config/res as the default folder to persist generated icons (not backwards compatible)
- Add --help option
- Ability to specify output path
- Backwards-compatibility mode to use platforms path instead of new defaults (-c)

## [0.6.0] - 2016-03-08
- Allow platform-specific icons (0c26dfe)

Expand All @@ -15,5 +23,3 @@ This project *tries to* adhere to [Semantic Versioning](http://semver.org/).
## [0.4.1] - 2016-02-24
- Add various things that will help to maintain the project (editorconfig, guidelines, changelog...)
- Update path for iOS icons ([358e491](https://github.com/AlexDisler/cordova-icon/commit/358e491ce01645d6b15b1c0bae3313f08f18df0e) + [426984b](https://github.com/AlexDisler/cordova-icon/commit/426984b39335055be56d838ca2ed118433588c55)) - Please use [an older version](https://github.com/AlexDisler/cordova-icon/tree/891d17fdf271a6139c1c8e97beacab817169d282) if this leads to problems


13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ Then run:

$ cordova-icon

You may specify the output path and directory as follows:

# output to path/to/res/icon
$ cordova-splash -p path/to/res icon

WARNING: If you were using a previous version of cordova-icon and expect the generated files to be in their respective ./platforms
path, use the compability mode:

$ cordova-icon -c

This will override the -p and -i settings.

For good results, your file shoud be:

- square
- for Android and iOS, at least 192\*192px (512\*512px recommended to be future-proof)
- for Windows, at least 1240\*1240px


### Creating a cordova-cli hook

Since the execution of cordova-icon is pretty fast, you can add it as a cordova-cli hook to execute before every build.
Expand Down
64 changes: 52 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ var colors = require('colors');
var _ = require('underscore');
var Q = require('q');
var wrench = require('wrench');
var optparse = require('optparse');

/**
* Check which platforms are added to the project and return their icon names and sizes
* Check which platforms are added to the project and return their icon names
* and sizes
*
* @param {String} projectName
* @param {String} projectName
* @return {Promise} resolves with an array of platforms
*/
var getPlatforms = function (projectName) {
Expand All @@ -20,7 +22,9 @@ var getPlatforms = function (projectName) {
name : 'ios',
// TODO: use async fs.exists
isAdded : fs.existsSync('platforms/ios'),
iconsPath : 'platforms/ios/' + projectName + '/Images.xcassets/AppIcon.appiconset/',
// The xcode dir: 'platforms/ios/' + projectName + '/Resources/icons/'
iconsPath : (settings.RESOURCE_PATH + '/' + settings.ICON_DIR + '/ios/').replace('//', '/'),
platformIconsPath: 'platforms/ios/' + projectName + '/Resources/icons/',
icons : [
{ name : 'icon-40.png', size : 40 },
{ name : '[email protected]', size : 80 },
Expand All @@ -44,7 +48,8 @@ var getPlatforms = function (projectName) {
platforms.push({
name : 'android',
isAdded : fs.existsSync('platforms/android'),
iconsPath : 'platforms/android/res/',
iconsPath : (settings.RESOURCE_PATH + '/' + settings.ICON_DIR + '/android/').replace('//', '/'),
platformIconsPath: 'platforms/android/res/',
icons : [
{ name : 'drawable/icon.png', size : 96 },
{ name : 'drawable-hdpi/icon.png', size : 72 },
Expand All @@ -58,7 +63,8 @@ var getPlatforms = function (projectName) {
platforms.push({
name : 'windows',
isAdded : fs.existsSync('platforms/windows'),
iconsPath : 'platforms/windows/images/',
iconsPath : (settings.RESOURCE_PATH + '/' + settings.ICON_DIR + '/windows/').replace('//', '/'),
platformIconsPath: 'platforms/windows/images/',
icons : [
{ name : 'StoreLogo.scale-100.png', size : 50 },
{ name : 'StoreLogo.scale-125.png', size : 63 },
Expand Down Expand Up @@ -110,6 +116,9 @@ var getPlatforms = function (projectName) {
var settings = {};
settings.CONFIG_FILE = 'config.xml';
settings.ICON_FILE = 'icon.png';
settings.RESOURCE_PATH = 'config/res'; // without trailing slash
settings.ICON_DIR = 'icon'; // without slashes
settings.USE_PLATFORMS_PATH = false; // true to use platforms path

/**
* @var {Object} console utils
Expand Down Expand Up @@ -155,8 +164,8 @@ var getProjectName = function () {
/**
* Resizes, crops (if needed) and creates a new icon in the platform's folder.
*
* @param {Object} platform
* @param {Object} icon
* @param {Object} platform
* @param {Object} icon
* @return {Promise}
*/
var generateIcon = function (platform, icon) {
Expand All @@ -166,7 +175,8 @@ var generateIcon = function (platform, icon) {
if (fs.existsSync(platformPath)) {
srcPath = platformPath;
}
var dstPath = platform.iconsPath + icon.name;
var dstPath = (settings.USE_PLATFORMS_PATH ?
platform.platformIconsPath : platform.iconsPath) + icon.name;
var dst = path.dirname(dstPath);
if (!fs.existsSync(dst)) {
wrench.mkdirSyncRecursive(dst);
Expand All @@ -183,7 +193,7 @@ var generateIcon = function (platform, icon) {
deferred.reject(err);
} else {
deferred.resolve();
display.success(icon.name + ' created');
display.success(icon.name + ' created [' + dstPath + ']');
}
});
if (icon.height) {
Expand All @@ -209,7 +219,7 @@ var generateIcon = function (platform, icon) {
/**
* Generates icons based on the platform object
*
* @param {Object} platform
* @param {Object} platform
* @return {Promise}
*/
var generateIconsForPlatform = function (platform) {
Expand All @@ -225,7 +235,7 @@ var generateIconsForPlatform = function (platform) {
/**
* Goes over all the platforms and triggers icon generation
*
* @param {Array} platforms
* @param {Array} platforms
* @return {Promise}
*/
var generateIcons = function (platforms) {
Expand All @@ -247,7 +257,8 @@ var generateIcons = function (platforms) {
/**
* Checks if at least one platform was added to the project
*
* @return {Promise} resolves if at least one platform was found, rejects otherwise
* @return {Promise} resolves if at least one platform was found, rejects
otherwise
*/
var atLeastOnePlatformFound = function () {
var deferred = Q.defer();
Expand Down Expand Up @@ -304,6 +315,35 @@ var configFileExists = function () {
return deferred.promise;
};

/**
* parse command line options
*/
var parseOptions = function() {
var switches = [
['-h', '--help', 'Show this help'],
['-p', '--path PATH', 'resource path, defaults to ' + settings.RESOURCE_PATH],
['-i', '--icon DIR', 'icon directory in PATH, defaults to ' + settings.ICON_DIR],
['-c', '--compat', 'uses default path in platforms (backwards compatibility, overrides -p and -i)'],
];
var parser = new optparse.OptionParser(switches);
parser.on('help', function() {
console.log(parser.toString());
process.exit();
});
parser.on('path', function(opt, path) {
settings.RESOURCE_PATH = path;
});
parser.on('icon', function(opt, path) {
settings.SCREEN_DIR = path;
});
parser.on('compat', function() {
settings.USE_PLATFORMS_PATH = true;
});
parser.parse(process.argv);
}

parseOptions();

display.header('Checking Project & Icon');

atLeastOnePlatformFound()
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-icon",
"version": "0.7.0",
"version": "0.8.0",
"description": "Automatic icon resizing for Cordova",
"main": "index.js",
"preferGlobal": "true",
Expand Down Expand Up @@ -31,6 +31,7 @@
"q": "^1.0.1",
"underscore": "^1.6.0",
"wrench": "^1.5.8",
"xml2js": "^0.4.3"
"xml2js": "^0.4.3",
"optparse": "^1.0.5"
}
}