playcademy 0.14.21 → 0.14.23
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/constants.d.ts +35 -9
- package/dist/constants.js +33 -15
- package/dist/db.js +33 -27
- package/dist/index.js +215 -192
- package/dist/utils.js +109 -83
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -1708,9 +1708,15 @@ init_file_loader();
|
|
|
1708
1708
|
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
1709
1709
|
|
|
1710
1710
|
// src/constants/api.ts
|
|
1711
|
+
import { join as join2 } from "node:path";
|
|
1712
|
+
|
|
1713
|
+
// src/constants/server.ts
|
|
1711
1714
|
import { join } from "node:path";
|
|
1712
|
-
var
|
|
1713
|
-
var SERVER_LIB_DIRECTORY = join(
|
|
1715
|
+
var SERVER_ROOT_DIRECTORY = "server";
|
|
1716
|
+
var SERVER_LIB_DIRECTORY = join(SERVER_ROOT_DIRECTORY, "lib");
|
|
1717
|
+
|
|
1718
|
+
// src/constants/api.ts
|
|
1719
|
+
var DEFAULT_API_ROUTES_DIRECTORY = join2(SERVER_ROOT_DIRECTORY, "api");
|
|
1714
1720
|
|
|
1715
1721
|
// ../../package.json
|
|
1716
1722
|
var package_default = {
|
|
@@ -1835,12 +1841,20 @@ var ENV_FILES = [
|
|
|
1835
1841
|
".env.local"
|
|
1836
1842
|
// Overrides all (highest priority)
|
|
1837
1843
|
];
|
|
1844
|
+
var TSCONFIG_JSON = "tsconfig.json";
|
|
1845
|
+
var TSCONFIG_APP_JSON = "tsconfig.app.json";
|
|
1838
1846
|
var TSCONFIG_FILES = [
|
|
1839
|
-
|
|
1847
|
+
TSCONFIG_APP_JSON,
|
|
1840
1848
|
// Modern tooling (try first)
|
|
1841
|
-
|
|
1849
|
+
TSCONFIG_JSON
|
|
1842
1850
|
// Standard (fallback)
|
|
1843
1851
|
];
|
|
1852
|
+
var TSCONFIG_REQUIRED_INCLUDES = [
|
|
1853
|
+
"playcademy-env.d.ts",
|
|
1854
|
+
// Generated type definitions
|
|
1855
|
+
"server"
|
|
1856
|
+
// Server-side code
|
|
1857
|
+
];
|
|
1844
1858
|
|
|
1845
1859
|
// src/constants/bucket.ts
|
|
1846
1860
|
var BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
|
|
@@ -1857,41 +1871,41 @@ var CLOUDFLARE_BINDINGS = {
|
|
|
1857
1871
|
};
|
|
1858
1872
|
|
|
1859
1873
|
// src/constants/database.ts
|
|
1860
|
-
import { join as
|
|
1861
|
-
var DEFAULT_DATABASE_DIRECTORY =
|
|
1874
|
+
import { join as join3 } from "path";
|
|
1875
|
+
var DEFAULT_DATABASE_DIRECTORY = join3("server", "db");
|
|
1862
1876
|
var DRIZZLE_CONFIG_FILES = ["drizzle.config.ts", "drizzle.config.js"];
|
|
1863
1877
|
|
|
1864
1878
|
// src/constants/godot.ts
|
|
1865
|
-
import { join as
|
|
1879
|
+
import { join as join4 } from "node:path";
|
|
1866
1880
|
var GODOT_BUILD_DIRECTORIES = {
|
|
1867
1881
|
/** Root build directory (cleared before each export) */
|
|
1868
1882
|
ROOT: "build",
|
|
1869
1883
|
/** Web export subdirectory */
|
|
1870
|
-
WEB:
|
|
1884
|
+
WEB: join4("build", "web")
|
|
1871
1885
|
};
|
|
1872
1886
|
var GODOT_BUILD_OUTPUTS = {
|
|
1873
1887
|
/** Exported web build entry point */
|
|
1874
|
-
INDEX_HTML:
|
|
1888
|
+
INDEX_HTML: join4("build", "web", "index.html"),
|
|
1875
1889
|
/** Packaged zip file (created by Godot export) */
|
|
1876
|
-
ZIP:
|
|
1890
|
+
ZIP: join4("build", "web_playcademy.zip")
|
|
1877
1891
|
};
|
|
1878
1892
|
|
|
1879
1893
|
// src/constants/paths.ts
|
|
1880
|
-
import { join as
|
|
1894
|
+
import { join as join5 } from "path";
|
|
1881
1895
|
var WORKSPACE_NAME = ".playcademy";
|
|
1882
1896
|
var CLI_DIRECTORIES = {
|
|
1883
1897
|
/** Root directory for CLI artifacts in workspace */
|
|
1884
1898
|
WORKSPACE: WORKSPACE_NAME,
|
|
1885
1899
|
/** Database directory within workspace */
|
|
1886
|
-
DATABASE:
|
|
1900
|
+
DATABASE: join5(WORKSPACE_NAME, "db"),
|
|
1887
1901
|
/** KV storage directory within workspace */
|
|
1888
|
-
KV:
|
|
1902
|
+
KV: join5(WORKSPACE_NAME, "kv"),
|
|
1889
1903
|
/** Bucket storage directory within workspace */
|
|
1890
|
-
BUCKET:
|
|
1904
|
+
BUCKET: join5(WORKSPACE_NAME, "bucket")
|
|
1891
1905
|
};
|
|
1892
1906
|
var CLI_DEFAULT_OUTPUTS = {
|
|
1893
1907
|
/** Default worker bundle output for debug command */
|
|
1894
|
-
WORKER_BUNDLE:
|
|
1908
|
+
WORKER_BUNDLE: join5(WORKSPACE_NAME, "worker-bundle.js")
|
|
1895
1909
|
};
|
|
1896
1910
|
|
|
1897
1911
|
// src/constants/ports.ts
|
|
@@ -1947,7 +1961,7 @@ var CORE_GAME_UUIDS = {
|
|
|
1947
1961
|
// ../utils/src/package-manager.ts
|
|
1948
1962
|
import { execSync } from "child_process";
|
|
1949
1963
|
import { existsSync as existsSync2 } from "fs";
|
|
1950
|
-
import { join as
|
|
1964
|
+
import { join as join6 } from "path";
|
|
1951
1965
|
function isCommandAvailable(command) {
|
|
1952
1966
|
try {
|
|
1953
1967
|
execSync(`command -v ${command}`, { stdio: "ignore" });
|
|
@@ -1957,16 +1971,16 @@ function isCommandAvailable(command) {
|
|
|
1957
1971
|
}
|
|
1958
1972
|
}
|
|
1959
1973
|
function detectPackageManager(cwd = process.cwd()) {
|
|
1960
|
-
if (existsSync2(
|
|
1974
|
+
if (existsSync2(join6(cwd, "bun.lock")) || existsSync2(join6(cwd, "bun.lockb"))) {
|
|
1961
1975
|
return "bun";
|
|
1962
1976
|
}
|
|
1963
|
-
if (existsSync2(
|
|
1977
|
+
if (existsSync2(join6(cwd, "pnpm-lock.yaml"))) {
|
|
1964
1978
|
return "pnpm";
|
|
1965
1979
|
}
|
|
1966
|
-
if (existsSync2(
|
|
1980
|
+
if (existsSync2(join6(cwd, "yarn.lock"))) {
|
|
1967
1981
|
return "yarn";
|
|
1968
1982
|
}
|
|
1969
|
-
if (existsSync2(
|
|
1983
|
+
if (existsSync2(join6(cwd, "package-lock.json"))) {
|
|
1970
1984
|
return "npm";
|
|
1971
1985
|
}
|
|
1972
1986
|
return detectByCommandAvailability();
|
|
@@ -3192,14 +3206,14 @@ function processConfigVariables(config) {
|
|
|
3192
3206
|
|
|
3193
3207
|
// src/lib/dev/server.ts
|
|
3194
3208
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
3195
|
-
import { join as
|
|
3209
|
+
import { join as join16 } from "path";
|
|
3196
3210
|
import { Log, LogLevel, Miniflare } from "miniflare";
|
|
3197
3211
|
|
|
3198
3212
|
// ../utils/src/port.ts
|
|
3199
3213
|
import { existsSync as existsSync3, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3200
3214
|
import { createServer } from "node:net";
|
|
3201
3215
|
import { homedir } from "node:os";
|
|
3202
|
-
import { join as
|
|
3216
|
+
import { join as join7 } from "node:path";
|
|
3203
3217
|
async function isPortAvailableOnHost(port, host) {
|
|
3204
3218
|
return new Promise((resolve4) => {
|
|
3205
3219
|
const server = createServer();
|
|
@@ -3238,11 +3252,11 @@ async function findAvailablePort(startPort = 4321) {
|
|
|
3238
3252
|
}
|
|
3239
3253
|
function getRegistryPath() {
|
|
3240
3254
|
const home = homedir();
|
|
3241
|
-
const dir =
|
|
3255
|
+
const dir = join7(home, ".playcademy");
|
|
3242
3256
|
if (!existsSync3(dir)) {
|
|
3243
3257
|
mkdirSync(dir, { recursive: true });
|
|
3244
3258
|
}
|
|
3245
|
-
return
|
|
3259
|
+
return join7(dir, ".proc");
|
|
3246
3260
|
}
|
|
3247
3261
|
function readRegistry() {
|
|
3248
3262
|
const registryPath = getRegistryPath();
|
|
@@ -3325,7 +3339,7 @@ init_package_json();
|
|
|
3325
3339
|
// src/lib/secrets/env.ts
|
|
3326
3340
|
init_file_loader();
|
|
3327
3341
|
import { existsSync as existsSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
3328
|
-
import { join as
|
|
3342
|
+
import { join as join8 } from "path";
|
|
3329
3343
|
function parseEnvFile(contents) {
|
|
3330
3344
|
const secrets = {};
|
|
3331
3345
|
for (const line of contents.split("\n")) {
|
|
@@ -3361,10 +3375,10 @@ async function readEnvFile(workspace) {
|
|
|
3361
3375
|
return secrets;
|
|
3362
3376
|
}
|
|
3363
3377
|
function getLoadedEnvFiles(workspace) {
|
|
3364
|
-
return ENV_FILES.filter((filename) => existsSync4(
|
|
3378
|
+
return ENV_FILES.filter((filename) => existsSync4(join8(workspace, filename)));
|
|
3365
3379
|
}
|
|
3366
3380
|
function hasEnvFile(workspace) {
|
|
3367
|
-
return ENV_FILES.some((filename) => existsSync4(
|
|
3381
|
+
return ENV_FILES.some((filename) => existsSync4(join8(workspace, filename)));
|
|
3368
3382
|
}
|
|
3369
3383
|
|
|
3370
3384
|
// src/lib/templates/loader.ts
|
|
@@ -3391,12 +3405,12 @@ function loadTemplateString(filename) {
|
|
|
3391
3405
|
// src/lib/core/import.ts
|
|
3392
3406
|
import { mkdtempSync, rmSync } from "fs";
|
|
3393
3407
|
import { tmpdir } from "os";
|
|
3394
|
-
import { join as
|
|
3408
|
+
import { join as join9 } from "path";
|
|
3395
3409
|
import { pathToFileURL } from "url";
|
|
3396
3410
|
import * as esbuild from "esbuild";
|
|
3397
3411
|
async function importTypescriptFile(filePath, bundleOptions) {
|
|
3398
|
-
const tempDir = mkdtempSync(
|
|
3399
|
-
const outFile =
|
|
3412
|
+
const tempDir = mkdtempSync(join9(tmpdir(), "playcademy-import-"));
|
|
3413
|
+
const outFile = join9(tempDir, "bundle.mjs");
|
|
3400
3414
|
try {
|
|
3401
3415
|
await esbuild.build({
|
|
3402
3416
|
entryPoints: [filePath],
|
|
@@ -3425,7 +3439,7 @@ async function importTypescriptDefault(filePath, bundleOptions) {
|
|
|
3425
3439
|
|
|
3426
3440
|
// src/lib/deploy/bundle.ts
|
|
3427
3441
|
import { existsSync as existsSync6 } from "fs";
|
|
3428
|
-
import { join as
|
|
3442
|
+
import { join as join11 } from "path";
|
|
3429
3443
|
|
|
3430
3444
|
// ../edge-play/src/entry.ts
|
|
3431
3445
|
var entry_default = "/**\n * Game Backend Entry Point\n *\n * This file is the main entry point for deployed game backends.\n * It creates a Hono app and registers all enabled integration routes.\n *\n * Bundled with esbuild and deployed to Cloudflare Workers (or AWS Lambda).\n * Config is injected at build time via esbuild's `define` option.\n *\n * DO NOT REMOVE any code wrapped by \u26A0\uFE0F BUILD_MARKER: <marker> \u26A0\uFE0F\n */\n\nimport { Hono } from 'hono'\n\nimport {\n registerApiNotFoundHandler,\n registerAssetFallback,\n registerCors,\n registerEnvSetup,\n registerPlaycademyUser,\n registerSdkInit,\n} from './entry/middleware'\nimport { setupProcessGlobal } from './entry/setup'\nimport { registerBuiltinRoutes } from './register-routes'\n\nimport type { RuntimeConfig } from './entry/types'\nimport type { HonoEnv } from './types'\n\n// DO NOT REMOVE THE BELOW COMMENT\n// \u26A0\uFE0F BUILD_MARKER: CUSTOM_ROUTE_IMPORTS \u26A0\uFE0F\n\n/**\n * Config injected at build time by esbuild\n *\n * The `declare const` tells TypeScript \"this exists at runtime, trust me.\"\n * During bundling, esbuild's `define` option does literal text replacement:\n *\n * Example bundling:\n * Source: if (PLAYCADEMY_CONFIG.integrations.timeback) { ... }\n * Define: { 'PLAYCADEMY_CONFIG': JSON.stringify({ integrations: { timeback: {...} } }) }\n * Output: if ({\"integrations\":{\"timeback\":{...}}}.integrations.timeback) { ... }\n *\n * This enables tree-shaking: if timeback is not configured, those code paths are removed.\n * The bundled Worker only includes the routes that are actually enabled.\n */\ndeclare const PLAYCADEMY_CONFIG: RuntimeConfig\n\n// Setup process global polyfill for SDK compatibility\nsetupProcessGlobal()\n\n// Create Hono app\nconst app = new Hono<HonoEnv>()\n\n// Register middleware\nregisterCors(app)\nregisterEnvSetup(app, PLAYCADEMY_CONFIG)\nregisterSdkInit(app, PLAYCADEMY_CONFIG)\nregisterPlaycademyUser(app)\n\n// DO NOT REMOVE THE BELOW COMMENT\n// \u26A0\uFE0F BUILD_MARKER: SESSION_MIDDLEWARE \u26A0\uFE0F\n\n// Register built-in integration routes based on enabled integrations\n// This function conditionally imports and registers routes like:\n// - GET /api (always included)\n// - GET /api/health (always included)\n// - POST /api/integrations/timeback/end-activity (if timeback enabled)\n//\n// Uses dynamic imports for tree-shaking: if an integration is not enabled,\n// its route code is completely removed from the bundle.\nawait registerBuiltinRoutes(app, PLAYCADEMY_CONFIG.integrations)\n\n// DO NOT REMOVE THE BELOW COMMENT\n// \u26A0\uFE0F BUILD_MARKER: CUSTOM_ROUTES \u26A0\uFE0F\n\n// Register API 404 handler\n// Returns JSON error for unmatched /api/* routes\n// Must be registered after all API routes\nregisterApiNotFoundHandler(app)\n\n// Register static asset fallback handler\n// Serves frontend assets from Workers Assets binding\n// MUST be registered last as it uses a wildcard GET route (app.get('*', ...))\n//\n// In production: Serves frontend assets from Workers Assets binding\n// In local dev: Returns 404 (Vite serves the frontend separately)\nregisterAssetFallback(app)\n\nexport default app\n";
|
|
@@ -3698,7 +3712,7 @@ function textLoaderPlugin() {
|
|
|
3698
3712
|
init_file_loader();
|
|
3699
3713
|
import { mkdir, writeFile } from "fs/promises";
|
|
3700
3714
|
import { tmpdir as tmpdir2 } from "os";
|
|
3701
|
-
import { join as
|
|
3715
|
+
import { join as join10, relative } from "path";
|
|
3702
3716
|
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
3703
3717
|
|
|
3704
3718
|
// src/lib/deploy/hash.ts
|
|
@@ -3718,8 +3732,8 @@ async function discoverRoutes(apiDir) {
|
|
|
3718
3732
|
const routes = await Promise.all(
|
|
3719
3733
|
files.map(async (file) => {
|
|
3720
3734
|
const routePath = filePathToRoutePath(file);
|
|
3721
|
-
const absolutePath =
|
|
3722
|
-
const relativePath = relative(getWorkspace(), absolutePath);
|
|
3735
|
+
const absolutePath = join10(apiDir, file);
|
|
3736
|
+
const relativePath = relative(getWorkspace(), absolutePath).replace(/\\/g, "/");
|
|
3723
3737
|
const methods = await detectExportedMethods(absolutePath);
|
|
3724
3738
|
return {
|
|
3725
3739
|
path: routePath,
|
|
@@ -3780,10 +3794,10 @@ async function transpileRoute(filePath) {
|
|
|
3780
3794
|
if (!result.outputFiles?.[0]) {
|
|
3781
3795
|
throw new Error("Transpilation failed: no output");
|
|
3782
3796
|
}
|
|
3783
|
-
const tempDir =
|
|
3797
|
+
const tempDir = join10(tmpdir2(), "playcademy-dev");
|
|
3784
3798
|
await mkdir(tempDir, { recursive: true });
|
|
3785
3799
|
const hash = hashContent(filePath).slice(0, 12);
|
|
3786
|
-
const jsPath =
|
|
3800
|
+
const jsPath = join10(tempDir, `${hash}.mjs`);
|
|
3787
3801
|
await writeFile(jsPath, result.outputFiles[0].text);
|
|
3788
3802
|
return jsPath;
|
|
3789
3803
|
}
|
|
@@ -3794,7 +3808,7 @@ async function discoverCustomRoutes(config) {
|
|
|
3794
3808
|
const workspace = getWorkspace();
|
|
3795
3809
|
const customRoutesConfig = config.integrations?.customRoutes;
|
|
3796
3810
|
const customRoutesDir = typeof customRoutesConfig === "object" && customRoutesConfig.directory || DEFAULT_API_ROUTES_DIRECTORY;
|
|
3797
|
-
const customRoutes = await discoverRoutes(
|
|
3811
|
+
const customRoutes = await discoverRoutes(join11(workspace, customRoutesDir));
|
|
3798
3812
|
const customRouteData = customRoutes.map((r) => ({
|
|
3799
3813
|
path: r.path,
|
|
3800
3814
|
file: r.file,
|
|
@@ -3806,15 +3820,15 @@ async function discoverCustomRoutes(config) {
|
|
|
3806
3820
|
function resolveEmbeddedSourcePaths() {
|
|
3807
3821
|
const workspace = getWorkspace();
|
|
3808
3822
|
const distDir = new URL(".", import.meta.url).pathname;
|
|
3809
|
-
const embeddedEdgeSrc =
|
|
3823
|
+
const embeddedEdgeSrc = join11(distDir, "edge-play", "src");
|
|
3810
3824
|
const isBuiltPackage = existsSync6(embeddedEdgeSrc);
|
|
3811
3825
|
const monorepoRoot = getMonorepoRoot();
|
|
3812
|
-
const monorepoEdgeSrc =
|
|
3826
|
+
const monorepoEdgeSrc = join11(monorepoRoot, "packages/edge-play/src");
|
|
3813
3827
|
const edgePlaySrc = isBuiltPackage ? embeddedEdgeSrc : monorepoEdgeSrc;
|
|
3814
|
-
const cliPackageRoot = isBuiltPackage ?
|
|
3815
|
-
const cliNodeModules = isBuiltPackage ?
|
|
3816
|
-
const workspaceNodeModules =
|
|
3817
|
-
const constantsEntry = isBuiltPackage ?
|
|
3828
|
+
const cliPackageRoot = isBuiltPackage ? join11(distDir, "../../..") : join11(monorepoRoot, "packages/cli");
|
|
3829
|
+
const cliNodeModules = isBuiltPackage ? join11(cliPackageRoot, "node_modules") : monorepoRoot;
|
|
3830
|
+
const workspaceNodeModules = join11(workspace, "node_modules");
|
|
3831
|
+
const constantsEntry = isBuiltPackage ? join11(embeddedEdgeSrc, "..", "..", "constants", "src", "index.ts") : join11(monorepoRoot, "packages", "constants", "src", "index.ts");
|
|
3818
3832
|
return {
|
|
3819
3833
|
isBuiltPackage,
|
|
3820
3834
|
edgePlaySrc,
|
|
@@ -3879,22 +3893,22 @@ function createEsbuildConfig(entryCode, paths, bundleConfig, customRoutesDir, op
|
|
|
3879
3893
|
// │ Example: import * as route from '@game-api/hello.ts' │
|
|
3880
3894
|
// │ Resolves to: /user-project/server/api/hello.ts │
|
|
3881
3895
|
// └─────────────────────────────────────────────────────────────────┘
|
|
3882
|
-
"@game-api":
|
|
3896
|
+
"@game-api": join11(workspace, customRoutesDir),
|
|
3883
3897
|
// ┌─ User's server lib directory ───────────────────────────────────┐
|
|
3884
3898
|
// │ @game-server is a virtual module for server utilities/config │
|
|
3885
3899
|
// │ Example: import { getAuth } from '@game-server/lib/auth' │
|
|
3886
3900
|
// │ Resolves to: /user-project/server/lib/auth.ts │
|
|
3887
3901
|
// └─────────────────────────────────────────────────────────────────┘
|
|
3888
|
-
"@game-server":
|
|
3902
|
+
"@game-server": join11(workspace, "server"),
|
|
3889
3903
|
// ┌─ Node.js polyfills for Cloudflare Workers ──────────────────────┐
|
|
3890
3904
|
// │ Workers don't have fs, path, os, etc. Redirect to polyfills │
|
|
3891
3905
|
// │ that throw helpful errors if user code tries to use them. │
|
|
3892
3906
|
// └─────────────────────────────────────────────────────────────────┘
|
|
3893
|
-
fs:
|
|
3894
|
-
"fs/promises":
|
|
3895
|
-
path:
|
|
3896
|
-
os:
|
|
3897
|
-
process:
|
|
3907
|
+
fs: join11(edgePlaySrc, "polyfills.js"),
|
|
3908
|
+
"fs/promises": join11(edgePlaySrc, "polyfills.js"),
|
|
3909
|
+
path: join11(edgePlaySrc, "polyfills.js"),
|
|
3910
|
+
os: join11(edgePlaySrc, "polyfills.js"),
|
|
3911
|
+
process: join11(edgePlaySrc, "polyfills.js")
|
|
3898
3912
|
},
|
|
3899
3913
|
// ──── Build Plugins ────
|
|
3900
3914
|
plugins: [textLoaderPlugin()],
|
|
@@ -3984,12 +3998,12 @@ var protectedRouteTemplate = loadTemplateString("api/sample-protected.ts");
|
|
|
3984
3998
|
|
|
3985
3999
|
// src/lib/init/database.ts
|
|
3986
4000
|
import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
3987
|
-
import { join as
|
|
4001
|
+
import { join as join12 } from "path";
|
|
3988
4002
|
|
|
3989
4003
|
// package.json
|
|
3990
4004
|
var package_default2 = {
|
|
3991
4005
|
name: "playcademy",
|
|
3992
|
-
version: "0.14.
|
|
4006
|
+
version: "0.14.22",
|
|
3993
4007
|
type: "module",
|
|
3994
4008
|
exports: {
|
|
3995
4009
|
".": {
|
|
@@ -4076,7 +4090,7 @@ var dbSeedTemplate = loadTemplateString("database/db-seed.ts");
|
|
|
4076
4090
|
var packageTemplate = loadTemplateString("database/package.json");
|
|
4077
4091
|
function hasDatabaseSetup() {
|
|
4078
4092
|
const workspace = getWorkspace();
|
|
4079
|
-
return DRIZZLE_CONFIG_FILES.some((filename) => existsSync7(
|
|
4093
|
+
return DRIZZLE_CONFIG_FILES.some((filename) => existsSync7(join12(workspace, filename)));
|
|
4080
4094
|
}
|
|
4081
4095
|
|
|
4082
4096
|
// src/lib/init/scaffold.ts
|
|
@@ -4100,16 +4114,16 @@ function hasBucketSetup(config) {
|
|
|
4100
4114
|
init_file_loader();
|
|
4101
4115
|
import { execSync as execSync2 } from "child_process";
|
|
4102
4116
|
import { existsSync as existsSync10, writeFileSync as writeFileSync5 } from "fs";
|
|
4103
|
-
import { dirname as dirname4, join as
|
|
4117
|
+
import { dirname as dirname4, join as join15 } from "path";
|
|
4104
4118
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
4105
4119
|
|
|
4106
4120
|
// src/lib/deploy/backend.ts
|
|
4107
4121
|
import { existsSync as existsSync8 } from "node:fs";
|
|
4108
|
-
import { join as
|
|
4122
|
+
import { join as join13 } from "node:path";
|
|
4109
4123
|
function getCustomRoutesDirectory(projectPath, config) {
|
|
4110
4124
|
const customRoutes = config?.integrations?.customRoutes;
|
|
4111
4125
|
const customRoutesDir = typeof customRoutes === "object" && customRoutes.directory || DEFAULT_API_ROUTES_DIRECTORY;
|
|
4112
|
-
return
|
|
4126
|
+
return join13(projectPath, customRoutesDir);
|
|
4113
4127
|
}
|
|
4114
4128
|
function hasLocalCustomRoutes(projectPath, config) {
|
|
4115
4129
|
const customRoutesDir = getCustomRoutesDirectory(projectPath, config);
|
|
@@ -4119,15 +4133,22 @@ function hasLocalCustomRoutes(projectPath, config) {
|
|
|
4119
4133
|
// src/lib/init/tsconfig.ts
|
|
4120
4134
|
init_file_loader();
|
|
4121
4135
|
import { existsSync as existsSync9, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
4122
|
-
import { join as
|
|
4123
|
-
function
|
|
4124
|
-
|
|
4136
|
+
import { join as join14 } from "path";
|
|
4137
|
+
function hasAllRequiredIncludes(config) {
|
|
4138
|
+
if (!config.include) return false;
|
|
4139
|
+
return TSCONFIG_REQUIRED_INCLUDES.every((entry) => config.include.includes(entry));
|
|
4125
4140
|
}
|
|
4126
|
-
function
|
|
4141
|
+
function getMissingIncludes(config) {
|
|
4142
|
+
if (!config.include) return [...TSCONFIG_REQUIRED_INCLUDES];
|
|
4143
|
+
return TSCONFIG_REQUIRED_INCLUDES.filter((entry) => !config.include.includes(entry));
|
|
4144
|
+
}
|
|
4145
|
+
function addRequiredIncludes(config) {
|
|
4127
4146
|
if (!config.include) {
|
|
4128
4147
|
config.include = [];
|
|
4129
4148
|
}
|
|
4130
|
-
config
|
|
4149
|
+
for (const entry of getMissingIncludes(config)) {
|
|
4150
|
+
config.include.push(entry);
|
|
4151
|
+
}
|
|
4131
4152
|
}
|
|
4132
4153
|
function updateExistingIncludeArray(content) {
|
|
4133
4154
|
const includeRegex = /"include"\s*:\s*\[([^\]]*)\]/;
|
|
@@ -4137,20 +4158,24 @@ function updateExistingIncludeArray(content) {
|
|
|
4137
4158
|
}
|
|
4138
4159
|
const fullMatch = match[0];
|
|
4139
4160
|
const arrayContents = match[1];
|
|
4140
|
-
|
|
4161
|
+
const missingEntries = TSCONFIG_REQUIRED_INCLUDES.filter(
|
|
4162
|
+
(entry) => !arrayContents.includes(entry)
|
|
4163
|
+
);
|
|
4164
|
+
if (missingEntries.length === 0) {
|
|
4141
4165
|
return content;
|
|
4142
4166
|
}
|
|
4143
4167
|
const trimmedContents = arrayContents.trim();
|
|
4144
|
-
const
|
|
4168
|
+
const newEntries = missingEntries.map((entry) => `"${entry}"`);
|
|
4145
4169
|
let newArrayContents;
|
|
4146
4170
|
if (trimmedContents === "") {
|
|
4147
|
-
newArrayContents =
|
|
4171
|
+
newArrayContents = newEntries.join(", ");
|
|
4148
4172
|
} else if (arrayContents.includes("\n")) {
|
|
4149
|
-
|
|
4150
|
-
${
|
|
4173
|
+
const entriesStr = newEntries.map((e) => `
|
|
4174
|
+
${e}`).join(",");
|
|
4175
|
+
newArrayContents = `${arrayContents},${entriesStr}
|
|
4151
4176
|
`;
|
|
4152
4177
|
} else {
|
|
4153
|
-
newArrayContents = `${trimmedContents}, ${
|
|
4178
|
+
newArrayContents = `${trimmedContents}, ${newEntries.join(", ")}`;
|
|
4154
4179
|
}
|
|
4155
4180
|
const newIncludeArray = `"include": [${newArrayContents}]`;
|
|
4156
4181
|
return content.replace(fullMatch, newIncludeArray);
|
|
@@ -4165,9 +4190,10 @@ function addNewIncludeProperty(content) {
|
|
|
4165
4190
|
const insertPosition = closingBraceMatch.index;
|
|
4166
4191
|
const beforeClosing = content.slice(0, insertPosition).trim();
|
|
4167
4192
|
const needsComma = beforeClosing.endsWith("]") || beforeClosing.endsWith("}") || beforeClosing.endsWith('"');
|
|
4193
|
+
const entriesStr = TSCONFIG_REQUIRED_INCLUDES.map((e) => `"${e}"`).join(", ");
|
|
4168
4194
|
const comma = needsComma ? "," : "";
|
|
4169
4195
|
const includeEntry = `${comma}
|
|
4170
|
-
${propertyIndent}"include": [
|
|
4196
|
+
${propertyIndent}"include": [${entriesStr}]`;
|
|
4171
4197
|
const updatedContent = content.slice(0, insertPosition) + includeEntry + content.slice(insertPosition);
|
|
4172
4198
|
return updatedContent;
|
|
4173
4199
|
}
|
|
@@ -4176,7 +4202,7 @@ function addToIncludeArrayPreservingComments(content) {
|
|
|
4176
4202
|
}
|
|
4177
4203
|
async function ensureTsconfigIncludes(workspace) {
|
|
4178
4204
|
for (const filename of TSCONFIG_FILES) {
|
|
4179
|
-
const configPath =
|
|
4205
|
+
const configPath = join14(workspace, filename);
|
|
4180
4206
|
if (!existsSync9(configPath)) {
|
|
4181
4207
|
continue;
|
|
4182
4208
|
}
|
|
@@ -4186,10 +4212,10 @@ async function ensureTsconfigIncludes(workspace) {
|
|
|
4186
4212
|
stripComments: true
|
|
4187
4213
|
});
|
|
4188
4214
|
if (!config) continue;
|
|
4189
|
-
if (config.references && filename !==
|
|
4215
|
+
if (config.references && filename !== TSCONFIG_JSON) {
|
|
4190
4216
|
continue;
|
|
4191
4217
|
}
|
|
4192
|
-
if (
|
|
4218
|
+
if (hasAllRequiredIncludes(config)) {
|
|
4193
4219
|
return filename;
|
|
4194
4220
|
}
|
|
4195
4221
|
try {
|
|
@@ -4201,7 +4227,7 @@ async function ensureTsconfigIncludes(workspace) {
|
|
|
4201
4227
|
}
|
|
4202
4228
|
} catch {
|
|
4203
4229
|
}
|
|
4204
|
-
|
|
4230
|
+
addRequiredIncludes(config);
|
|
4205
4231
|
writeFileSync4(configPath, JSON.stringify(config, null, 4) + "\n");
|
|
4206
4232
|
return filename;
|
|
4207
4233
|
} catch {
|
|
@@ -4226,8 +4252,8 @@ function hasAnyBackend(features) {
|
|
|
4226
4252
|
return Object.values(features).some(Boolean);
|
|
4227
4253
|
}
|
|
4228
4254
|
async function setupPlaycademyDependencies(workspace) {
|
|
4229
|
-
const playcademyDir =
|
|
4230
|
-
const playcademyPkgPath =
|
|
4255
|
+
const playcademyDir = join15(workspace, CLI_DIRECTORIES.WORKSPACE);
|
|
4256
|
+
const playcademyPkgPath = join15(playcademyDir, "package.json");
|
|
4231
4257
|
const __dirname = dirname4(fileURLToPath2(import.meta.url));
|
|
4232
4258
|
const cliPkg = await loadPackageJson({ cwd: __dirname, searchUp: true, required: true });
|
|
4233
4259
|
const workersTypesVersion = cliPkg?.devDependencies?.["@cloudflare/workers-types"] || "latest";
|
|
@@ -4312,14 +4338,14 @@ async function ensurePlaycademyTypes(options = {}) {
|
|
|
4312
4338
|
const bindingsStr = generateBindingsTypeString(features);
|
|
4313
4339
|
const secretsStr = await generateSecretsTypeString(workspace, verbose);
|
|
4314
4340
|
const hasAuth = !!config.integrations?.auth;
|
|
4315
|
-
const hasAuthFile = existsSync10(
|
|
4341
|
+
const hasAuthFile = existsSync10(join15(workspace, "server/lib/auth.ts"));
|
|
4316
4342
|
const authVariablesString = generateAuthVariablesString(hasAuth, hasAuthFile);
|
|
4317
4343
|
let envContent = playcademyEnvTemplate.replace("{{BINDINGS}}", bindingsStr);
|
|
4318
4344
|
envContent = envContent.replace("{{SECRETS}}", secretsStr);
|
|
4319
4345
|
envContent = envContent.replace("{{AUTH_IMPORT}}", authVariablesString.authImport);
|
|
4320
4346
|
envContent = envContent.replace("{{VARIABLES}}", authVariablesString.variables);
|
|
4321
4347
|
envContent = envContent.replace("{{CONTEXT_VARS}}", authVariablesString.contextVars);
|
|
4322
|
-
const envPath =
|
|
4348
|
+
const envPath = join15(workspace, "playcademy-env.d.ts");
|
|
4323
4349
|
writeFileSync5(envPath, envContent);
|
|
4324
4350
|
if (verbose) {
|
|
4325
4351
|
logger.success(`Generated <playcademy-env.d.ts>`);
|
|
@@ -4432,7 +4458,7 @@ async function startDevServer(options) {
|
|
|
4432
4458
|
return { server: mf, port };
|
|
4433
4459
|
}
|
|
4434
4460
|
async function ensureDatabaseDirectory() {
|
|
4435
|
-
const dbDir =
|
|
4461
|
+
const dbDir = join16(getWorkspace(), CLI_DIRECTORIES.DATABASE);
|
|
4436
4462
|
try {
|
|
4437
4463
|
await mkdir2(dbDir, { recursive: true });
|
|
4438
4464
|
} catch (error) {
|
|
@@ -4441,7 +4467,7 @@ async function ensureDatabaseDirectory() {
|
|
|
4441
4467
|
return dbDir;
|
|
4442
4468
|
}
|
|
4443
4469
|
async function ensureKvDirectory() {
|
|
4444
|
-
const kvDir =
|
|
4470
|
+
const kvDir = join16(getWorkspace(), CLI_DIRECTORIES.KV);
|
|
4445
4471
|
try {
|
|
4446
4472
|
await mkdir2(kvDir, { recursive: true });
|
|
4447
4473
|
} catch (error) {
|
|
@@ -4450,7 +4476,7 @@ async function ensureKvDirectory() {
|
|
|
4450
4476
|
return kvDir;
|
|
4451
4477
|
}
|
|
4452
4478
|
async function ensureBucketDirectory() {
|
|
4453
|
-
const bucketDir =
|
|
4479
|
+
const bucketDir = join16(getWorkspace(), CLI_DIRECTORIES.BUCKET);
|
|
4454
4480
|
try {
|
|
4455
4481
|
await mkdir2(bucketDir, { recursive: true });
|
|
4456
4482
|
} catch (error) {
|
|
@@ -4473,7 +4499,7 @@ async function writeBackendServerInfo(port) {
|
|
|
4473
4499
|
}
|
|
4474
4500
|
|
|
4475
4501
|
// src/lib/dev/reload.ts
|
|
4476
|
-
import { join as
|
|
4502
|
+
import { join as join17, relative as relative2 } from "path";
|
|
4477
4503
|
import chokidar from "chokidar";
|
|
4478
4504
|
import { bold as bold5, cyan as cyan3, dim as dim4, green as green2 } from "colorette";
|
|
4479
4505
|
function formatTime() {
|
|
@@ -4490,9 +4516,9 @@ function startHotReload(onReload, options = {}) {
|
|
|
4490
4516
|
const customRoutesConfig = options.config?.integrations?.customRoutes;
|
|
4491
4517
|
const customRoutesDir = typeof customRoutesConfig === "object" && customRoutesConfig.directory || DEFAULT_API_ROUTES_DIRECTORY;
|
|
4492
4518
|
const watchPaths = [
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4519
|
+
join17(workspace, customRoutesDir),
|
|
4520
|
+
join17(workspace, "playcademy.config.js"),
|
|
4521
|
+
join17(workspace, "playcademy.config.json")
|
|
4496
4522
|
];
|
|
4497
4523
|
const watcher = chokidar.watch(watchPaths, {
|
|
4498
4524
|
persistent: true,
|
package/dist/version.js
CHANGED