Skip to content

Commit 9188068

Browse files
committed
Add markdown tree plugin
1 parent 855abae commit 9188068

File tree

30 files changed

+1305
-429
lines changed

30 files changed

+1305
-429
lines changed

docs/.vitepress/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Vitepress config
2+
import { directoryTreePlugin } from '@sourceacademy/markdown-plugin-directory-tree';
23
import { defineConfig, type UserConfig } from 'vitepress';
34
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons';
45
import { withMermaid } from 'vitepress-plugin-mermaid';
@@ -16,6 +17,10 @@ const vitepressOptions: UserConfig = {
1617
markdown: {
1718
config(md) {
1819
md.use(groupIconMdPlugin);
20+
md.use(directoryTreePlugin);
21+
},
22+
languageAlias: {
23+
dirtree: 'yml'
1924
}
2025
},
2126
outDir: `${import.meta.dirname}/../../build/devdocs`,
@@ -63,11 +68,11 @@ const vitepressOptions: UserConfig = {
6368
items: [
6469
{
6570
text: 'Build Tools',
66-
link: '/buildtools'
71+
link: '/buildtools/'
6772
},
6873
{
6974
text: 'Repo Tools',
70-
link: '/repotools'
75+
link: '/repotools/'
7176
},
7277
]
7378
}

docs/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"vitepress-plugin-group-icons": "^1.6.1",
1818
"vitepress-plugin-mermaid": "^2.0.17",
1919
"vitepress-sidebar": "^1.31.1"
20+
},
21+
"devDependencies": {
22+
"@sourceacademy/markdown-plugin-directory-tree": "workspace:^"
2023
}
2124
}

