Skip to content

Commit af4466c

Browse files
authored
Merge pull request microsoft#563 from Microsoft/pgonzal/office-addin-fixes
[api-documenter] Various fixes to improve generation of docs for Office Add-ins
2 parents 20f7c79 + f237ee5 commit af4466c

41 files changed

Lines changed: 574 additions & 148 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/api-documenter/src/markdown/MarkdownDocumenter.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as fsx from 'fs-extra';
55
import * as path from 'path';
66

7+
import { Text } from '@microsoft/node-core-library';
78
import {
89
IApiClass,
910
IApiEnum,
@@ -588,13 +589,15 @@ export class MarkdownDocumenter {
588589
throw new Error('Unresolved: ' + JSON.stringify(args.reference));
589590
}
590591

591-
const docFilename: string = this._getFilenameForDocItem(resolveResult.docItem);
592+
// NOTE: GitHub's markdown renderer does not resolve relative hyperlinks correctly
593+
// unless they start with "./" or "../".
594+
const docFilename: string = './' + this._getFilenameForDocItem(resolveResult.docItem);
592595
args.prefix = '[';
593596
args.suffix = '](' + docFilename + ')';
594597
}
595598
});
596599

597-
fsx.writeFileSync(filename, content);
600+
fsx.writeFileSync(filename, Text.convertToCrLf(content));
598601
}
599602

