Skip to content

Commit d4bc685

Browse files
committed
Add a vitepress documentation server for the repository
1 parent 5e962c8 commit d4bc685

File tree

16 files changed

+872
-0
lines changed

16 files changed

+872
-0
lines changed

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vitepress/cache
2+
.vitepress/dist

docs/.vitepress/config.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { defineConfig } from 'vitepress';
2+
import _package from '../../package.json' with { type: 'json' };
3+
4+
// https://vitepress.dev/reference/site-config
5+
export default defineConfig({
6+
title: 'Modules Developer Documentation',
7+
description: 'Developer documentation for the Source Academy modules repository',
8+
srcDir: 'src',
9+
themeConfig: {
10+
// https://vitepress.dev/reference/default-theme-config
11+
nav: [
12+
{ text: 'Home', link: '/' },
13+
{ text: 'Develop a Module', link: '/modules' }
14+
],
15+
16+
sidebar: {
17+
'/': [{
18+
text: 'Examples',
19+
items: [
20+
{ text: 'Markdown Examples', link: '/markdown-examples' },
21+
{ text: 'Runtime API Examples', link: '/api-examples' }
22+
]
23+
}],
24+
'/modules/': [
25+
{
26+
text: 'Developing Modules',
27+
items: [
28+
{
29+
text: 'Modules Overview',
30+
link: '/modules'
31+
},
32+
{
33+
text: 'Writing Tests',
34+
link: '/modules/testing'
35+
},
36+
{
37+
text: 'Linting',
38+
link: '/modules/linting'
39+
},
40+
{
41+
text: 'Module Contexts',
42+
link: '/modules/context'
43+
},
44+
{
45+
text: 'Bundles',
46+
items: [
47+
{
48+
text: 'Bundles Overview',
49+
link: '/modules/bundle'
50+
},
51+
{
52+
text: 'Creating a Bundle',
53+
link: '/modules/bundle/creating'
54+
},
55+
{
56+
text: 'Editing a Bundle',
57+
link: '/modules/bundle/editing'
58+
},
59+
{
60+
text: 'Compiling a Bundle',
61+
link: '/modules/bundle/compiling'
62+
}
63+
]
64+
},
65+
{
66+
text: 'Tabs',
67+
items: [{
68+
text:' Tabs Overview',
69+
link: '/modules/tabs/overview'
70+
}]
71+
}
72+
]
73+
},
74+
]
75+
},
76+
77+
socialLinks: [
78+
{ icon: 'github', link: _package.repository }
79+
]
80+
}
81+
});

docs/.vitepress/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"module": "nodenext",
4+
"moduleResolution": "nodenext",
5+
"noEmit": true,
6+
"resolveJsonModule": true,
7+
"verbatimModuleSyntax": true
8+
},
9+
"include": ["./config.ts"]
10+
}

docs/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@sourceacademy/modules-devdocs",
3+
"description": "Developer documentation for the Source Academy modules repository",
4+
"private": true,
5+
"version": "1.0.0",
6+
"type": "module",
7+
"devDependencies": {
8+
"vitepress": "^1.6.3"
9+
},
10+
"scripts": {
11+
"docs:dev": "vitepress dev .",
12+
"docs:build": "vitepress build .",
13+
"docs:preview": "vitepress preview ."
14+
}
15+
}

