docgen: use repo root as base path but exclude types in node_modules
This commit is contained in:
@@ -42,7 +42,7 @@ export default class ApiDocGenerator {
|
||||
|
||||
constructor(
|
||||
private readonly checker: ts.TypeChecker,
|
||||
private readonly sourcePath: string,
|
||||
private readonly basePath: string,
|
||||
) {}
|
||||
|
||||
toDoc(apiInstance: ExportedInstance): ApiDoc {
|
||||
@@ -55,7 +55,7 @@ export default class ApiDocGenerator {
|
||||
|
||||
const id = this.getObjectPropertyLiteral(info, 'id');
|
||||
const description = this.getObjectPropertyLiteral(info, 'description');
|
||||
const file = relative(this.sourcePath, source.fileName);
|
||||
const file = relative(this.basePath, source.fileName);
|
||||
const { line } = source.getLineAndCharacterOfPosition(
|
||||
apiInstance.node.getStart(),
|
||||
);
|
||||
@@ -102,7 +102,7 @@ export default class ApiDocGenerator {
|
||||
const name = (type.aliasSymbol || type.symbol).name;
|
||||
const [declaration] = (type.aliasSymbol || type.symbol).declarations;
|
||||
const sourceFile = declaration.getSourceFile();
|
||||
const file = relative(this.sourcePath, sourceFile.fileName);
|
||||
const file = relative(this.basePath, sourceFile.fileName);
|
||||
const { line } = sourceFile.getLineAndCharacterOfPosition(
|
||||
declaration.getStart(),
|
||||
);
|
||||
@@ -216,7 +216,7 @@ export default class ApiDocGenerator {
|
||||
const { line } = sourceFile.getLineAndCharacterOfPosition(
|
||||
declaration.getStart(),
|
||||
);
|
||||
const file = relative(this.sourcePath, sourceFile.fileName);
|
||||
const file = relative(this.basePath, sourceFile.fileName);
|
||||
const typeInfo = {
|
||||
id: (symbol as any).id,
|
||||
name: symbol.name,
|
||||
@@ -260,7 +260,7 @@ export default class ApiDocGenerator {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!declaration.getSourceFile().fileName.startsWith(this.sourcePath)) {
|
||||
if (declaration.getSourceFile().fileName.includes('node_modules')) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import { ApiDoc, InterfaceInfo } from './types';
|
||||
|
||||
// TODO(Rugvip): provide through options?
|
||||
const GH_BASE_URL = 'https://github.com/spotify/backstage';
|
||||
const SRC_PATH = 'packages/core-api/src';
|
||||
|
||||
const COMMIT_SHA =
|
||||
process.env.COMMIT_SHA || execSync('git rev-parse HEAD').toString('utf8');
|
||||
@@ -42,7 +41,7 @@ export default class ApiDocPrinter {
|
||||
text?: string,
|
||||
) {
|
||||
const linkText = text ?? `${file}:${lineInFile}`;
|
||||
const href = `${GH_BASE_URL}/blob/${COMMIT_SHA}/${SRC_PATH}/${file}#L${lineInFile}`;
|
||||
const href = `${GH_BASE_URL}/blob/${COMMIT_SHA}/${file}#L${lineInFile}`;
|
||||
return `[${linkText}](${href}){:target="_blank"}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import TypescriptHighlighter from './docgen/TypescriptHighlighter';
|
||||
import MarkdownPrinter from './docgen/MarkdownPrinter';
|
||||
|
||||
export async function generate(targetPath: string) {
|
||||
const rootDir = resolvePath(__dirname, '..');
|
||||
const srcDir = resolvePath(rootDir, '..', 'core-api', 'src');
|
||||
const rootDir = resolvePath(__dirname, '../../..');
|
||||
const srcDir = resolvePath(rootDir, 'packages', 'core-api', 'src');
|
||||
const targetDir = resolvePath(targetPath);
|
||||
const docsDir = resolvePath(targetDir, 'docs');
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function generate(targetPath: string) {
|
||||
),
|
||||
});
|
||||
|
||||
const apiDocGenerator = ApiDocGenerator.fromProgram(program, srcDir);
|
||||
const apiDocGenerator = ApiDocGenerator.fromProgram(program, rootDir);
|
||||
const apiDocs = apis
|
||||
.map(api => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user