600603
private _getFilenameForDocItem(docItem: DocItem): string {

‎apps/api-documenter/src/utils/MarkdownRenderer.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,12 @@ export class MarkdownRenderer {
229229
break;
230230
case 'code':
231231
writer.write('`');
232-
writer.write(element.text);
232+
if (context.insideTable) {
233+
const parts: string[] = element.text.split(/[\r\n]+/g);
234+
writer.write(parts.join('`<p/>`'));
235+
} else {
236+
writer.write(element.text);
237+
}
233238
writer.write('`');
234239
break;
235240
case 'api-link':

‎apps/api-documenter/src/yaml/OfficeYamlDocumenter.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import * as colors from 'colors';
45
import * as fsx from 'fs-extra';
56
import * as path from 'path';
67
import yaml = require('js-yaml');
@@ -38,8 +39,9 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
3839
super.generateFiles(outputFolder);
3940

4041
// After we generate everything, check for any unused snippets
42+
console.log();
4143
for (const apiName of Object.keys(this._snippets)) {
42-
console.error('UNUSED SNIPPET: ' + apiName);
44+
console.error(colors.yellow('Warning: Unused snippet ' + apiName));
4345
}
4446
}
4547

‎apps/api-documenter/src/yaml/YamlDocumenter.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import * as fsx from 'fs-extra';
55
import * as path from 'path';
6+
import * as colors from 'colors';
7+
68
import yaml = require('js-yaml');
79
import { JsonFile, JsonSchema, Text } from '@microsoft/node-core-library';
810
import {
@@ -13,7 +15,8 @@ import {
1315
IApiProperty,
1416
IApiEnumMember,
1517
IApiClass,
16-
IApiInterface
18+
IApiInterface,
19+
Markup
1720
} from '@microsoft/api-extractor';
1821

1922
import { DocItemSet, DocItem, DocItemKind, IDocItemSetResolveResult } from '../utils/DocItemSet';
@@ -354,7 +357,8 @@ export class YamlDocumenter {
354357
const result: IDocItemSetResolveResult = this._docItemSet.resolveApiItemReference(args.reference);
355358
if (!result.docItem) {
356359
// Eventually we should introduce a warnings file
357-
console.error('==> UNRESOLVED REFERENCE: ' + JSON.stringify(args.reference));
360+
console.error(colors.yellow('Warning: Unresolved hyperlink to '
361+
+ Markup.formatApiItemReference(args.reference)));
358362
} else {
359363
args.prefix = '[';
360364
args.suffix = `](xref:${this._getUid(result.docItem)})`;

‎apps/api-extractor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/colors": "1.1.3",
4545
"@types/lodash": "4.14.74",
4646
"gulp": "~3.9.1",
47-
"@microsoft/node-library-build": "4.3.13",
47+
"@microsoft/node-library-build": "4.3.20",
4848
"@types/jest": "21.1.10"
4949
}
5050
}

‎apps/api-extractor/src/ExtractorContext.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PackageJsonLookup } from '@microsoft/node-core-library';
99
import { AstPackage } from './ast/AstPackage';
1010
import { DocItemLoader } from './DocItemLoader';
1111
import { ILogger } from './extractor/ILogger';
12-
import { IExtractorPoliciesConfig } from './extractor/IExtractorConfig';
12+
import { IExtractorPoliciesConfig, IExtractorValidationRulesConfig } from './extractor/IExtractorConfig';
1313

1414
/**
1515
* Options for ExtractorContext constructor.
@@ -35,6 +35,8 @@ export interface IExtractorContextOptions {
3535
logger: ILogger;
3636

3737
policies: IExtractorPoliciesConfig;
38+
39+
validationRules: IExtractorValidationRulesConfig;
3840
}
3941

4042
/**
@@ -55,6 +57,8 @@ export class ExtractorContext {
5557

5658
public readonly policies: IExtractorPoliciesConfig;
5759

60+
public readonly validationRules: IExtractorValidationRulesConfig;
61+
5862
private _packageName: string;
5963

6064
// If the entry point is "C:\Folder\project\src\index.ts" and the nearest package.json
@@ -67,6 +71,7 @@ export class ExtractorContext {
6771
this.packageJsonLookup = new PackageJsonLookup();
6872

6973
this.policies = options.policies;
74+
this.validationRules = options.validationRules;
7075

7176
const folder: string | undefined = this.packageJsonLookup.tryGetPackageFolder(options.entryPointFile);
7277
if (!folder) {

‎apps/api-extractor/src/ast/AstFunction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class AstFunction extends AstItem {
2727
if (methodDeclaration.parameters) {
2828
this.params = [];
2929
for (const param of methodDeclaration.parameters) {
30-
const declarationSymbol: ts.Symbol = TypeScriptHelpers.tryGetSymbolForDeclaration(param);
30+
const declarationSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(param);
3131
const astParameter: AstParameter = new AstParameter({
3232
context: this.context,
3333
declaration: param,

‎apps/api-extractor/src/ast/AstItem.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,17 @@ export abstract class AstItem {
536536
if (this.parentContainer && this.parentContainer.kind === AstItemKind.Package) {
537537
// Don't warn about items that failed to parse.
538538
if (!this.documentation.failedToParse) {
539-
// If there is no release tag, and this is a top-level export of the package, then
540-
// report an error
541-
this.reportError(`A release tag (@alpha, @beta, @public, @internal) must be specified`
542-
+ ` for ${this.name}`);
539+
if (this.context.validationRules.missingReleaseTags === 'error') {
540+
// If there is no release tag, and this is a top-level export of the package, then
541+
// report an error
542+
this.reportError(`A release tag (@alpha, @beta, @public, @internal) must be specified`
543+
+ ` for ${this.name}`);
544+
}
543545
}
546+
547+
// If the release tag was not specified for a top-level export, then it defaults
548+
// to @public (even if we reported an error above)
549+
this.documentation.releaseTag = ReleaseTag.Public;
544550
}
545551
}
546552
}

‎apps/api-extractor/src/ast/AstMethod.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// See LICENSE in the project root for license information.
33

44
import * as ts from 'typescript';
5-
import { AstItemKind, IAstItemOptions } from './AstItem';
5+
import { AstItem, AstItemKind, IAstItemOptions } from './AstItem';
66
import { AstMember } from './AstMember';
77
import { AstParameter } from './AstParameter';
88
import { TypeScriptHelpers } from '../utils/TypeScriptHelpers';
@@ -36,7 +36,7 @@ export class AstMethod extends AstMember {
3636
if (methodDeclaration.parameters) {
3737
this.params = [];
3838
for (const param of methodDeclaration.parameters) {
39-
const declarationSymbol: ts.Symbol = TypeScriptHelpers.tryGetSymbolForDeclaration(param);
39+
const declarationSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(param);
4040
const astParameter: AstParameter = new AstParameter({
4141
context: this.context,
4242
declaration: param,
@@ -65,23 +65,38 @@ export class AstMethod extends AstMember {
6565
// If this is a class constructor, and if the documentation summary was omitted, then
6666
// we fill in a default summary versus flagging it as "undocumented".
6767
// Generally class constructors have uninteresting documentation.
68-
if (this.kind === AstItemKind.Constructor) {
68+
if (this.kind === AstItemKind.Constructor && this.parentContainer) {
6969
if (this.documentation.summary.length === 0) {
7070
this.documentation.summary.push(
7171
...Markup.createTextElements('Constructs a new instance of the '));
7272

7373
const scopedPackageName: IScopedPackageName = ApiDefinitionReference
7474
.parseScopedPackageName(this.context.package.name);
7575

76-
this.documentation.summary.push(
77-
Markup.createApiLinkFromText(this.parentContainer!.name, {
78-
scopeName: scopedPackageName.scope,
79-
packageName: scopedPackageName.package,
80-
exportName: this.parentContainer!.name,
81-
memberName: ''
82-
}
83-
)
84-
);
76+
const parentParentContainer: AstItem | undefined = this.parentContainer.parentContainer;
77+
if (parentParentContainer && parentParentContainer.kind === AstItemKind.Namespace) {
78+
// This is a temporary workaround to support policies.namespaceSupport === permissive
79+
// until the new AstSymbolTable engine is wired up
80+
this.documentation.summary.push(
81+
Markup.createApiLinkFromText(this.parentContainer.name, {
82+
scopeName: scopedPackageName.scope,
83+
packageName: scopedPackageName.package,
84+
exportName: parentParentContainer.name,
85+
memberName: this.parentContainer.name
86+
}
87+
)
88+
);
89+
} else {
90+
this.documentation.summary.push(
91+
Markup.createApiLinkFromText(this.parentContainer.name, {
92+
scopeName: scopedPackageName.scope,
93+
packageName: scopedPackageName.package,
94+
exportName: this.parentContainer.name,
95+
memberName: ''
96+
}
97+
)
98+
);
99+
}
85100

86101
this.documentation.summary.push(...Markup.createTextElements(' class'));
87102
}

‎apps/api-extractor/src/ast/AstPackage.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ export class AstPackage extends AstModule {
1818
private _exportedNormalizedSymbols: IExportedSymbol[] = [];
1919

2020
private static _getOptions(context: ExtractorContext, rootFile: ts.SourceFile): IAstItemOptions {
21-
const rootFileSymbol: ts.Symbol = TypeScriptHelpers.getSymbolForDeclaration(rootFile);
21+
const rootFileSymbol: ts.Symbol | undefined = TypeScriptHelpers.tryGetSymbolForDeclaration(rootFile);
22+
23+
if (!rootFileSymbol) {
24+
throw new Error('The entry point file does not appear to have any exports:\n' + rootFile.fileName
25+
+ '\nNote that API Extractor does not yet support libraries consisting entirely of ambient types.');
26+
}
2227

2328
if (!rootFileSymbol.declarations) {
2429
throw new Error('Unable to find a root declaration for this package');

0 commit comments

Comments
 (0)