Skip to content

Commit 02963c7

Browse files
author
hariria
committed
[dev-docs] Add prebuild to check for .env vars
1 parent 963d3c1 commit 02963c7

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

README.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
- [Installation](#installation)
55
- [Requirements](#requirements)
66
- [Clone the Developer docs repo](#clone-the-developer-docs-repo)
7-
- [Build and serve the docs locally](#build-and-serve-the-docs-locally)
7+
- [Install deps](#install-deps)
8+
- [Develop on Nextra (New)](#develop-on-nextra-new)
9+
- [Develop on Docusaurus (Legacy)](#develop-on-docusaurus-legacy)
810
- [Debugging](#debugging)
911
- [Regenerating contributors](#regenerating-contributors)
1012

@@ -41,45 +43,66 @@ curl -fsSL https://get.pnpm.io/install.sh | sh -
4143
git clone https://github.com/aptos-labs/developer-docs.git
4244
```
4345

44-
## Build and serve the docs locally
45-
46-
1. Run `pnpm`.
46+
## Install deps
4747

4848
```sh
4949
pnpm install
5050
```
5151

52-
2. Build the repository
52+
## Develop on Nextra (New)
53+
54+
> Note: PLEASE SEE `apps/nextra/README.md` for more details!
55+
56+
57+
0. Setup environment
58+
59+
Ensure you have configured your `.env` properly under `apps/nextra/.env`. There is a `.env.example` there that you can duplicate and rename to `.env` for simplicity.
60+
61+
To ensure you have the right setup, you can run
5362

5463
```sh
55-
pnpm build
64+
pnpm prebuild
5665
```
5766

58-
3. Navigate to the correct subdirectory
67+
1. Build Nextra
5968

60-
**Docusaurus**
61-
```sh
62-
cd apps/docusaurus
69+
```bash
70+
npx turbo run build --filter={apps/nextra}...
6371
```
6472

65-
**Nextra**
73+
This will build `apps/nextra` and all local packages it depends on.
74+
75+
2. Navigate to the correct subdirectory
76+
6677
```sh
6778
cd apps/nextra
6879
```
6980

70-
4. Run the development server
81+
3. Run development server
7182

72-
**Docusaurus**
7383
```sh
74-
pnpm serve
84+
pnpm dev
7585
```
7686

77-
**Nextra**
87+
## Develop on Docusaurus (Legacy)
88+
89+
1. Navigate to the correct subdirectory
90+
7891
```sh
79-
pnpm dev
92+
cd apps/docusaurus
8093
```
8194

82-
See the README.md in each respective app for more information
95+
2. Build the repository
96+
97+
```sh
98+
pnpm build
99+
```
100+
101+
3. Navigate to the correct subdirectory
102+
103+
```sh
104+
pnpm serve
105+
```
83106

84107
## Debugging
85108

apps/nextra/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_ORIGIN="http://localhost:3030"

apps/nextra/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the local dev server:
1010
1. From the root of the `developer-docs` directory, run:
1111

1212
```bash filename="Terminal"
13-
pnpm i && pnpm build
13+
pnpm i
1414
```
1515

1616
2. Navigate back to `nextra`
@@ -21,6 +21,9 @@ Create a `.env` file in the root of `nextra` with the following
2121
NEXT_PUBLIC_ORIGIN="http://localhost:3030"
2222
```
2323

24+
Note: There is an example at `apps/nextra/.env.example` that
25+
you can duplicate and rename the duplicate to `.env`.
26+
2427
3. Then run
2528

2629
```bash filename="Terminal"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "developer-docs",
33
"private": true,
44
"scripts": {
5+
"prebuild": "node prebuild.js",
56
"build": "turbo build",
67
"dev": "turbo dev",
78
"lint": "turbo lint",

prebuild.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const ENV_FILE = path.join(__dirname, "apps/nextra/.env");
5+
6+
try {
7+
if (!fs.existsSync(ENV_FILE)) {
8+
console.error("Error: .env file does not exist under apps/nextra.");
9+
process.exit(1);
10+
}
11+
12+
const envFileContent = fs.readFileSync(ENV_FILE, "utf8");
13+
if (!envFileContent.includes("NEXT_PUBLIC_ORIGIN=")) {
14+
console.error("Error: NEXT_PUBLIC_ORIGIN is not defined in the .env file.");
15+
process.exit(1);
16+
}
17+
18+
console.log("Pre-build check passed.");
19+
} catch (err) {
20+
console.error("An error occurred during the pre-build check:", err);
21+
process.exit(1);
22+
}

0 commit comments

Comments
 (0)