Merge pull request #2275 from tschaub/relative

Allow build task to be run from anywhere and provide option for resolving relative paths.
This commit is contained in:
Tim Schaub
2014-06-29 15:16:47 -04:00
4 changed files with 35 additions and 24 deletions
+8 -7
View File
@@ -19,15 +19,16 @@
"htmlparser2": "~3.7.1" "htmlparser2": "~3.7.1"
}, },
"devDependencies": { "devDependencies": {
"closure-util": "~0.14.0", "closure-util": "0.17.0",
"jshint": "~2.5.1",
"jsdoc": "~3.3.0-alpha7",
"taffydb": "~2.7.0",
"underscore": "~1.6.0",
"walk": "~2.3.3",
"fs-extra": "~0.8.1", "fs-extra": "~0.8.1",
"graceful-fs": "~3.0.2",
"jsdoc": "~3.3.0-alpha7",
"jshint": "~2.5.1",
"nomnom": "~1.6.2", "nomnom": "~1.6.2",
"phantomjs": "~1.9.7-5",
"taffydb": "~2.7.0",
"temp": "~0.7.0", "temp": "~0.7.0",
"phantomjs": "~1.9.7-5" "underscore": "~1.6.0",
"walk": "~2.3.3"
} }
} }
+25 -15
View File
@@ -1,12 +1,12 @@
/** /**
* This task builds OpenLayers with the Closure Compiler. * This task builds OpenLayers with the Closure Compiler.
*/ */
var fs = require('fs');
var path = require('path'); var path = require('path');
var async = require('async'); var async = require('async');
var closure = require('closure-util'); var closure = require('closure-util');
var fse = require('fs-extra'); var fse = require('fs-extra');
var fs = require('graceful-fs');
var nomnom = require('nomnom'); var nomnom = require('nomnom');
var temp = require('temp').track(); var temp = require('temp').track();
@@ -106,21 +106,31 @@ function writeExports(exports, callback) {
/** /**
* Get the list of sources sorted in dependency order. * Get the list of sources sorted in dependency order.
* @param {Array.<string>} src List of paths or patterns to source files. By * @param {Object} config Build configuration object.
* default, all .js files in the src directory are included.
* @param {string} exports Exports code (with goog.exportSymbol calls). * @param {string} exports Exports code (with goog.exportSymbol calls).
* @param {function(Error, Array.<string>)} callback Called with a list of paths * @param {function(Error, Array.<string>)} callback Called with a list of paths
* or any error. * or any error.
*/ */
function getDependencies(src, exports, callback) { function getDependencies(config, exports, callback) {
writeExports(exports, function(err, exportsPath) { writeExports(exports, function(err, exportsPath) {
if (err) { if (err) {
callback(err); callback(err);
return; return;
} }
log.info('ol', 'Parsing dependencies'); log.info('ol', 'Parsing dependencies');
src = src || ['src/**/*.js']; var options;
closure.getDependencies({lib: src}, function(err, paths) { 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) { if (err) {
callback(err); callback(err);
return; return;
@@ -159,19 +169,19 @@ function concatenate(paths, callback) {
* any error. * any error.
*/ */
function build(config, paths, callback) { function build(config, paths, callback) {
var options = config.compile; var options = {
if (!options) { compile: config.compile,
cwd: config.cwd || root,
jvm: config.jvm
};
if (!options.compile) {
log.info('ol', 'No compile options found. Concatenating ' + log.info('ol', 'No compile options found. Concatenating ' +
paths.length + ' sources'); paths.length + ' sources');
concatenate(paths, callback); concatenate(paths, callback);
} else { } else {
log.info('ol', 'Compiling ' + paths.length + ' sources'); log.info('ol', 'Compiling ' + paths.length + ' sources');
options.js = paths.concat(options.js || []); options.compile.js = paths.concat(options.compile.js || []);
if (config.jvm) { closure.compile(options, callback);
closure.compile(options, config.jvm, callback);
} else {
closure.compile(options, callback);
}
} }
} }
@@ -187,7 +197,7 @@ function main(config, callback) {
async.waterfall([ async.waterfall([
assertValidConfig.bind(null, config), assertValidConfig.bind(null, config),
generateExports.bind(null, config), generateExports.bind(null, config),
getDependencies.bind(null, config.src), getDependencies.bind(null, config),
build.bind(null, config) build.bind(null, config)
], callback); ], callback);
} }
-2
View File
@@ -7,8 +7,6 @@ var nomnom = require('nomnom');
var generateInfo = require('./generate-info'); var generateInfo = require('./generate-info');
var build = path.join(__dirname, '..', 'build');
/** /**
* Get the configuration from the config file. If configPath is provided * Get the configuration from the config file. If configPath is provided
+2
View File
@@ -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. * **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. * **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']`. * **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']`.