Include typedefs in externs
This commit is contained in:
@@ -15,29 +15,39 @@ var olxPath = path.join(__dirname, '..', 'externs', 'olx.js');
|
|||||||
* @param {funciton(Error, Array.<string>, Array.<Object>)} callback Called
|
* @param {funciton(Error, Array.<string>, Array.<Object>)} callback Called
|
||||||
* with the patterns and symbols (or any error).
|
* with the patterns and symbols (or any error).
|
||||||
*/
|
*/
|
||||||
function getSymbols(callback) {
|
function getTypedefsAndSymbols(callback) {
|
||||||
generateInfo(function(err) {
|
generateInfo(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(new Error('Trouble generating info: ' + err.message));
|
callback(new Error('Trouble generating info: ' + err.message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var typedefs = require('../build/info.json').typedefs;
|
||||||
var symbols = require('../build/info.json').symbols;
|
var symbols = require('../build/info.json').symbols;
|
||||||
callback(null, symbols);
|
callback(null, typedefs, symbols);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate externs code given a list symbols.
|
* Generate externs code given a list symbols.
|
||||||
|
* @param {Array.<Object>} typedefs List of typedefs.
|
||||||
* @param {Array.<Object>} symbols List of symbols.
|
* @param {Array.<Object>} symbols List of symbols.
|
||||||
* @param {string|undefined} namespace Target object for exported symbols.
|
* @param {string|undefined} namespace Target object for exported symbols.
|
||||||
* @return {string} Export code.
|
* @return {string} Export code.
|
||||||
*/
|
*/
|
||||||
function generateExterns(symbols) {
|
function generateExterns(typedefs, symbols) {
|
||||||
var lines = [];
|
var lines = [];
|
||||||
var namespaces = {};
|
var namespaces = {};
|
||||||
var constructors = {};
|
var constructors = {};
|
||||||
|
|
||||||
|
typedefs.forEach(function(typedef) {
|
||||||
|
lines.push('/**');
|
||||||
|
lines.push(' * @typedef {' + typedef.types.join('|') + '}');
|
||||||
|
lines.push(' */');
|
||||||
|
lines.push(typedef.name + ';');
|
||||||
|
lines.push('\n');
|
||||||
|
});
|
||||||
|
|
||||||
symbols.forEach(function(symbol) {
|
symbols.forEach(function(symbol) {
|
||||||
var parts = symbol.name.split('#')[0].split('.');
|
var parts = symbol.name.split('#')[0].split('.');
|
||||||
parts.pop();
|
parts.pop();
|
||||||
@@ -72,12 +82,6 @@ function generateExterns(symbols) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lines.push('/**');
|
lines.push('/**');
|
||||||
if ('default' in symbol) {
|
|
||||||
lines.push(' * @define');
|
|
||||||
lines.push(' * @type {boolean}');
|
|
||||||
lines.push(' */');
|
|
||||||
lines.push(symbol.name + ';');
|
|
||||||
} else {
|
|
||||||
if (symbol.kind == 'class') {
|
if (symbol.kind == 'class') {
|
||||||
constructors[name] = true;
|
constructors[name] = true;
|
||||||
lines.push(' * @constructor');
|
lines.push(' * @constructor');
|
||||||
@@ -108,7 +112,6 @@ function generateExterns(symbols) {
|
|||||||
} else {
|
} else {
|
||||||
lines.push(name + ';');
|
lines.push(name + ';');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
lines.push('\n');
|
lines.push('\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,13 +127,13 @@ function generateExterns(symbols) {
|
|||||||
*/
|
*/
|
||||||
function main(callback) {
|
function main(callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
getSymbols,
|
getTypedefsAndSymbols,
|
||||||
function(symbols, done) {
|
function(typedefs, symbols, done) {
|
||||||
var code, err;
|
var code, err;
|
||||||
try {
|
try {
|
||||||
var olx = fs.readFileSync(olxPath, {encoding: 'utf-8'})
|
var olx = fs.readFileSync(olxPath, {encoding: 'utf-8'})
|
||||||
.replace(/ \* @api ?(.*)?(\r\n|\n|\r)/gm, '');
|
.replace(/ \* @api ?(.*)?(\r\n|\n|\r)/gm, '');
|
||||||
code = olx + '\n\n' + generateExterns(symbols);
|
code = olx + '\n\n' + generateExterns(typedefs, symbols);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user