@microsoft/api-documenter
Version:
Read JSON files from api-extractor, generate documentation pages
43 lines • 1.72 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import { JsonSchema, JsonFile, NewlineKind } from '@rushstack/node-core-library';
import apiDocumenterSchema from '../schemas/api-documenter.schema.json';
/**
* Helper for loading the api-documenter.json file format. Later when the schema is more mature,
* this class will be used to represent the validated and normalized configuration, whereas `IConfigFile`
* represents the raw JSON file structure.
*/
export class DocumenterConfig {
constructor(filePath, configFile) {
this.configFilePath = filePath;
this.configFile = configFile;
switch (configFile.newlineKind) {
case 'lf':
this.newlineKind = NewlineKind.Lf;
break;
case 'os':
this.newlineKind = NewlineKind.OsDefault;
break;
default:
this.newlineKind = NewlineKind.CrLf;
break;
}
}
/**
* Load and validate an api-documenter.json file.
*/
static loadFile(configFilePath) {
const configFile = JsonFile.loadAndValidate(configFilePath, DocumenterConfig.jsonSchema);
return new DocumenterConfig(path.resolve(configFilePath), configFile);
}
}
/**
* The JSON Schema for API Documenter config file (api-documenter.schema.json).
*/
DocumenterConfig.jsonSchema = JsonSchema.fromLoadedObject(apiDocumenterSchema);
/**
* The config file name "api-documenter.json".
*/
DocumenterConfig.FILENAME = 'api-documenter.json';
//# sourceMappingURL=DocumenterConfig.js.map