Skip to content

Commit dd43ad6

Browse files
bryanmacfarlaneericsciple
authored andcommitted
more docs
1 parent 491c6f6 commit dd43ad6

File tree

5 files changed

+2100
-18
lines changed

5 files changed

+2100
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _test
55
node/*.d.ts
66
node/*.js
77
node/docs/temp
8+
node/docs/*.js
89

910
# Logs
1011
logs

node/docs/TypeScriptSourceToJson.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var path = require('path');
55

66
export interface DocEntry {
77
name?: string,
8+
type?: string,
89
documentation?: string,
910
kind?: string,
1011
signatures?: DocEntry[],
@@ -170,8 +171,21 @@ function visit(node: ts.Node): void {
170171
}
171172

172173
function getDockEntryFromSignature(signature: ts.Signature): DocEntry {
174+
let paramEntries: DocEntry[] = [];
175+
let params: ts.Symbol[] = signature.parameters;
176+
params.forEach((ps: ts.Symbol) => {
177+
let de = {} as DocEntry;
178+
de.name = ps.getName();
179+
180+
let decls: ts.Declaration[] = ps.declarations;
181+
let paramType: ts.Type = checker.getTypeAtLocation(decls[0]);
182+
de.type = checker.typeToString(paramType);
183+
de.documentation = ts.displayPartsToString(ps.getDocumentationComment());
184+
paramEntries.push(de);
185+
});
186+
173187
let e: DocEntry = {
174-
parameters: signature.parameters.map(getDockEntryFromSymbol),
188+
parameters: paramEntries,
175189
members: {} as { string: [DocEntry]},
176190
return: checker.typeToString(signature.getReturnType()),
177191
documentation: ts.displayPartsToString(signature.getDocumentationComment())

node/docs/docs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"toolrunner.line",
3131
"toolrunner.argIf",
3232
"toolrunner.IExecOptions",
33-
"toolrunner.ToolRunner.exec",
34-
"toolrunner.ToolRunner.execSync",
33+
"toolrunner.exec",
34+
"toolrunner.execSync",
3535
"toolrunner.pipeExecOutputToTool",
3636
"toolrunner.IExecResult",
3737
"task.exec",

node/docs/gendocs.ts

Lines changed: 142 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,94 @@ function anchorName(name) {
4242
}
4343

4444
shell.rm('-rf', mdpath);
45-
var ds = docs.structure;
45+
var docsStructure = docs.structure;
4646
var aliasCache = {} as { string : [ts2json.DocEntry]};
4747

48-
function getItem(item: string): ts2json.DocEntry {
48+
function getDocEntry(namespace: string): ts2json.DocEntry {
4949
let d: ts2json.DocEntry;
5050

51-
let parts: string[] = item.split('.');
51+
let parts: string[] = namespace.split('.');
52+
if (parts.length != 2) {
53+
console.error(namespace + ' invalid. doc entry must have two parts. alias.itemName');
54+
}
55+
5256
let alias: string = parts[0];
57+
let entryName: string = parts[1];
5358
let stmt: string = 'doc.' + docs.aliases[alias];
54-
59+
5560
if (!aliasCache[alias]) {
5661
aliasCache[alias] = eval(stmt);
5762
}
58-
59-
d = aliasCache[alias];
63+
d = aliasCache[alias][entryName];
6064

6165
if (!d) {
62-
console.error('Could not evaluate: ' + item + '(' + stmt + ')');
66+
console.error('Could not evaluate: ' + namespace + '(' + stmt + ')');
6367
}
6468

6569
return d;
6670
}
6771

72+
// TODO: enums
73+
// TODO: isOptional on params
74+
// TODO: params type
75+
76+
var writeFunction = function(name: string, item: ts2json.DocEntry) {
77+
writeLine("<br/>");
78+
writeLine('<div id="' + anchorName(name) + '">');
79+
writeLine('### ' + name + ' <a href="#index">(^)</a>');
80+
81+
var sigs = item.signatures;
82+
sigs.forEach((sig: ts2json.DocEntry) => {
83+
// comments
84+
var comment = sig.documentation;
85+
if (comment) {
86+
writeLine(comment);
87+
}
88+
89+
// signature
90+
91+
var sigLine = item.name + '(';
92+
93+
if (sig.parameters) {
94+
for (var i = 0; i < sig.parameters.length; i++) {
95+
var param = sig.parameters[i];
96+
sigLine += param.name;
97+
98+
// if (param.flags.isOptional) {
99+
// sigLine += '?';
100+
// }
101+
102+
sigLine += (':' + param.type);
103+
104+
if (i < (sig.parameters.length - 1)) {
105+
sigLine += ', ';
106+
}
107+
}
108+
}
109+
110+
sigLine += '):' + sig.return;
111+
112+
writeLine('```javascript');
113+
writeLine(sigLine);
114+
writeLine('```');
115+
116+
// params table
117+
118+
if (sig.parameters) {
119+
writeLine();
120+
writeLine('Param | Type | Description');
121+
writeLine('--- | --- | ---');
122+
for (var i = 0; i < sig.parameters.length; i++) {
123+
var param = sig.parameters[i];
124+
125+
var pc = param.documentation ? param.documentation || ' - ' : ' - ';
126+
writeLine(param.name + ' | ' + param.type + ' | ' + pc);
127+
}
128+
writeLine();
129+
}
130+
});
131+
}
132+
68133
writeLine('# VSTS-TASK-LIB TYPESCRIPT API');
69134
writeLine();
70135
writeLine('## Dependencies');
@@ -89,19 +154,81 @@ writeLine();
89154
//
90155
writeLine('<div id="index">');
91156
writeLine('## Index');
92-
for (var secName in ds) {
157+
for (var sectionName in docsStructure) {
93158
writeLine();
94-
writeLine('### ' + secName + ' <a href="#' + anchorName(secName) + '">(v)</a>');
159+
writeLine('### ' + sectionName + ' <a href="#' + anchorName(sectionName) + '">(v)</a>');
95160
writeLine();
96161

97-
var sec = ds[secName];
98-
var docLabels: string[] = sec.Document as string[];
99-
docLabels.forEach((docItem: string) => {
100-
var item: ts2json.DocEntry = getItem(docItem);
162+
var section = docsStructure[sectionName];
163+
var docItems: string[] = section.Document as string[];
164+
docItems.forEach((docItem: string) => {
165+
var docEntry: ts2json.DocEntry = getDocEntry(docItem);
166+
167+
if (docEntry) {
168+
writeLine('<a href="#' + anchorName(docItem) + '">' + docEntry.name + '</a><br/>');
169+
}
170+
})
171+
}
172+
173+
//
174+
// Docs
175+
//
176+
for (var sectionName in docsStructure) {
177+
writeLine();
178+
writeLine("<br/>");
179+
writeLine('<div id="' + anchorName(sectionName) + '">');
180+
writeLine('## ' + sectionName);
181+
writeLine();
182+
writeLine('---');
183+
writeLine();
184+
185+
var sec = docsStructure[sectionName];
186+
if (sec.Summary) {
187+
writeLine(sec.Summary);
188+
}
189+
190+
if (sec.Sample) {
191+
try {
192+
writeLine();
193+
var contents = fs.readFileSync(path.join(__dirname, sec.Sample));
194+
writeLine("```javascript");
195+
if (!contents || contents.length == 0) {
196+
writeLine('No content');
197+
}
198+
writeLine(contents.toString());
199+
writeLine("```");
200+
}
201+
catch(err) {
202+
console.error(err);
203+
}
204+
}
205+
206+
var documents = sec.Document;
207+
documents.forEach((docItem) => {
208+
console.log('docItem', docItem);
209+
var item: ts2json.DocEntry = getDocEntry(docItem);
101210

102211
if (item) {
103-
let idxTitle = docItem.substring(docItem.indexOf('.') + 1);
104-
writeLine('<a href="#' + anchorName(docItem) + '">' + idxTitle + '</a><br/>');
212+
switch (item.kind) {
213+
case "Constructor":
214+
case "method":
215+
//case "Enumeration":
216+
case "function":
217+
writeFunction(docItem, item);
218+
break;
219+
220+
case "interface":
221+
//writeInterface(doc, item);
222+
break;
223+
224+
default:
225+
console.log('warning: skipping ' + item.kind);
226+
console.log(item);
227+
process.exit();
228+
}
105229
}
106230
})
107231
}
232+
233+
console.log('Done');
234+

0 commit comments

Comments
 (0)