Skip to content

Commit

Permalink
No need to check for plugin already installed Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
csantanapr committed Apr 10, 2015
1 parent dbe0e16 commit 0907285
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 37 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
More information about [Apache Cordova Command-line Interface](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface)
More information about [Chrome Apps for Mobile](https://github.com/MobileChromeApps/mobile-chrome-apps)

## Getting Started
This plugin requires Grunt `^0.4.5`
NPM module `cordova-cli` or `cca` needs to be install locally or globally
## First Install Cordova or CCA
- This plugin requires Grunt `^0.4.5`
- NPM module `cordova-cli` version >=3.0.0 or `cca` >=0.5.1 needs to be install locally or at peer location as node module grunt-cordovacli, or in a node_module directory of the parent directory structure
```shell
npm install cordova@latest --save
```
or
```shell
npm install cca@latest --save
```

## Gettings Started with Grunt and the Cordova/CCA Grunt Plugin
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

```shell
Expand All @@ -34,7 +42,7 @@ In your project's Gruntfile, add a section named `cordovacli` to the data object
cordovacli: {
options: {
path: 'myHybridAppFolder'
cli: 'cca'
cli: 'cca' // cca or cordova
},
cordova: {
options: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-cordovacli",
"description": "Wraps a web application as a hybrid app with Apache Cordova CLI 3.x",
"version": "0.7.1-dev",
"version": "0.7.1",
"homepage": "https://github.com/csantanapr/grunt-cordovacli",
"author": {
"name": "Carlos Santana",
Expand Down
42 changes: 10 additions & 32 deletions tasks/cordovacli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = function (grunt) {
runPlatform,
runPlugin,
isPlatformExists,
isPluginExists,
cordova_path,
cordova_json,
cordova_pkg,
Expand Down Expand Up @@ -159,38 +158,24 @@ module.exports = function (grunt) {
platform_name = isPlatformExists(p,options.path);
if(platform_name){
skip = true;
grunt.log.writeln('Platform '+platform_name+' already exists skipping add');
grunt.log.writeln('Platform '+platform_name+' already exists skipping add');
}
}
if(!skip){
f = function (callback) {
runCordova(['platform', options.action, p ].concat(options.args), {cwd:options.path}, callback);
};
tasks.push(f);
}
}
});
if ( cordova_cli === 'cca'){
runCordovaSeries(tasks, done);
} else {
runCordovaParallel(tasks, done);
}

};

isPluginExists = function(p, cordovaRootPath) {
var plugin_cdv_dir;
var plugin_id;

// valid platform is like org.apache.cordova.console or [email protected]
plugin_id = p.split('@')[0];
//let check if plugin already added
plugin_cdv_dir = path.resolve(cordovaRootPath, 'plugins', plugin_id);
if (fs.existsSync(plugin_cdv_dir)) {
return plugin_id;
} else {
return false;
}
};

runPlugin = function (options, done) {
//plugin(s) [{add|remove|rm} <PATH|URI>]
var tasks = [];
Expand All @@ -207,20 +192,13 @@ module.exports = function (grunt) {
if(cordova_plugins_map[p]){
p = cordova_plugins_map[p];
}
if(options.action == 'add'){
plugin_id = isPluginExists(p,options.path);
if(plugin_id){
skip = true;
grunt.log.writeln('Plugin '+plugin_id+' already exists skipping add');
}
}
if(!skip){
f = function (callback) {
runCordova(['plugin', options.action, p ].concat(options.args), {cwd:options.path}, callback);
};
tasks.push(f);
}


f = function (callback) {
runCordova(['plugin', options.action, p ].concat(options.args), {cwd:options.path}, callback);
};
tasks.push(f);


});
runCordovaSeries(tasks, done);
};
Expand Down

0 comments on commit 0907285

Please sign in to comment.