Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejpeters committed Jun 4, 2015
0 parents commit 86fa8a9
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Carlos Antonio

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.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# cordova-android-res

Automatic Android resource resizing for Cordova. Create an `android-res` folder containing the images you want to resize
in the root folder of your Cordova project and use cordova-android-res to automatically resize and copy the images for
all current Android devices.

### Manual usage

1. `npm install -g cordova-android-res`
2. Create an `android-res` folder containing the images you want to resize in the root folder of your Cordova project
3. Run `cordova-android-res`.

### Automated usage

1. `npm install cordova-android-res --save-dev`

2. Create `my-android-res-hook.js`
```javascript
var cordovaAndroidRes = require('cordova-android-res');

module.exports = function() {
return cordovaAndroidRes();
};
```

3. Add hook to `config.xml`
```xml
<hook src="my-android-res-hook.js" type="after_platform_add" />
```

That's it. Now every time you `cordova add platform`, the Android resources will be auto generated.
### Requirements
- GraphicsMagick
- Android platform added to your project
### License
MIT
2 changes: 2 additions & 0 deletions bin/cordova-android-res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../')();
73 changes: 73 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var androidRes = require('android-res');
var colors = require('colors');
var glob = require("glob")
var Q = require('q');

/**
* @var {Object} console utils
*/
var display = {
success: function (str) {
str = '✓ '.green + str;
console.log(' ' + str);
},
error: function (str) {
str = '✗ '.red + str;
console.log(' ' + str);
},
header: function (str) {
console.log('');
console.log(' ' + str.cyan.underline);
console.log('');
}
};

/**
* Generates Android resources from the android-res folder.
*/
function run() {
var completeDeferred = Q.defer();
var promises = [];
var options = {
dest: 'platforms/android/res/'
};

display.header('Generating Android resources');

glob('android-res/**/*', function (err, files) {
if (err) {
display.error(err);
return;
}

if (files.length === 0) {
display.error('No resources found at "android-res/"');
return;
}

files.forEach(function (file) {
var promise = androidRes(file, options);
promise
.catch(function (err) {
display.error(err);
})
.progress(function (data) {
display.success(data.dest + ' (' + data.width + 'x' + data.height + ')');
});
promises.push(promise);
});

Q.all(promises)
.catch(function (err) {
completeDeferred.reject(err);
})
.then(function() {
console.log('');
completeDeferred.resolve();
});
});

return completeDeferred.promise;
}

module.exports = run;
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "cordova-android-res",
"version": "0.0.1",
"description": "Android resource resizing for Cordova",
"main": "index.js",
"preferGlobal": "true",
"directories": {
"bin": "./bin"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "[email protected]:boundstate/cordova-android-res.git"
},
"keywords": [
"cordova",
"android",
"resource",
"resize"
],
"author": "Bound State Software Inc <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/boundstate/cordova-android-res/issues"
},
"homepage": "https://github.com/boundstate/cordova-android-res",
"dependencies": {
"android-res": "0.0.3",
"colors": "^1.1.0",
"glob": "^5.0.10",
"q": "^1.4.1"
}
}

0 comments on commit 86fa8a9

Please sign in to comment.