@playcademy/vite-plugin 0.1.25 → 0.1.26-alpha.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.
Files changed (36) hide show
  1. package/README.md +40 -20
  2. package/dist/config/proxy.d.ts +12 -0
  3. package/dist/config/vite-config.d.ts +8 -0
  4. package/dist/hooks/close-bundle.d.ts +9 -0
  5. package/dist/hooks/config-resolved.d.ts +10 -0
  6. package/dist/hooks/config.d.ts +10 -0
  7. package/dist/hooks/configure-server.d.ts +10 -0
  8. package/dist/hooks/write-bundle.d.ts +9 -0
  9. package/dist/index.d.ts +3 -7
  10. package/dist/index.js +37775 -37647
  11. package/dist/lib/backend/hot-reload.d.ts +11 -0
  12. package/dist/lib/backend/index.d.ts +5 -0
  13. package/dist/lib/{cli-server.d.ts → backend/server.d.ts} +1 -1
  14. package/dist/lib/build/index.d.ts +4 -0
  15. package/dist/lib/{manifest.d.ts → build/manifest.d.ts} +2 -2
  16. package/dist/lib/logging/adapter.d.ts +19 -0
  17. package/dist/lib/logging/index.d.ts +6 -0
  18. package/dist/lib/{logging.d.ts → logging/utils.d.ts} +3 -3
  19. package/dist/lib/sandbox/index.d.ts +6 -0
  20. package/dist/lib/sandbox/project-info.d.ts +10 -0
  21. package/dist/lib/{sandbox.d.ts → sandbox/server.d.ts} +2 -1
  22. package/dist/lib/sandbox/timeback.d.ts +11 -0
  23. package/dist/plugin.d.ts +15 -0
  24. package/dist/server/cleanup.d.ts +7 -0
  25. package/dist/server/lifecycle.d.ts +8 -0
  26. package/dist/server/platform-mode.d.ts +17 -0
  27. package/dist/server/standalone-mode.d.ts +9 -0
  28. package/dist/server/state.d.ts +36 -0
  29. package/dist/types/index.d.ts +5 -0
  30. package/dist/types/internal.d.ts +73 -0
  31. package/dist/types/options.d.ts +51 -0
  32. package/package.json +3 -8
  33. package/dist/types.d.ts +0 -97
  34. package/dist/types.js +0 -0
  35. package/dist/utils.d.ts +0 -7
  36. /package/dist/{lib/server.d.ts → server/middleware.d.ts} +0 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hot reload callbacks for backend server
