Skip to content

Commit b7881f5

Browse files
committed
refactor(docs-gen): modularize extension extractor
1 parent 758c209 commit b7881f5

16 files changed

Lines changed: 410 additions & 304 deletions

infra/docs-gen/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
},
1616
"scripts": {
1717
"build": "node src/generate-docs.mjs && yfm -i ../../tmp/docs-src -o ../../dist/docs",
18-
"extract:names": "node src/extract-extension-names.mjs",
19-
"test": "node --test src/*.test.mjs"
18+
"extract": "node src/extract-extension-data.mjs",
19+
"test": "node --test src/extractor/*.test.mjs"
2020
},
2121
"dependencies": {
2222
"@diplodoc/cli": "5.43.0",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
import {fileURLToPath} from 'node:url';
3+
4+
import {DOCS_GEN_DIR} from './extractor/config.mjs';
5+
import {extractExtensionData} from './extractor/index.mjs';
6+
import {writeExtensionsJson} from './extractor/output.mjs';
7+
8+
export function main() {
9+
writeExtensionsJson(DOCS_GEN_DIR, extractExtensionData());
10+
}
11+
12+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
13+
main();
14+
}

infra/docs-gen/src/extract-extension-names.mjs

Lines changed: 0 additions & 267 deletions
This file was deleted.

infra/docs-gen/src/extract-extension-names.test.mjs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Extension Extractor Layout
2+
3+
This extractor is intentionally modular from the first PR, even though it currently writes only
4+
the `name` field.
5+
6+
- `config.mjs` defines repository paths and extension entry points.
7+
- `blacklist.mjs` owns internal and public extension skip lists.
8+
- `entry-points.mjs` turns configured entry points into extension refs and applies blacklist
9+
filtering.
10+
- `source-files.mjs` reads TypeScript/TSX sources for one extension ref.
11+
- `ast/` contains TypeScript AST primitives and source scanners.
12+
- `fields/` contains one controller per extracted field.
13+
- `field-config.mjs` declares the active output fields and connects each field to its controller.
14+
- `index.mjs` orchestrates ref collection, source reading, field extraction, and record creation.
15+
- `output.mjs` writes extracted records to `tmp/docs-gen/extensions.json`.
16+
17+
To add another field later, add its controller under `fields/`, add any focused AST scanner under
18+
`ast/`, then register the field in `field-config.mjs`.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import ts from 'typescript';
2+
3+
export function parseSource(content, fileName = 'source.tsx') {
4+
return ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
5+
}
6+
7+
export function forEachNode(root, callback) {
8+
const visit = (node) => {
9+
callback(node);
10+
ts.forEachChild(node, visit);
11+
};
12+
13+
visit(root);
14+
}
15+
16+
export function unwrapExpression(expression) {
17+
let current = expression;
18+
19+
while (
20+
ts.isParenthesizedExpression(current) ||
21+
ts.isAsExpression(current) ||
22+
ts.isSatisfiesExpression(current) ||
23+
ts.isNonNullExpression(current) ||
24+
ts.isTypeAssertionExpression(current)
25+
) {
26+
current = current.expression;
27+
}
28+
29+
return current;
30+
}
31+
32+
export function hasExportModifier(node) {
33+
return ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
34+
}
35+
36+
export function unique(values) {
37+
return [...new Set(values.filter(Boolean))];
38+
}

0 commit comments

Comments
 (0)