Skip to content

Commit 4ff050c

Browse files
committed
Update configuration for docserver
1 parent 9c6fea1 commit 4ff050c

File tree

26 files changed

+260
-40
lines changed

26 files changed

+260
-40
lines changed

.github/workflows/pull-request.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ jobs:
2727
- 'lib/**'
2828
modules:
2929
- src/{bundles,tabs}/**
30+
docs:
31+
- docs/**
3032
outputs:
3133
# if the workflow file was modified, then we rerun the entire job
3234
devserver: ${{ steps.filter.outputs.devserver || steps.filter.outputs.workflows }}
33-
modules: ${{ steps.filter.outputs.modules || steps.filter.outputs.workflows }}
35+
# if the devserver needs to be tested bundles and tabs need to bre rebuilt
36+
modules: ${{ steps.filter.outputs.modules || steps.filter.outputs.workflows || steps.filter.outputs.devserver }}
3437
libraries: ${{ steps.filter.outputs.libraries || steps.filter.outputs.workflows }}
38+
docs: ${{ steps.filter.outputs.docs || steps.filter.outputs.workflows }}
3539

3640
test:
3741
name: Verify all tests pass and build success
@@ -70,16 +74,20 @@ jobs:
7074
run: yarn test:libs
7175

7276
- name: Build, lint and run tsc for bundles and tabs
73-
if: needs.paths-filter.outputs.devserver == 'true' || needs.paths-filter.outputs.modules == 'true'
77+
if: needs.paths-filter.outputs.devserver == 'true'
7478
run: yarn workspaces foreach -j 5 -ptW --from "./src/{bundles,tsc}/*" run build --tsc --lint
7579

7680
- name: Test bundles and tabs
7781
if: needs.paths-filter.outputs.modules == 'true'
7882
run: yarn test:modules
7983

8084
- name: Build manifest
81-
if: needs.paths-filter.outputs.devserver == 'true' || needs.paths-filter.outputs.modules == 'true'
85+
if: needs.paths-filter.outputs.devserver == 'true'
8286
run: yarn buildtools build manifest
87+
88+
- name: Build Docs Server
89+
if: needs.paths-filter.outputs.docs == 'true'
90+
run: yarn workspaces foreach -A --include "@sourceacademy/mdoules-docserver" run build
8391

8492
- name: Run tsc for Dev Server
8593
if: needs.paths-filter.outputs.devserver == 'true'

docs/.vitepress/config.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,43 @@ import _package from '../../package.json' with { type: 'json' };
55

66
// https://vitepress.dev/reference/site-config
77
const vitepressOptions: UserConfig = {
8+
base: '/devdocs/',
89
description: 'Developer documentation for the Source Academy modules repository',
10+
ignoreDeadLinks: 'localhostLinks',
11+
outDir: `${import.meta.dirname}/../../build/devdocs`,
912
srcDir: 'src',
1013
title: 'Modules Developer Documentation',
1114
themeConfig: {
1215
// https://vitepress.dev/reference/default-theme-config
1316
nav: [
1417
{ text: 'Home', link: '/' },
15-
{ text: 'Module Development', link: '/modules/' },
18+
{
19+
text: 'Module Development',
20+
items: [
21+
{
22+
text: 'Overview',
23+
link: '/modules/1-getting-started/1-overview'
24+
},
25+
{
26+
text: 'Getting Started',
27+
link: '/modules/1-getting-started/2-overview'
28+
}
29+
]
30+
},
1631
{ text: 'Common Library', link: '/lib' },
17-
{ text: 'Build Tools', link: '/buildtools' }
32+
{
33+
text: 'Dev Tools',
34+
items: [
35+
{
36+
text: 'Build Tools',
37+
link: '/buildtools'
38+
},
39+
{
40+
text: 'Repo Tools',
41+
link: '/repotools'
42+
},
43+
]
44+
}
1845
],
1946
siteTitle: 'SA Modules',
2047
socialLinks: [

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@sourceacademy/modules-devdocs",
2+
"name": "@sourceacademy/modules-docserver",
33
"description": "Developer documentation for the Source Academy modules repository",
44
"private": true,
55
"version": "1.0.0",
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/src/buildtools/1-builders/index.md renamed to docs/src/buildtools/3-builders/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ title: Builders
44
# Builders Overview
55
The following pages contains information on how each asset type is produced
66

7-
- [Bundles and Tabs](./1-modules.md)
7+
- [Bundles and Tabs](./1-modules)
88
- [Documentation](./2-docs)
99
- [Manifest](./3-manifest)

docs/src/buildtools/4-prebuild.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Prebuild Tasks
2+
3+
There are two "prebuild" tasks, linting and type checking that need to be run before any kind of building takes place.
4+
5+
The buildtools call both ESLint and `tsc` in parallel since they are not dependent on each others' outputs.
6+
7+
## Running ESLint from the Command Line
8+
ESLint provides [documentation](https://eslint.org/docs/latest/integrate/nodejs-api) detailing how to use its Node API. Below is the code that does just that:
9+
10+
<<< ../../../lib/buildtools/src/prebuild/lint.ts {ts:line-numbers}
11+
12+
Because the configuration file for the repository is located at the root of the repository, we need to set the `cwd` to the path to the root of the repository when
13+
initializing the `ESLint` instance. This allows ESLint to resolve the configuration correctly.
14+
15+
Linting warnings and errors come in two types, fixable and non-fixable. Fixable errors don't cause a non-zero exit code when ESLint is run with `--fix`, while non-fixable
16+
errors always cause a non-zero exit code.
17+
18+
ESLint provides several [formatters](https://eslint.org/docs/latest/use/formatters/) for processing the results objects it returns. To produce the human readable output that is printed to the command line, the `stylish` formatter
19+
is loaded and used.
20+
21+
## Calling Typescript from Node
22+
23+
Most of the code for running Typescript functionality from Node was taken from [this](https://github.com/Microsoft/TypeScript/issues/6387) Github issue.
24+
25+
<<< ../../../lib/buildtools/src/prebuild/tsc.ts {ts:line-numbers}
26+
27+
The high level overview of this process is as follows:
28+
1. Read the raw text from the `tsconfig.json`
29+
2. Parse the `tsconfig.json` into a JSON object using `ts.parseConfigFileTextToJson`
30+
3. Parse the JSON object into actual compiler options using `ts.parseJsonConfigFileContent`. This also returns an array of file names for parsing.
31+
4. Use `ts.createProgram` to get the preliminary program for type checking only.
32+
5. Call `typecheckProgram.emit()` to produce the typechecking results.
33+
6. Combine the results with `ts.getPreEmitDiagonstics`.
34+
7. If there were no typechecking errors and the `tsconfig.json` did not specify <nobr><code>noEmit: true</code></nobr>, use `ts.createProgram` again with the typecheck program to perform compilation and declaration file emission excluding test files.
35+
8. Format the diagnostic objects using `ts.formatDiagnosticsWithColorAndContext`
36+
37+
### Reading and Parsing `tsconfig.json`
38+
The first three steps in the process involve reading the raw text from the `tsconfig.json` and then parsing it. At the end of it, `ts.parseJsonConfigFileContent` resolves all the inherited options and produces the compiler options
39+
in use, as well as the file paths to the files that are to be processed.
40+
41+
### Type Checking
42+
The first time `ts.createProgram` is called, it is called with every single file as returned from `ts.parseJsonConfigFileContent`. However, it is called with `noEmit: true`. This prevents any Javascript and Typescript declaration files from being written.
43+
This is important because we want test files to be type checked, but we don't want them to be compiled into Javascript and exported with the rest of the code. If they were included and the `tsconfig` was configured to produce outputs, the test files would end
44+
up being written to the `outDir`. `typecheckProgram.emit` is called to perform the type checking.
45+
46+
If there are no errors and the `tsconfig` was configured to produce outputs, `ts.createProgram` is called again. This time, test files are filtered out. `ts.createProgram` has a parameter for passing in the previous program object, allowing it to reuse
47+
an existing program so it doesn't have to reinitialize the entire object again. `program.emit` is called to produce any compiled Javascript and Typescript declaration files.

0 commit comments

Comments
 (0)