Skip to content

Commit

Permalink
CB-8441 platformVersion flag not required anymore. Grab version from …
Browse files Browse the repository at this point in the history
…dependecy platform versions
  • Loading branch information
stevengill committed May 18, 2015
1 parent 100e435 commit 358ca61
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ A unified JavaScript layer for [Apache Cordova](http://cordova.apache.org/) proj
| | |-bootstrap.js ... bootstrap the Cordova platform, inject APIs and fire events
| | '-require.js ..... module definition and require() impl
| |
| '-<platform>/ ....... contains the platform-specific base modules
| |-legacy-exec/ ...... contains old platform specific modules
| | |-<platform>/ .... contains the platform-specific base modules
|
|-tasks/ ............... custom grunt tasks
|-tests/ ............... unit tests
Expand All @@ -62,19 +63,19 @@ All of the build tasks can be run via the `grunt` node module. Install it global

Then from the repository root run:

grunt --platformVersion=3.6.0
grunt --platformVersion=4.0.0

To compile the js for just one platform, run:

grunt compile:android --platformVersion=3.6.0
grunt compile:android --platformVersion=4.0.0

To create the browserify version of the js, run:

grunt compile-browserify --platformVersion=3.6.0
grunt compile-browserify --platformVersion=4.0.0

To compile the browserify version of the js for just one platform, run:

grunt compile-browserify:android --platformVersion=3.6.0
grunt compile-browserify:android --platformVersion=4.0.0

For integration, see the 'Integration' section below.

Expand Down Expand Up @@ -126,14 +127,14 @@ Once the new js file has been added, any new projects created will use the updat

# Adding a New Platform

1. Add your platform as a directory under the `src` folder.
1. Add your platform as a directory under the `legacy-exec` folder.
2. Write a module that encapsulates your platform's `exec` method and
call it `exec.js`. The `exec` method is a JavaScript function
that enables communication from the platform's JavaScript environment
into the platform's native environment. Each platform uses a different
mechanism to enable this bridge. We recommend you check out the other
platform `exec` definitions for inspiration. Drop this into the
`src/<platform>` folder you created in step 1. The `exec` method has the following method
`src/legacy-exec/<platform>` folder you created in step 1. The `exec` method has the following method
signature: `function(success, fail, service, action, args)`, with the
following parameters:
- `success`: a success function callback
Expand All @@ -146,7 +147,7 @@ Once the new js file has been added, any new projects created will use the updat
by the `exec` call
It is required that new platform additions be as consistent as
possible with the existing `service` and `action` labels.
2. Define your platform definition object and name it `platform.js`. Drop this into the `src/<platform>` folder. This file should contain a **JSON** object with the following properties:
2. Define your platform definition object and name it `platform.js`. Drop this into the `src/legacy-exec/<platform>` folder. This file should contain a **JSON** object with the following properties:
- `id`: a string representing the platform. This should be the same
name the .js file has
- `objects`: the property names defined as children of this property
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"node": "~0.10.x"
},
"scripts": {
"test": "grunt test --platformVersion=3.6.0"
"test": "grunt test --platformVersion=4.0.0",
"build": "grunt --platfromVersion=4.0.0",
"build-browserify": "grunt compile:browserify --platformVersion=4.0.0"
},
"contributors": [
{
Expand Down Expand Up @@ -69,20 +71,21 @@
"jasmine-node": "1.14.5",
"jsdom-nogyp": "0.8.3",
"mkdirp": "^0.5.0",
"grunt-cli": "0.1.13"
},
"dependencies": {
"browserify": "10.1.3",
"through": "2.3.4",
"uglify-js": "^2.4.15",
"cordova-android": "4.x",
"grunt-cli": "0.1.13",
"cordova-android": "4.0.x",
"cordova-ios": "3.8.x",
"cordova-blackberry10": "3.7.x" ,
"cordova-firefoxos": "3.6.x",
"cordova-ubuntu": "4.0.x",
"cordova-amazon-fireos": "3.6.x",
"cordova-wp8": "3.8.x",
"cordova-windows": "3.8.x",
"cordova-browser": "3.6.0"
"cordova-browser": "3.6.x"

},
"dependencies": {
"browserify": "10.1.3",
"through": "2.3.4",
"uglify-js": "^2.4.15"
}
}
14 changes: 11 additions & 3 deletions tasks/compile-browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
var fs = require('fs');
var path = require('path');

try {
require('browserify');
} catch (e) {
Expand All @@ -41,9 +44,14 @@ module.exports = function(grunt) {
}
});
if(!platformVersion){
console.log('please add a platform version flag and value');
console.log('ex: grunt compile-browserify --platformVersion=3.6.0');
throw new Error("platformVersion is required!");
if(fs.existsSync(path.join('node_modules','cordova-'+platformName))) {
var platformPkgJson = require('../node_modules/cordova-'+platformName+'/package.json');
platformVersion = platformPkgJson.version;
} else {
console.log('please add a platform version flag and value');
console.log('ex: grunt compile-browserify --platformVersion=3.6.0');
throw new Error("platformVersion is required!");
}
}
generate(platformName, useWindowsLineEndings, platformVersion, done);
});
Expand Down
11 changes: 7 additions & 4 deletions tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ module.exports = function(grunt) {
platformVersion = flag.slice(equalIndex + 1);
}
});
if(!platformVersion){
//console.log('please add a platform version flag and value');
//console.log('ex: grunt compile --platformVersion=3.6.0');
platformVersion="N/A";
if(!platformVersion) {
if(fs.existsSync(path.join('node_modules','cordova-'+platformName))) {
var platformPkgJson = require('../node_modules/cordova-'+platformName+'/package.json');
platformVersion = platformPkgJson.version;
} else {
platformVersion="N/A";
}
}

generate(platformName, useWindowsLineEndings, platformVersion, done);
Expand Down
3 changes: 0 additions & 3 deletions tasks/lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports = function bundle(platform, debug, commitId, platformVersion) {
var platformDep = path.join('node_modules', 'cordova-'+platform);
//check to see if platform dependency has cordova-js-src directory
if(fs.existsSync(platformDep) && fs.existsSync(path.join(platformDep, 'cordova-js-src'))) {
console.log('using node module platform dependency');
copyProps(modules, collectFiles(path.join('node_modules', 'cordova-'+platform, 'cordova-js-src')));
} else {
if(platform !== 'test') {
Expand All @@ -44,8 +43,6 @@ module.exports = function bundle(platform, debug, commitId, platformVersion) {
}

}
console.log(modules)

if (platform === 'test') {
// Add any platform-specific modules that have tests to the test bundle.
var testFilesPath = path.join('node_modules', 'cordova-android', 'cordova-js-src', 'android');
Expand Down
3 changes: 1 addition & 2 deletions tasks/lib/require-tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ function _updateRequires(code, platform) {
}

var module = node.args[0].value;

// make sure require only has one argument and that it starts with cordova (old style require.js)
if(module !== undefined &&
module.indexOf("cordova") === 0) {

var scriptpath;
var cordovajssrc = path.join(process.cwd(), "platforms", platform, "platform_www", "cordova-js-src")


// require('cordova') -> cordova.js
if(module === "cordova") {
scriptPath = node.args[0].value = path.join(root, "src", "cordova_b");
Expand Down

0 comments on commit 358ca61

Please sign in to comment.