bakit 2.0.2 → 2.1.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/dist/cli.js +79 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +10 -5
package/dist/cli.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
|
+
import { fork } from 'child_process';
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
import { program } from 'commander';
|
|
6
|
+
import glob from 'tiny-glob';
|
|
7
|
+
import { startServiceServer } from '@bakit/service';
|
|
8
|
+
|
|
9
|
+
// package.json
|
|
10
|
+
var package_default = {
|
|
11
|
+
name: "bakit",
|
|
12
|
+
version: "2.1.1"};
|
|
13
|
+
|
|
14
|
+
// src/lib/cli/index.ts
|
|
15
|
+
config();
|
|
16
|
+
program.name(package_default.name).description("Bakit CLI tool").version(package_default.version);
|
|
17
|
+
program.command("start").description("Start the services").argument("[name...]", "Name of the service to start").action(start);
|
|
18
|
+
program.parse();
|
|
19
|
+
var cliPath = fileURLToPath(import.meta.url);
|
|
20
|
+
async function start(names) {
|
|
21
|
+
await runSupervisor(names);
|
|
22
|
+
}
|
|
23
|
+
async function runSupervisor(names = []) {
|
|
24
|
+
if (names.length === 1) {
|
|
25
|
+
await runServiceWorker(names[0]);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let services = await loadServices();
|
|
29
|
+
if (names.length === 0)
|
|
30
|
+
return spawnServices(services);
|
|
31
|
+
let nameSet = new Set(names), toStart = services.filter((s) => nameSet.has(s.name));
|
|
32
|
+
if (toStart.length !== nameSet.size) {
|
|
33
|
+
let found = new Set(toStart.map((s) => s.name)), missing = names.filter((n) => !found.has(n));
|
|
34
|
+
console.error(`Service(s) not found: ${missing.join(", ")}`), process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
return spawnServices(toStart);
|
|
37
|
+
}
|
|
38
|
+
function spawnServices(services) {
|
|
39
|
+
let children = [];
|
|
40
|
+
process.on("SIGINT", shutdown), process.on("SIGTERM", shutdown);
|
|
41
|
+
let hasTSX = hasPackage("tsx");
|
|
42
|
+
for (let service of services) {
|
|
43
|
+
let child = fork(cliPath, ["start", service.name], {
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
BAKIT_SERVICE_NAME: service.name,
|
|
47
|
+
NODE_OPTIONS: hasTSX ? "--import tsx" : void 0
|
|
48
|
+
},
|
|
49
|
+
stdio: "inherit"
|
|
50
|
+
});
|
|
51
|
+
child.on("exit", (code) => {
|
|
52
|
+
console.log(`Service "${service.name}" exited with code ${code}`);
|
|
53
|
+
}), children.push(child);
|
|
54
|
+
}
|
|
55
|
+
async function shutdown() {
|
|
56
|
+
await Promise.all(
|
|
57
|
+
children.map((child) => new Promise((resolve) => {
|
|
58
|
+
child.once("exit", resolve), child.kill("SIGTERM"), setTimeout(() => child.kill("SIGKILL"), 5e3);
|
|
59
|
+
}))
|
|
60
|
+
), process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function loadServices() {
|
|
64
|
+
let paths = await glob("src/services/**/*.{js,ts}");
|
|
65
|
+
return await Promise.all(
|
|
66
|
+
paths.map(async (path) => (await import(pathToFileURL(path).href)).default)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
async function runServiceWorker(name) {
|
|
70
|
+
let service = (await loadServices()).find((s) => s.name === name);
|
|
71
|
+
service || (console.error(`Service "${name}" not found.`), process.exit(1)), await startServiceServer(service), console.log(`Service "${name}" started as server`);
|
|
72
|
+
}
|
|
73
|
+
function hasPackage(name) {
|
|
74
|
+
try {
|
|
75
|
+
return import.meta.resolve(name), !0;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DEFAULT_GATEWAY_MANAGER_OPTIONS, DEFAULT_WORKER_PATH, GatewayManager, GatewayManagerEvents, GatewayManagerOptions, GatewayWorker, GatewayWorkerEvents, GatewayWorkerOptions, GatewayWorkerState, createGatewayManager, createWorker } from '@bakit/gateway';
|
|
2
|
-
export { REST, RESTEndpoint, RESTEvents, RESTMethod, RESTOptions,
|
|
2
|
+
export { REST, RESTEndpoint, RESTEvents, RESTMethod, RESTOptions, createREST } from '@bakit/rest';
|
|
3
3
|
export { Awaitable, Collection, EventBus, EventMap, FunctionLike, Promisify, PromisifyValue, Queue, QueueOptions, ReadonlyCollection, RejectFn, ResolveFn, attachEventBus, capitalize, createEventBus, createQueue, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
|
|
4
4
|
export { RPCError, RPCErrorPayload, RPCHandler, RPCRequestMessage, RPCResponseMessage, Serializable, Service, ServiceFunction, ServiceOptions, TransportClient, TransportClientOptions, TransportDriver, TransportServer, TransportServerOptions, createIPCClient, createIPCServer, createService, createTransportClient, createTransportServer, deserializeRPCError, getIPCPath, serializeRPCError } from '@bakit/service';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DEFAULT_GATEWAY_MANAGER_OPTIONS, DEFAULT_WORKER_PATH, createGatewayManager, createWorker } from '@bakit/gateway';
|
|
2
|
-
export { createREST
|
|
2
|
+
export { createREST } from '@bakit/rest';
|
|
3
3
|
export { Collection, attachEventBus, capitalize, createEventBus, createQueue, isPlainObject, isPromiseLike, promisify, sleep } from '@bakit/utils';
|
|
4
4
|
export { RPCError, createIPCClient, createIPCServer, createService, createTransportClient, createTransportServer, deserializeRPCError, getIPCPath, serializeRPCError } from '@bakit/service';
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bakit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A framework for discordeno",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts"
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
|
+
"./cli": "./dist/cli.js"
|
|
11
12
|
},
|
|
12
13
|
"bin": {
|
|
13
14
|
"bakit": "./dist/cli.js"
|
|
@@ -30,13 +31,17 @@
|
|
|
30
31
|
],
|
|
31
32
|
"author": "louiszn",
|
|
32
33
|
"license": "MIT",
|
|
34
|
+
"optionalDependencies": {
|
|
35
|
+
"tsx": "^4.21.0"
|
|
36
|
+
},
|
|
33
37
|
"dependencies": {
|
|
34
38
|
"commander": "^14.0.2",
|
|
39
|
+
"dotenv": "^17.2.3",
|
|
35
40
|
"tiny-glob": "^0.2.9",
|
|
36
41
|
"type-fest": "^4.41.0",
|
|
37
|
-
"@bakit/
|
|
38
|
-
"@bakit/
|
|
39
|
-
"@bakit/
|
|
42
|
+
"@bakit/gateway": "^2.1.4",
|
|
43
|
+
"@bakit/service": "^3.2.0",
|
|
44
|
+
"@bakit/rest": "^2.1.0",
|
|
40
45
|
"@bakit/utils": "^2.0.0"
|
|
41
46
|
},
|
|
42
47
|
"scripts": {
|