@playcademy/vite-plugin 0.1.26-alpha.1 → 0.1.26-alpha.2

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/dist/index.js CHANGED
@@ -41138,11 +41138,25 @@ import { DEFAULT_PORTS as DEFAULT_PORTS3 } from "playcademy/constants";
41138
41138
  // src/server/state.ts
41139
41139
  var serverState = {
41140
41140
  sandbox: null,
41141
- backend: null
41141
+ backend: null,
41142
+ viteServer: null,
41143
+ currentMode: "platform"
41142
41144
  };
41143
41145
  function hasActiveServers() {
41144
41146
  return !!(serverState.backend || serverState.sandbox);
41145
41147
  }
41148
+ function getCurrentMode() {
41149
+ return serverState.currentMode;
41150
+ }
41151
+ function setCurrentMode(mode) {
41152
+ serverState.currentMode = mode;
41153
+ }
41154
+ function getViteServerRef() {
41155
+ return serverState.viteServer;
41156
+ }
41157
+ function setViteServerRef(server) {
41158
+ serverState.viteServer = server;
41159
+ }
41146
41160
 
41147
41161
  // src/server/cleanup.ts
41148
41162
  async function cleanupServers() {
@@ -41179,10 +41193,13 @@ function setupProcessShutdownHandlers() {
41179
41193
  process.on("SIGINT", shutdown);
41180
41194
  process.on("SIGTERM", shutdown);
41181
41195
  }
41196
+
41197
+ // src/server/mode-switcher.ts
41198
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
41182
41199
  // package.json
41183
41200
  var package_default = {
41184
41201
  name: "@playcademy/vite-plugin",
41185
- version: "0.1.25",
41202
+ version: "0.1.26",
41186
41203
  type: "module",
41187
41204
  exports: {
41188
41205
  ".": {
@@ -41197,8 +41214,8 @@ var package_default = {
41197
41214
  ],
41198
41215
  scripts: {
41199
41216
  build: "rm -rf dist && bun build.ts",
41200
- pub: "bun publish.ts",
41201
- docs: "typedoc --skipErrorChecking"
41217
+ docs: "typedoc --skipErrorChecking",
41218
+ pub: "bun publish.ts"
41202
41219
  },
41203
41220
  dependencies: {
41204
41221
  archiver: "^7.0.1",
@@ -205912,6 +205929,10 @@ function generateLoaderHTML(sandboxUrl, gameId, realtimeUrl, showBadge, gameUrl)
205912
205929
  }
205913
205930
  function devServerMiddleware(server, sandbox, gameUrl, showBadge) {
205914
205931
  server.middlewares.use("/", (req, res, next) => {
205932
+ if (getCurrentMode() !== "platform") {
205933
+ next();
205934
+ return;
205935
+ }
205915
205936
  if (req.url === "/" && req.method === "GET") {
205916
205937
  const secFetchDest = req.headers["sec-fetch-dest"];
205917
205938
  if (secFetchDest === "iframe") {
@@ -205979,28 +206000,77 @@ async function configureStandaloneMode(server, viteConfig, preferredPort) {
205979
206000
  });
205980
206001
  }
205981
206002
 
206003
+ // src/server/mode-switcher.ts
206004
+ async function toggleMode(options) {
206005
+ const currentMode = getCurrentMode();
206006
+ const newMode = currentMode === "platform" ? "standalone" : "platform";
206007
+ const viteServer = getViteServerRef();
206008
+ if (!viteServer) {
206009
+ options.viteConfig.logger.error("[Playcademy] Cannot toggle mode: no Vite server reference");
206010
+ return;
206011
+ }
206012
+ options.viteConfig.logger.info("");
206013
+ options.viteConfig.logger.info(import_picocolors7.default.yellow(`Switching from ${import_picocolors7.default.bold(currentMode)} to ${import_picocolors7.default.bold(newMode)} mode...`));
206014
+ options.viteConfig.logger.info("");
206015
+ await cleanupServers();
206016
+ await new Promise((resolve2) => setTimeout(resolve2, 100));
206017
+ setCurrentMode(newMode);
206018
+ if (newMode === "standalone") {
206019
+ await configureStandaloneMode(viteServer, options.viteConfig, options.platformModeOptions.preferredBackendPort);
206020
+ } else {
206021
+ await configurePlatformMode(viteServer, options.viteConfig, options.platformModeOptions);
206022
+ }
206023
+ options.viteConfig.logger.info("");
206024
+ options.viteConfig.logger.info(import_picocolors7.default.green(`✓ Switched to ${import_picocolors7.default.bold(newMode)} mode`));
206025
+ options.viteConfig.logger.info("");
206026
+ }
206027
+
205982
206028
  // src/hooks/configure-server.ts
205983
206029
  async function configureServerHook(server, context) {
205984
206030
  if (!context.viteConfig) {
205985
206031
  throw new Error("[Playcademy] Vite config not resolved before configureServer");
205986
206032
  }
206033
+ setViteServerRef(server);
206034
+ setCurrentMode(context.options.mode);
205987
206035
  setupProcessShutdownHandlers();
205988
206036
  if (hasActiveServers()) {
205989
206037
  await cleanupServers();
205990
206038
  await new Promise((resolve2) => setTimeout(resolve2, 100));
205991
206039
  }
205992
206040
  const preferredPort = context.backendPort ?? DEFAULT_PORTS3.BACKEND;
206041
+ const platformModeOptions = {
206042
+ startSandbox: context.options.startSandbox,
206043
+ verbose: context.options.verbose,
206044
+ sandboxUrl: context.options.sandboxUrl,
206045
+ recreateDb: context.options.recreateDb,
206046
+ showBadge: context.options.showBadge,
206047
+ preferredBackendPort: preferredPort
206048
+ };
205993
206049
  if (context.options.mode === "standalone") {
205994
206050
  await configureStandaloneMode(server, context.viteConfig, preferredPort);
205995
206051
  } else {
205996
- await configurePlatformMode(server, context.viteConfig, {
205997
- startSandbox: context.options.startSandbox,
205998
- verbose: context.options.verbose,
205999
- sandboxUrl: context.options.sandboxUrl,
206000
- recreateDb: context.options.recreateDb,
206001
- showBadge: context.options.showBadge,
206002
- preferredBackendPort: preferredPort
206003
- });
206052
+ await configurePlatformMode(server, context.viteConfig, platformModeOptions);
206053
+ }
206054
+ const originalBindCLIShortcuts = server.bindCLIShortcuts?.bind(server);
206055
+ if (originalBindCLIShortcuts) {
206056
+ server.bindCLIShortcuts = (options) => {
206057
+ originalBindCLIShortcuts({
206058
+ ...options,
206059
+ customShortcuts: [
206060
+ ...options?.customShortcuts || [],
206061
+ {
206062
+ key: "m",
206063
+ description: "toggle platform/standalone mode",
206064
+ action: async () => {
206065
+ await toggleMode({
206066
+ viteConfig: context.viteConfig,
206067
+ platformModeOptions
206068
+ });
206069
+ }
206070
+ }
206071
+ ]
206072
+ });
206073
+ };
206004
206074
  }
206005
206075
  }
206006
206076
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Mode switching functionality
3
+ * Handles toggling between platform and standalone modes
4
+ */
5
+ import type { ResolvedConfig } from 'vite';
6
+ import type { PlatformModeOptions } from './platform-mode';
7
+ export interface ModeSwitcherOptions {
8
+ viteConfig: ResolvedConfig;
9
+ platformModeOptions: PlatformModeOptions;
10
+ }
11
+ /**
12
+ * Toggle between platform and standalone modes
13
+ */
14
+ export declare function toggleMode(options: ModeSwitcherOptions): Promise<void>;
@@ -6,13 +6,17 @@
6
6
  * but the servers continue running in the same Node process. We maintain
7
7
  * these references at module scope to properly clean them up on restart.
8
8
  */
9
+ import type { ViteDevServer } from 'vite';
9
10
  import type { CliServerManager, SandboxManager } from '../types';
11
+ import type { PlaycademyMode } from '../types/options';
10
12
  /**
11
13
  * Module-level server references
12
14
  */
13
15
  export declare const serverState: {
14
16
  sandbox: SandboxManager | null;
15
17
  backend: CliServerManager | null;
18
+ viteServer: ViteDevServer | null;
19
+ currentMode: PlaycademyMode;
16
20
  };
17
21
  /**
18
22
  * Get sandbox server reference
@@ -34,3 +38,19 @@ export declare function setBackendRef(backend: CliServerManager | null): void;
34
38
  * Check if any servers are currently running
35
39
  */
36
40
  export declare function hasActiveServers(): boolean;
41
+ /**
42
+ * Get current mode
43
+ */
44
+ export declare function getCurrentMode(): PlaycademyMode;
45
+ /**
46
+ * Set current mode
47
+ */
48
+ export declare function setCurrentMode(mode: PlaycademyMode): void;
49
+ /**
50
+ * Get Vite dev server reference
51
+ */
52
+ export declare function getViteServerRef(): ViteDevServer | null;
53
+ /**
54
+ * Set Vite dev server reference
55
+ */
56
+ export declare function setViteServerRef(server: ViteDevServer | null): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/vite-plugin",
3
- "version": "0.1.26-alpha.1",
3
+ "version": "0.1.26-alpha.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,8 +15,8 @@
15
15
  ],
16
16
  "scripts": {
17
17
  "build": "rm -rf dist && bun build.ts",
18
- "pub": "bun publish.ts",
19
- "docs": "typedoc --skipErrorChecking"
18
+ "docs": "typedoc --skipErrorChecking",
19
+ "pub": "bun publish.ts"
20
20
  },
21
21
  "dependencies": {
22
22
  "archiver": "^7.0.1",