Support for debug builds (concatenation only)

Whitespace builds are still painful to debug.  Skipping the compiler altogether and simply concatenating sources is a better option for development and debugging.  By ommitting the `compile` option in a build config, the output is "uncompiled" - a straight concatenation of all sources in dependency order.
This commit is contained in:
Tim Schaub
2014-05-14 10:39:51 -06:00
parent ab9d42f2cd
commit c3184f2cce
2 changed files with 39 additions and 12 deletions

View File

@@ -27,8 +27,8 @@ function assertValidConfig(config, callback) {
callback(new Error('Config missing "exports" array'));
return;
}
if (typeof config.compile !== 'object') {
callback(new Error('Config missing "compile" object'));
if (config.compile && typeof config.compile !== 'object') {
callback(new Error('Config "compile" must be an object'));
return;
}
if (config.jvm && !Array.isArray(config.jvm)) {
@@ -128,6 +128,25 @@ function getDependencies(src, exports, callback) {
}
/**
* Concatenate all sources.
* @param {Array.<string>} paths List of paths to source files.
* @param {function(Error, string)} callback Called with the concatenated
* output or any error.
*/
function concatenate(paths, callback) {
async.map(paths, fs.readFile, function(err, results) {
if (err) {
var msg = 'Trouble concatenating sources. ' + err.message;
callback(new Error(msg));
} else {
var preamble = 'var CLOSURE_NO_DEPS = true;\n';
callback(null, preamble + results.join('\n'));
}
});
}
/**
* Run the compiler.
* @param {Object} config Build configuration object.
@@ -136,13 +155,19 @@ function getDependencies(src, exports, callback) {
* any error.
*/
function build(config, paths, callback) {
log.info('ol', 'Compiling ' + paths.length + ' sources');
var options = config.compile;
options.js = paths.concat(options.js || []);
if (config.jvm) {
closure.compile(options, config.jvm, callback);
if (!options) {
log.info('ol', 'No compile options found. Concatenating ' +
paths.length + ' sources');
concatenate(paths, callback);
} else {
closure.compile(options, callback);
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);
}
}
}

View File

@@ -15,15 +15,17 @@ Build configuration files are JSON files that are used to determine what should
**Required configuration properties**
* **exports** - `Array.<string>` An array of symbol names or patterns to be exported (names that are used in your application). For example, including `"ol.Map"` will export the map constructor. Method names are prefixed with `#`. So `"ol.Map#getView"` will export the map's `getView` method. You can use a `*` at the end to match multiple names. The pattern `"ol.Map#*"` will export all map methods.
* **compile** - `Object` An object whose properties are [Closure Compiler options](https://github.com/openlayers/closure-util/blob/master/compiler-options.txt). Property names match the option names without the `--` prefix (e.g. `"compilation_level": "ADVANCED_OPTIMIZATIONS"` would set the `--compilation_level` option). Where an option can be specified multiple times, use an array for the value (e.g. `"externs": ["one.js", "two.js"]`). Where an option is used as a flag, use a boolean value (e.g. `"use_types_for_optimization": true`).
* **exports** - `Array.<string>` An array of symbol names or patterns to be exported (names that are used in your application). For example, including `"ol.Map"` will export the map constructor. Method names are prefixed with `#`. So `"ol.Map#getView"` will export the map's `getView` method. You can use a `*` at the end to match multiple names. The pattern `"ol.Map#*"` will export all map methods.
**Optional configuration properties**
* **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.
* **compile** - `Object` An object whose properties are [Closure Compiler options](https://github.com/openlayers/closure-util/blob/master/compiler-options.txt). Property names match the option names without the `--` prefix (e.g. `"compilation_level": "ADVANCED_OPTIMIZATIONS"` would set the `--compilation_level` option). Where an option can be specified multiple times, use an array for the value (e.g. `"externs": ["one.js", "two.js"]`). Where an option is used as a flag, use a boolean value (e.g. `"use_types_for_optimization": true`).
* **jvm** - `Array.<string>` Optional array of [command line options](https://code.google.com/p/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']`.
If the **compile** object is not provided, the build task will generate a "debug" build of the library without any variable naming or other minification. This is suitable for development or debugging purposes, but should not be used in production.
* **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.
* **jvm** - `Array.<string>` Optional array of [command line options](https://code.google.com/p/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']`.
The build task generates a list of source files sorted in dependency order and passes these to the compiler. This takes the place of the `--js` options that you would use when calling the compiler directly. If you want to add additional source files, typically you would use the `src` array described above. This works with sources that have `goog.require` and/or `goog.provide` calls (which are used to sort dependencies). If you want to force the inclusion of files that don't use `goog.require` or `goog.provide`, you can use the `js` property of the `compile` object. Paths in the `js` array will be passed to the compiler **after** all other source files.