diff --git a/package.json b/package.json index 46d2831856..a821d0e34d 100644 --- a/package.json +++ b/package.json @@ -19,15 +19,16 @@ "htmlparser2": "~3.7.1" }, "devDependencies": { - "closure-util": "~0.14.0", - "jshint": "~2.5.1", - "jsdoc": "~3.3.0-alpha7", - "taffydb": "~2.7.0", - "underscore": "~1.6.0", - "walk": "~2.3.3", + "closure-util": "0.17.0", "fs-extra": "~0.8.1", + "graceful-fs": "~3.0.2", + "jsdoc": "~3.3.0-alpha7", + "jshint": "~2.5.1", "nomnom": "~1.6.2", + "phantomjs": "~1.9.7-5", + "taffydb": "~2.7.0", "temp": "~0.7.0", - "phantomjs": "~1.9.7-5" + "underscore": "~1.6.0", + "walk": "~2.3.3" } } diff --git a/tasks/build.js b/tasks/build.js index 4481843b32..fd97113a46 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -1,12 +1,12 @@ /** * This task builds OpenLayers with the Closure Compiler. */ -var fs = require('fs'); var path = require('path'); var async = require('async'); var closure = require('closure-util'); var fse = require('fs-extra'); +var fs = require('graceful-fs'); var nomnom = require('nomnom'); var temp = require('temp').track(); @@ -106,21 +106,31 @@ function writeExports(exports, callback) { /** * Get the list of sources sorted in dependency order. - * @param {Array.} src List of paths or patterns to source files. By - * default, all .js files in the src directory are included. + * @param {Object} config Build configuration object. * @param {string} exports Exports code (with goog.exportSymbol calls). * @param {function(Error, Array.)} callback Called with a list of paths * or any error. */ -function getDependencies(src, exports, callback) { +function getDependencies(config, exports, callback) { writeExports(exports, function(err, exportsPath) { if (err) { callback(err); return; } log.info('ol', 'Parsing dependencies'); - src = src || ['src/**/*.js']; - closure.getDependencies({lib: src}, function(err, paths) { + var options; + if (config.src) { + options = { + lib: config.src, + cwd: config.cwd + }; + } else { + options = { + lib: ['src/**/*.js'], + cwd: root + }; + } + closure.getDependencies(options, function(err, paths) { if (err) { callback(err); return; @@ -159,19 +169,19 @@ function concatenate(paths, callback) { * any error. */ function build(config, paths, callback) { - var options = config.compile; - if (!options) { + var options = { + compile: config.compile, + cwd: config.cwd || root, + jvm: config.jvm + }; + if (!options.compile) { log.info('ol', 'No compile options found. Concatenating ' + paths.length + ' sources'); concatenate(paths, callback); } else { log.info('ol', 'Compiling ' + paths.length + ' sources'); - options.js = paths.concat(options.js || []); - if (config.jvm) { - closure.compile(options, config.jvm, callback); - } else { - closure.compile(options, callback); - } + options.compile.js = paths.concat(options.compile.js || []); + closure.compile(options, callback); } } @@ -187,7 +197,7 @@ function main(config, callback) { async.waterfall([ assertValidConfig.bind(null, config), generateExports.bind(null, config), - getDependencies.bind(null, config.src), + getDependencies.bind(null, config), build.bind(null, config) ], callback); } diff --git a/tasks/readme.md b/tasks/readme.md index 2d32bfc732..abb4c79a32 100644 --- a/tasks/readme.md +++ b/tasks/readme.md @@ -27,6 +27,8 @@ Build configuration files are JSON files that are used to determine what should * **src** - `Array.` Optional array of [path patterns](https://github.com/isaacs/minimatch/blob/master/README.md) for source files. This defaults to `["src/**/*.js"]` which will match all `.js` files in the `src` directory. To include a different set of source files, provide an array of path patterns. Note that these patterns are `/` delimited even on Windows. + * **cwd** - `string` Optional path to be used as the current working directory. All paths in the `compile` object are assumed to be relative to `cwd`. Default is the root of the ol3 repository. + * **namespace** - `string` Optional namespace for exporting the `ol` object. By default, `ol` is assigned to the global object. * **jvm** - `Array.` Optional array of [command line options](https://github.com/google/closure-compiler/wiki/FAQ#what-are-the-recommended-java-vm-command-line-options) for the compiler. By default, the Compiler is run with `['-server', '-XX:+TieredCompilation']`.