forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeno-types.ts
More file actions
49 lines (38 loc) · 1.24 KB
/
Copy pathdeno-types.ts
File metadata and controls
49 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Project, ts } from "ts-morph";
import $ from "dax";
await Deno.mkdir("types", { recursive: true });
const tempFile = await Deno.makeTempFile();
await $`deno types`.stdout($.path(tempFile));
const project = new Project();
const file = project.addSourceFileAtPath(tempFile);
const modules: Record<string, string> = {
"deno": "",
};
const UNSTABLE_PREFIX = "**UNSTABLE**: New API, yet to be vetted.";
for (const jsdoc of file.getDescendantsOfKind(ts.SyntaxKind.JSDoc)) {
const text = jsdoc.getText();
if (text?.includes?.(UNSTABLE_PREFIX)) {
jsdoc.replaceWithText(text.replace(UNSTABLE_PREFIX, ""));
}
}
for (
const denoNs of file.getDescendantsOfKind(ts.SyntaxKind.ModuleDeclaration)
.filter((descendant) => descendant.getName() === "Deno")
) {
const denoNsJSDoc = denoNs.getFirstChildIfKind(ts.SyntaxKind.JSDoc);
if (denoNsJSDoc) {
denoNsJSDoc.addTag({
tagName: "module",
});
modules["deno"] = denoNsJSDoc.getText() + "\n\n " + modules["deno"];
denoNsJSDoc.remove();
}
modules["deno"] += denoNs.getFullText();
denoNs.remove();
}
modules["web"] = file.getFullText();
await Promise.all(
Object.entries(modules).map(([name, content]) =>
Deno.writeTextFile(`types/${name}.d.ts`, content)
),
);