|
| 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) |
0 commit comments