Skip to content
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
27 changes: 11 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Setup

- Clone this repository.
- Open the repository in the command line and run `npm install`
- Clone this repository.
- Open the repository in the command line and run `npm link`

```
git clone https://github.com/lpender/meteor-assets
cd meteor-assets
npm install
npm link
```

## Environmental Dependencies
Expand All @@ -21,6 +21,11 @@ This project requires `imagemagick`.
sudo apt-get install imagemagick imagemagick-doc
```

For arch-based distros:
```
sudo pacman -S imagemagick
```

#### Os X

Install [homebrew](http://brew.sh/) and then:
Expand All @@ -46,17 +51,11 @@ _Note_: You can use the same icon cross platform but it's not recommended in
some cases. See [this issue](https://github.com/lpender/meteor-assets/issues/6)
for more details.

1. Generate icons at 1024x1024 and place them in `resources/icon-ios.png` and
`resources/icon-android.png`.

2. Generate splash screens at 2208x2208 and place them in
`resources/splash-ios.png` and `resources/splash-android.png`.
1. Run `meteor-assets gen` and inform source files and target directory.

3. Run `node meteor-assets`.
2. Use the `-f` flag to use the same source file for all images.

4. Copy the `resources` directory to your app: `cp -R resources /path/to/my/app`.

5. Add this to your `mobile-config.js`
3. Add this to your `mobile-config.js` (replace "/resource/icons/" or "/resources/splash/" with your selected directory).

```javascript
App.icons({
Expand Down Expand Up @@ -124,7 +123,3 @@ Sizes thanks to

- This will crop splashes horizontally centered and vertically centered.
- This does not currently generate [9 patch](https://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch) images for Android.

## Contributing

It wouldn't be so bad to turn this into a proper CLI node package.
68 changes: 68 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node

const program = require("commander");
const inquirer = require("inquirer");
const runCode = require("./meteor-assets");


let questions = [
{
type: 'input',
name: 'sourceAndroidIcon',
message: "Image icon android:"
},
{
type: 'input',
name: 'sourceIosIcon',
message: "Image icon ios:",
},
{
type: 'input',
name: 'sourceAndroidSplash',
message: "Image splash android:",
},
{
type: 'input',
name: 'sourceIosSplash',
message: "Image splash ios:",
},
{
type: 'input',
name: 'dir',
message: "Directory:",
}]

let questionsUniqueFile = [
{
type: 'input',
name: 'sourceFile',
message: "File to be used in all assets:",
},
{
type: 'input',
name: 'dir',
message: "Directory:",
}]

program.version('1.0.0');

program
.option('-f, --file', 'use only one source image for all generated images.')

program.command('gen').description('generate assets').action(() => {
if (!program.file) {
inquirer.prompt(questions).then((answers) => {
runCode.run(answers);
})
} else {
inquirer.prompt(questionsUniqueFile).then((answers) => {
runCode.run(answers);
})
}
})

program.parse(process.argv);




50 changes: 27 additions & 23 deletions meteor-assets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require("fs"),
gm = require("gm").subClass({ imageMagick: true });
const fs = require("fs");
const gm = require("gm").subClass({imageMagick: true});

var icons = [
{ name: "app_store", size: "1024x1024" },
Expand Down Expand Up @@ -116,28 +116,32 @@ function crop(source, target, image) {
});
}

// Run the code

if (!fs.existsSync(__dirname + "/resources/icons")) {
fs.mkdirSync(__dirname + "/resources/icons");
}

if (!fs.existsSync(__dirname + "/resources/splashes")) {
fs.mkdirSync(__dirname + "/resources/splashes");
}
module.exports.run = ({sourceFile, sourceAndroidIcon, sourceIosIcon, sourceAndroidSplash, sourceIosSplash, dir}) => {
if(!fs.existsSync(dir + '/resources/icons')) {
fs.mkdirSync(dir + '/resources/icons', {recursive: true});
}

icons.forEach(function(icon) {
if (icon.name.indexOf("android") == 0) {
resize("resources/icon-android.png", "resources/icons/", icon);
} else {
resize("resources/icon-ios.png", "resources/icons/", icon);
if(!fs.existsSync(dir + '/resources/splashes')) {
fs.mkdirSync(dir + '/resources/splashes', {recursive: true});
}
});

splashes.forEach(function(splash) {
if (splash.name.indexOf("android") == 0) {
crop("resources/splash-android.png", "resources/splashes/", splash);
} else {
crop("resources/splash-ios.png", "resources/splashes/", splash);
if (sourceFile) {
sourceAndroidIcon = sourceAndroidSplash = sourceIosIcon = sourceIosSplash = sourceFile;
}
});

icons.forEach(function(icon) {
if (icon.name.indexOf('android') === 0) {
resize(sourceAndroidIcon, dir + '/resources/icons/', icon);
} else {
resize(sourceIosIcon, dir + '/resources/icons/', icon);
}
});

splashes.forEach(function(splash) {
if (splash.name.indexOf('android') === 0) {
crop(sourceAndroidSplash,dir + '/resources/splashes/', splash);
} else {
crop(sourceIosSplash, dir + '/resources/splashes/', splash);
}
});
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"version": "0.0.3",
"description": "Generate icon and splash assets for mobile meteor apps.",
"main": "meteor-assets.js",
"bin": {
"meteor-assets": "cli.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Lee Pender",
"license": "ISC",
"dependencies": {
"gm": "^1.21.1"
"commander": "^5.1.0",
"gm": "^1.21.1",
"inquirer": "^7.1.0"
}
}