Comparing version 0.5.7 to 0.5.8
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
module.exports = { | ||
@@ -2,0 +21,0 @@ url: 'http://plugins.cordova.io', |
@@ -5,3 +5,3 @@ { | ||
"description": "install/uninstall Cordova plugins", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var fs = require('fs') // use existsSync in 0.6.x | ||
@@ -7,9 +26,9 @@ , path = require('path') | ||
, getConfigChanges = require('../util/config-changes') | ||
, searchAndReplace = require('../util/search-and-replace') | ||
, xml_helpers = require('../util/xml-helpers') | ||
, assetsDir = 'assets/www' | ||
, sourceDir = 'src'; | ||
, assetsDir = 'assets/www' // relative path to project's web assets | ||
, sourceDir = 'src' | ||
, xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers')); | ||
exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) { | ||
exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, variables) { | ||
var plugin_id = plugin_et._root.attrib['id'] | ||
@@ -24,7 +43,8 @@ , version = plugin_et._root.attrib['version'] | ||
, libFiles = platformTag.findall('./library-file') | ||
, PACKAGE_NAME = androidPackageName(project_dir) | ||
, configChanges = getConfigChanges(platformTag); | ||
// get config.xml filename | ||
var config_xml_filename = 'res/xml/config.xml'; | ||
variables = variables || {} | ||
// get config.xml filename | ||
var config_xml_filename = 'res/xml/config.xml'; | ||
if(fs.existsSync(path.resolve(project_dir, 'res/xml/plugins.xml'))) { | ||
@@ -35,21 +55,25 @@ config_xml_filename = 'res/xml/plugins.xml'; | ||
// collision detection | ||
if(action == "install" && pluginInstalled(plugin_et, project_dir, config_xml_filename)) { | ||
throw "Plugin "+plugin_id+" already installed" | ||
} else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir, config_xml_filename)) { | ||
throw "Plugin "+plugin_id+" not installed" | ||
if(action.match(/force-/) == null) { | ||
if(action == "install" && pluginInstalled(plugin_et, project_dir, config_xml_filename)) { | ||
throw "Plugin "+plugin_id+" already installed" | ||
} else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir, config_xml_filename)) { | ||
throw "Plugin "+plugin_id+" not installed" | ||
} | ||
} else { | ||
action = action.replace('force-', ''); | ||
} | ||
root = et.Element("config-file"); | ||
root.attrib['parent'] = '.' | ||
plugin_et.findall('./access').forEach(function (tag) { | ||
root.append(tag); | ||
}); | ||
root = et.Element("config-file"); | ||
root.attrib['parent'] = '.' | ||
plugin_et.findall('./access').forEach(function (tag) { | ||
root.append(tag); | ||
}); | ||
if (root.len()) { | ||
(configChanges[config_xml_filename]) ? | ||
configChanges[config_xml_filename].push(root) : | ||
configChanges[config_xml_filename] = [root]; | ||
} | ||
if (root.len()) { | ||
(configChanges[config_xml_filename]) ? | ||
configChanges[config_xml_filename].push(root) : | ||
configChanges[config_xml_filename] = [root]; | ||
} | ||
// find which config-files we're interested in | ||
// find which config-files we're interested in | ||
Object.keys(configChanges).forEach(function (configFile) { | ||
@@ -160,5 +184,11 @@ if (!fs.existsSync(path.resolve(project_dir, configFile))) { | ||
output = xmlDoc.write({indent: 4}); | ||
output = output.replace(/\$PACKAGE_NAME/g, PACKAGE_NAME); | ||
fs.writeFileSync(filepath, output); | ||
}); | ||
if (action == 'install') { | ||
variables['PACKAGE_NAME'] = androidPackageName(project_dir); | ||
searchAndReplace(path.resolve(project_dir, config_xml_filename), variables); | ||
searchAndReplace(path.resolve(project_dir, 'AndroidManifest.xml'), variables); | ||
} | ||
} | ||
@@ -189,5 +219,11 @@ | ||
var tag_xpath = util.format('./platform[@name="android"]/config-file[@target="%s"]/plugin', config_xml_filename); | ||
var plugin_name = plugin_et.find(tag_xpath).attrib.name; | ||
var plugin_tag = plugin_et.find(tag_xpath); | ||
if (!plugin_tag) { | ||
return false; | ||
} | ||
var plugin_name = plugin_tag.attrib.name; | ||
return (fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8') | ||
.match(new RegExp(plugin_name, "g")) != null); | ||
} |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var path = require('path') | ||
@@ -9,7 +28,8 @@ , fs = require('../util/fs') // use existsSync in 0.6.x | ||
, shell = require('shelljs') | ||
, xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers')) | ||
, getConfigChanges = require(path.join(__dirname, '..', 'util', 'config-changes')) | ||
, xml_helpers = require('../util/xml-helpers') | ||
, searchAndReplace = require('../util/search-and-replace') | ||
, getConfigChanges = require('../util/config-changes') | ||
, assetsDir = 'www'; // relative path to project's web assets | ||
exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) { | ||
exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, variables) { | ||
var plugin_id = plugin_et._root.attrib['id'] | ||
@@ -19,2 +39,4 @@ , version = plugin_et._root.attrib['version'] | ||
, matched; | ||
variables = variables || {} | ||
// grab and parse pbxproj | ||
@@ -24,3 +46,3 @@ // we don't want CordovaLib's xcode project | ||
if (!project_files.length) throw "does not appear to be an xcode project"; | ||
if (!project_files.length) throw "does not appear to be an xcode project (no xcode project file)"; | ||
var pbxPath = project_files[0]; | ||
@@ -37,6 +59,2 @@ | ||
if (!config_files.length) { | ||
throw "does not appear to be a PhoneGap project"; | ||
} | ||
config_files = config_files.filter(function (val) { | ||
@@ -46,11 +64,26 @@ return !(/^build\//.test(val)); | ||
var pluginsDir = path.resolve(config_files[0], '..', 'Plugins'); | ||
var resourcesDir = path.resolve(config_files[0], '..', 'Resources'); | ||
if (!config_files.length) { | ||
throw "does not appear to be a PhoneGap project"; | ||
} | ||
var config_file = config_files[0]; | ||
var xcode_dir = path.dirname(config_file); | ||
var pluginsDir = path.resolve(xcode_dir, 'Plugins'); | ||
var resourcesDir = path.resolve(xcode_dir, 'Resources'); | ||
// get project plist for package name | ||
var project_plists = glob.sync(xcode_dir + '/*-Info.plist'); | ||
var projectPListPath = project_plists[0]; | ||
// collision detection | ||
if(action == "install" && pluginInstalled(plugin_et, config_files[0])) { | ||
throw "Plugin "+plugin_id+" already installed" | ||
} else if(action == "uninstall" && !pluginInstalled(plugin_et, config_files[0])) { | ||
throw "Plugin "+plugin_id+" not installed" | ||
if(action.match(/force-/) == null) { | ||
if(action == "install" && pluginInstalled(plugin_et, config_file)) { | ||
throw "Plugin "+plugin_id+" already installed" | ||
} else if(action == "uninstall" && !pluginInstalled(plugin_et, config_file)) { | ||
throw "Plugin "+plugin_id+" not installed" | ||
} | ||
} else { | ||
action = action.replace('force-', ''); | ||
} | ||
var assets = plugin_et.findall('./asset'), | ||
@@ -64,3 +97,3 @@ platformTag = plugin_et.find('./platform[@name="ios"]'), | ||
// move asset files into www | ||
assets.forEach(function (asset) { | ||
assets && assets.forEach(function (asset) { | ||
var srcPath = path.resolve( | ||
@@ -72,10 +105,16 @@ plugin_dir, asset.attrib['src']); | ||
assetsDir, asset.attrib['target']); | ||
var stat = fs.statSync(srcPath); | ||
if(stat.isDirectory()) { | ||
shell.mkdir('-p', targetPath); | ||
} | ||
if (action == 'install') { | ||
shell.cp('-r', srcPath, targetPath); | ||
var stat = fs.statSync(srcPath); | ||
if(stat.isDirectory()) { | ||
shell.mkdir('-p', targetPath); | ||
checkLastCommand(); | ||
shell.cp('-r', srcPath, targetPath); | ||
checkLastCommand(); | ||
} else { | ||
shell.cp(srcPath, targetPath); | ||
} | ||
checkLastCommand(); | ||
} else { | ||
shell.rm('-rf', targetPath); | ||
checkLastCommand(); | ||
} | ||
@@ -85,3 +124,3 @@ }); | ||
// move native files (source/header/resource) | ||
sourceFiles.forEach(function (sourceFile) { | ||
sourceFiles && sourceFiles.forEach(function (sourceFile) { | ||
var src = sourceFile.attrib['src'], | ||
@@ -95,3 +134,5 @@ srcFile = path.resolve(plugin_dir, 'src/ios', src), | ||
shell.mkdir('-p', targetDir); | ||
checkLastCommand(); | ||
shell.cp(srcFile, destFile); | ||
checkLastCommand(); | ||
} else { | ||
@@ -102,6 +143,7 @@ xcodeproj.removeSourceFile('Plugins/' + path.basename(src)); | ||
shell.rm('-rf', targetDir); | ||
checkLastCommand(); | ||
} | ||
}); | ||
headerFiles.forEach(function (headerFile) { | ||
headerFiles && headerFiles.forEach(function (headerFile) { | ||
var src = headerFile.attrib['src'], | ||
@@ -115,3 +157,5 @@ srcFile = path.resolve(plugin_dir, 'src/ios', src), | ||
shell.mkdir('-p', targetDir); | ||
checkLastCommand(); | ||
shell.cp(srcFile, destFile); | ||
checkLastCommand(); | ||
} else { | ||
@@ -122,6 +166,7 @@ xcodeproj.removeHeaderFile('Plugins/' + path.basename(src)); | ||
shell.rm('-rf', targetDir); | ||
checkLastCommand(); | ||
} | ||
}); | ||
resourceFiles.forEach(function (resource) { | ||
resourceFiles && resourceFiles.forEach(function (resource) { | ||
var src = resource.attrib['src'], | ||
@@ -136,4 +181,6 @@ srcFile = path.resolve(plugin_dir, 'src/ios', src), | ||
shell.cp('-R', srcFile, resourcesDir); | ||
checkLastCommand(); | ||
} else { | ||
shell.cp(srcFile, destFile); | ||
checkLastCommand(); | ||
} | ||
@@ -143,6 +190,7 @@ } else { | ||
shell.rm('-rf', destFile); | ||
checkLastCommand(); | ||
} | ||
}); | ||
frameworks.forEach(function (framework) { | ||
frameworks && frameworks.forEach(function (framework) { | ||
var src = framework.attrib['src'], | ||
@@ -152,3 +200,3 @@ weak = framework.attrib['weak']; | ||
if (action == 'install') { | ||
var opt = { weak: (weak && weak.toLowerCase() == 'true') }; | ||
var opt = { weak: (weak && weak.toLowerCase() == 'true') }; | ||
xcodeproj.addFramework(src, opt); | ||
@@ -160,6 +208,23 @@ } else { | ||
updateConfig(action, config_files[0], plugin_et); | ||
// write out xcodeproj file | ||
fs.writeFileSync(pbxPath, xcodeproj.writeSync()); | ||
// add plugin and whitelisted hosts | ||
try { | ||
updateConfig(action, config_file, plugin_et); | ||
} catch(e) { | ||
throw { | ||
name: "ConfigurationError", | ||
level: "ERROR", | ||
message: "Error updating configuration: "+e.message, | ||
} | ||
} | ||
if (action == 'install') { | ||
variables['PACKAGE_NAME'] = plist.parseFileSync(projectPListPath).CFBundleIdentifier; | ||
searchAndReplace(pbxPath, variables); | ||
searchAndReplace(projectPListPath, variables); | ||
searchAndReplace(config_file, variables); | ||
} | ||
} | ||
@@ -203,3 +268,3 @@ | ||
// add hosts to whitelist (ExternalHosts) in plist | ||
hosts.forEach(function(host) { | ||
hosts && hosts.forEach(function(host) { | ||
plistObj.ExternalHosts.push(host.attrib['origin']); | ||
@@ -216,3 +281,3 @@ }); | ||
matched = false; | ||
hosts.forEach(function(host) { | ||
hosts && hosts.forEach(function(host) { | ||
if(host === plistObj.ExternalHosts[i]) { | ||
@@ -240,2 +305,5 @@ matched = true; | ||
plugin_et.find('./platform[@name="ios"]/plugins-plist'); | ||
if (!config_tag) { | ||
return false; | ||
} | ||
var plugin_name = config_tag.attrib.name || config_tag.attrib.key; | ||
@@ -249,4 +317,4 @@ return (fs.readFileSync(config_path, 'utf8').match(new RegExp(plugin_name, "g")) != null); | ||
plistEle = platformTag.find('./plugins-plist'), // use this for older that have plugins-plist | ||
configChanges = getConfigChanges(platformTag), | ||
base_config_path = path.basename(config_path); | ||
configChanges = getConfigChanges(platformTag), | ||
base_config_path = path.basename(config_path); | ||
@@ -256,10 +324,10 @@ // edit configuration files | ||
output, | ||
pListOnly = plistEle; | ||
pListOnly = plistEle; | ||
if (configChanges[path.basename(config_path)]) { | ||
configChanges[path.basename(config_path)].forEach(function (val) { | ||
if (val.find("plugin")) pListOnly = false; | ||
}); | ||
} | ||
if (configChanges[path.basename(config_path)]) { | ||
configChanges[path.basename(config_path)].forEach(function (val) { | ||
if (val.find("plugin")) pListOnly = false; | ||
}); | ||
} | ||
if (pListOnly) { | ||
@@ -279,34 +347,33 @@ // if the plugin supports the old plugins-plist element only | ||
} | ||
} | ||
// add whitelist hosts | ||
root = et.Element("config-file"); | ||
root.attrib['parent'] = '.' | ||
hosts.forEach(function (tag) { | ||
root.append(tag); | ||
}); | ||
// add whitelist hosts | ||
root = et.Element("config-file"); | ||
root.attrib['parent'] = '.' | ||
hosts.forEach(function (tag) { | ||
root.append(tag); | ||
}); | ||
if (root.len()) { | ||
(configChanges[path.basename(config_path)]) ? | ||
configChanges[path.basename(config_path)].push(root) : | ||
configChanges[path.basename(config_path)] = [root]; | ||
} | ||
if (root.len()) { | ||
(configChanges[path.basename(config_path)]) ? | ||
configChanges[path.basename(config_path)].push(root) : | ||
configChanges[path.basename(config_path)] = [root]; | ||
} | ||
if (configChanges[path.basename(config_path)]) { | ||
if (configChanges[path.basename(config_path)]) { | ||
configChanges[base_config_path].forEach(function (configNode) { | ||
var selector = configNode.attrib["parent"], | ||
children = configNode.findall('*'); | ||
if( action == 'install') { | ||
if (!xml_helpers.graftXML(xmlDoc, children, selector)) { | ||
throw new Error('failed to add children to ' + filename); | ||
} | ||
} else { | ||
if (!xml_helpers.pruneXML(xmlDoc, children, selector)) { | ||
throw new Error('failed to remove children from' + filename); | ||
} | ||
} | ||
}); | ||
} | ||
configChanges[base_config_path].forEach(function (configNode) { | ||
var selector = configNode.attrib["parent"], | ||
children = configNode.findall('*'); | ||
if( action == 'install') { | ||
if (!xml_helpers.graftXML(xmlDoc, children, selector)) { | ||
throw new Error('failed to add children to ' + selector + ' in ' + config_path); | ||
} | ||
} else { | ||
if (!xml_helpers.pruneXML(xmlDoc, children, selector)) { | ||
throw new Error('failed to remove children from ' + selector + ' in ' + config_path); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -325,1 +392,5 @@ output = xmlDoc.write({indent: 4}); | ||
} | ||
// throws error if last command returns code != 0 | ||
function checkLastCommand() { | ||
if(shell.error() != null) throw {name: "ShellError", message: shell.error()}; | ||
} |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var path = require('path') | ||
@@ -2,0 +21,0 @@ , fs = require('fs') |
#!/usr/bin/env node | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
@@ -14,7 +32,7 @@ // copyright (c) 2013 Andrew Lunny, Adobe Systems | ||
'ios': require('./platforms/ios'), | ||
'bb10': require('./platforms/bb10'), | ||
'blackberry': require('./platforms/blackberry'), | ||
'www': require('./platforms/www') | ||
}; | ||
var known_opts = { 'platform' : [ 'ios', 'android', 'bb10' ,'www' ] | ||
var known_opts = { 'platform' : [ 'ios', 'android', 'blackberry' ,'www' ] | ||
, 'project' : path | ||
@@ -26,3 +44,4 @@ , 'plugin' : [String, path, url] | ||
, 'debug' : Boolean | ||
}; | ||
, 'variable' : Array | ||
}, shortHands = { 'var' : 'variable' }; | ||
@@ -57,3 +76,11 @@ var cli_opts = nopt(known_opts); | ||
else { | ||
handlePlugin('install', cli_opts.platform, cli_opts.project, cli_opts.plugin); | ||
var cli_variables = {} | ||
if (cli_opts.variable) { | ||
cli_opts.variable.forEach(function (variable) { | ||
var tokens = variable.split('='); | ||
var key = tokens.shift().toUpperCase(); | ||
if (/^[\w-_]+$/.test(key)) cli_variables[key] = tokens.join('='); | ||
}); | ||
} | ||
handlePlugin('install', cli_opts.platform, cli_opts.project, cli_opts.plugin, cli_variables); | ||
} | ||
@@ -63,20 +90,53 @@ | ||
platforms = known_opts.platform.join('|'); | ||
console.log('Usage\n---------'); | ||
console.log('Add a plugin:\n\t' + package.name + ' --platform <'+ platforms +'> --project <directory> --plugin <directory|git-url|name>\n'); | ||
console.log('Remove a plugin:\n\t' + package.name + ' --remove --platform <'+ platforms +'> --project <directory> --plugin <directory|git-url|name>\n'); | ||
console.log('List plugins:\n\t' + package.name + ' --list\n'); | ||
console.error('Usage\n---------'); | ||
console.error('Add a plugin:\n\t' + package.name + ' --platform <'+ platforms +'> --project <directory> --variable <preference_name>="<substituion>" --plugin <directory|git-url|name>\n'); | ||
console.error('Remove a plugin:\n\t' + package.name + ' --remove --platform <'+ platforms +'> --project <directory> --plugin <directory|git-url|name>\n'); | ||
console.error('List plugins:\n\t' + package.name + ' --list\n'); | ||
process.exit(1); | ||
} | ||
function execAction(action, platform, project_dir, plugin_dir) { | ||
function execAction(action, platform, project_dir, plugin_dir, cli_variables) { | ||
var xml_path = path.join(plugin_dir, 'plugin.xml') | ||
, xml_text = fs.readFileSync(xml_path, 'utf-8') | ||
, plugin_et = new et.ElementTree(et.XML(xml_text)); | ||
, plugin_et = new et.ElementTree(et.XML(xml_text)) | ||
, filtered_variables = {}; | ||
if (action == 'install') { | ||
// checking preferences | ||
prefs = plugin_et.findall('./preference') || []; | ||
prefs = prefs.concat(plugin_et.findall('./platform[@name="'+platform+'"]/preference')); | ||
var missing_vars = []; | ||
prefs.forEach(function (pref) { | ||
var key = pref.attrib["name"].toUpperCase(); | ||
if (cli_variables[key] == undefined) | ||
missing_vars.push(key) | ||
else | ||
filtered_variables[key] = cli_variables[key] | ||
}) | ||
if (missing_vars.length > 0) { | ||
console.error('Variable missing: ' + missing_vars.join(", ")); | ||
return; | ||
} | ||
if((info = plugin_et.find('./platform[@name="'+platform+'"]/info'))) { | ||
console.log(info.text); | ||
} | ||
} | ||
// run the platform-specific function | ||
platform_modules[platform].handlePlugin(action, project_dir, plugin_dir, plugin_et); | ||
console.log('plugin ' + action + 'ed'); | ||
try { | ||
platform_modules[platform].handlePlugin(action, project_dir, plugin_dir, plugin_et, filtered_variables); | ||
console.log('plugin ' + action + 'ed'); | ||
} catch(e) { | ||
var revert = (action == "install" ? "force-uninstall" : "force-install" ); | ||
console.error("An error occurred for action", action, ":", e.message, "\nTrying to revert changes..."); | ||
try { | ||
platform_modules[platform].handlePlugin(revert, project_dir, plugin_dir, plugin_et, filtered_variables); | ||
} catch(e) { | ||
console.log("Changes might have not been reverted: "+e.message); | ||
} | ||
} | ||
} | ||
function handlePlugin(action, platform, project_dir, plugin_dir) { | ||
function handlePlugin(action, platform, project_dir, plugin_dir, cli_variables) { | ||
var plugin_xml_path, async = false; | ||
@@ -95,3 +155,3 @@ | ||
function(plugin_info) { | ||
execAction(action, platform, project_dir, plugins.clonePluginGitRepo(plugin_info.url)); | ||
execAction(action, platform, project_dir, plugins.clonePluginGitRepo(plugin_info.url), cli_variables); | ||
}, | ||
@@ -110,5 +170,5 @@ function(e) { | ||
if(!async) { | ||
execAction(action, platform, project_dir, plugin_dir); | ||
execAction(action, platform, project_dir, plugin_dir, cli_variables); | ||
} | ||
} | ||
@@ -324,2 +324,16 @@ plugman | ||
### <info> | ||
The tool will provide additionnal information to users. This is useful when you require some extra steps that can't be easily automated or are out of the scope of plugman. | ||
Examples: | ||
<info> | ||
You need to install **Google Play Services** from the `Android Extras` section using the Android SDK manager (run `android`). | ||
You need to add the following line to your `local.properties` | ||
android.library.reference.1=PATH_TO_ANDROID_SDK/sdk/extras/google/google_play_services/libproject/google-play-services_lib | ||
</info> | ||
## Variables | ||
@@ -348,2 +362,10 @@ | ||
plugman can request users to specify variables required by a plugin. For example API keys for C2M and Google Maps can be specified as a command line argument like so: | ||
plugman --platform ios|android --project /path/to/project --plugin name|git-url|path --variable API_KEY="!@CFATGWE%^WGSFDGSDFW$%^#$%YTHGsdfhsfhyer56734" | ||
A preference tag will need to be present inside the platform tag to make the variable mandatory like so: | ||
<preference name="API_KEY"> | ||
Certain variable names should be reserved - these are listed below. | ||
@@ -350,0 +372,0 @@ |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// Test installation on Cordova 1.x project | ||
@@ -48,3 +67,3 @@ | ||
android.handlePlugin('install', test_project_dir, dummy_plugin_dir, dummy_plugin_et); | ||
android.handlePlugin('install', test_project_dir, dummy_plugin_dir, dummy_plugin_et, { APP_ID: 12345 }); | ||
@@ -56,3 +75,3 @@ test.done(); | ||
var jsPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www', 'childbrowser.js'); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
fs.stat(jsPath, function(err, stats) { | ||
@@ -66,3 +85,3 @@ test.ok(!err); | ||
exports['should move the directory'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -79,3 +98,3 @@ var assetPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www', 'childbrowser'); | ||
exports['should move the src file'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -88,3 +107,3 @@ var javaPath = path.join(test_dir, 'projects', 'android_one', 'src', 'com', 'phonegap', 'plugins', 'childBrowser', 'ChildBrowser.java'); | ||
exports['should add ChildBrowser to plugins.xml'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -102,3 +121,3 @@ var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml'); | ||
exports['should add ChildBrowser to AndroidManifest.xml'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -122,3 +141,3 @@ var manifestPath = path.join(test_dir, 'projects', 'android_one', 'AndroidManifest.xml'); | ||
exports['should add whitelist hosts'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -131,4 +150,28 @@ var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml'); | ||
test.equal(pluginsDoc.findall("access")[0].attrib["origin"], "build.phonegap.com") | ||
test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "s3.amazonaws.com") | ||
test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "12345.s3.amazonaws.com") | ||
test.done(); | ||
} | ||
exports['should search/replace plugin.xml'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml'); | ||
var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'), | ||
pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)); | ||
test.equal(pluginsDoc.findall("access").length, 2, "/access"); | ||
test.equal(pluginsDoc.findall("access")[0].attrib["origin"], "build.phonegap.com") | ||
test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "12345.s3.amazonaws.com") | ||
test.done(); | ||
} | ||
exports['should search/replace manifest.xml files'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
var manifestXmlPath = path.join(test_dir, 'projects', 'android_one', 'AndroidManifest.xml'); | ||
var manifestTxt = fs.readFileSync(manifestXmlPath, 'utf-8'), | ||
manifestDoc = new et.ElementTree(et.XML(manifestTxt)); | ||
test.equal(manifestDoc.findall("appid")[0].attrib["value"], "12345") | ||
test.done(); | ||
} |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// Test uninstallation on Cordova 1.x project | ||
@@ -2,0 +21,0 @@ |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// Test installation on Cordova 2 project | ||
@@ -49,3 +68,3 @@ | ||
android.handlePlugin('install', test_project_dir, dummy_plugin_dir, dummy_plugin_et); | ||
android.handlePlugin('install', test_project_dir, dummy_plugin_dir, dummy_plugin_et, { APP_ID: 12345 }); | ||
@@ -58,3 +77,3 @@ test.done(); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
fs.stat(jsPath, function(err, stats) { | ||
@@ -80,3 +99,3 @@ test.ok(!err); | ||
exports['should move the src file'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -89,3 +108,3 @@ var javaPath = path.join(test_dir, 'projects', 'android_two', 'src', 'com', 'phonegap', 'plugins', 'childBrowser', 'ChildBrowser.java'); | ||
exports['should add ChildBrowser to config.xml'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -103,3 +122,3 @@ var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml'); | ||
exports['should add ChildBrowser to AndroidManifest.xml'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -125,3 +144,3 @@ var manifestPath = path.join(test_dir, 'projects', 'android_two', 'AndroidManifest.xml'); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -134,3 +153,3 @@ test.throws(function() {android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);}, /already installed/); | ||
exports['should add whitelist hosts'] = function (test) { | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et); | ||
android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 }); | ||
@@ -143,4 +162,4 @@ var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml'); | ||
test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "build.phonegap.com") | ||
test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "s3.amazonaws.com") | ||
test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "12345.s3.amazonaws.com") | ||
test.done(); | ||
} |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// Test uninstallation on Cordova 2 project | ||
@@ -2,0 +21,0 @@ |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var configChanges = require('../util/config-changes'), | ||
@@ -2,0 +21,0 @@ fs = require('fs'), |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var path = require('path') | ||
@@ -2,0 +21,0 @@ , xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers')) |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// Test plugin.xml with multiple child elements | ||
@@ -2,0 +21,0 @@ var fs = require('fs') |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var path = require('path'), | ||
@@ -2,0 +21,0 @@ plugins = require(path.join(__dirname, '..', 'util', 'plugins')); |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var fs = require('fs') | ||
@@ -2,0 +21,0 @@ , path = require('path') |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
// takes an xml list of config-file tags | ||
@@ -2,0 +21,0 @@ // returns a JS object with an easy to use structure |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var fs = require('fs'); | ||
@@ -2,0 +21,0 @@ |
#!/usr/bin/env node | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
var http = require('http'), | ||
@@ -3,0 +22,0 @@ osenv = require('osenv'), |
@@ -0,1 +1,20 @@ | ||
/* | ||
* | ||
* Copyright 2013 Anis Kadri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
/** | ||
@@ -2,0 +21,0 @@ * contains XML utility functions, some of which are specific to elementtree |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4055390
173
3829
395
39
5