Accept a path for exports file
This commit is contained in:
@@ -221,7 +221,7 @@ def build_ol_all_js(t):
|
|||||||
|
|
||||||
@target('build/exports.js', SRC)
|
@target('build/exports.js', SRC)
|
||||||
def build_exports_js(t):
|
def build_exports_js(t):
|
||||||
t.run('node', 'tasks/generate-exports.js')
|
t.run('node', 'tasks/generate-exports.js', 'build/exports.js')
|
||||||
|
|
||||||
|
|
||||||
for glsl_src in GLSL_SRC:
|
for glsl_src in GLSL_SRC:
|
||||||
|
|||||||
+2
-1
@@ -22,6 +22,7 @@
|
|||||||
"jsdoc": "~3.3.0-alpha5",
|
"jsdoc": "~3.3.0-alpha5",
|
||||||
"walk": "~2.3.1",
|
"walk": "~2.3.1",
|
||||||
"fs-extra": "~0.8.1",
|
"fs-extra": "~0.8.1",
|
||||||
"nomnom": "~1.6.2"
|
"nomnom": "~1.6.2",
|
||||||
|
"temp": "~0.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-11
@@ -8,6 +8,7 @@ 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 nomnom = require('nomnom');
|
var nomnom = require('nomnom');
|
||||||
|
var temp = require('temp').track();
|
||||||
|
|
||||||
var generateExports = require('./generate-exports');
|
var generateExports = require('./generate-exports');
|
||||||
|
|
||||||
@@ -70,22 +71,59 @@ function readConfig(configPath, callback) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of sources sorted in dependency order.
|
* Write the exports code to a temporary file.
|
||||||
* @param {Array.<string>} src List of paths or patterns to source files. By
|
* @param {string} exports Exports code.
|
||||||
* default, all .js files in the src directory are included.
|
* @param {function(Error, string)} callback Called with the path to the temp
|
||||||
* @param {function(Error, Array.<string>)} callback Called with a list of paths
|
* file (or any error).
|
||||||
* or any error.
|
|
||||||
*/
|
*/
|
||||||
function getDependencies(src, callback) {
|
function writeExports(exports, callback) {
|
||||||
log.info('ol', 'Parsing dependencies');
|
temp.open({prefix: 'exports', suffix: '.js'}, function(err, info) {
|
||||||
src = src || ['src/**/*.js'];
|
|
||||||
closure.getDependencies({lib: src}, function(err, paths) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
paths.push(path.join(root, 'build', 'exports.js'));
|
log.verbose('build', 'Writing exports: ' + info.path);
|
||||||
callback(null, paths);
|
fs.writeFile(info.path, exports, function(err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fs.close(info.fd, function(err) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(null, info.path);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {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) {
|
||||||
|
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) {
|
||||||
|
if (err) {
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
paths.push(exportsPath);
|
||||||
|
callback(null, paths);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+36
-28
@@ -2,6 +2,8 @@ var fs = require('fs');
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var fse = require('fs-extra');
|
||||||
|
var nomnom = require('nomnom');
|
||||||
|
|
||||||
var generateSymbols = require('./generate-symbols');
|
var generateSymbols = require('./generate-symbols');
|
||||||
|
|
||||||
@@ -159,52 +161,58 @@ function generateExports(names) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the build/exports.js file.
|
* Generate the exports code.
|
||||||
* @param {Array.<string>} names List of symbol names.
|
|
||||||
* @param {function(Error)} callback Callback.
|
|
||||||
*/
|
|
||||||
function writeExports(names, callback) {
|
|
||||||
var code = generateExports(names);
|
|
||||||
fs.writeFile(path.join(build, 'exports.js'), code, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate the build/exports.js file. If the options.config value is provided,
|
|
||||||
* it is assumed to be a path to a JSON file with an 'exports' member whose
|
|
||||||
* value is an array of symbol names or patterns.
|
|
||||||
*
|
*
|
||||||
* @param {Array.<string>} patterns List of symbol names or patterns.
|
* @param {Array.<string>} patterns List of symbol names or patterns.
|
||||||
* @param {function(Error)} callback Callback.
|
* @param {function(Error, string)} callback Called with the exports code or any
|
||||||
|
* error generating it.
|
||||||
*/
|
*/
|
||||||
function main(patterns, callback) {
|
function main(patterns, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
getSymbols.bind(null, patterns),
|
getSymbols.bind(null, patterns),
|
||||||
filterSymbols,
|
filterSymbols,
|
||||||
writeExports
|
function(names, done) {
|
||||||
|
var code, err;
|
||||||
|
try {
|
||||||
|
code = generateExports(names);
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
done(err, code);
|
||||||
|
}
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If running this module directly, read the config file and call the main
|
* If running this module directly, read the config file, call the main
|
||||||
* function.
|
* function, and write the output file.
|
||||||
*/
|
*/
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
var configPath = process.argv[2];
|
var options = nomnom.options({
|
||||||
getPatterns(configPath, function(err, patterns) {
|
output: {
|
||||||
|
position: 0,
|
||||||
|
required: true,
|
||||||
|
help: 'Output file path'
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
abbr: 'c',
|
||||||
|
help: 'Path to JSON config file',
|
||||||
|
metavar: 'CONFIG'
|
||||||
|
}
|
||||||
|
}).parse();
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
getPatterns.bind(null, options.config),
|
||||||
|
main,
|
||||||
|
fse.outputFile.bind(fse, options.output)
|
||||||
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
main(patterns, function(err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err.message);
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user