On Wed, Jan 9, 2013 at 10:28 AM, Gord Tanner <gtan...@gmail.com> wrote:

> Ideally the require paths should stay true to the following rules (not that
> we follow them exactly now but we are close):
>
> 1. should always start with cordova (in case we ever share a require
> framework)
> 2. should follow as close as possible to the folder structure.
>
> We don't really do this now (but we are close).  It is mainly to help with
> navigation of the project from a require statement:
>
>      var foo = require('cordova/plugin/foo/submodule')
>
> Ideally I should be able to navigate to a file that lives in:
>
>      ~/cordova.js/plugin/foo/submodule.js
>
> But realistically we are probably going to see:
>
>     ~/cordova.js/plugin/foo/js/submodule.js
>
> Assuming we are dumping everything into a js folder here is the "mapping"
> off the top of my head:
>
>     var foo = require('cordova/plugin/foo')
>     ~/cordova.js/plugin/foo/js/index.js
>
>     var foo = require('cordova/plugin/foo/ios')
>     ~/cordova.js/plugin/foo/js/ios.js
>
>     var foo = require('cordova/plugin/foo/blackberry/qnx')
>     ~/cordova.js/plugin/foo/js/blackberry/qnx.js
>
> What does a plugin (native and js code) folder structure look like?
>


Have a look at this plugin: https://github.com/shazron/KeychainPlugin

With the JS changes I'm proposing, it would look like:
/src/ios/*.h, *.m
/www  <- empty!
/src/js/common/keychain.js
    or
/src/js/ios/keychain.js

So, the idea behind moving all of the plugins to /plugin/$PLUGIN_NAME
within cordova-js, is that when they move out, there will be the mapping:
cordova-js/plugin/$PLUGIN_NAME --->  $PLUGIN_REPO/src/js


When a plugin is installed into a project via cordova-cli, I suggest that
we get a structure like this:

MyApp/platforms/ios/... same as before ...
MyApp/cordova-js/... copy of cordova-js
MyApp/cordova-js/plugin/keychain/common/keychain.js
MyApp/plugins/keychain/plugin.xml
MyApp/www

So, the idea here is that the cordova-js will have no top-level plugin/
directory, but one will be added when plugins are added.

Also, like other sources, .js file should be listed in the plugin.xml so
that they can be reliably removed.



About the require paths. I think for files in cordova-js, the prefix should
be "cordova/", but for plugin files, it should be "plugin/" (or maybe
"cordovaplugin/"?), so that plugin JS doesn't accidentally clobber core
cordova modules.

For the keychain example: require('cordovaplugin/keychain/keychain')


In terms of changes to the builder, we'd need to add the idea of multiple
roots. Instead of just 'lib', there will also be 'plugin' as a root.




>
> On Wed, Jan 9, 2013 at 9:42 AM, Andrew Grieve <agri...@google.com> wrote:
>
> > I'd like to take a first step towards moving plugin JS into separate
> repos
> > by first moving them around within cordova-js.
> >
> > Here is my proposal:
> >
> > Current structure:
> >         lib/common/plugin/*.js
> >         lib/$PLATFORM/plugin/*.js
> >
> > New structure:
> >         plugin/$PLUGIN_NAME/js/common/*.js
> >         plugin/$PLUGIN_NAME/js/$PLATFORM/*.js
> >
> > The require path will need to change. Going from:
> >         cordova.require('cordova/plugin/FileTransferError')
> > To:
> >         cordova.require('plugin/file/FileTransferError')
> >
> >
> > I'll obviously need to update the builder scripts accordingly. The idea
> > here is that we:
> >         1. "cordova plugin add" will copy files into a project's plugins
> > directory
> >         2. "cordova build ios" will use the cordova-js packager and pass
> it
> > the plugin/ directory to use
> >
> > This will not involve changing how we export modules onto namespaces in
> > common.js / platform.js. That will come next though.
> >
> >
> > The resulting structure will look like:
> >
> > plugin/accelerometer/js/common/Acceleration.js
> > plugin/accelerometer/js/common/accelerometer.js
> > plugin/battery/js/common/battery.js
> > plugin/compass/js/common/Compass*.js
> > plugin/contacts/js/common/Contact*.js
> > plugin/device/js/common/device.js
> > plugin/geolocation/js/common/Coordinates.js
> > plugin/geolocation/js/common/Position*.js
> > plugin/globalization/js/common/Globalization*.js
> > plugin/inappbrowser/js/common/InAppBrowser.js
> > plugin/logger/js/common/logger.js
> > plugin/logger/js/common/console-via-logger.js
> > plugin/media/js/common/Capture*.js
> > plugin/media/js/common/ConfigurationData.js
> > plugin/media/js/common/Media*.js
> > plugin/network/js/common/Connection.js
> > plugin/notification/js/common/notification.js
> > plugin/camera/js/common/Camera*.js
> > plugin/echo/js/common/echo.js
> > plugin/file/js/common/Directory*.js
> > plugin/file/js/common/Entry.js
> > plugin/file/js/common/File*.js
> > plugin/file/js/common/Flags.js
> > plugin/file/js/common/LocalFileSystem.js
> > plugin/file/js/common/Metadata.js
> > plugin/file/js/common/ProgressEvent.js
> > plugin/splashscreen/js/common/splashscreen.js
> >
>

Reply via email to