@playcademy/vite-plugin 0.0.1-beta.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,136 +1,358 @@
1
1
  # @playcademy/vite-plugin
2
2
 
3
- A Vite plugin to generate a `playcademy.manifest.json` for Playcademy games and optionally create a zip archive of the build output.
3
+ **Vite plugin for Playcademy game development and deployment**
4
+
5
+ This plugin integrates Playcademy's development sandbox and build tools into your Vite workflow, automatically generating manifests, managing development environments, and creating deployment-ready archives.
6
+
7
+ ## Overview
8
+
9
+ The Playcademy Vite plugin streamlines game development by providing:
10
+
11
+ - **Development Sandbox**: Automatically starts a local Playcademy API server and real-time WebSocket server during development.
12
+ - **Manifest Generation**: Creates required `playcademy.manifest.json` files for platform deployment
13
+ - **Build Optimization**: Configures Vite settings for optimal Playcademy platform compatibility
14
+ - **Deployment Packaging**: Optionally creates zip archives ready for platform upload
15
+
16
+ ### Key Benefits
17
+
18
+ - **Zero-Config Development**: Works out of the box with sensible defaults
19
+ - **Hot Reload Integration**: Seamless development experience with Vite's hot module replacement
20
+ - **Platform Compatibility**: Ensures builds work correctly on the Playcademy platform
21
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
22
+ - **Flexible Configuration**: Extensive options for customizing both development and build processes
4
23
 
5
24
  ## Installation
6
25
 
26
+ Install the plugin in your Playcademy game project:
27
+
7
28
  ```bash
8
- # Using bun
29
+ # Using Bun (recommended)
9
30
  bun add -D @playcademy/vite-plugin
10
31
 
11
- # Using pnpm
12
- pnpm add -D @playcademy/vite-plugin
32
+ # Using npm
33
+ npm install --save-dev @playcademy/vite-plugin
13
34
 
14
35
  # Using yarn
15
36
  yarn add --dev @playcademy/vite-plugin
16
37
 
17
- # Using npm
18
- npm install --save-dev @playcademy/vite-plugin
38
+ # Using pnpm
39
+ pnpm add -D @playcademy/vite-plugin
19
40
  ```
20
41
 
21
- ## Usage
42
+ ## Quick Start
22
43
 
23
- Add the plugin to your `vite.config.ts` or `vite.config.js`:
44
+ Add the plugin to your `vite.config.ts`:
24
45
 
25
46
  ```typescript
26
- // vite.config.ts
27
47
  import { defineConfig } from 'vite'
48
+
49
+ import { playcademy } from '@playcademy/vite-plugin'
50
+
51
+ export default defineConfig({
52
+ plugins: [
53
+ playcademy(), // Uses all defaults
54
+ ],
55
+ })
56
+ ```
57
+
58
+ Start development:
59
+
60
+ ```bash
61
+ bun dev
62
+ ```
63
+
64
+ The plugin will:
65
+
66
+ - Start the sandbox server at `http://localhost:4321/api`
67
+ - Enable API integration for your game
68
+ - Provide hot reload for rapid development
69
+
70
+ ## Configuration
71
+
72
+ ### Basic Configuration
73
+
74
+ ```typescript
28
75
  import { playcademy } from '@playcademy/vite-plugin'
29
76
 
30
77
  export default defineConfig({
31
78
  plugins: [
32
79
  playcademy({
33
80
  export: {
34
- // bootMode: 'iframe',
35
- // entryPoint: 'my-game.html',
36
- // styles: ['src/main.css'],
37
- // platform: 'web',
38
- // autoZip: true, // Set to true to enable zipping locally
81
+ bootMode: 'iframe', // 'iframe' | 'module'
82
+ entryPoint: 'index.html', // Main HTML file
83
+ platform: 'web', // 'web' | 'godot' | 'unity'
84
+ autoZip: false, // Create deployment zip
85
+ styles: [], // Additional CSS files
39
86
  },
40
87
  sandbox: {
41
- // autoStart: true, // Auto-start sandbox during development
42
- // url: 'http://localhost:4321/api', // Custom sandbox URL
43
- // verbose: true, // Enable verbose logging from sandbox
88
+ autoStart: true, // Start sandbox automatically
89
+ url: 'http://localhost:4321', // Sandbox URL
90
+ verbose: false, // Enable debug logging
91
+ realtime: {
92
+ enabled: false, // Disabled by default, enable for multiplayer
93
+ port: 4322, // Defaults to API port + 1
94
+ },
44
95
  },
45
96
  }),
46
97
  ],
47
- // ...other Vite config
48
98
  })
49
99
  ```