docs/src/buildtools/5-builders/2-docs.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@
33
There are two types of documentation used by Source, which are the jsons and the HTML documentation. Both are built using the [`typedoc`](https://typedoc.org) tool. By reading comments and type annotations, `typedoc` is able to generate both human readable documentation and documentation in the form of JSON.
44

55
## Typedoc Overview
6-
Typedoc has been configured to use the [`package` entry point strategy](https://typedoc.org/documents/Options.Input.html#packages). To make sure that each bundle's documentation is generated with the proper name, each bundle's `tsconfig.json` contains
7-
a `typedocOptions` section which minimally, has the name of the bundle. Using the `package` strategy allows each bundle to customize its own `typedoc` options this way.
6+
Documentation generation is a two-step process:
87

9-
Typedoc is initialized with the following options:
8+
Firstly, the `buildtools build docs` is called on each bundle. This produces two JSON files:
109

11-
<<< ../../../../lib/buildtools/src/build/docs/docsUtils.ts#commonOpts
10+
1. `build/jsons/[bundle_name].json`, which is the JSON documentation used by `js-slang` and the frontend
11+
2. `docs.json`, which is JSON documentation format used by `typedoc` to generate the HTML documentation later
1212

13-
The package options are applied to each bundle, while the common options are used overall.
14-
15-
Initializing `typedoc` returns an [`Application`](https://typedoc.org/api/classes/Application.html) object, which can then be used to generate a [`ProjectReflection`](https://typedoc.org/api/classes/Models.ProjectReflection.html). The reflection always contains more reflection models
16-
as its children, each of which represents a different bundle.
13+
Second, `buildtools manifest` is called, which then takes the `docs.json` files from each bundle and uses the [`merge` entry point strategy](https://typedoc.org/documents/Options.Input.html#merge) to create the HTML
14+
documentation
1715

1816
> [!NOTE]
1917
> Since type checking is supposed to be performed by `tsc`, `skipErrorChecking` has been set to true. This means that if there are type errors in the source files being processed,
2018
> `typedoc` simply returns `undefined` when `Application.convert` is called.
2119
20+
This allows each bundle to have its own Typedoc option set.
21+
2222
## HTML Generation
2323
It is not possible to generate the HTML documentation on a per-bundle basis. Thus, when HTML documentation needs to be regenerated, the source files of every single bundle needs to be processed.
2424

2525
## JSON Generation
2626
`typedoc` represents each bundle as a [`DeclarationReflection`](https://typedoc.org/api/classes/Models.DeclarationReflection.html) internally. Each of these `DeclarationReflection`s contains an array of "children" elements which
2727
represents that bundle's exports. Each of these elements is parsed by various parsers to produce the desired documentation object, which is then written to disk after converted into a JSON string.
28-
29-
It is possible to generate the JSON documentation of each bundle separately. Hence, the JSON builder doesn't initialize `typedoc`, leaving the caller to choose between initializing `typedoc` for all bundles at once
30-
or just for that single bundle.

docs/src/buildtools/index.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,42 @@ The build tools are comprised of several sections:
2020
- Code for the template command
2121

2222
## Structure of the Build Tools package
23-
```txt
24-
uildtools
25-
├── bin
26-
│ ├── templates // Actual template files, retrieved at runtime
27-
│ ├── docsreadme.md // Docs HTML readme, retrieved at runtime
28-
│ └── index.js // The compiled buildtools
29-
├── src
30-
│ ├── ___test_mocks__ // Contains a set of mock bundles and tabs for testing
31-
│ ├── build
32-
│ │ ├── docs // Docs Builders
33-
│ │ ├── modules
34-
│ │ │ ├── bundle // Bundle Builder
35-
│ │ │ ├── tab // Tab Builder
36-
│ │ │ └── manifest.schema.json // Schema used to validate bundle manifests
37-
│ │ └── manifest // Code related to manipulating manifests
38-
│ ├── commands // Code where command handlers are defined
39-
│ ├── prebuild // Code for running ESLint and tsc
40-
│ ├── templates // Code for the template commands
41-
│ └── testing.ts // Code for running Vitest from Node
42-
└── workspacer.py // Python code for updating JSON files across bundles and tabs
23+
```dirtree
24+
path: ../../../lib/buildtools/
25+
children:
26+
- name: bin
27+
children:
28+
- name: templates
29+
comment: Actual template files, retrieved at runtime
30+
- name: docsreadme.md
31+
comment: Docs HTML readme, retrieved at runtime
32+
- name: index.js
33+
comment: The compiled and bundled buildtools
34+
- name: src
35+
children:
36+
- name: __tests_mocks__
37+
comment: Contains a set of mock bundles and tabs for testing
38+
- name: build
39+
children:
40+
- name: docs
41+
comment: Builders for HTML and JSON documentation
42+
- name: modules
43+
comment: Builders for bundles and tabs
44+
children:
45+
- name: manifest.schema.json
46+
comment: Schema used to validate bundle manifests
47+
- name: all.ts
48+
comment: Combined builder for a specific bundle or tab
49+
- name: manifest.ts
50+
comment: Code for working with bundle manifests and bundle/tab resolution
51+
- name: commands
52+
comment: Code where command handlers are defined
53+
- name: prebuild
54+
comment: Code for running ESLint and tsc, both separately and in parallel
55+
- name: templates
56+
comment: Code for template commands
57+
- name: testing.ts
58+
comment: Code for running Vitest from NodeJS
59+
- name: workspacer.py
60+
comment: Python code for updating JSON files across bundles and tabs
4361
```

docs/src/modules/2-bundle/1-overview/1-overview.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ For example, the `binary_tree` module may want to provide an abstraction for Sou
77
## Bundle Directory Structure Overview
88

99
The typical bundle structure for a bundle is shown below. Each section will have its own explanation.
10-
```txt
11-
bundle_name // Name of the root folder is the name of the bundle
12-
├── src
13-
│ ├── __tests__ // Folder containing unit tests
14-
│ │ └── index.ts // File containing unit tests
15-
│ ├── index.ts // Entry Point
16-
│ ├── functions.ts // Example file
17-
│ └── .... // Other files your bundle may use
18-
├── package.json // Package Manifest
19-
├── manifest.json // Bundle Manifest
20-
└── tsconfig.json // Typescript Configuration
10+
```dirtree
11+
name: bundle_name
12+
children:
13+
- name: src
14+
children:
15+
- name: __tests__
16+
comment: Folder containing unit tests
17+
- name: index.ts
18+
comment: Entry point
19+
- name: functions.ts
20+
comment: Example file
21+
- name: package.json
22+
comment: Package Manifest; Used by Yarn
23+
- name: manifest.json
24+
comment: Bundle Manifest
25+
- name: tsconfig.json
26+
comment: Typescript Configuration
2127
```
2228

2329
> [!NOTE]

docs/src/modules/3-tabs/1-overview.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,44 @@ be used with the [frontend](https://github.com/source-academy/frontend).
55
## Tab Directory Structure Overview
66
The typical tab directory structure is shown below.
77

8-
```txt
9-
TabName
10-
├── index.tsx
11-
├── tsconfig.json
12-
└── package.json
8+
```dirtree
9+
name: TabName
10+
children:
11+
- index.tsx
12+
- tsconfig.json
13+
- package.json
1314
```
1415

1516
Alternatively, should you wish to use a `src` folder:
16-
```txt
17-
TabName
18-
├── src
19-
│ ├── index.tsx
20-
│ ├── component.tsx
21-
│ └── ...
22-
├── tsconfig.json
23-
└── package.json
17+
```dirtree
18+
name: TabName
19+
children:
20+
- name: src
21+
children:
22+
- index.tsx
23+
- component.tsx
24+
- tsconfig.json
25+
- package.json
2426
```
2527
> [!NOTE]
2628
> The name of the root folder will be the name of the tab
2729
2830
Tabs also support testing (using both `.ts` and `.tsx` extensions):
29-
```txt
30-
TabName
31-
├── src
32-
│ ├── __tests__
33-
│ │ └── test.tsx
34-
│ ├── index.tsx
35-
│ ├── component.tsx
36-
│ └── ...
37-
├── tsconfig.json
38-
└── package.json
31+
```dirtree
32+
name: TabName
33+
children:
34+
- name: src
35+
children:
36+
- name: __tests__
37+
children:
38+
- name: test.tsx
39+
comment: You can use a tsx file
40+
- name: test2.ts
41+
comment: Or a regular ts file
42+
- index.tsx
43+
- component.tsx
44+
- tsconfig.json
45+
- package.json
3946
```
4047

4148
The name of the tab is what you should refer to the tab as in its parent bundle's manifest:

docs/src/repotools/docserver/docserver.md renamed to docs/src/repotools/docserver/1-overview.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
title: Overview
3+
---
14
# Developer Documentation Server
25

36
Originally most of the developer documentation was contained within the Github repository's wiki. However, as the documentation became more comprehensive in scope and complex in design,
@@ -13,26 +16,32 @@ some folder have contents that are labelled `1-something`, `2-something` etc. Ea
1316

1417
Folders produce item groups, the name of which can be customized using an `index.md` file within that folder.
1518

16-
```txt
17-
bundles
18-
├── index.md
19-
├── 1-getting-started
20-
│ ├── 1-overview.md
21-
│ ├── 2-start.md
22-
│ ├── 3.cheat.md
23-
│ ├── 4-faq.md
24-
│ └── index.md
25-
└── 2-bundle
26-
├── 1-overview
27-
│ └── 1-overview.md
28-
├── 2-creating
29-
│ └── 2-creating.md
30-
├── 3-editing.md
31-
├── 4-documentation
32-
│ └── 4-documentation.md
33-
├── 5-type_map.md
34-
├── 6-compiling.md
35-
└── index.md
19+
```dirtree
20+
name: bundles
21+
children:
22+
- index.md
23+
- name: 1-getting-started
24+
children:
25+
- 1-overview.md
26+
- 2-start.md
27+
- 3-cheat.md
28+
- 4-faq.md
29+
- index.md
30+
- name: 2-bundle
31+
children:
32+
- name: 1-overview
33+
children:
34+
- 1-overview.md
35+
- name: 2-creating.md
36+
children:
37+
- 2-creating.md
38+
- 3-editing.md
39+
- name: 4-documentation
40+
children:
41+
- 4-documentation.md
42+
- 5-type_map.md
43+
- 6-compiling.md
44+
- index.md
3645
```
3746

3847
The above file structure produces the menu below:
@@ -41,7 +50,7 @@ The above file structure produces the menu below:
4150
Each item takes its title value from either the frontmatter (if available) or the first heading of each page.
4251

4352
`index.md` files are only used to title the menus, they are not intended for navigation, though are navigable to if the user enters the address manually, so it is still recommended to keep some basic
44-
documentation in those pages or create rewrites so that users are automatically redirected away from those pages. Here are the contents of `2-bundle/index.md`:
53+
documentation in those pages or create rewrites so that users are automatically redirected away from those pages. Here are the contents of <nobr><code>2-bundle/index.md</code></nobr>:
4554

4655
<<< ../../modules/2-bundle/index.md
4756

@@ -78,4 +87,4 @@ this
7887
└── tree
7988
└── diagram
8089
```
81-
were generated from [this website](https://tree.nathanfriend.com/)
90+
are generated via their own markdown plugin, the details of which can be found [here](./2-dirtree).

0 commit comments

Comments
 (0)