docs/src/getting-started.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Setting up the development environment
2+
To begin developing using this repository, follow the following steps to setup your local development environment.
3+
4+
## 1. Download and Install NodeJS
5+
A stable version of [NodeJS](https://nodejs.org/en/) is required on your local development machine. Select a version of NodeJS that is compatible with the version that the repository uses (found in the `.node-version` file). Typically, the LTS release will suffice.
6+
7+
You can use [nvm](https://github.com/creationix/nvm#installation) _(macOS/Linux)_ or [nvm-windows](https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows) _(windows)_ to switch Node versions between different projects.
8+
9+
## 2. Clone this Repository
10+
Clone the modules repository to your local machine using `git` or your tool of choice.
11+
12+
## 3. Install Yarn
13+
The modules repository pipelines rely on the [Yarn](https://yarnpkg.com/) package manager. To install the Yarn package manager through [NPM](https://www.npmjs.com/), you can run the following command in the development directory: `npm install yarn`
14+
15+
> [!TIP]
16+
> If you already have Yarn installed, you might find that you have a different version installed than the one used by the repository. Use the `yarn set version` command to install the correct version.
17+
18+
> [!TIP]
19+
> If you are on MacOS, you may find that the version of Yarn used by your terminal is not correct, even after running `yarn set version`. You may have to run the command every time you start a new terminal instance.
20+
21+
At this point it is not necessary to run `yarn install` yet to install dependencies. Depending on what you are doing, there are different methods for installing dependencies.
22+
23+
## Next Steps
24+
Once your environment has been setup, refer to the following guides:
25+
* [Creating a new bundle](./bundle/creating)
26+
* [Creating a new tab](./creating/tab)
27+
* [Modifying an existing bundle](./idk)
28+
29+
## Development with local versions of `js-slang`
30+
31+
If you require a custom version of `js-slang` follow the instructions [here](https://github.com/source-academy/js-slang#using-your-js-slang-in-your-local-source-academy).

docs/src/index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# https://vitepress.dev/reference/default-theme-home-page
3+
layout: home
4+
5+
hero:
6+
name: "Modules Developer Documentation"
7+
text: "Developer documentation for the Source Academy modules repository"
8+
tagline: My great project tagline
9+
actions:
10+
- theme: brand
11+
text: Get Started
12+
link: /getting-started
13+
- theme: brand
14+
text: Create a tab or bundle
15+
link: /creating
16+
- theme: brand
17+
text: Repo Overview
18+
- theme: alt
19+
text: Developer Instructions
20+
link: /api-examples
21+
22+
features:
23+
- title: Creating a bundle
24+
details: Instructions for creating a bundle
25+
26+
- title: Creating a tab
27+
details: Instructions for creating a tab
28+
29+
- title: The Development Server
30+
details: How and why to use the development server
31+
32+
- title: Build Tools
33+
details: Details behind the tooling that compiles Source Academy modules
34+
---
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Compiling a Bundle
2+
This page contains information on compiling bundles, both for consumption by `js-slang` as well as other bundles.
3+
4+
> [!WARNING]
5+
> The build tools automatically ignore files under a `__tests__` directory. Such files are considered
6+
> test files and will not be included in the compiled output.
7+
8+
## For `js-slang`
9+
In its raw ESM format, the bundle is unsuitable for use with `js-slang`. It is thus necessary to compile your written Typescript into the format needed by `js-slang`.
10+
11+
Run the following command from within your bundle directory.
12+
13+
```sh
14+
yarn build
15+
```
16+
17+
Note that running this command will **NOT** perform typechecking. If you wish to perform typechecking, use the following command:
18+
```sh
19+
yarn build --tsc
20+
```
21+
22+
This will run the TypeScript compiler before compiling your bundle. If there are any type errors, it will be displayed in the command line
23+
and your bundle will not be compiled.
24+
25+
The output for your bundle will be placed at `/build/bundles/[your_bundle_name].js`.
26+
27+
## For Other Bundles
28+
A Source Bundle may use another Source Bundle as a dependency. As an example, the `plotly` bundle relies on the `curve` bundle:
29+
```ts {2,3}
30+
// plotly/src/curve_functions.ts
31+
import { x_of, y_of, z_of, r_of, g_of, b_of } from '@sourceacademy/bundle-curve';
32+
import type { Curve } from '@sourceacademy/bundle-curve/curves_webgl';
33+
import Plotly, { type Data, type Layout } from 'plotly.js-dist';
34+
import { CurvePlot } from './plotly';
35+
```
36+
37+
If you intend for your bundle to be consumed from other bundles, do the following:
38+
39+
### 1. Ensure that your `tsconfig.json` is properly configured
40+
```json
41+
{
42+
"compilerOptions" {
43+
"outDir": "./dist", // Make sure outDir is specified
44+
"noEmit": false, // noEmit needs to be false
45+
"declaration": true // declaration needs to be true
46+
}
47+
}
48+
```
49+
50+
### 2. Ensure that your `package.json` points to the correct exports
51+
```json
52+
{
53+
"name": "@sourceacademy/bundle-curve",
54+
"type": "module",
55+
"exports": {
56+
".": "./dist/index.js",
57+
"./*": "./dist/*.js"
58+
},
59+
"scripts": {
60+
"prepare": "yarn buildtools tsc"
61+
}
62+
}
63+
```
64+
Refer to [this page](https://nodejs.org/api/packages.html#package-entry-points) for more information on how to configure your package exports.
65+
66+
The `prepare` script is necessary as the bundle will need to be built using `tsc` during installation.
67+
68+
### 3. Run `tsc`
69+
If necessary, run `yarn tsc` to produce Javascript and Typescript declaration files.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Creating a Bundle
2+
This page contains instructions for creating a new bundle from scratch. If you are looking to edit an existing bundle refer to [these](../editing) instructions instead.
3+
## Running the Template Command
4+
> [!TIP]
5+
> If necessary, before running the `template` command, you can run
6+
> ```sh
7+
> yarn workspaces focus @sourceacademy/modules
8+
> ```
9+
> to install **only** the dependencies required for your creating nbundle.
10+
11+
To create a new bundle, use the `template` command.
12+
13+
```sh
14+
yarn template
15+
```
16+
This will start an interactive prompt that will help you through the process of creating a bundle. Enter `module` to create a new bundle.
17+
18+
```
19+
What would you like to create? (module/tab)
20+
module
21+
```
22+
23+
Then enter the name of your new bundle. It must be in `snake_case`.
24+
```
25+
What would you like to create? (module/tab)
26+
module
27+
28+
What is the name of your new module? (eg. binary_tree)
29+
new_bundle
30+
```
31+
32+
This will create a folder under `src/bundles/new_bundle` with all the necessary files for creating your bundle:
33+
34+
![](image.png)
35+
36+
From there you can edit your bundle as necessary
37+
38+
When you are ready to compile you can refer to [this](../editing/compiling) page.
8.84 KB
Loading

docs/src/modules/bundle/editing.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Editing an Existing Bundle
2+
This page contains instructions for modifying an existing bundle. If you are creating a new bundle from scratch, refer to [these](../creating/) instructions instead.
3+
4+
## Installing Dependencies
5+
To install **only** the dependencies required by the bundle you are modifying, use the command below:
6+
7+
```sh
8+
yarn workspaces focus @sourceacademy/bundle-[desired bundle]
9+
```
10+
11+
## Adding Dependencies
12+
Your bundle may need other Javascript packages. To add a dependency to your bundle, run the command below:
13+
```sh
14+
yarn add [dependency]
15+
```
16+
17+
If the dependency does not need to be present during runtime, then use:
18+
```sh
19+
yarn add --dev [dependency]
20+
```
21+
This adds the dependency to `devDependencies` instead.
22+
23+
> [!WARNING]
24+
> You should only run this command in the directory of your bundle. Otherwise, the dependency will end up being added to the
25+
> root repository.
26+
27+
> [!NOTE]
28+
> There are certain dependencies that are common to all bundles (like `react`). When adding such a dependency, remember to add the exact version
29+
> specified in the root repository `package.json`:
30+
> ```sh
31+
> yarn add react@^18.3.1
32+
> ```
33+
> You can also use the command `yarn constraints` to check if you have incorrectly specified the version of a dependency.
34+
35+
> [!NOTE]
36+
> When adding dependencies that originate from the repository (e.g `@sourceacademy/modules-lib`), use `workspace:^` as the given version:
37+
> ```sh
38+
> yarn add @sourceacademy/modules-lib@workspace:^
39+
> ```

0 commit comments

Comments
 (0)