Allow cwd to be configured for build
By default, all paths in the build config (e.g. externs) are assumed to be relative to the ol3 repo root. To make it so relative paths are resolved from a different directory, use the cwd option. In addition, this change makes it so the `build.js` task can be run from another directory.
This commit is contained in:
15
package.json
15
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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.<string>} 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.<string>)} 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);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ Build configuration files are JSON files that are used to determine what should
|
||||
|
||||
* **src** - `Array.<string>` 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.<string>` 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']`.
|
||||
|
||||
Reference in New Issue
Block a user