-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
skip platform add is platform is already present skip plugin if it's already install
- Loading branch information
1 parent
f7cbd56
commit 9e8758c
Showing
3 changed files
with
120 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,10 +146,13 @@ Specify the action to perform | |
|
||
#### options.platforms | ||
Type: `String` `'Array'` | ||
Valid value: `'ios'` `'android'` `'blackberry10'` `'wp7'` `'wp8'` | ||
Valid value: `'ios'` `'android'` `'blackberry10'` `'wp8'` `'ubuntu'` `'firefoxos'` `'amazon-fireos'` | ||
Version can be specified like `'[email protected]'` | ||
Can also pass a director containing the platform git repository | ||
Required for Commands: `'platform'` | ||
Not Applicable for Commands: `'plugin'` | ||
Optional for other commands | ||
If using with option.action=add and platform already added, then it's skip | ||
|
||
Specify the platform type | ||
|
||
|
@@ -181,10 +184,11 @@ Specify the plugin to add to the Cordova project | |
It can be specify in 4 forms: | ||
|
||
* Shortcut (i.e. 'camera' it will be downloaded form plugins.cordova.io) | ||
* ID (i.e. org.apache.cordova.device it will be downloaded from plugins.cordova.io) | ||
* ID or ID@version (i.e. org.apache.cordova.device it will be downloaded from plugins.cordova.io) | ||
* Git Url (i.e. https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git) | ||
* Directory Path (~/userid/cordova/plugins/plugin1) | ||
|
||
If options.action=add and using ID or ID@version, and plugin already added, then it's skip | ||
|
||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
*/ | ||
/*global module */ | ||
var path = require('path'), | ||
os = require('os'); | ||
os = require('os'), | ||
fs = require('fs'); | ||
|
||
|
||
module.exports = function (grunt) { | ||
'use strict'; | ||
|
@@ -22,6 +24,8 @@ module.exports = function (grunt) { | |
runCreate, | ||
runPlatform, | ||
runPlugin, | ||
isPlatformExists, | ||
isPluginExists, | ||
cordova_path = path.dirname(require.resolve('cordova')), | ||
cordova_json = path.join(cordova_path,'package.json'), | ||
cordova_pkg = grunt.file.readJSON(cordova_json), | ||
|
@@ -44,7 +48,18 @@ module.exports = function (grunt) { | |
'network-information': 'org.apache.cordova.network-information', | ||
'splashscreen': 'org.apache.cordova.splashscreen', | ||
'vibration': 'org.apache.cordova.vibration' | ||
}; | ||
}, | ||
validPlatforms = [ | ||
'ios', | ||
'android', | ||
'ubuntu', | ||
'amazon-fireos', | ||
'wp8', | ||
'blackberry10', | ||
'firefoxos', | ||
'windows8', | ||
'windows', | ||
'browser']; | ||
runCordova = function (args, opts, done) { | ||
var cordova_cli, spawn_cmd; | ||
|
||
|
@@ -101,20 +116,74 @@ module.exports = function (grunt) { | |
var args = ['create', options.path, options.id, options.name].concat(options.args); | ||
runCordova(args, {}, done); | ||
}; | ||
|
||
isPlatformExists = function (p, cordovaRootPath) { | ||
var platform_name; | ||
var platform_cdv_dir; | ||
var platform_src_dir; | ||
var pkg; | ||
// valid platform is like android or [email protected] | ||
platform_name = p.split('@')[0]; | ||
if(validPlatforms.indexOf(p) === -1){ | ||
//then a directory is passed, let's check what platform it is | ||
platform_src_dir = path.resolve(cordovaRootPath,p); | ||
try { | ||
pkg = require(path.join(platform_src_dir, 'package')); | ||
platform_name = pkg.name.split('-')[1]; | ||
} catch(err){ | ||
grunt.log.writeln("For some reason can't read platform package.json"); | ||
} | ||
} | ||
//let check if platform is already added | ||
platform_cdv_dir = path.resolve(cordovaRootPath, 'platforms', platform_name); | ||
if (fs.existsSync(platform_cdv_dir)) { | ||
return platform_name; | ||
} else { | ||
return false; | ||
} | ||
|
||
}; | ||
|
||
runPlatform = function (options, done) { | ||
//platform(s) [{add|remove|rm} <PLATFORM>] | ||
var tasks = []; | ||
tasks.length = 0; | ||
options.platforms.forEach(function (p) { | ||
var f; | ||
f = function (callback) { | ||
runCordova(['platform', options.action, p ].concat(options.args), {cwd:options.path}, callback); | ||
}; | ||
tasks.push(f); | ||
var skip = false; | ||
var platform_name; | ||
|
||
if(options.action === 'add'){ | ||
platform_name = isPlatformExists(p,options.path); | ||
if(platform_name){ | ||
skip = true; | ||
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); | ||
} | ||
}); | ||
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 = []; | ||
|
@@ -126,13 +195,25 @@ module.exports = function (grunt) { | |
|
||
options.plugins.forEach(function (p) { | ||
var f; | ||
var skip = false; | ||
var plugin_id; | ||
if(cordova_plugins_map[p]){ | ||
p = cordova_plugins_map[p]; | ||
} | ||
f = function (callback) { | ||
runCordova(['plugin', options.action, p ].concat(options.args), {cwd:options.path}, callback); | ||
}; | ||
tasks.push(f); | ||
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); | ||
} | ||
|
||
}); | ||
runCordovaSeries(tasks, done); | ||
}; | ||
|