@divizend/scratch-core 1.0.0 → 1.0.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/basic/index.ts CHANGED
@@ -347,7 +347,9 @@ class BasicParser {
347
347
  this.statements.push(
348
348
  `${" ".repeat(
349
349
  this.indent
350
- )}context.result = await context.universe!.call(context, "${endpointName}"${argsStr ? `, ${argsStr}` : ""});`
350
+ )}context.result = await context.universe!.call(context, "${endpointName}"${
351
+ argsStr ? `, ${argsStr}` : ""
352
+ });`
351
353
  );
352
354
  }
353
355
  }
@@ -488,3 +490,6 @@ export function compileBasicToTypeScript(
488
490
  const compiler = new BasicCompiler();
489
491
  return compiler.compile(basicCode, opcode);
490
492
  }
493
+
494
+ // Export DEFAULT_BASIC_DEMO from demo.ts
495
+ export { DEFAULT_BASIC_DEMO } from "./demo";
@@ -28,7 +28,16 @@ export async function getProjectRoot(): Promise<string> {
28
28
  const __dirname = dirname(__filename);
29
29
 
30
30
  // Start from the current file's directory and walk up
31
+ // If we're in node_modules, walk up to the actual project root
31
32
  let currentDir = resolve(__dirname);
33
+
34
+ // If we're in node_modules/@divizend/scratch-core, walk up to the workspace root
35
+ if (currentDir.includes("node_modules/@divizend/scratch-core")) {
36
+ // Walk up from node_modules/@divizend/scratch-core to the workspace root
37
+ while (currentDir.includes("node_modules") && currentDir !== dirname(currentDir)) {
38
+ currentDir = dirname(currentDir);
39
+ }
40
+ }
32
41
 
33
42
  // Marker files that indicate project root
34
43
  const markers = ["package.json", "tsconfig.json"];
package/core/Universe.ts CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  } from "..";
25
25
  import { Auth } from "./Auth";
26
26
  import { HttpServer } from "../http-server";
27
- import { NativeHttpServer } from "../http-server/NativeHttpServer";
27
+ import { ExpressHttpServer } from "../http-server/ExpressHttpServer";
28
28
  import { ScratchContext, ScratchBlock } from "./Scratch";
29
29
  import { resolve, join, dirname } from "node:path";
30
30
  import { fileURLToPath } from "node:url";
@@ -76,10 +76,8 @@ export class Universe {
76
76
  */
77
77
  static async construct({
78
78
  gsuite: initGSuite = true,
79
- endpointsDirectory,
80
79
  }: {
81
80
  gsuite?: boolean;
82
- endpointsDirectory?: string;
83
81
  } = {}): Promise<Universe> {
84
82
  const universe = new Universe();
85
83
 
@@ -187,36 +185,31 @@ export class Universe {
187
185
  universe.emailQueue = new EmailQueue(profiles);
188
186
 
189
187
  // Initialize HTTP server
190
- universe.httpServer = new NativeHttpServer(universe);
191
-
188
+ universe.httpServer = new ExpressHttpServer(universe);
189
+
190
+ // Initialize default endpoints (loadEndpoints, loadEndpointsUI) - BEFORE static files
191
+ await universe.httpServer.initializeDefaultEndpoints();
192
+
192
193
  // Get project root for static files
193
194
  const { getProjectRoot } = await import("./ProjectRoot");
194
195
  const projectRoot = await getProjectRoot();
195
196
 
196
- // Register static files
197
+ // Register static files - AFTER endpoints so endpoints take precedence
197
198
  universe.httpServer.registerStaticFiles(projectRoot);
198
199
 
199
- // Load and register endpoints (if directory is provided)
200
- if (endpointsDirectory) {
201
- const endpointsDir = resolve(endpointsDirectory);
202
- await universe.httpServer.loadEndpointsFromDirectory(endpointsDir);
203
- }
204
-
205
- // Log all registered endpoints (if endpoints were loaded)
206
- if (endpointsDirectory) {
207
- const endpointInfos = await universe.httpServer.getRegisteredEndpoints();
208
- console.log("\nšŸ“‹ Registered Scratch Endpoints:");
209
- console.log("=".repeat(50));
210
- endpointInfos.forEach((info) => {
211
- console.log(
212
- ` ${info.method.padEnd(4)} ${info.endpoint.padEnd(30)} ${
213
- info.blockType
214
- }${info.auth}`
215
- );
216
- });
217
- console.log("=".repeat(50));
218
- console.log(`Total: ${endpointInfos.length} endpoints\n`);
219
- }
200
+ // Log all registered endpoints
201
+ const endpointInfos = await universe.httpServer.getRegisteredEndpoints();
202
+ console.log("\nšŸ“‹ Registered Scratch Endpoints:");
203
+ console.log("=".repeat(50));
204
+ endpointInfos.forEach((info) => {
205
+ console.log(
206
+ ` ${info.method.padEnd(4)} ${info.endpoint.padEnd(30)} ${
207
+ info.blockType
208
+ }${info.auth}`
209
+ );
210
+ });
211
+ console.log("=".repeat(50));
212
+ console.log(`Total: ${endpointInfos.length} endpoints\n`);
220
213
 
221
214
  // Start the server (skip if running in Bun, as Bun handles server lifecycle)
222
215
  if (typeof Bun === "undefined") {