diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a1537b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +node_modules diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d907128 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0fa4271 --- /dev/null +++ b/README.md @@ -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 + + ``` + +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 \ No newline at end of file diff --git a/bin/cordova-android-res b/bin/cordova-android-res new file mode 100644 index 0000000..5dab7f1 --- /dev/null +++ b/bin/cordova-android-res @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('../')(); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..6615534 --- /dev/null +++ b/index.js @@ -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; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5d25cbd --- /dev/null +++ b/package.json @@ -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": "git@github.com:boundstate/cordova-android-res.git" + }, + "keywords": [ + "cordova", + "android", + "resource", + "resize" + ], + "author": "Bound State Software Inc ", + "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" + } +}