playcademy 0.13.22 → 0.14.0

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.
@@ -2,24 +2,21 @@
2
2
  * Database Seed
3
3
  *
4
4
  * Populate the database with initial data.
5
+ * This seed function works both locally and remotely.
5
6
  */
6
7
 
7
- import Database from 'better-sqlite3'
8
- import { drizzle } from 'drizzle-orm/better-sqlite3'
9
-
10
- import { getPath } from 'playcademy/db'
11
-
8
+ import { getDb } from '.'
12
9
  import * as schema from './schema'
13
10
 
14
11
  /**
15
12
  * Seed the database with initial data
13
+ *
14
+ * @param c - Context with env bindings
16
15
  */
17
- export async function seed() {
18
- const dbPath = getPath()
19
- const sqlite = new Database(dbPath)
20
- const db = drizzle(sqlite, { schema })
16
+ export async function seed(c: Context) {
17
+ const db = getDb(c.env.DB)
21
18
 
22
- // Seed users
19
+ // Seed users
23
20
  const [user] = await db
24
21
  .insert(schema.users)
25
22
  .values({
@@ -40,13 +37,4 @@ export async function seed() {
40
37
  level: 1,
41
38
  createdAt: new Date().toISOString(),
42
39
  })
43
-
44
- sqlite.close()
45
- }
46
-
47
- /**
48
- * Run seed if this file is executed directly (from e.g. a package.json script)
49
- */
50
- if (import.meta.url === `file://${process.argv[1]}`) {
51
- seed().catch(console.error)
52
40
  }
package/dist/utils.js CHANGED
@@ -325,6 +325,33 @@ var init_config = __esm({
325
325
  }
326
326
  });
327
327
 
328
+ // src/constants/bucket.ts
329
+ var BUCKET_ALWAYS_SKIP;
330
+ var init_bucket = __esm({
331
+ "src/constants/bucket.ts"() {
332
+ "use strict";
333
+ init_config();
334
+ BUCKET_ALWAYS_SKIP = [".git", ".DS_Store", ".gitignore", ...ENV_FILES];
335
+ }
336
+ });
337
+
338
+ // src/constants/cloudflare.ts
339
+ var CLOUDFLARE_COMPATIBILITY_DATE, CLOUDFLARE_BINDINGS;
340
+ var init_cloudflare = __esm({
341
+ "src/constants/cloudflare.ts"() {
342
+ "use strict";
343
+ CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
344
+ CLOUDFLARE_BINDINGS = {
345
+ /** R2 bucket binding name */
346
+ BUCKET: "BUCKET",
347
+ /** KV namespace binding name */
348
+ KV: "KV",
349
+ /** D1 database binding name */
350
+ DB: "DB"
351
+ };
352
+ }
353
+ });
354
+
328
355
  // src/constants/database.ts
329
356
  var init_database = __esm({
330
357
  "src/constants/database.ts"() {
@@ -492,11 +519,12 @@ var init_urls = __esm({
492
519
  });
493
520
 
494
521
  // src/constants/index.ts
495
- var CLOUDFLARE_COMPATIBILITY_DATE;
496
522
  var init_constants = __esm({
497
523
  "src/constants/index.ts"() {
498
524
  "use strict";
499
525
  init_api();
526
+ init_bucket();
527
+ init_cloudflare();
500
528
  init_config();
501
529
  init_database();
502
530
  init_http_server();
@@ -504,7 +532,6 @@ var init_constants = __esm({
504
532
  init_ports();
505
533
  init_timeback();
506
534
  init_urls();
507
- CLOUDFLARE_COMPATIBILITY_DATE = "2024-01-01";
508
535
  }
509
536
  });
510
537
 
@@ -1252,6 +1279,13 @@ var init_game = __esm({
1252
1279
  }
1253
1280
  });
1254
1281
 
1282
+ // src/lib/core/gitignore.ts
1283
+ var init_gitignore = __esm({
1284
+ "src/lib/core/gitignore.ts"() {
1285
+ "use strict";
1286
+ }
1287
+ });
1288
+
1255
1289
  // src/lib/core/import.ts
1256
1290
  import { mkdtempSync, rmSync } from "fs";
1257
1291
  import { tmpdir } from "os";
@@ -1292,6 +1326,13 @@ var init_import = __esm({
1292
1326
  }
1293
1327
  });
1294
1328
 
1329
+ // src/lib/core/mime.ts
1330
+ var init_mime2 = __esm({
1331
+ "src/lib/core/mime.ts"() {
1332
+ "use strict";
1333
+ }
1334
+ });
1335
+
1295
1336
  // src/lib/core/index.ts
1296
1337
  var init_core = __esm({
1297
1338
  "src/lib/core/index.ts"() {
@@ -1301,8 +1342,10 @@ var init_core = __esm({
1301
1342
  init_context();
1302
1343
  init_errors();
1303
1344
  init_game();
1345
+ init_gitignore();
1304
1346
  init_import();
1305
1347
  init_logger();
1348
+ init_mime2();
1306
1349
  }
1307
1350
  });
1308
1351
 
@@ -1434,6 +1477,9 @@ var isDevelopment = () => {
1434
1477
  var isInteractiveTTY = () => {
1435
1478
  return typeof process !== "undefined" && Boolean(process.stdout && process.stdout.isTTY);
1436
1479
  };
1480
+ var isSilent = () => {
1481
+ return typeof process !== "undefined" && process.env.LOG_SILENT === "true";
1482
+ };
1437
1483
  var detectOutputFormat = () => {
1438
1484
  if (isBrowser()) {
1439
1485
  return "browser";
@@ -1554,6 +1600,7 @@ var getMinimumLogLevel = () => {
1554
1600
  return isProduction() ? "info" : "debug";
1555
1601
  };
1556
1602
  var shouldLog = (level) => {
1603
+ if (isSilent()) return false;
1557
1604
  const minLevel = getMinimumLogLevel();
1558
1605
  return levelPriority[level] >= levelPriority[minLevel];
1559
1606
  };
@@ -1943,6 +1990,7 @@ var dbSchemaScoresTemplate = loadTemplateString("database/db-schema-scores.ts");
1943
1990
  var dbSchemaIndexTemplate = loadTemplateString("database/db-schema-index.ts");
1944
1991
  var dbIndexTemplate = loadTemplateString("database/db-index.ts");
1945
1992
  var dbTypesTemplate = loadTemplateString("database/db-types.ts");
1993
+ var dbSeedTemplate = loadTemplateString("database/db-seed.ts");
1946
1994
  var packageTemplate = loadTemplateString("database/package.json");
1947
1995
  function hasDatabaseSetup() {
1948
1996
  const workspace = getWorkspace();
@@ -2000,6 +2048,8 @@ init_core();
2000
2048
  init_string();
2001
2049
 
2002
2050
  // src/lib/deploy/schema.ts
2051
+ init_constants2();
2052
+ init_config3();
2003
2053
  init_core();
2004
2054
 
2005
2055
  // src/lib/deploy/secrets.ts
@@ -2321,11 +2371,11 @@ async function startDevServer(options) {
2321
2371
  }
2322
2372
  ],
2323
2373
  bindings,
2324
- d1Databases: hasDatabase ? ["DB"] : [],
2374
+ d1Databases: hasDatabase ? [CLOUDFLARE_BINDINGS.DB] : [],
2325
2375
  d1Persist: dbDir,
2326
- kvNamespaces: hasKV ? ["KV"] : [],
2376
+ kvNamespaces: hasKV ? [CLOUDFLARE_BINDINGS.KV] : [],
2327
2377
  kvPersist: kvDir,
2328
- r2Buckets: hasBucket ? ["BUCKET"] : [],
2378
+ r2Buckets: hasBucket ? [CLOUDFLARE_BINDINGS.BUCKET] : [],
2329
2379
  r2Persist: bucketDir,
2330
2380
  compatibilityDate: CLOUDFLARE_COMPATIBILITY_DATE
2331
2381
  });
@@ -2363,7 +2413,7 @@ async function ensureBucketDirectory() {
2363
2413
  return bucketDir;
2364
2414
  }
2365
2415
  async function initializeDatabase(mf) {
2366
- const d1 = await mf.getD1Database("DB");
2416
+ const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
2367
2417
  await d1.exec("SELECT 1");
2368
2418
  }
2369
2419
  async function writeBackendServerInfo(port) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playcademy",
3
- "version": "0.13.22",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "main": "./dist/index.js",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@inquirer/prompts": "^7.8.6",
43
- "@playcademy/sdk": "0.1.10",
43
+ "@playcademy/sdk": "0.1.12",
44
44
  "better-sqlite3": "^12.4.1",
45
45
  "chokidar": "^4.0.3",
46
46
  "colorette": "^2.0.20",