50
100
 
51
- ## What it does
52
-
53
- 1. **Auto-starts Development Sandbox**:
54
- During development (`vite dev`), the plugin automatically starts a local Playcademy sandbox server that provides game APIs for testing. This allows you to develop your game locally with full API integration.
55
-
56
- 2. **Generates `playcademy.manifest.json`**:
57
- This file is created in your Vite build's output directory (`dist` by default). It contains metadata about your game, such as its entry point, boot mode, and engine type, which is used by the Playcademy platform.
101
+ ### Production Build Configuration
58
102
 
59
- 3. **Creates Output Zip Archive (Optional)**:
60
- If `autoZip` is enabled, the plugin will create a zip file named `{your-project-name}.zip` inside a `.playcademy` directory at the root of your project (e.g., `my-game/.playcademy/my-game.zip`).
61
- This archive contains all the contents of your build output directory and can be uploaded directly to the Playcademy platform.
103
+ ```typescript
104
+ export default defineConfig({
105
+ plugins: [
106
+ playcademy({
107
+ export: {
108
+ autoZip: true, // Creates .playcademy/{project-name}.zip
109
+ },
110
+ }),
111
+ ],
112
+ })
113
+ ```
62
114
 
63
- 4. **Sets Vite `base` Configuration (if not set by user)**:
64
- The plugin defaults Vite's `base` configuration to `'./'`. This is necessary for games to correctly reference assets when deployed on the Playcademy platform. If you explicitly set a `base` path in your `vite.config.ts`, the plugin will respect your configuration and not override it.
115
+ ### Custom Sandbox Configuration
65
116
 
66
- ## Options (`PlaycademyPluginOptions`)
117
+ ```typescript
118
+ export default defineConfig({
119
+ plugins: [
120
+ playcademy({
121
+ sandbox: {
122
+ autoStart: false, // Disable auto-start
123
+ url: 'http://localhost:8080', // Custom port
124
+ verbose: true, // Enable debug logs
125
+ },
126
+ }),
127
+ ],
128
+ })
129
+ ```
67
130
 
68
- The `playcademy()` plugin accepts an optional options object with two main namespaces:
131
+ ## Plugin Options
69
132
 
70
133
  ### Export Options (`export`)
71
134
 
72
135
  Configuration for manifest generation and build output:
73
136
 
74
- - **`bootMode`**:
137
+ | Option | Type | Default | Description |
138
+ | ------------ | ----------------------------- | -------------- | ------------------------------- |
139
+ | `bootMode` | `'iframe' \| 'module'` | `'iframe'` | How the game should be launched |
140
+ | `entryPoint` | `string` | `'index.html'` | Main HTML file for your game |
141
+ | `platform` | `'web' \| 'godot' \| 'unity'` | `'web'` | Game engine/platform type |
142
+ | `autoZip` | `boolean` | `false` | Create deployment zip archive |
143
+ | `styles` | `string[]` | `[]` | Additional CSS files to load |
75
144
 
76
- - Type: `'iframe' | 'module'`
77
- - Default: `'iframe'`
78
- - Specifies how the game should be launched.
145
+ ### Sandbox Options (`sandbox`)
79
146
 
80
- - **`entryPoint`**:
147
+ Configuration for the development sandbox server:
81
148
 
82
- - Type: `string`
83
- - Default: `'index.html'`
84
- - The main HTML file for your game.
149
+ | Option | Type | Default | Description |
150
+ | ----------- | --------- | ----------------------------- | -------------------------------- |
151
+ | `autoStart` | `boolean` | `true` | Start sandbox during development |
152
+ | `url` | `string` | `'http://localhost:4321/api'` | Sandbox server URL |
153
+ | `verbose` | `boolean` | `false` | Enable verbose logging |
154
+ | `realtime` | `object` | `{...}` | Real-time server configuration |
85
155
 
