Include goog.require calls in exports file

This commit is contained in:
Tim Schaub
2014-04-28 17:29:36 -06:00
parent d087fdbefd
commit ec6aa21912
+18 -9
View File
@@ -75,8 +75,8 @@ function getSymbols(patterns, callback) {
* @param {Array.<string>} patterns A list of symbol names to match. Wildcards * @param {Array.<string>} patterns A list of symbol names to match. Wildcards
* at the end of a string will match multiple names. * at the end of a string will match multiple names.
* @param {Array.<Object>} symbols List of symbols. * @param {Array.<Object>} symbols List of symbols.
* @param {function(Error, Array.<string>)} callback Called with the filtered * @param {function(Error, Array.<Object>)} callback Called with the filtered
* list of symbol names (or any error). * list of symbols (or any error).
*/ */
function filterSymbols(patterns, symbols, callback) { function filterSymbols(patterns, symbols, callback) {
var matches = []; var matches = [];
@@ -93,14 +93,14 @@ function filterSymbols(patterns, symbols, callback) {
name = name.substr(0, name.length - 1); name = name.substr(0, name.length - 1);
symbols.forEach(function(symbol) { symbols.forEach(function(symbol) {
if (symbol.name.indexOf(name) === 0) { if (symbol.name.indexOf(name) === 0) {
matches.push(symbol.name); matches.push(symbol);
match = true; match = true;
} }
}); });
} else { } else {
var symbol = lookup[name]; var symbol = lookup[name];
if (symbol) { if (symbol) {
matches.push(symbol.name); matches.push(symbol);
match = true; match = true;
} }
} }
@@ -144,18 +144,27 @@ function formatPropertyExport(name) {
/** /**
* Generate export code given a list symbol names. * Generate export code given a list symbol names.
* @param {Array.<string>} names List of symbol names. * @param {Array.<Object>} symbols List of symbols.
* @return {string} Export code. * @return {string} Export code.
*/ */
function generateExports(names) { function generateExports(symbols) {
var blocks = []; var blocks = [];
names.forEach(function(name) { var requires = {};
symbols.forEach(function(symbol) {
symbol.provides.forEach(function(provide) {
requires[provide] = true;
});
var name = symbol.name;
if (name.indexOf('#') > 0) { if (name.indexOf('#') > 0) {
blocks.push(formatPropertyExport(name)); blocks.push(formatPropertyExport(name));
} else { } else {
blocks.push(formatSymbolExport(name)); blocks.push(formatSymbolExport(name));
} }
}); });
blocks.unshift('\n');
Object.keys(requires).sort().reverse().forEach(function(name) {
blocks.unshift('goog.require(\'' + name + '\');');
});
return blocks.join('\n'); return blocks.join('\n');
} }
@@ -171,10 +180,10 @@ function main(patterns, callback) {
async.waterfall([ async.waterfall([
getSymbols.bind(null, patterns), getSymbols.bind(null, patterns),
filterSymbols, filterSymbols,
function(names, done) { function(symbols, done) {
var code, err; var code, err;
try { try {
code = generateExports(names); code = generateExports(symbols);
} catch (e) { } catch (e) {
err = e; err = e;
} }