Skip to content

Commit 0bf232b

Browse files
committed
fix: move and add public file inside the npm package
1 parent ad350b2 commit 0bf232b

15 files changed

+196
-35
lines changed

README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# @workadventure/map-starter-kit-core
2+
3+
Core app, HTML pages and static assets for the **WorkAdventure Map Starter Kit**. Update this package to get new UI and server features without touching your maps or config.
4+
5+
## Features
6+
7+
- **Web UI** – Step-by-step wizard (Git, hosting, steps, validation) for setting up and validating your map project
8+
- **Map listing** – Discovers `.tmj` maps on disk with properties (name, description, image, copyright, size, last modified)
9+
- **Uploader** – Configure and run map uploads to [map-storage](https://github.com/workadventure/map-storage); list maps from map-storage for self-hosted flows
10+
- **Static assets** – Serves public assets, tilesets, and compiled JS; transforms and serves TypeScript under `/src` (esbuild) for browser scripts
11+
- **Express app** – CORS, JSON body parsing, cache headers; can be mounted in another app or run standalone via Vite
12+
13+
## Installation
14+
15+
```bash
16+
npm install @workadventure/map-starter-kit-core
17+
```
18+
19+
**Peer / consumer:** The built server expects `express` to be available at runtime. For TypeScript consumers, `@types/express` is used for the exported `Application` type.
20+
21+
## Usage
22+
23+
### As a dependency (programmatic)
24+
25+
Use the built Express app in your own server:
26+
27+
```ts
28+
import core from "@workadventure/map-starter-kit-core/dist/server.js";
29+
30+
const app = core.default; // or core.viteNodeApp
31+
32+
// Mount or start your server
33+
app.listen(3000, () => console.log("Listening on 3000"));
34+
```
35+
36+
Types are provided: `core` is typed as `{ default: Application; viteNodeApp: Application }` (see `types/server.d.ts`).
37+
38+
### Development server (standalone)
39+
40+
From the **map-starter-kit** repo (or a project that uses this package as the core):
41+
42+
```bash
43+
npm run dev
44+
```
45+
46+
Runs the Vite dev server with vite-plugin-node (Express). Opens the app at the configured host (e.g. `http://localhost:5173/`).
47+
48+
### Build for production
49+
50+
```bash
51+
npm run build
52+
```
53+
54+
- Runs `tsc` (type-check only; `noEmit: true` in tsconfig)
55+
- Builds the server bundle with Vite into `dist/server.js`
56+
- Copies `types/server.d.ts` to `dist/server.d.ts` for published types
57+
58+
## Project structure
59+
60+
```
61+
map-starter-kit-core/
62+
├── src/
63+
│ ├── server.ts # Express app entry (CORS, static, routes)
64+
│ ├── getCoreRoot.ts # Resolve core package root (cwd vs package dir)
65+
│ ├── controllers/
66+
│ │ ├── FrontController.ts # HTML pages (Mustache): /, step1-git, step2-hosting, step3-*, step4-*
67+
│ │ ├── MapController.ts # /maps/list – list .tmj maps with properties
68+
│ │ └── UploaderController.ts # /uploader/* – configure, status, maps-storage-list, upload
69+
│ └── views/ # Mustache HTML templates
70+
│ ├── index.html
71+
│ ├── step1-git.html … step4-validated-selfhosted.html
72+
├── public/ # Static assets (images, styles, etc.)
73+
├── types/
74+
│ └── server.d.ts # Module declaration for dist/server.js (copied to dist on build)
75+
├── dist/ # Build output (server.js, server.d.ts, assets)
76+
├── vite.config.ts
77+
├── tsconfig.json
78+
└── package.json
79+
```
80+
81+
## API / Routes
82+
83+
| Method | Path | Description |
84+
|--------|------|-------------|
85+
| **Front (HTML)** | | |
86+
| GET | `/` | Home (index) |
87+
| GET | `/step1-git` | Step 1 – Git |
88+
| GET | `/step2-hosting` | Step 2 – Hosting |
89+
| GET | `/step3-steps` | Step 3 – Steps |
90+
| GET | `/step3-steps-selfhosted` | Step 3 – Self-hosted |
91+
| GET | `/step4-validated` | Step 4 – Validated |
92+
| GET | `/step4-validated-selfhosted` | Step 4 – Validated (self-hosted) |
93+
| **Maps** | | |
94+
| GET | `/maps/list` | List `.tmj` maps with properties (path, mapName, mapImage, size, lastModified, etc.) |
95+
| **Uploader** | | |
96+
| POST | `/uploader/configure` | Configure MAP_STORAGE (body: `mapStorageUrl`, `mapStorageApiKey`, `uploadDirectory`) |
97+
| GET | `/uploader/status` | Current config status (e.g. presence of `.env.secret`) |
98+
| GET | `/uploader/maps-storage-list` | List maps from map-storage (for self-hosted step 4) |
99+
| POST | `/uploader/upload` | Run the upload (uses config from `.env.secret`) |
100+
101+
Static and special paths:
102+
103+
- `/public/*` – Static files from core’s `public/`
104+
- `/assets/*` – From project’s `dist/assets/`
105+
- `/tilesets/*` – From project’s `tilesets/`
106+
- `/src/*.ts` – Served as compiled JS (esbuild), e.g. for browser scripts using WorkAdventure APIs
107+
108+
## Configuration
109+
110+
### Uploader (MAP_STORAGE)
111+
112+
Configure via **POST `/uploader/configure`** with:
113+
114+
- `mapStorageUrl` – map-storage base URL
115+
- `mapStorageApiKey` – API key for map-storage
116+
- `uploadDirectory` – Local directory to upload from
117+
118+
This writes (or updates) a secret file (e.g. `.env.secret` or `src/.env.secret` depending on route) used by the upload and maps-storage-list endpoints. Do not commit this file.
119+
120+
### Core root
121+
122+
`getCoreRoot()` resolves the root of the core package:
123+
124+
- When run from the **project root** (e.g. map-starter-kit): `process.cwd()`
125+
- When run from **packages/map-starter-kit-core** or **node_modules**: the package directory
126+
127+
So templates and `public` are always loaded from the core package, while maps, `.env`, and `tilesets` stay in the project root.
128+
129+
## Scripts
130+
131+
| Script | Command | Description |
132+
|--------|---------|-------------|
133+
| `dev` | `vite` | Start dev server (Express via vite-plugin-node) |
134+
| `build` | `tsc && vite build && node -e "…"` | Type-check, build server to `dist/`, copy `server.d.ts` |
135+
136+
## Releasing
137+
138+
Releases are automated with **semantic-release** and **GitHub Actions**:
139+
140+
- **Workflow:** `.github/workflows/release.yml`
141+
- **Trigger:** Push to `main` or `master`
142+
- **Conventions:** [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `BREAKING CHANGE:`) determine the next version; a release is published only when there are relevant commits.
143+
- **Artifacts:** GitHub Release + **npm** publish of `@workadventure/map-starter-kit-core`.
144+
145+
**npm auth (after classic token deprecation):**
146+
147+
- **Recommended:** [Trusted Publishing (OIDC)](https://docs.npmjs.com/trusted-publishers) for this repo and workflow (no long-lived token).
148+
- **Alternative:** Create a **granular access token** on [npm](https://www.npmjs.com/settings/~/tokens), then set the **NPM_TOKEN** secret in the repo.
149+
150+
## Tech stack
151+
152+
- **Runtime:** Node.js, Express 5
153+
- **Build:** TypeScript 5, Vite 7, vite-plugin-node
154+
- **Templates:** Mustache
155+
- **Release:** semantic-release
156+
157+
## License
158+
159+
MIT. See [LICENSE](LICENSE).
160+
161+
## Links
162+
163+
- **Repository:** [github.com/workadventure/map-starter-kit-core](https://github.com/workadventure/map-starter-kit-core)
164+
- **Issues:** [github.com/workadventure/map-starter-kit-core/issues](https://github.com/workadventure/map-starter-kit-core/issues)
165+
- **npm:** [@workadventure/map-starter-kit-core](https://www.npmjs.com/package/@workadventure/map-starter-kit-core)

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@workadventure/map-starter-kit-core",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Core app, HTML pages and static assets for the WorkAdventure Map Starter Kit. Update this package to get new UI and server features without touching your maps or config.",
55
"main": "src/server.ts",
66
"scripts": {
@@ -26,7 +26,12 @@
2626
"release": {
2727
"branches": ["main", "master"]
2828
},
29-
"files": ["dist", "README.md"],
29+
"files": [
30+
"dist",
31+
"types",
32+
"public",
33+
"README.md"
34+
],
3035
"exports": {
3136
".": {
3237
"types": "./dist/server.d.ts",
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

13-
<title>WorkAdventure test map</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
15-
<script src="https://cdn.jsdelivr.net/npm/mustache@4.2.0/mustache.min.js"></script>
13+
<title>WorkAdventure build your map</title>
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1615
<script type="module">
1716
document.addEventListener("DOMContentLoaded", (event) => {
1817
// Load index.js to have access to getMapsList
19-
import('/public/assets/index.js').then(() => {
18+
import('/public/assets/js/index.js').then(() => {
2019
loadTMJ();
2120
});
2221
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

13-
<title>WorkAdventure test map</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
13+
<title>WorkAdventure build your map</title>
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
<script type="module">
1616
document.addEventListener("DOMContentLoaded", (event) => {
1717
// Load index.js to have access to getMapsList
18-
import('/public/assets/index.js').then(() => {
18+
import('/public/assets/js/index.js').then(() => {
1919
window.createBackgroundImageFade();
2020
});
2121
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

13-
<title>WorkAdventure test map</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
13+
<title>WorkAdventure build your map</title>
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
</head>
1616

1717
<body>
@@ -47,7 +47,7 @@
4747
<script type="module">
4848
document.addEventListener("DOMContentLoaded", (event) => {
4949
// Load index.js to have access to getMapsList
50-
import('/public/assets/index.js').then(() => {
50+
import('/public/assets/js/index.js').then(() => {
5151
window.createBackgroundImageFade();
5252
});
5353
});

src/views/step3-steps-selfhosted.html renamed to public/assets/views/step3-steps-selfhosted.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

1313
<title>WorkAdventure test map - Self-hosted</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
<script type="module">
1616
document.addEventListener("DOMContentLoaded", (event) => {
17-
import('/public/assets/index.js').then(() => {
17+
import('/public/assets/js/index.js').then(() => {
1818
window.createBackgroundImageFade();
1919
});
2020
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

13-
<title>WorkAdventure test map</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
13+
<title>WorkAdventure build your map</title>
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
<script type="module">
1616
document.addEventListener("DOMContentLoaded", (event) => {
1717
// Load index.js to have access to getMapsList
18-
import('/public/assets/index.js').then(() => {
18+
import('/public/assets/js/index.js').then(() => {
1919
window.createBackgroundImageFade();
2020
});
2121
});

src/views/step4-validated-selfhosted.html renamed to public/assets/views/step4-validated-selfhosted.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

1313
<title>Your maps - Self-hosted</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
<script type="module">
1616
document.addEventListener("DOMContentLoaded", async () => {
17-
await import('/public/assets/index.js');
17+
await import('/public/assets/js/index.js');
1818
const main = document.querySelector('main .maps-container');
1919
const emptyEl = document.getElementById('maps-empty');
2020
const errorEl = document.getElementById('maps-error');
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
<link href="public/styles/styles.css" rel="stylesheet">
1212

13-
<title>WorkAdventure test map</title>
14-
<link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
13+
<title>WorkAdventure build your map</title>
14+
<link rel="icon" href="public/images/favicon.svg" type="image/svg+xml">
1515
<script type="module">
1616
document.addEventListener("DOMContentLoaded", (event) => {
1717
// Load index.js to have access to getMapsList
18-
import('/public/assets/index.js').then(() => {
18+
import('/public/assets/js/index.js').then(() => {
1919
window.createBackgroundImageFade();
2020
});
2121
});

0 commit comments

Comments
 (0)