86
- - **`styles`**:
156
+ ## Build Output
87
157
 
88
- - Type: `string[]`
89
- - Default: `[]`
90
- - An array of CSS file paths (relative to the project root) that should be loaded by the Playcademy platform.
158
+ ### Development Mode
91
159
 
92
- - **`platform`**:
160
+ During `bun dev`, the plugin:
93
161
 
94
- - Type: `'web' | 'godot' | 'unity'`
95
- - Default: `'web'`
96
- - Specifies the game engine used.
162
+ - Starts the sandbox server (if enabled)
163
+ - Provides game API simulation
164
+ - Enables hot reload for game code
97
165
 
98
- - **`autoZip`**:
99
- - Type: `boolean`
100
- - Default: `false`
101
- - Controls whether to automatically create a zip archive of the build output.
166
+ Console output:
102
167
 
103
- ### Sandbox Options (`sandbox`)
168
+ ```
169
+ VITE v6.3.5 ready in 500ms
104
170
 
105
- Configuration for the development sandbox server:
171
+ ➜ Local: http://localhost:5173/
172
+ ➜ Network: use --host to expose
106
173
 
107
- - **`autoStart`**:
174
+ PLAYCADEMY v1.2.3
108
175
 
109
- - Type: `boolean`
110
- - Default: `true`
111
- - Controls whether to automatically start the development sandbox during `vite dev`.
176
+ ➜ Game: my-game
177
+ ➜ Sandbox: http://localhost:4321/api
178
+ ➜ Realtime: ws://localhost:4322
179
+ ```
180
+
181
+ ### Production Build
182
+
183
+ During `bun run build`, the plugin:
184
+
185
+ - Generates `playcademy.manifest.json` in `dist/`
186
+ - Creates deployment zip (if `autoZip: true`)
187
+ - Optimizes build for platform deployment
188
+
189
+ Console output:
190
+
191
+ ```
192
+ dist/index.html 2.45 kB │ gzip: 1.12 kB
193
+ dist/assets/index-Bj8fxu6c.js 135.24 kB │ gzip: 43.82 kB
194
+
195
+ [Playcademy]
196
+ playcademy.manifest.json 0.25 kB
197
+ .playcademy/my-game.zip 1,234.56 kB
198
+ ```
112
199
 
113
- - **`url`**:
200
+ ## Generated Files
114
201
 
