Skip to content

Commit ce150ba

Browse files
committed
@webdoc/externalize DocumentedInterface
1 parent 46687ac commit ce150ba

File tree

15 files changed

+312
-72
lines changed

15 files changed

+312
-72
lines changed

packages/eslint-config/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ module.exports = {
1212
globals: {
1313
Atomics: "readonly",
1414
SharedArrayBuffer: "readonly",
15+
$Keys: "readonly",
16+
$Values: "readonly",
17+
$ReadOnly: "readonly",
18+
$Exact: "readonly",
19+
$Diff: "readonly",
20+
$Rest: "readonly",
21+
$PropertyType: "readonly",
22+
$ElementType: "readonly",
23+
$NonMaybeType: "readonly",
24+
$ObjMap: "readonly",
25+
$ObjMapi: "readonly",
26+
$TupleMap: "readonly",
27+
$Call: "readonly",
28+
Class: "readonly",
1529
$Shape: "readonly",
30+
$Exports: "readonly",
31+
$Supertype: "readonly",
32+
$Subtype: "readonly",
1633
$ReadOnlyArray: "readonly",
1734
},
1835
parser: "babel-eslint",

packages/webdoc-cli/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async function main(argv: yargs.Argv) {
126126
const db = exportTaffy(documentTree);
127127

128128
const _path = `${getTemplate(config)}/publish`;
129-
// $FlowFixMe
129+
// $FlowFixMe[unsupported-syntax]
130130
const template = require(_path);
131131

132132
log.info(tag.CLI, "Executing template");

packages/webdoc-default-template/helper/crawl/crawl.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const {crawlReference} = require("./crawl-reference-explorer");
44
const {crawlTutorials} = require("./crawl-tutorials");
5-
const {traverse} = require("@webdoc/model");
5+
const model = require("@webdoc/model");
66
const {linker} = require("../linker");
77

88
// This file crawls the document tree to:
@@ -15,6 +15,10 @@ import type {
1515
DocType,
1616
} from "@webdoc/types";
1717
18+
import type {
19+
LinkTable,
20+
} from "@webdoc/template-library";
21+
1822
import type {ExplorerTarget} from './crawl-reference-explorer';
1923
2024
export type CategorizedDocumentList = {
@@ -63,18 +67,22 @@ function crawl(tree /*: RootDoc */, index /*: string */)/*: CrawlData */ {
6367

6468
module.exports = ({crawl}/*: {crawl: typeof crawl} */);
6569

66-
function buildLinks(tree /*: RootDoc */) /*: void */ {
67-
traverse(tree, (doc) => {
70+
function buildLinks(tree /*: RootDoc */) /*: LinkTable */ {
71+
const linkTable = {};
72+
73+
model.traverse(tree, (doc) => {
6874
if (doc.type === "RootDoc") {
6975
doc.packages.forEach((packageDoc) => {
70-
linker.getURI(packageDoc);
76+
linkTable[packageDoc.path] = linker.getURI(packageDoc);
7177
});
7278

7379
return;
7480
}
7581

76-
linker.getURI(doc);
82+
linkTable[doc.path] = linker.getURI(doc);
7783
});
84+
85+
return linkTable;
7886
}
7987

8088
function buildIndex(
@@ -86,7 +94,7 @@ function buildIndex(
8694
classes: Object.assign(([] /*: any */), {url: classIndexUrl}),
8795
};
8896

89-
traverse(tree, (doc) => {
97+
model.traverse(tree, (doc) => {
9098
switch (doc.type) {
9199
case "ClassDoc":
92100
index.classes.push(doc);

packages/webdoc-default-template/publish.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ exports.publish = async function publish(options /*: PublishOptions */) {
8989
crawlData.tutorials.children[Object.keys(crawlData.tutorials.children)[0]].page,
9090
},
9191
}),
92-
});
92+
}, _.pick(config.template.appBar.items, [
93+
"reference",
94+
"tutorials",
95+
]));
9396
const renderer = new TemplateRenderer(path.join(__dirname, "tmpl"), null, docTree)
9497
.setLayoutTemplate("layout.tmpl")
9598
.installPlugin("linker", linker)
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
declare module "@webdoc/externalize" {
22
import type {RootDoc} from "@webdoc/types";
33

4-
declare export function readDoctree(data: string): RootDoc;
5-
declare export function writeDoctree(doc: RootDoc): string;
4+
declare export type DocumentedInterface = {
5+
version: string;
6+
metadata: {
7+
linker?: "require('@webdoc/template-library').LinkerPlugin" | string;
8+
[string]: string;
9+
};
10+
root: RootDoc;
11+
registry: {
12+
[string]: {
13+
uri: string;
14+
};
15+
};
16+
};
17+
18+
declare export function fromTree(tree: RootDoc): DocumentedInterface;
19+
declare export function read(data: string): DocumentedInterface;
20+
declare export function write(doc: DocumentedInterface): string;
621

722
declare export default {
8-
readDoctree: readDoctree,
9-
writeDoctree: writeDoctree
23+
fromTree,
24+
read,
25+
write,
1026
};
1127
}

packages/webdoc-externalize/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "index.js",
1616
"directories": {
1717
"lib": "lib",
18-
"test": "__tests__"
18+
"unit-test": "mocha ./test/* --require ../../scripts/configureWebdocTesting"
1919
},
2020
"files": [
2121
"lib"
@@ -40,7 +40,8 @@
4040
"dependencies": {
4141
"@babel/core": "^7.9.0",
4242
"@webdoc/model": "^1.3.2",
43-
"@webdoc/types": "^1.3.2"
43+
"@webdoc/types": "^1.3.2",
44+
"lodash": "^4.17.20"
4445
},
4546
"devDependencies": {
4647
"@babel/core": "^7.9.0",
@@ -52,6 +53,7 @@
5253
"@babel/register": "^7.9.0",
5354
"@webdoc/babel-preset": "^1.0.0",
5455
"@webdoc/eslint-config": "^1.0.0",
56+
"@webdoc/parser": "^1.3.2",
5557
"del": "5.1.0",
5658
"eslint": "^6.8.0",
5759
"flow-bin": "^0.130.0",

packages/webdoc-externalize/src/SanitizedDoc.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type {BaseDoc, Param} from "@webdoc/types";
2+
3+
// NOTE: "description" is truncated so it should not be in these lists.
4+
5+
// Props that are copied from all documents, without any restrictions.
6+
export const BASE_PROPS: Array<$Keys<BaseDoc>> = [
7+
"id",
8+
"name",
9+
"brief",
10+
"abstract",
11+
"access",
12+
"authors",
13+
"copyright",
14+
"defaultValue",
15+
"deprecated",
16+
"examples",
17+
"license",
18+
"readonly",
19+
"scope",
20+
"see",
21+
"since",
22+
"type",
23+
"version",
24+
];
25+
26+
// Props that hold document links
27+
export const LINK_PROPS = [
28+
"extends",
29+
"implements",
30+
"mixes",
31+
];
32+
33+
// Props from params to be copied without serialization
34+
export const PARAM_PROPS: Array<$Keys<Param>> = [
35+
"identifier",
36+
"optional",
37+
"default",
38+
"variadic",
39+
];
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
import readDoctree from "./readDoctree";
2-
import writeDoctree from "./writeDoctree";
1+
import write, {fromTree} from "./write";
2+
import read from "./read";
33

44
export default {
5-
readDoctree,
6-
writeDoctree,
5+
fromTree,
6+
readDoctree: read,
7+
read,
8+
writeDoctree: write,
9+
write,
710
};
811

9-
export {readDoctree, writeDoctree};
12+
export {
13+
fromTree,
14+
read,
15+
read as readDoctree,
16+
write,
17+
write as writeDoctree,
18+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// @flow
2+
3+
import type {RootDoc} from "@webdoc/types";
4+
5+
export type SerializedDataType = {
6+
tokens: Array<{
7+
value: string,
8+
kind: "link" | "canonical",
9+
}>,
10+
template: string,
11+
};
12+
13+
export type SerializedParam = {
14+
identifier: string,
15+
dataType?: ?SerializedDataType,
16+
description: string,
17+
optional?: string,
18+
default?: string,
19+
variadic?: boolean,
20+
};
21+
22+
export type SerializedReturn = {
23+
description: string,
24+
dataType: SerializedDataType,
25+
};
26+
27+
export type DocumentedInterface = {
28+
version: string;
29+
metadata: {
30+
linker?: "require('@webdoc/template-library').LinkerPlugin" | string;
31+
[string]: string;
32+
};
33+
root: RootDoc;
34+
registry: {
35+
[string]: {
36+
uri: string;
37+
};
38+
};
39+
};

0 commit comments

Comments
 (0)