Skip to content

Commit

Permalink
Merge pull request #2 from isleofcode/feat-0.1
Browse files Browse the repository at this point in the history
Feat 0.1
  • Loading branch information
alexblom authored Jul 12, 2016
2 parents f880e12 + ace6d44 commit 749cbc4
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 138 deletions.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2016 Isle of Code Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
#ALEX TODO WRITE ME PLS
#Splicon (0.1)

Splicon is a command tool for automagically generating icons &
splash screens for Cordova applications from a single svg, and updating config.xml.

There is a cli, but can be included in other libraries. It was
originally built for use in [ember-cordova](https://github.com/isleofcode/ember-cordova).

##Icons

For an integration example, see [ember-cordovas make-icon command](https://github.com/isleofcode/ember-cordova/tree/master/lib/commands/make-icons.js).

Using the cli, from your cordova project, simply run:

```
splicon-icons
```

This command will:

1. Look for a file called 'icon.svg';
2. Resize the SVG for each required platform/icon combination;
3. Move the icons to res/icons/platformName (and create the dir if it
does not exist);
4. Update your config.xml to represent the new icons & paths;
5. Ensure there are no duplicate icon nodes in config.xml;

By default, all platforms will be generated. You can pass the platforms
you would like generated as arguments:

```
splicon icons ios android windows
```

For more granular control (such as setting the destination path), you
will need to require lib/icon-task and run the function yourself.

There is a TODO to enhance cli flag, but in most cases this is handled in [ember-cordova](https://github.com/isleofcode/ember-cordova).

##Splash
Not done yet, nearly there.

##Testing
A test suite is being implemented by Jordan Yee.

##Contributing

PRs are very welcome. You can read our style guides [here](https://github.com/isleofcode/style-guide).

If you are unsure about your contribution idea, please feel free to
open an Issue for feedback.

##Credits

ember-cordova is maintained by [Isle of Code](https://isleofcode.com).
The library was written by Alex Blom, based on different half-baked
build tools by Chris Thoburn and Alex Blom.
14 changes: 0 additions & 14 deletions bin/cordova-icons.js → bin/splicon-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,13 @@

const IconTask = require('../lib/icon-task');
const chalk = require('chalk');
const _filter = require('lodash').filter;

const ALLOWED_PLATFORMS = ['all', 'ios', 'android', 'blackberry', 'windows'];

(function() {
const args = process.argv.slice(2);
console.log(chalk.green(
`Generating cordova icons for ${args}`
));

const invalidPlatforms = _filter(args, (item) => {
return ALLOWED_PLATFORMS.indexOf(item) === -1;
});

if (invalidPlatforms.length > 0) {
console.log(chalk.red(
`Platforms ${invalidPlatforms} do not match ${ALLOWED_PLATFORMS}. Aborting`
));
process.exit();
}

IconTask({platforms: args}).then(() => {
console.log(chalk.green(
"Done!"
Expand Down
92 changes: 52 additions & 40 deletions lib/default-icons.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
/* jshint node:true, esversion: 6 */

module.exports = {
ios: [
{ size : 40, name : 'icon-40' },
{ size : 80, name : 'icon-40@2x' },
{ size : 120, name : 'icon-40@3x' },
{ size : 60, name : 'icon-60' },
{ size : 120, name : 'icon-60@2x' },
{ size : 180, name : 'icon-60@3x' },
{ size : 57, name : 'icon' },
{ size : 114, name : 'icon@2x' },
{ size : 29, name : 'icon-small' },
{ size : 58, name : 'icon-small@2x' },
{ size : 87, name : 'icon-small@3x' },
{ size : 152, name : 'icon-76@2x' },
{ size : 76, name : 'icon-76' },
{ size : 72, name : 'icon-72' },
{ size : 144, name : 'icon-72@2x' },
{ size : 50, name : 'icon-50' },
{ size : 100, name : 'icon-50@2x' }
],
ios: {
itemKey: 'width',
items: [
{ size : 40, name : 'icon-40' },
{ size : 80, name : 'icon-40@2x' },
{ size : 120, name : 'icon-40@3x' },
{ size : 60, name : 'icon-60' },
{ size : 120, name : 'icon-60@2x' },
{ size : 180, name : 'icon-60@3x' },
{ size : 57, name : 'icon' },
{ size : 114, name : 'icon@2x' },
{ size : 29, name : 'icon-small' },
{ size : 58, name : 'icon-small@2x' },
{ size : 87, name : 'icon-small@3x' },
{ size : 152, name : 'icon-76@2x' },
{ size : 76, name : 'icon-76' },
{ size : 72, name : 'icon-72' },
{ size : 144, name : 'icon-72@2x' },
{ size : 50, name : 'icon-50' },
{ size : 100, name : 'icon-50@2x' }
]
},

android: [
{ size : 36, name : 'ldpi' },
{ size : 48, name : 'mdpi' },
{ size : 72, name : 'hdpi' },
{ size : 96, name : 'xhdpi' },
{ size : 144, name : 'xxhdpi' },
{ size : 192, name : 'xxxhdpi' }
],
android: {
itemKey: 'density',
items: [
{ size : 36, name : 'ldpi' },
{ size : 48, name : 'mdpi' },
{ size : 72, name : 'hdpi' },
{ size : 96, name : 'xhdpi' },
{ size : 144, name : 'xxhdpi' },
{ size : 192, name : 'xxxhdpi' }
]
},

blackberry: [
{ size : 86, name : 'icon-86' },
{ size : 150, name : 'icon-150' },
],
blackberry: {
itemKey: 'src',
items: [
{ size : 86, name : 'icon-86' },
{ size : 150, name : 'icon-150' }
]
},

windows: [
{ size : 50, name : 'StoreLogo' },
{ size : 30, name : 'smalllogo', attrs: { target : 'Square30x30Logo' }},
{ size : 44, name : 'Square44x44Logo' },
{ size : 70, name : 'Square70x70Logo' },
{ size : 71, name : 'Square71x71Logo' },
{ size : 150, name : 'Square150x150Logo' },
{ size : 310, name : 'Square310x310Logo' }
]
windows: {
itemKey: 'width',
items: [
{ size : 50, name : 'StoreLogo' },
{ size : 30, name : 'smalllogo', attrs: { target : 'Square30x30Logo' }},
{ size : 44, name : 'Square44x44Logo' },
{ size : 70, name : 'Square70x70Logo' },
{ size : 71, name : 'Square71x71Logo' },
{ size : 150, name : 'Square150x150Logo' },
{ size : 310, name : 'Square310x310Logo' }
]
}
};
77 changes: 37 additions & 40 deletions lib/icon-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,29 @@ const DefaultIcons = require('../lib/default-icons');
const RasterizeList = require('../utils/rasterize-list');
const SaveCdvXML = require('../utils/save-cordova-xml');
const MakeDir = require('../utils/make-dir');
const SerializeIcon = require('../utils/serialize-icon');
const ValidPlatform = require('../utils/validate-platforms');

const RSVP = require('rsvp');
const chalk = require('chalk');
const existsSync = require('fs').existsSync;
const normalizePath = require('path').normalize;
const _defaults = require('lodash').defaults;
const _forOwn = require('lodash').forOwn;
const _union = require('lodash').union;

const getIcons = function(platforms) {
if (platforms.length === 0 || platforms.indexOf('all') > -1) {
return DefaultIcons;
} else {
let targets = [];
platforms.forEach((platform) => {
targets[platform] = DefaultIcons[platform];
});
return targets;
}
};
let targets = [];

const serializeIconFn = function(platform, iconData) {
if (!iconData.src) {
console.log(chalk.red(
`No src found for icon ${iconData.name}. Aborting`
));
process.exit();
if (platforms.length === 0 || platforms.indexOf('all') > -1) {
platforms = ['ios', 'android', 'windows', 'blackberry'];
}

let props = {src: iconData.src};
if (platform === 'ios') {
props.height = iconData.size;
props.width = iconData.size;
} else if (platform === 'android') {
props.density = iconData.name;
} else if (platform === 'windows') {
props.target = iconData.name;
}
platforms.forEach((platform) => {
targets[platform] = DefaultIcons[platform];
});

return props;
return targets;
};

module.exports = function(opts) {
Expand All @@ -52,9 +36,11 @@ module.exports = function(opts) {

_defaults(opts, {
source: 'icon.svg',
dest: 'cordova/res/icons',
platforms: {all: true}
dest: 'res/icon',
projectPath: './cordova',
platforms: ['all']
});
let destPath = `${opts.projectPath}/${opts.dest}`;

if (!existsSync(opts.source)) {
console.log(chalk.red(
Expand All @@ -63,32 +49,43 @@ module.exports = function(opts) {
process.exit();
}

if (!existsSync(opts.dest)) {
if (!existsSync(destPath)) {
console.log(chalk.yellow(
`dest path ${opts.dest} does not exist. creating it for you`
`dest path ${destPath} does not exist. creating it for you`
));
MakeDir('./', opts.dest);
MakeDir('./', destPath);
}

if(!ValidPlatform(opts.platforms)) {
console.log(chalk.red(
`Platforms ${opts.platforms} are not all valid. Aborting`
));
process.exit();
}

const targetIcons = getIcons(opts.platforms);
let rasterizeQueue = [];

_forOwn(targetIcons, (icons, platform) => {
MakeDir('./', `${opts.dest}/${platform}`);
MakeDir('./', `${destPath}/${platform}`);

icons.map((icon) => {
return icon.src = `${opts.dest}/${platform}/${icon.name}.png`;
icons.items.map((item) => {
item.src = `${opts.dest}/${platform}/${item.name}.png`;
item.path = normalizePath(`${opts.projectPath}/${item.src}`);
});

rasterizeQueue = _union(rasterizeQueue, icons);
rasterizeQueue = _union(rasterizeQueue, icons.items);
});

RasterizeList({
src: opts.source,
dest: opts.dest,
toRasterize: rasterizeQueue
}).then(() => {
SaveCdvXML(targetIcons, 'icon', serializeIconFn);
}).then(resolve);
})
.then(SaveCdvXML({
projectPath: opts.projectPath,
desiredNodes: targetIcons,
keyName: 'icon',
serializeFn: SerializeIcon
}))
.then(resolve);
});
};
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"splicon": "bin/cordova-icons.js"
"splicon-icons": "bin/splicon-icons.js"
},
"keywords": [
"cordova",
Expand All @@ -20,6 +20,17 @@
"email": "[email protected]",
"url": "https://isleofcode.com"
},
"contributors": [
{
"name": "Chris Thoburn",
"email": "[email protected]",
"url": "https://isleofcode.com"
}, {
"name": "Jordan Yee",
"email": "[email protected]",
"url": "https://isleofcode.com"
}
],
"license": "MIT",
"dependencies": {
"chalk": "^0.4.0",
Expand Down
2 changes: 1 addition & 1 deletion utils/rasterize-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (options) {

let rasterizeTask = svg2png(buffer, { width: width, height: height })
.then((pngBuffer) => {
fs.writeFileSync(rasterize.src, pngBuffer);
fs.writeFileSync(rasterize.path, pngBuffer);
});

rasterizeTasks.push(rasterizeTask);
Expand Down
Loading

0 comments on commit 749cbc4

Please sign in to comment.