115
- - Type: `string`
116
- - Default: `'http://localhost:4321/api'`
117
- - The URL of the sandbox server to use (useful if you're running your own sandbox instance).
202
+ ### Manifest File
118
203
 
119
- - **`verbose`**:
120
- - Type: `boolean`
121
- - Default: `false`
122
- - Enables verbose logging from the sandbox server and API handlers for debugging.
204
+ The plugin generates `dist/playcademy.manifest.json`:
205
+
206
+ ```json
207
+ {
208
+ "version": 1,
209
+ "slug": "my-game",
210
+ "displayName": "My Game",
211
+ "description": "An awesome Playcademy game",
212
+ "entryPoint": "index.html",
213
+ "bootMode": "iframe",
214
+ "platform": "web",
215
+ "styles": [],
216
+ "gameVersion": "1.0.0"
217
+ }
218
+ ```
219
+
220
+ ### Deployment Archive
221
+
222
+ With `autoZip: true`, creates `.playcademy/{project-name}.zip` containing all build files ready for platform upload.
123
223
 
124
224
  ## Development
125
225
 
126
- To install dependencies for this package:
226
+ ### Development Workflow
127
227
 
128
228
  ```bash
129
- bun install
229
+ # Start the development environment from monorepo root
230
+ bun dev
231
+
232
+ # This starts all applications with proper port allocation:
233
+ # - Landing: http://localhost:5173
234
+ # - Hub: http://localhost:5174
235
+ # - Docs: http://localhost:5175
236
+ # - Blog: http://localhost:5176
237
+ # - Sandbox: http://localhost:4321
130
238
  ```
131
239
 
132
- To build the plugin:
240
+ For package-specific development:
133
241
 
134
242
  ```bash
243
+ # Change to package directory
244
+ cd packages/vite-plugin
245
+
246
+ # Build the plugin
135
247
  bun run build
248
+
249
+ # Publish to npm (requires permissions)
250
+ bun run pub
251
+ ```
252
+
253
+ ## Dependencies
254
+
255
+ ### Runtime Dependencies
256
+
257
+ - **archiver**: Zip file creation for deployment packages
258
+ - **picocolors**: Terminal color output for logging
259
+
260
+ ### Development Dependencies
261
+
262
+ - **@playcademy/sandbox**: Development sandbox server
263
+ - **@types/archiver**: TypeScript definitions for archiver
264
+ - **yocto-spinner**: Progress indicators for build operations
265
+
266
+ ### Peer Dependencies
267
+
268
+ - **typescript**: TypeScript compiler (v5+)
269
+
270
+ ## Common Use Cases
271
+
272
+ ### Basic Web Game
273
+
274
+ ```typescript
275
+ // Minimal configuration for most web games
276
+ export default defineConfig({
277
+ plugins: [playcademy()],
278
+ })
279
+ ```
280
+
281
+ ### Enabling Real-time Features
282
+
283
+ ```typescript
284
+ // Enable the real-time server for multiplayer games
285
+ export default defineConfig({
286
+ plugins: [
287
+ playcademy({
288
+ sandbox: {
289
+ realtime: {
290
+ enabled: true,
291
+ },
292
+ },
293
+ }),
294
+ ],
295
+ })
296
+ ```
297
+
298
+ ### Godot Export
299
+
300
+ ```typescript
301
+ // Configuration for Godot HTML5 exports
302
+ export default defineConfig({
303
+ plugins: [
304
+ playcademy({
305
+ export: {
306
+ platform: 'godot',
307
+ entryPoint: 'game.html',
308
+ },
309
+ }),
310
+ ],
311
+ })
312
+ ```
313
+
314
+ ### Production Deployment
315
+
316
+ ```typescript
317
+ // Optimized for production builds
318
+ export default defineConfig(({ mode }) => ({
319
+ plugins: [
320
+ playcademy({
321
+ export: {
322
+ autoZip: mode === 'production',
323
+ },
324
+ sandbox: {
325
+ verbose: mode === 'development',
326
+ },
327
+ }),
328
+ ],
329
+ }))
330
+ ```
331
+
332
+ ## Troubleshooting
333
+
334
+ ### Common Issues
335
+
336
+ **Manifest not generated**
337
+
338
+ - Ensure plugin is properly configured in `vite.config.ts`
339
+ - Check for build errors in console output
340
+ - Verify the build completes successfully
341
+
342
+ **Zip file not created**
343
+
344
+ - Enable `autoZip: true` in export options
345
+ - Check that build completed without errors
346
+ - Look for zip in `.playcademy/` directory
347
+
348
+ ### Debug Mode
349
+
350
+ Enable verbose logging for troubleshooting:
351
+
352
+ ```typescript
353
+ playcademy({
354
+ sandbox: {
355
+ verbose: true,
356
+ },
357
+ })
136
358
  ```
package/dist/index.d.ts CHANGED
@@ -7,21 +7,5 @@
7
7
  * - Build-time manifest generation and optional zip packaging
8
8
  */
9
9
  import type { Plugin } from 'vite';
10
- import type { ManifestV1 } from '@playcademy/types';
11
- export interface PlaycademyExportOptions {
12
- bootMode?: ManifestV1['bootMode'];
13
- entryPoint?: string;
14
- styles?: string[];
15
- platform?: ManifestV1['platform'];
16
- autoZip?: boolean;
17
- }
18
- export interface PlaycademySandboxOptions {
19
- autoStart?: boolean;
20
- url?: string;
21
- verbose?: boolean;
22
- }
23
- export interface PlaycademyPluginOptions {
24
- export?: PlaycademyExportOptions;
25
- sandbox?: PlaycademySandboxOptions;
26
- }
10
+ import type { PlaycademyPluginOptions } from './types';
27
11
  export declare function playcademy(options?: PlaycademyPluginOptions): Plugin;