3
+ */
4
+ import type { ResolvedConfig } from 'vite';
5
+ /**
6
+ * Creates hot reload callbacks for logging backend updates.
7
+ */
8
+ export declare function createHotReloadCallbacks(viteConfig: ResolvedConfig): {
9
+ onSuccess: (changedPath?: string) => void;
10
+ onError: (error: unknown) => void;
11
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Backend server management
3
+ */
4
+ export { setupCliDevServer } from './server';
5
+ export { createHotReloadCallbacks } from './hot-reload';
@@ -1,4 +1,4 @@
1
- import type { CliDevServerOptions, CliServerManager } from '../types';
1
+ import type { CliDevServerOptions, CliServerManager } from '../../types';
2
2
  /**
3
3
  * Sets up the CLI dev server with hot reload enabled.
4
4
  * Loads config, checks if backend is needed, and starts server if appropriate.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Build-time utilities
3
+ */
4
+ export { generatePlaycademyManifest, createOutputZipArchive, performPlaycademyLogging, } from './manifest';
@@ -2,7 +2,7 @@
2
2
  * Manifest generation and build output functionality
3
3
  */
4
4
  import type { ResolvedConfig } from 'vite';
5
- import type { ManifestOptions, PlaycademyOutputData } from '../types';
6
- export declare function generatePlaycademyManifest(config: ResolvedConfig, options: ManifestOptions, outDir: string, buildOutputs: PlaycademyOutputData): Promise<void>;
5
+ import type { PlaycademyOutputData } from '../../types';
6
+ export declare function generatePlaycademyManifest(config: ResolvedConfig, outDir: string, buildOutputs: PlaycademyOutputData): Promise<void>;
7
7
  export declare function createOutputZipArchive(config: ResolvedConfig, outDir: string, buildOutputs: PlaycademyOutputData): Promise<void>;
8
8
  export declare function performPlaycademyLogging(config: ResolvedConfig, buildOutputs: PlaycademyOutputData): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Logger adapter for vite plugin
3
+ *
4
+ * Provides a logger interface that can be passed to sandbox and CLI dev server
5
+ * to ensure consistent Vite-style logging when servers are started by the plugin.
6
+ */
7
+ /**
8
+ * Simple logger interface that sandbox and backend can accept
9
+ */
10
+ export interface PluginLogger {
11
+ info: (msg: string) => void;
12
+ warn: (msg: string) => void;
13
+ error: (msg: string) => void;
14
+ }
15
+ /**
16
+ * Creates a logger adapter that formats logs in Vite's style with [playcademy] prefix
17
+ * @param prefix - Prefix to add to all logs (e.g., 'backend', 'sandbox')
18
+ */
19
+ export declare function createLoggerAdapter(prefix: string): PluginLogger;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Logging utilities
3
+ */
4
+ export { createLoggerAdapter } from './adapter';
5
+ export type { PluginLogger } from './adapter';
6
+ export { log, printBanner } from './utils';
@@ -1,5 +1,5 @@
1
1
  import type { ResolvedConfig } from 'vite';
2
- import type { ProjectInfo } from '../types';
2
+ import type { ProjectInfo } from '../../types';
3
3
  /**
4
4
  * Centralized logging utilities for the Vite plugin.
5
5
  * Provides clear, prefixed, and color-coded output for multiple servers.
@@ -15,9 +15,9 @@ export declare const log: {
15
15
  * @param viteConfig - Vite resolved configuration
16
16
  * @param servers - Object containing port numbers for each server
17
17
  * @param projectInfo - Project information
18
- * @param sandboxVersion - Sandbox version string
18
+ * @param pluginVersion - Vite plugin version string
19
19
  */
20
20
  export declare function printBanner(viteConfig: ResolvedConfig, servers: {
21
21
  sandbox: number;
22
22
  backend?: number;
23
- }, projectInfo: ProjectInfo, sandboxVersion: string): void;
23
+ }, projectInfo: ProjectInfo, pluginVersion: string): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sandbox server management
3
+ */
4
+ export { startSandbox } from './server';
5
+ export { extractProjectInfo } from './project-info';
6
+ export { detectTimebackOptions } from './timeback';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Project information extraction for sandbox initialization
3
+ */
4
+ import type { ResolvedConfig } from 'vite';
5
+ import type { ProjectInfo } from '../../types';
6
+ /**
7
+ * Extracts project information from playcademy.config and package.json
8
+ * Used to initialize sandbox with correct project metadata
9
+ */
10
+ export declare function extractProjectInfo(viteConfig: ResolvedConfig): Promise<ProjectInfo>;
@@ -1,7 +1,8 @@
1
1
  import type { ResolvedConfig } from 'vite';
2
- import type { SandboxManager } from '../types';
2
+ import type { SandboxManager } from '../../types';
3
3
  export declare function startSandbox(viteConfig: ResolvedConfig, autoStart?: boolean, options?: {
4
4
  verbose?: boolean;
5
5
  customUrl?: string;
6
6
  quiet?: boolean;
7
+ recreateDb?: boolean;
7
8
  }): Promise<SandboxManager>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * TimeBack configuration detection from environment variables
