X Tutup
Skip to content

Commit b9466ac

Browse files
committed
Add api-documenter; comment updates
1 parent 6211a14 commit b9466ac

File tree

10 files changed

+85
-6
lines changed

10 files changed

+85
-6
lines changed

apps/api-documenter/src/documenters/DocumenterConfig.ts

Lines changed: 19 additions & 1 deletion
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 path from 'path';
5-
import { JsonSchema, JsonFile } from '@microsoft/node-core-library';
5+
import { JsonSchema, JsonFile, NewlineKind } from '@microsoft/node-core-library';
66
import { IConfigFile } from './IConfigFile';
77

88
/**
@@ -14,6 +14,12 @@ export class DocumenterConfig {
1414
public readonly configFilePath: string;
1515
public readonly configFile: IConfigFile;
1616

17+
/**
18+
* Specifies what type of newlines API Documenter should use when writing output files. By default, the output files
19+
* will be written with Windows-style newlines.
20+
*/
21+
public readonly newlineKind: NewlineKind;
22+
1723
/**
1824
* The JSON Schema for API Extractor config file (api-extractor.schema.json).
1925
*/
@@ -28,6 +34,18 @@ export class DocumenterConfig {
2834
private constructor(filePath: string, configFile: IConfigFile) {
2935
this.configFilePath = filePath;
3036
this.configFile = configFile;
37+
38+
switch (configFile.newlineKind) {
39+
case 'lf':
40+
this.newlineKind = NewlineKind.Lf;
41+
break;
42+
case 'os':
43+
this.newlineKind = NewlineKind.OsDefault;
44+
break;
45+
default:
46+
this.newlineKind = NewlineKind.CrLf;
47+
break;
48+
}
3149
}
3250

3351
/**

apps/api-documenter/src/documenters/IConfigFile.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ export interface IConfigPlugin {
6969
}
7070

7171
/**
72-
* This interface represents the api-extractor.json file format.
72+
* This interface represents the api-documenter.json file format.
7373
*/
7474
export interface IConfigFile {
7575
/**
7676
* Specifies the output target.
7777
*/
7878
outputTarget: 'docfx' | 'markdown';
7979

80+
/**
81+
* Specifies what type of newlines API Documenter should use when writing output files.
82+
*
83+
* @remarks
84+
* By default, the output files will be written with Windows-style newlines.
85+
* To use POSIX-style newlines, specify "lf" instead.
86+
* To use the OS's default newline kind, specify "os".
87+
*/
88+
newlineKind?: 'crlf' | 'lf' | 'os';
89+
8090
/** {@inheritDoc IConfigPlugin} */
8191
plugins?: IConfigPlugin[];
8292

apps/api-documenter/src/documenters/MarkdownDocumenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class MarkdownDocumenter {
285285
}
286286

287287
FileSystem.writeFile(filename, pageContent, {
288-
convertLineEndings: NewlineKind.CrLf
288+
convertLineEndings: this._documenterConfig ? this._documenterConfig.newlineKind : NewlineKind.CrLf
289289
});
290290
}
291291

apps/api-documenter/src/schemas/api-documenter-template.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@
44
{
55
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-documenter.schema.json",
66

7+
/**
8+
* Specifies the output target.
9+
* Supported values are "docfx" or "markdown"
10+
*/
11+
// "outputTarget": "markdown",
12+
13+
/**
14+
* Specifies what type of newlines API Documenter should use when writing output files. By default, the output files
15+
* will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
16+
* To use the OS's default newline kind, specify "os".
17+
*
18+
* DEFAULT VALUE: "crlf"
19+
*/
20+
// "newlineKind": "crlf",
21+
22+
/**
23+
* Describes plugin packages to be loaded, and which features to enable.
24+
*/
25+
"plugins": [
26+
// {
27+
// "packageName": "doc-plugin-example",
28+
// "enabledFeatureNames": [ "example-feature" ]
29+
// }
30+
],
31+
732
/**
833
* Configures how the table of contents is generated.
934
*/

apps/api-documenter/src/schemas/api-documenter.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
]
1818
},
1919

20+
"newlineKind": {
21+
"description": "Specifies what type of newlines API Documenter should use when writing output files. By default, the output files will be written with Windows-style newlines. To use POSIX-style newlines, specify \"lf\" instead. To use the OS's default newline kind, specify \"os\".",
22+
"type": "string",
23+
"enum": ["crlf", "lf", "os"],
24+
"default": "crlf"
25+
},
26+
2027
"plugins": {
2128
"description": "Specifies plugin packages to be loaded",
2229
"type": "array"

apps/api-extractor/src/api/IConfigFile.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,12 @@ export interface IConfigFile {
368368
tsdocMetadata?: IConfigTsdocMetadata;
369369

370370
/**
371-
* Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
372-
* will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
371+
* Specifies what type of newlines API Extractor should use when writing output files.
372+
*
373+
* @remarks
374+
* By default, the output files will be written with Windows-style newlines.
375+
* To use POSIX-style newlines, specify "lf" instead.
373376
* To use the OS's default newline kind, specify "os".
374-
* @defaultValue 'crlf'
375377
*/
376378
newlineKind?: 'crlf' | 'lf' | 'os';
377379

apps/api-extractor/src/schemas/api-extractor-defaults.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
"bundledPackages": [ ],
77

8+
"newlineKind": "crlf",
9+
810
"compiler": {
911
"tsconfigFilePath": "<projectFolder>/tsconfig.json",
1012
"skipLibCheck": false

build-tests/api-documenter-test/config/api-documenter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-documenter.schema.json",
33

4+
"newlineKind": "crlf",
5+
46
"tableOfContents": {
57
"tocConfig": {
68
"items": [

build-tests/api-documenter-test/config/api-extractor.json

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

44
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
55

6+
"newlineKind": "crlf",
7+
68
"apiReport": {
79
"enabled": true,
810
},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-documenter",
5+
"comment": "Make newline type for generated files configurable",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/api-documenter",
10+
"email": "ecraig12345@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)
X Tutup