more robust class name detection
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/4d08ca3d Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/4d08ca3d Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/4d08ca3d Branch: refs/heads/master Commit: 4d08ca3d21a09240a728f3b3d016a9899f5828ba Parents: 30b91b2 Author: David Barth <[email protected]> Authored: Fri Sep 4 13:41:13 2015 +0200 Committer: Steve Gill <[email protected]> Committed: Tue Nov 24 17:58:06 2015 -0800 ---------------------------------------------------------------------- cordova-lib/src/plugman/platforms/ubuntu.js | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/4d08ca3d/cordova-lib/src/plugman/platforms/ubuntu.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/plugman/platforms/ubuntu.js b/cordova-lib/src/plugman/platforms/ubuntu.js index 727e4e6..4494a8f 100644 --- a/cordova-lib/src/plugman/platforms/ubuntu.js +++ b/cordova-lib/src/plugman/platforms/ubuntu.js @@ -29,6 +29,19 @@ function toCamelCase(str) { }).join(''); } +function findClassName(str) { + var class_name; + + if (str.match(/\.[^.]+$/)) { + // old-style plugin name + class_name = str.match(/\.[^.]+$/)[0].substr(1); + } else { + class_name = str.match(/cordova\-plugin\-([\w\-]+)$/)[0].substr(15); + } + + return class_name; +} + var shell = require('shelljs') , fs = require('fs') , path = require('path') @@ -71,13 +84,7 @@ module.exports = { var src = String(fs.readFileSync(plugins)); src = src.replace('INSERT_HEADER_HERE', '#include "plugins/' + plugin_id + '/' + path.basename(obj.src) +'"\nINSERT_HEADER_HERE'); - var class_name; - if (plugin_id.match(/\.[^.]+$/)) { - // old-style plugin name - class_name = plugin_id.match(/\.[^.]+$/)[0].substr(1); - } else { - class_name = plugin_id.match(/\-[^\-]+$/)[0].substr(1); - } + var class_name = findClassName(plugin_id); class_name = toCamelCase(class_name); src = src.replace('INSERT_PLUGIN_HERE', 'INIT_PLUGIN(' + class_name + ');INSERT_PLUGIN_HERE'); @@ -91,13 +98,7 @@ module.exports = { var src = String(fs.readFileSync(plugins)); src = src.replace('#include "plugins/' + plugin_id + '/' + path.basename(obj.src) +'"', ''); - var class_name; - if (plugin_id.match(/\.[^.]+$/)) { - // old-style plugin name - class_name = plugin_id.match(/\.[^.]+$/)[0].substr(1); - } else { - class_name = plugin_id.match(/\-[^\-]+$/)[0].substr(1); - } + var class_name = findClassName(plugin_id); class_name = toCamelCase(class_name); src = src.replace('INIT_PLUGIN(' + class_name + ');', ''); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
