@b9g/shovel 0.2.0-beta.2 → 0.2.0-beta.20
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/CHANGELOG.md +184 -172
- package/README.md +313 -54
- package/bin/cli.d.ts +0 -1
- package/bin/cli.js +62 -786
- package/bin/create.js +79 -37
- package/package.json +33 -37
- package/src/_chunks/build-IWPEM2EW.js +160 -0
- package/src/_chunks/chunk-PTLNYIRW.js +1158 -0
- package/src/_chunks/chunk-VWH6D26D.js +1062 -0
- package/src/_chunks/develop-VHR5FLGQ.js +85 -0
- package/src/_chunks/info-TDUY3FZN.js +13 -0
- package/src/worker-entry.d.ts +0 -7
- package/src/worker-entry.js +0 -37
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ServerBundler,
|
|
3
|
+
createPlatform
|
|
4
|
+
} from "./chunk-VWH6D26D.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULTS
|
|
7
|
+
} from "./chunk-PTLNYIRW.js";
|
|
8
|
+
|
|
9
|
+
// src/commands/develop.ts
|
|
10
|
+
import { getLogger } from "@logtape/logtape";
|
|
11
|
+
import { resolvePlatform } from "@b9g/platform";
|
|
12
|
+
var logger = getLogger(["shovel"]);
|
|
13
|
+
async function developCommand(entrypoint, options, config) {
|
|
14
|
+
try {
|
|
15
|
+
const platformName = resolvePlatform({ ...options, config });
|
|
16
|
+
const workerCount = getWorkerCount(options, config);
|
|
17
|
+
const port = parseInt(options.port || String(DEFAULTS.SERVER.PORT), 10);
|
|
18
|
+
const host = options.host || DEFAULTS.SERVER.HOST;
|
|
19
|
+
logger.debug("Platform: {platform}", { platform: platformName });
|
|
20
|
+
logger.debug("Worker count: {workerCount}", { workerCount });
|
|
21
|
+
const platformInstance = await createPlatform(platformName, {
|
|
22
|
+
port,
|
|
23
|
+
host,
|
|
24
|
+
workers: workerCount
|
|
25
|
+
});
|
|
26
|
+
const platformESBuildConfig = platformInstance.getESBuildConfig();
|
|
27
|
+
logger.info("Starting development server");
|
|
28
|
+
let serverStarted = false;
|
|
29
|
+
const startOrReloadServer = async (workerPath) => {
|
|
30
|
+
if (!serverStarted) {
|
|
31
|
+
await platformInstance.serviceWorker.register(workerPath);
|
|
32
|
+
await platformInstance.serviceWorker.ready;
|
|
33
|
+
await platformInstance.listen();
|
|
34
|
+
serverStarted = true;
|
|
35
|
+
logger.info("Server running at http://{host}:{port}", { host, port });
|
|
36
|
+
} else {
|
|
37
|
+
await platformInstance.serviceWorker.reloadWorkers(workerPath);
|
|
38
|
+
logger.info("Reloaded");
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const outDir = "dist";
|
|
42
|
+
const bundler = new ServerBundler({
|
|
43
|
+
entrypoint,
|
|
44
|
+
outDir,
|
|
45
|
+
platform: platformInstance,
|
|
46
|
+
platformESBuildConfig,
|
|
47
|
+
development: true
|
|
48
|
+
});
|
|
49
|
+
const { success: buildSuccess, outputs } = await bundler.watch({
|
|
50
|
+
onRebuild: async (result) => {
|
|
51
|
+
if (result.success && result.outputs.worker) {
|
|
52
|
+
await startOrReloadServer(result.outputs.worker);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (buildSuccess && outputs.worker) {
|
|
57
|
+
await startOrReloadServer(outputs.worker);
|
|
58
|
+
} else {
|
|
59
|
+
logger.error("Initial build failed, watching for changes to retry");
|
|
60
|
+
}
|
|
61
|
+
const shutdown = async (signal) => {
|
|
62
|
+
logger.debug("Shutting down ({signal})", { signal });
|
|
63
|
+
await bundler.stop();
|
|
64
|
+
await platformInstance.dispose();
|
|
65
|
+
logger.debug("Shutdown complete");
|
|
66
|
+
process.exit(0);
|
|
67
|
+
};
|
|
68
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
69
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
70
|
+
await new Promise(() => {
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logger.error("Failed to start development server: {error}", { error });
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function getWorkerCount(options, config) {
|
|
78
|
+
if (options.workers) {
|
|
79
|
+
return parseInt(options.workers, 10);
|
|
80
|
+
}
|
|
81
|
+
return config?.workers ?? DEFAULTS.WORKERS;
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
developCommand
|
|
85
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/commands/info.ts
|
|
2
|
+
import { getLogger } from "@logtape/logtape";
|
|
3
|
+
import { detectRuntime, detectDevelopmentPlatform } from "@b9g/platform";
|
|
4
|
+
var logger = getLogger(["shovel"]);
|
|
5
|
+
async function infoCommand() {
|
|
6
|
+
logger.info("Shovel Platform Information", {});
|
|
7
|
+
logger.info("---", {});
|
|
8
|
+
logger.info("Current Runtime", { runtime: detectRuntime() });
|
|
9
|
+
logger.info("Default Platform", { platform: detectDevelopmentPlatform() });
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
infoCommand
|
|
13
|
+
};
|
package/src/worker-entry.d.ts
DELETED
package/src/worker-entry.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/// <reference types="./worker-entry.d.ts" />
|
|
2
|
-
// src/worker-entry.ts
|
|
3
|
-
import { getLogger } from "@logtape/logtape";
|
|
4
|
-
var logger = getLogger(["worker"]);
|
|
5
|
-
var Platform;
|
|
6
|
-
if (PLATFORM === "bun") {
|
|
7
|
-
Platform = (await import("@b9g/platform-bun")).default;
|
|
8
|
-
} else {
|
|
9
|
-
Platform = (await import("@b9g/platform-node")).default;
|
|
10
|
-
}
|
|
11
|
-
var PORT = parseInt(import.meta.env.PORT || "8080", 10);
|
|
12
|
-
var HOST = import.meta.env.HOST || "0.0.0.0";
|
|
13
|
-
logger.info("Starting production server", {});
|
|
14
|
-
logger.info("Workers", { count: WORKER_COUNT });
|
|
15
|
-
var platform = new Platform();
|
|
16
|
-
var userCodeURL = new URL("./server.js", import.meta.url);
|
|
17
|
-
var userCodePath = userCodeURL.pathname;
|
|
18
|
-
var serviceWorker = await platform.loadServiceWorker(userCodePath, {
|
|
19
|
-
workerCount: WORKER_COUNT
|
|
20
|
-
});
|
|
21
|
-
var server = platform.createServer(serviceWorker.handleRequest, {
|
|
22
|
-
port: PORT,
|
|
23
|
-
host: HOST
|
|
24
|
-
});
|
|
25
|
-
await server.listen();
|
|
26
|
-
logger.info("Server running", { url: `http://${HOST}:${PORT}` });
|
|
27
|
-
logger.info("Load balancing", { workers: WORKER_COUNT });
|
|
28
|
-
var shutdown = async () => {
|
|
29
|
-
logger.info("Shutting down server", {});
|
|
30
|
-
await serviceWorker.dispose();
|
|
31
|
-
await platform.dispose();
|
|
32
|
-
await server.close();
|
|
33
|
-
logger.info("Server stopped", {});
|
|
34
|
-
process.exit(0);
|
|
35
|
-
};
|
|
36
|
-
process.on("SIGINT", shutdown);
|
|
37
|
-
process.on("SIGTERM", shutdown);
|