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:
Tim Schaub
2014-06-29 13:51:50 -04:00
parent fb7d39005e
commit a8a035468b
3 changed files with 35 additions and 22 deletions
+25 -15
View File
@@ -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);
}