3
+ */
4
+ import type { TimebackConfig } from '@playcademy/sandbox/config';
5
+ /**
6
+ * Auto-detect TimeBack configuration from environment variables
7
+ *
8
+ * Checks for local or remote TimeBack setup and returns appropriate config.
9
+ * Returns undefined if no TimeBack configuration is detected.
10
+ */
11
+ export declare function detectTimebackOptions(): Partial<TimebackConfig> | undefined;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Main plugin factory
3
+ * Orchestrates all plugin hooks and manages plugin context
4
+ */
5
+ import type { Plugin } from 'vite';
6
+ import type { PlaycademyPluginOptions } from './types/options';
7
+ /**
8
+ * Playcademy Vite Plugin
9
+ *
10
+ * Provides:
11
+ * - Auto-starting sandbox server during development
12
+ * - Hijacking dev server to serve Playcademy loader environment
13
+ * - Build-time manifest generation and optional zip packaging
14
+ */
15
+ export declare function playcademy(options?: PlaycademyPluginOptions): Plugin;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Server cleanup utilities
3
+ */
4
+ /**
5
+ * Cleanup servers without exiting process (for Vite restarts)
6
+ */
7
+ export declare function cleanupServers(): Promise<void>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Process lifecycle management (SIGINT/SIGTERM handlers)
3
+ */
4
+ /**
5
+ * Setup cleanup handlers for graceful process shutdown (SIGINT/SIGTERM)
6
+ * Only registers handlers once at module scope to avoid duplicates
7
+ */
8
+ export declare function setupProcessShutdownHandlers(): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Platform mode server configuration
3
+ * Full Playcademy platform: sandbox + backend + shell wrapper
4
+ */
5
+ import type { ResolvedConfig, ViteDevServer } from 'vite';
6
+ export interface PlatformModeOptions {
7
+ startSandbox: boolean;
8
+ verbose: boolean;
9
+ sandboxUrl: string;
10
+ recreateDb: boolean;
11
+ showBadge: boolean;
12
+ preferredBackendPort: number;
13
+ }
14
+ /**
15
+ * Configure server in platform mode (sandbox + backend + shell)
16
+ */
17
+ export declare function configurePlatformMode(server: ViteDevServer, viteConfig: ResolvedConfig, options: PlatformModeOptions): Promise<void>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Standalone mode server configuration
3
+ * Backend only, no sandbox or shell wrapper
4
+ */
5
+ import type { ResolvedConfig, ViteDevServer } from 'vite';
6
+ /**
7
+ * Configure server in standalone mode (backend only, no sandbox or shell)
8
+ */
9
+ export declare function configureStandaloneMode(server: ViteDevServer, viteConfig: ResolvedConfig, preferredPort: number): Promise<void>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Module-level server state management
3
+ *
4
+ * Server references persist across Vite config reloads.
5
+ * When Vite restarts due to config changes, it creates a new plugin instance,
6
+ * but the servers continue running in the same Node process. We maintain
7
+ * these references at module scope to properly clean them up on restart.
8
+ */
9
+ import type { CliServerManager, SandboxManager } from '../types';
10
+ /**
11
+ * Module-level server references
12
+ */
13
+ export declare const serverState: {
14
+ sandbox: SandboxManager | null;
15
+ backend: CliServerManager | null;
16
+ };
17
+ /**
18
+ * Get sandbox server reference
19
+ */
20
+ export declare function getSandboxRef(): SandboxManager | null;
21
+ /**
22
+ * Set sandbox server reference
23
+ */
24
+ export declare function setSandboxRef(sandbox: SandboxManager | null): void;
25
+ /**
26
+ * Get backend server reference
27
+ */
28
+ export declare function getBackendRef(): CliServerManager | null;
29
+ /**
30
+ * Set backend server reference
31
+ */
32
+ export declare function setBackendRef(backend: CliServerManager | null): void;
33
+ /**
34
+ * Check if any servers are currently running
35
+ */
36
+ export declare function hasActiveServers(): boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Type exports for the Playcademy Vite Plugin
3
+ */
4
+ export type { PlaycademyExportOptions, PlaycademySandboxOptions, PlaycademyShellOptions, PlaycademyPluginOptions, PlaycademyMode, } from './options';
5
+ export type { ResolvedPluginOptions, PluginContext, PlaycademyOutputData, ProjectInfo, SandboxManager, CliServerManager, CliDevServerOptions, } from './internal';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Internal plugin state and context types
3
+ */
4
+ import type { ResolvedConfig } from 'vite';
5
+ import type { PlaycademyMode } from './options';
6
+ /**
7
+ * Internal resolved plugin options
8
+ */
9
+ export interface ResolvedPluginOptions {
10
+ mode: PlaycademyMode;
11
+ autoZip: boolean;
12
+ sandboxUrl: string;
13
+ startSandbox: boolean;
14
+ verbose: boolean;
15
+ recreateDb: boolean;
16
+ showBadge: boolean;
17
+ }
18
+ /**
19
+ * Plugin context shared across hooks
20
+ */
21
+ export interface PluginContext {
22
+ options: ResolvedPluginOptions;
23
+ viteConfig: ResolvedConfig | null;
24
+ backendPort: number | null;
25
+ buildOutputs: PlaycademyOutputData;
26
+ }
27
+ /**
28
+ * Build output data for logging and tracking
29
+ */
30
+ export interface PlaycademyOutputData {
31
+ manifestPath?: string;
32
+ manifestSizeKb?: string;
33
+ zipPath?: string;
34
+ zipSizeKb?: string;
35
+ }
36
+ /**
37
+ * Project information extracted from package.json and directory structure
38
+ */
39
+ export interface ProjectInfo {
40
+ slug: string;
41
+ displayName: string;
42
+ version: string;
43
+ description?: string;
44
+ }
45
+ /**
46
+ * Sandbox manager interface for controlling sandbox lifecycle
47
+ */
48
+ export interface SandboxManager {
49
+ baseUrl: string;
50
+ realtimeUrl: string;
51
+ port: number;
52
+ project: ProjectInfo | null;
53
+ cleanup: () => void;
54
+ }
55
+ /**
56
+ * CLI server manager interface for controlling backend server lifecycle
57
+ */
58
+ export interface CliServerManager {
59
+ server: {
60
+ dispose: () => Promise<void>;
61
+ };
62
+ port: number;
63
+ stopHotReload: () => void;
64
+ cleanup: () => void;
65
+ }
66
+ /**
67
+ * Options for setting up the CLI dev server
68
+ */
69
+ export interface CliDevServerOptions {
70
+ preferredPort: number;
71
+ viteConfig: ResolvedConfig;
72
+ platformUrl?: string;
73
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Plugin configuration options
3
+ */
4
+ /**
5
+ * Plugin operation mode
6
+ * - 'platform': Full Playcademy platform with sandbox + backend + shell wrapper (default)
7
+ * - 'standalone': Backend only, no sandbox or shell (for testing integrations)
8
+ */
9
+ export type PlaycademyMode = 'platform' | 'standalone';
10
+ /**
11
+ * Configuration options for exporting Playcademy games
12
+ */
13
+ export interface PlaycademyExportOptions {
14
+ autoZip?: boolean;
15
+ }
16
+ /**
17
+ * Configuration options for the Playcademy sandbox server
18
+ */
19
+ export interface PlaycademySandboxOptions {
20
+ autoStart?: boolean;
21
+ url?: string;
22
+ verbose?: boolean;
23
+ /**
24
+ * Recreate the sandbox database on each start
25
+ * @default false
26
+ */
27
+ recreateDb?: boolean;
28
+ }
29
+ /**
30
+ * Configuration options for the development shell wrapper
31
+ */
32
+ export interface PlaycademyShellOptions {
33
+ /**
34
+ * Show the Playcademy badge in the corner during development
35
+ * @default true
36
+ */
37
+ showBadge?: boolean;
38
+ }
39
+ /**
40
+ * Main plugin configuration options
41
+ */
42
+ export interface PlaycademyPluginOptions {
43
+ /**
44
+ * Plugin operation mode
45
+ * @default 'platform'
46
+ */
47
+ mode?: PlaycademyMode;
48
+ export?: PlaycademyExportOptions;
49
+ sandbox?: PlaycademySandboxOptions;
50
+ shell?: PlaycademyShellOptions;
51
+ }
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "name": "@playcademy/vite-plugin",
3
- "version": "0.1.25",
3
+ "version": "0.1.26-alpha.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
7
7
  "import": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts"
9
- },
10
- "./types": {
11
- "import": "./dist/types.js",
12
- "types": "./dist/types.d.ts"
13
9
  }
