@divizend/scratch-core 1.0.0 ā 1.0.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/basic/index.ts +6 -1
- package/core/ProjectRoot.ts +9 -0
- package/core/Universe.ts +20 -27
- package/http-server/ExpressHttpServer.ts +1175 -0
- package/http-server/HttpServer.ts +13 -10
- package/http-server/default-endpoints/index.ts +4 -0
- package/http-server/default-endpoints/loadEndpoints.ts +69 -0
- package/http-server/default-endpoints/loadEndpointsUI.ts +43 -0
- package/http-server/index.ts +1 -1
- package/index.ts +43 -0
- package/package.json +3 -1
- package/s2/index.ts +19 -0
- package/http-server/NativeHttpServer.ts +0 -1084
- package/http-server/middlewares/01-cors.ts +0 -33
- package/http-server/middlewares/02-static.ts +0 -67
- package/http-server/middlewares/03-request-logger.ts +0 -159
- package/http-server/middlewares/04-body-parser.ts +0 -54
- package/http-server/middlewares/05-no-cache.ts +0 -23
- package/http-server/middlewares/06-response-handler.ts +0 -39
- package/http-server/middlewares/handler-wrapper.ts +0 -250
- package/http-server/middlewares/index.ts +0 -37
- package/http-server/middlewares/types.ts +0 -27
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}"${
|
|
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";
|
package/core/ProjectRoot.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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") {
|