Add all symbols to the legacy build

This commit is contained in:
Andreas Hocevar
2020-11-04 19:56:24 +01:00
parent 00415c6774
commit 68d6a6b84c
4 changed files with 24 additions and 37 deletions

View File

@@ -1,11 +0,0 @@
/**
* Handle the api annotation.
* @param {Object} dictionary The tag dictionary.
*/
exports.defineTags = function (dictionary) {
dictionary.defineTag('api', {
onTagged: function (doclet, tag) {
doclet.api = true;
},
});
};

View File

@@ -11,7 +11,6 @@
}, },
"plugins": [ "plugins": [
"jsdoc-plugin-typescript", "jsdoc-plugin-typescript",
"config/jsdoc/info/api-plugin",
"config/jsdoc/info/define-plugin", "config/jsdoc/info/define-plugin",
"config/jsdoc/info/virtual-plugin" "config/jsdoc/info/virtual-plugin"
], ],

View File

@@ -27,19 +27,20 @@ exports.publish = function (data, opts) {
{define: {isObject: true}}, {define: {isObject: true}},
function () { function () {
if (this.kind == 'class') { if (this.kind == 'class') {
if (!('extends' in this) || typeof this.api == 'boolean') { classes[this.longname] = this;
classes[this.longname] = this; return true;
return true;
}
} }
return ( return (
typeof this.api == 'boolean' || this.meta &&
(this.meta && /[\\\/]externs$/.test(this.meta.path)) this.meta.path &&
this.longname.indexOf('<anonymous>') !== 0 &&
this.longname !== 'module:ol'
); );
}, },
], ],
{kind: {'!is': 'file'}}, {kind: {'!is': 'file'}},
{kind: {'!is': 'event'}} {kind: {'!is': 'event'}},
{kind: {'!is': 'module'}}
).get(); ).get();
// get symbols data, filter out those that are members of private classes // get symbols data, filter out those that are members of private classes
@@ -77,7 +78,7 @@ exports.publish = function (data, opts) {
path: path.join(doc.meta.path, doc.meta.filename), path: path.join(doc.meta.path, doc.meta.filename),
default: doc.define.default, default: doc.define.default,
}); });
} else if (doc.kind == 'typedef' || doc.isEnum === true) { } else if (doc.type && (doc.kind == 'typedef' || doc.isEnum === true)) {
typedefs.push({ typedefs.push({
name: doc.longname, name: doc.longname,
types: getTypes(doc.type.names), types: getTypes(doc.type.names),
@@ -136,7 +137,7 @@ exports.publish = function (data, opts) {
}); });
} }
const target = isExterns ? externs : doc.api ? symbols : base; const target = isExterns ? externs : symbols;
const existingSymbol = symbolsByName[symbol.name]; const existingSymbol = symbolsByName[symbol.name];
if (existingSymbol) { if (existingSymbol) {
const idx = target.indexOf(existingSymbol); const idx = target.indexOf(existingSymbol);
@@ -145,10 +146,9 @@ exports.publish = function (data, opts) {
target.push(symbol); target.push(symbol);
symbolsByName[symbol.name] = symbol; symbolsByName[symbol.name] = symbol;
if (doc.api && symbol.extends) { if (symbol.extends) {
while ( while (
symbol.extends in classes && symbol.extends in classes &&
!classes[symbol.extends].api &&
classes[symbol.extends].augments classes[symbol.extends].augments
) { ) {
symbol.extends = classes[symbol.extends].augments[0]; symbol.extends = classes[symbol.extends].augments[0];

View File

@@ -20,7 +20,7 @@ async function getSymbols() {
function getImport(symbol, member) { function getImport(symbol, member) {
const defaultExport = symbol.name.split('~'); const defaultExport = symbol.name.split('~');
const namedExport = symbol.name.split('.'); const namedExport = symbol.name.split('.');
if (defaultExport.length > 1) { if (defaultExport.length > 1 && defaultExport[0].indexOf('.') === -1) {
const from = defaultExport[0].replace(/^module\:/, './'); const from = defaultExport[0].replace(/^module\:/, './');
const importName = from.replace(/[.\/]+/g, '$'); const importName = from.replace(/[.\/]+/g, '$');
return `import ${importName} from '${from}';`; return `import ${importName} from '${from}';`;
@@ -53,8 +53,11 @@ function formatSymbolExport(symbol, namespaces, imports) {
namespaces[line] = namespaces[line] =
(line in namespaces ? namespaces[line] : true) && i < ii - 1; (line in namespaces ? namespaces[line] : true) && i < ii - 1;
} }
line += ` = ${importName};`; line += ` = ${importName} || {};`;
imports[getImport(symbol, nsParts.pop())] = true; const imp = getImport(symbol, nsParts.pop());
if (imp) {
imports[imp] = true;
}
return line; return line;
} }
@@ -68,18 +71,15 @@ function formatSymbolExport(symbol, namespaces, imports) {
function generateExports(symbols) { function generateExports(symbols) {
const namespaces = {}; const namespaces = {};
const imports = []; const imports = [];
let blocks = []; const blocks = [];
symbols.forEach(function (symbol) { symbols.forEach(function (symbol) {
const name = symbol.name; const name = symbol.name;
if (name.indexOf('#') == -1) { if (name.indexOf('#') == -1) {
const imp = getImport(symbol); const imp = getImport(symbol);
if (imp) { if (imp) {
imports[getImport(symbol)] = true; imports[imp] = true;
}
const block = formatSymbolExport(symbol, namespaces, imports);
if (block !== blocks[blocks.length - 1]) {
blocks.push(block);
} }
blocks.push(formatSymbolExport(symbol, namespaces, imports));
} }
}); });
const nsdefs = []; const nsdefs = [];
@@ -89,11 +89,10 @@ function generateExports(symbols) {
nsdefs.push(`${ns[i]} = {};`); nsdefs.push(`${ns[i]} = {};`);
} }
} }
blocks = Object.keys(imports) const defs = ['\nvar ol = {};'].concat(nsdefs, [...new Set(blocks)]);
.concat('\nvar ol = {};\n', nsdefs.sort()) const lines = Object.keys(imports).concat(defs.sort());
.concat(blocks.sort()); lines.push('', 'export default ol;');
blocks.push('', 'export default ol;'); return lines.join('\n');
return blocks.join('\n');
} }
/** /**