14
10
  },
15
11
  "main": "dist/index.js",
@@ -25,14 +21,13 @@
25
21
  "dependencies": {
26
22
  "archiver": "^7.0.1",
27
23
  "picocolors": "^1.1.1",
28
- "playcademy": "0.14.2"
24
+ "playcademy": "0.14.3"
29
25
  },
30
26
  "devDependencies": {
31
27
  "@inquirer/prompts": "^7.8.6",
32
28
  "@playcademy/sandbox": "0.1.9",
33
29
  "@types/archiver": "^6.0.3",
34
- "@types/bun": "latest",
35
- "yocto-spinner": "^0.2.2"
30
+ "@types/bun": "latest"
36
31
  },
37
32
  "peerDependencies": {
38
33
  "typescript": "^5",
package/dist/types.d.ts DELETED
@@ -1,97 +0,0 @@
1
- /**
2
- * Type definitions for the Playcademy Vite Plugin
3
- */
4
- import type { ResolvedConfig } from 'vite';
5
- import type { ManifestV1 } from '@playcademy/data/types';
6
- /**
7
- * Project information extracted from package.json and directory structure
8
- */
9
- export interface ProjectInfo {
10
- slug: string;
11
- displayName: string;
12
- version: string;
13
- description?: string;
14
- }
15
- /**
16
- * Configuration options for exporting Playcademy games
17
- */
18
- export interface PlaycademyExportOptions {
19
- bootMode?: ManifestV1['bootMode'];
20
- entryPoint?: string;
21
- styles?: string[];
22
- platform?: ManifestV1['platform'];
23
- autoZip?: boolean;
24
- }
25
- /**
26
- * Configuration options for the Playcademy sandbox server
27
- */
28
- export interface PlaycademySandboxOptions {
29
- autoStart?: boolean;
30
- url?: string;
31
- verbose?: boolean;
32
- }
33
- /**
34
- * Configuration options for the dev server shell
35
- */
36
- export interface PlaycademyDevOptions {
37
- /**
38
- * Show the Playcademy badge in the corner during development
39
- * @default true
40
- */
41
- showBadge?: boolean;
42
- }
43
- /**
44
- * Main plugin configuration options
45
- */
46
- export interface PlaycademyPluginOptions {
47
- export?: PlaycademyExportOptions;
48
- sandbox?: PlaycademySandboxOptions;
49
- dev?: PlaycademyDevOptions;
50
- }
51
- /**
52
- * Build output data for logging and tracking
53
- */
54
- export interface PlaycademyOutputData {
55
- manifestPath?: string;
56
- manifestSizeKb?: string;
57
- zipPath?: string;
58
- zipSizeKb?: string;
59
- }
60
- /**
61
- * Options for manifest generation
62
- */
63
- export interface ManifestOptions {
64
- bootMode: ManifestV1['bootMode'];
65
- entryPoint: string;
66
- styles: string[];
67
- platform: ManifestV1['platform'];
68
- }
69
- /**
70
- * Sandbox manager interface for controlling sandbox lifecycle
71
- */
72
- export interface SandboxManager {
73
- baseUrl: string;
74
- realtimeUrl: string;
75
- port: number;
76
- project: ProjectInfo | null;
77
- cleanup: () => void;
78
- }
79
- /**
80
- * CLI server manager interface for controlling backend server lifecycle
81
- */
82
- export interface CliServerManager {
83
- server: {
84
- dispose: () => Promise<void>;
85
- };
86
- port: number;
87
- stopHotReload: () => void;
88
- cleanup: () => void;
89
- }
90
- /**
91
- * Options for setting up the CLI dev server
92
- */
93
- export interface CliDevServerOptions {
94
- preferredPort: number;
95
- viteConfig: ResolvedConfig;
96
- platformUrl?: string;
97
- }
package/dist/types.js DELETED
File without changes
package/dist/utils.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Utility functions for the Playcademy Vite plugin
3
- */
4
- import type { ResolvedConfig } from 'vite';
5
- import type { ProjectInfo } from './types';
6
- export declare function extractProjectInfo(viteConfig: ResolvedConfig): ProjectInfo;
7
- export declare function formatNumberWithCommas(numStr: string): string;