Skip to content

Commit

Permalink
Gen docs (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple authored Apr 5, 2017
1 parent 4dd8ef3 commit 6e7571d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 511 deletions.
32 changes: 17 additions & 15 deletions node/docs/TypeScriptSourceToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ let checker: ts.TypeChecker;
export function generate(filePaths: string[], options: ts.CompilerOptions): DocEntry {
program = ts.createProgram(filePaths, options);
checker = program.getTypeChecker();


let files: ts.SourceFile[] = program.getSourceFiles();
for (const sourceFile of program.getSourceFiles()) {


// only document files we specified. dependency files may be in program
if (filePaths.indexOf(sourceFile.fileName) >= 0) {
let name = path.basename(sourceFile.fileName, '.ts');
Expand Down Expand Up @@ -76,8 +73,8 @@ function visit(node: ts.Node): void {
let constructorType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
doc.constructors = constructorType.getConstructSignatures().map(getDocEntryFromSignature);
current.members[doc.name] = doc;
push(doc);

push(doc);
}
}
else if (node.kind == ts.SyntaxKind.InterfaceDeclaration) {
Expand Down Expand Up @@ -158,17 +155,22 @@ function visit(node: ts.Node): void {
current.members[doc.name] = doc;
}
}
// else if (node.kind === ts.SyntaxKind.ModuleDeclaration) {
// // This is a namespace, visit its children
// console.log('*********** module **************');
// let f: ts.ModuleDeclaration = <ts.ModuleDeclaration>node;
// let symbol = checker.getSymbolAtLocation(f.name);
// if (symbol) {
// console.log('module', symbol.getName());
// }
// }
// handle re-export from internal.ts
else if (node.kind === ts.SyntaxKind.VariableStatement && node.flags === ts.NodeFlags.Export) {
let statement = <ts.VariableStatement>node;
let list: ts.VariableDeclarationList = statement.declarationList;
for (let declaration of list.declarations) {
let symbol = checker.getSymbolAtLocation(declaration.name);
let doc: DocEntry = getDocEntryFromSymbol(symbol);
doc.kind = 'function'; // assume the re-export is a function
doc.name = symbol.getName();
let types = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
let sigs = types.getCallSignatures();
doc.signatures = sigs.map(getDocEntryFromSignature);
current.members[doc.name] = doc;
}
}


ts.forEachChild(node, visit);
}

Expand Down
2 changes: 1 addition & 1 deletion node/docs/gendocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getDocEntry(namespace: string): ts2json.DocEntry {
}

if (!d) {
console.error(namespace + 'invalid. doc entry not found.');
console.error(namespace + ' invalid. doc entry not found.');
process.exit(1);
}
}
Expand Down
Loading

0 comments on commit 6e7571d

Please sign in to comment.