{"id":1207,"date":"2013-08-02T12:12:13","date_gmt":"2013-08-02T18:12:13","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=1207"},"modified":"2013-07-23T14:56:27","modified_gmt":"2013-07-23T20:56:27","slug":"how-to-plugmanify-an-existing-plugin","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/1207","title":{"rendered":"How to &#8216;plugman&#8217;ify an existing plugin"},"content":{"rendered":"<p>In <a href=\"\/wordpress\/archives\/1204\">a previous post<\/a>, I talked about adding a new plugin that you wrote to your Cordova CLI project.  However, there are a ton of existing plugins out there, and many of them haven&#8217;t yet migrated over to the new plugman architecture.  What should you do when there is a plugin that solves your problem, but is not installable via plugman?<\/p>\n<p>Your options include:<\/p>\n<ul>\n<li>install the plugin the old fashioned way, by downloading and copying its files into your project directory.  This is a a bad idea because if there are future bug fixes or feature improvements to the plugin, you&#8217;ll have to manually pull them in.<\/li>\n<li>forego the plugin.  But you are looking at it specifically to save you time or allow you to implement a feature that would otherwise be too hard or time consuming&#8211;so you can&#8217;t exactly ignore it.<\/li>\n<li>search for another plugin that does the same thing&#8211;great, if you can find it.<\/li>\n<li>make the plugin plugman compatible&#8211;this is the best option.<\/li>\n<\/ul>\n<p>The first step to making a plugin plugman compatible is to file a bug\/issue with the project.  Perhaps they are already planning to do this work, and a request from you will get it moved up the queue.  If so, fantastic&#8211;see when they think it will be done.  If not, at least you&#8217;ve let them (and others who look at the issues list) know that this is something they should do.<\/p>\n<p>If it won&#8217;t be done in your timeframe (or at all), you can do it yourself.  The main tassks are writing a plugin.xml file, and possibly modifying some javascript files.  Start with <a href=\"https:\/\/github.com\/apache\/cordova-plugman\/blob\/master\/plugin_spec.md\">the plugin.xml spec<\/a>. <\/p>\n<p>Before you plunge in, though, think about the licensing surrounding the plugin, as, unless you are replacing everything or <a href=\"http:\/\/www.wtfpl.net\/txt\/copying\/\">the license is extremely permissive<\/a>, your contributions will need to be under the same or a compatible license as the original code, especially if you want to contribute the changes back.<\/p>\n<p>You want to make sure you use version control.  If you are modifying a plugin on github, it is as simple as forking that project.  You may be able to take the plugin code and import it into your version control system.<\/p>\n<p>Write the plugin.xml file, and make sure to check it into the version control system.  Writing a plugin.xml file is straightforward; however, there are two ways to handle javascript&#8211;you can treat it as an asset, where plugman dumbly copies it to the <code>www<\/code> directory wherever you tell it to, or you can treat it as a <code>js-module<\/code>.  Plugman does some extra work for <code>js-module<\/code> javascript, including injecting it into the <code>index.html<\/code> and adding the created javascript object to the window object.  Using <code>js-module<\/code> is the preferred method, but you may have to edit the javascript files and remove any <code>cordova.define<\/code> syntax.  Also, if you need to move plugin files around, or rename them to help code maintainability, do so.  <\/p>\n<p>Test and install it just as you would any other plugman managed plugin (<code>cordova plugins add http:\/\/...<\/code>).<\/p>\n<p>Once you&#8217;ve done this and it works, consider pointing to your plugin.xml in your open bug.  Some authors may be receptive to code contributions or pull requests.<\/p>\n<p>In the next post, I&#8217;ll discuss how Cordova CLI helps you release your application.<\/p>\n<p><a href=\"http:\/\/eepurl.com\/BHYJ9\">Subscribe to my infrequent Cordova newsletter<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous post, I talked about adding a new plugin that you wrote to your Cordova CLI project. However, there are a ton of existing plugins out there, and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,7,60],"tags":[],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry","category-cordova-cli","category-mobile-technology","category-phonegap"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":4,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1291,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/1207\/revisions\/1291"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}