Skip to content

Commit 773c3ce

Browse files
committed
docs: expand Configuration with flags/validation & tabbed snippets
1 parent 23d357f commit 773c3ce

3 files changed

Lines changed: 141 additions & 157 deletions

File tree

docs/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "StatikAPI",
33
"description": "Build static JSON endpoints from filesystem modules — like Next.js static export, but for APIs.",
44
"version": "0.4.0",
5-
"lastUpdated": "2025-11-08T00:30:00.000Z",
5+
"lastUpdated": "2025-11-08T00:40:00.000Z",
66
"repo": "https://github.com/zonayedpca/statikapi"
77
}

docs/cli.mdx

Lines changed: 0 additions & 151 deletions
This file was deleted.

docs/config.mdx

Lines changed: 140 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,151 @@
11
# Configuration
22

3-
Most projects work with **zero config**. When you need to customize directories, add `statikapi.config.js` at the project root:
3+
StatikAPI works with **zero config**. When you need to customize paths, create a **`statikapi.config.js`** in your project root.
44

55
```js
66
// statikapi.config.js
77
export default {
8-
srcDir: "src-api",
9-
outDir: "api-out"
8+
srcDir: 'src-api',
9+
outDir: 'api-out',
1010
};
11+
```
12+
13+
> Both directories are **relative to the project root**, must be **non-empty strings**, and **cannot be the same path**. Absolute paths and parent traversal (e.g. `../outside`) are not allowed.
14+
15+
---
16+
17+
## Fields
18+
19+
### `srcDir` (string, default: `"src-api"`)
20+
21+
- Folder that contains your **route modules**.
22+
- Supported extensions: **.js, .mjs, .cjs, .ts, .tsx**.
23+
- Files/folders that **start with `_`** are ignored (e.g. `_private/`).
24+
- `index.js` collapses to the folder route (e.g. `blog/index.js``/blog`).
25+
26+
### `outDir` (string, default: `"api-out"`)
27+
28+
- Folder where **generated JSON** is written.
29+
- Each URL path becomes a folder with **`index.json`** inside.
30+
- A build **manifest** is also written to `api-out/.statikapi/manifest.json` containing route → file mappings and sizes (handy for tooling/preview UIs).
31+
32+
---
33+
34+
## Path resolution & validation
35+
36+
The CLI normalizes and validates configuration:
37+
38+
- Paths are **normalized** with POSIX separators.
39+
- Must be **relative** (no absolute paths).
40+
- Must **not traverse** outside the project (no leading `../`).
41+
- `srcDir` and `outDir` must be **different**.
42+
43+
If validation fails, the CLI throws a helpful **ConfigError** before building.
44+
45+
---
46+
47+
## Override via CLI flags
48+
49+
You can override config values per-invocation. The current CLI reads **`--srcDir`** and **`--outDir`**:
50+
51+
<Tabs group="flags">
52+
<Tab label="pnpm">
53+
54+
```bash
55+
pnpm statikapi build --srcDir api --outDir public/api
56+
```
57+
58+
</Tab>
59+
<Tab label="yarn">
60+
61+
```bash
62+
yarn statikapi build --srcDir api --outDir public/api
63+
```
64+
65+
</Tab>
66+
<Tab label="npm">
67+
68+
```bash
69+
npx statikapi build --srcDir api --outDir public/api
70+
```
71+
72+
</Tab>
73+
</Tabs>
74+
75+
> Heads‑up: older notes might mention `--src` / `--out`. In the current CLI, use **`--srcDir`** and **`--outDir`** to affect configuration.
76+
77+
---
1178

79+
## Dev server notes
80+
81+
When running **`statikapi dev`**:
82+
83+
- Serves your built files and an interactive UI at `/_ui`.
84+
- Writes/updates `api-out/.statikapi/manifest.json` on changes.
85+
- Environment overrides (advanced):
86+
- **`STATIKAPI_UI_DIR`** — serve a custom, prebuilt UI directory (must contain `index.html`).
87+
- **`STATIKAPI_FORCE_DEV=1`** — keep dev running in non‑TTY environments (e.g., CI runners, `concurrently`).
88+
89+
<Tabs group="dev-flags">
90+
<Tab label="pnpm">
91+
92+
```bash
93+
pnpm statikapi dev --port 8788 --srcDir src-api --outDir api-out
94+
```
95+
96+
</Tab>
97+
<Tab label="yarn">
98+
99+
```bash
100+
yarn statikapi dev --port 8788 --srcDir src-api --outDir api-out
101+
```
102+
103+
</Tab>
104+
<Tab label="npm">
105+
106+
```bash
107+
npx statikapi dev --port 8788 --srcDir src-api --outDir api-out
108+
```
109+
110+
</Tab>
111+
</Tabs>
112+
113+
---
114+
115+
## Recipes
116+
117+
### 1) Customizing directories
118+
119+
```js
120+
// statikapi.config.js
121+
export default {
122+
srcDir: 'api', // move sources into /api
123+
outDir: 'public/api', // emit static JSON inside your public/ folder
124+
};
12125
```
13126

14-
You can override these from the CLI with `--src` and `--out`.
127+
### 2) Monorepo (package-local config)
128+
129+
Place `statikapi.config.js` in the **package root** that owns the `srcDir`. The CLI resolves paths **relative to the CWD** (where you run it).
130+
131+
### 3) TypeScript routes
132+
133+
You can freely use **.ts / .tsx** route files. The CLI transpiles on the fly and imports them, then enforces **JSON‑serializable** outputs.
134+
135+
---
136+
137+
## Troubleshooting
138+
139+
- **Config error “must be a relative path”** — remove any leading `/` or drive letter; use relative paths like `src-api`, `api-out`.
140+
- **“cannot traverse outside the project”** — avoid `../` path segments.
141+
- **`srcDir` and `outDir` must differ** — point them at different folders.
142+
- **Dynamic routes not emitting** — ensure the module exports `paths()` that returns **strings** (or arrays of strings for catch‑all). See **Routes** docs.
143+
- **Non‑serializable value** — only plain objects/arrays, finite numbers, strings, booleans, or `null`. No functions, symbols, BigInt, Dates, classes, or cycles.
144+
145+
---
146+
147+
## See also
15148

16-
> **Tip:** The scaffolders also generate `.nvmrc` and `.node-version` for Node 22, and can drop deploy files like `wrangler.toml`, `netlify.toml`, or a GitHub Pages workflow when selected.
149+
- **[CLI → StatikAPI (Core)](./cli/statikapi)** for flags and dev/build usage
150+
- **[Routes](./routes/index)** for file → URL mapping rules
151+
- **[Deployments](./deployments/index)** for hosting static JSON

0 commit comments

Comments
 (0)