miqro 6.1.1 → 6.1.3
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/build/esm/editor/auth.d.ts +6 -0
- package/build/esm/editor/auth.js +41 -0
- package/build/esm/editor/common/admin-interface.d.ts +36 -0
- package/build/esm/editor/common/admin-interface.js +44 -0
- package/build/esm/editor/common/constants.d.ts +4 -0
- package/build/esm/editor/common/constants.js +20 -0
- package/build/esm/editor/common/constants.server.d.ts +2 -0
- package/build/esm/editor/common/constants.server.js +4 -0
- package/build/esm/editor/common/editor-index.d.ts +2 -0
- package/build/esm/editor/common/editor-index.js +14 -0
- package/build/esm/editor/common/html-encode.d.ts +1 -0
- package/build/esm/editor/common/html-encode.js +14 -0
- package/build/esm/editor/common/log-socket.d.ts +15 -0
- package/build/esm/editor/common/log-socket.js +70 -0
- package/build/esm/editor/common/templates.d.ts +11 -0
- package/build/esm/editor/common/templates.js +461 -0
- package/build/esm/editor/components/api-preview.d.ts +11 -0
- package/build/esm/editor/components/api-preview.js +90 -0
- package/build/esm/editor/components/editor.d.ts +16 -0
- package/build/esm/editor/components/editor.js +357 -0
- package/build/esm/editor/components/file-browser.d.ts +37 -0
- package/build/esm/editor/components/file-browser.js +126 -0
- package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
- package/build/esm/editor/components/file-editor-toolbar.js +93 -0
- package/build/esm/editor/components/file-editor.d.ts +32 -0
- package/build/esm/editor/components/file-editor.js +59 -0
- package/build/esm/editor/components/filter-query.d.ts +1 -0
- package/build/esm/editor/components/filter-query.js +22 -0
- package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
- package/build/esm/editor/components/highlight-text-area.js +124 -0
- package/build/esm/editor/components/log-viewer.d.ts +6 -0
- package/build/esm/editor/components/log-viewer.js +69 -0
- package/build/esm/editor/components/new-file.d.ts +10 -0
- package/build/esm/editor/components/new-file.js +117 -0
- package/build/esm/editor/components/scroll-query.d.ts +7 -0
- package/build/esm/editor/components/scroll-query.js +21 -0
- package/build/esm/editor/components/start-page.d.ts +13 -0
- package/build/esm/editor/components/start-page.js +30 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +29 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +49 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +39 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +149 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +38 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +45 -0
- package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +7 -0
- package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/index.api.js +21 -0
- package/build/esm/editor/server.d.ts +3 -0
- package/build/esm/editor/server.js +49 -0
- package/build/esm/editor/ws.d.ts +3 -0
- package/build/esm/editor/ws.js +11 -0
- package/build/esm/src/bin/compile.d.ts +3 -0
- package/build/esm/src/bin/compile.js +30 -0
- package/build/esm/src/bin/doc-md.d.ts +17 -0
- package/build/esm/src/bin/doc-md.js +186 -0
- package/build/esm/src/bin/generate-doc.d.ts +6 -0
- package/build/esm/src/bin/generate-doc.js +53 -0
- package/build/esm/src/bin/test.d.ts +3 -0
- package/build/esm/src/bin/test.js +67 -0
- package/build/esm/src/bin/types.d.ts +3 -0
- package/build/esm/src/bin/types.js +20 -0
- package/editor/auth.ts +51 -0
- package/editor/common/admin-interface.ts +84 -0
- package/editor/common/constants.server.ts +5 -0
- package/editor/common/constants.ts +21 -0
- package/editor/common/editor-index.tsx +17 -0
- package/editor/common/html-encode.ts +14 -0
- package/editor/common/log-socket.tsx +85 -0
- package/editor/common/templates.ts +466 -0
- package/editor/components/api-preview.tsx +116 -0
- package/editor/components/editor.tsx +486 -0
- package/editor/components/file-browser.tsx +308 -0
- package/editor/components/file-editor-toolbar.tsx +191 -0
- package/editor/components/file-editor.tsx +122 -0
- package/editor/components/filter-query.tsx +22 -0
- package/editor/components/highlight-text-area.tsx +144 -0
- package/editor/components/log-viewer.tsx +110 -0
- package/editor/components/new-file.tsx +169 -0
- package/editor/components/scroll-query.tsx +22 -0
- package/editor/components/start-page.tsx +49 -0
- package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
- package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
- package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
- package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
- package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
- package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
- package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
- package/editor/http/admin/editor/editor.tsx +8 -0
- package/editor/http/admin/editor/index.api.tsx +39 -0
- package/editor/server.ts +57 -0
- package/editor/ws.ts +15 -0
- package/package.json +1 -1
- package/src/bin/compile.ts +35 -0
- package/src/bin/doc-md.ts +210 -0
- package/src/bin/generate-doc.ts +64 -0
- package/src/bin/test.ts +92 -0
- package/src/bin/types.ts +22 -0
- package/src/cluster.ts +27 -0
- package/src/common/arguments.ts +503 -0
- package/src/common/assets.ts +128 -0
- package/src/common/checksum.ts +58 -0
- package/src/common/constants.ts +18 -0
- package/src/common/content-type.ts +84 -0
- package/src/common/esbuild.ts +94 -0
- package/src/common/exit.ts +91 -0
- package/src/common/fs.ts +17 -0
- package/src/common/help.ts +51 -0
- package/src/common/jsx.ts +512 -0
- package/src/common/paths.ts +158 -0
- package/src/common/watch.ts +85 -0
- package/src/inflate/inflate-sea.ts +206 -0
- package/src/inflate/inflate.ts +99 -0
- package/src/inflate/md.ts +25 -0
- package/src/inflate/setup-auth.ts +40 -0
- package/src/inflate/setup-cors.ts +40 -0
- package/src/inflate/setup-db.ts +113 -0
- package/src/inflate/setup-error.ts +43 -0
- package/src/inflate/setup-http.ts +655 -0
- package/src/inflate/setup-log.ts +44 -0
- package/src/inflate/setup-middleware.ts +46 -0
- package/src/inflate/setup-server-config.ts +47 -0
- package/src/inflate/setup-test.ts +23 -0
- package/src/inflate/setup-ws.ts +48 -0
- package/src/inflate/setup.doc.ts +68 -0
- package/src/inflate/utils/sea-utils.ts +14 -0
- package/src/lib.ts +19 -0
- package/src/main.ts +87 -0
- package/src/services/app.ts +658 -0
- package/src/services/editor.tsx +101 -0
- package/src/services/globals.ts +143 -0
- package/src/services/hot-reload.ts +48 -0
- package/src/services/migrations.ts +66 -0
- package/src/services/utils/admin-interface.ts +37 -0
- package/src/services/utils/cache.ts +88 -0
- package/src/services/utils/cluster-cache.ts +230 -0
- package/src/services/utils/cluster-ws.ts +197 -0
- package/src/services/utils/db-manager.ts +92 -0
- package/src/services/utils/get-route.ts +70 -0
- package/src/services/utils/log-transport.ts +75 -0
- package/src/services/utils/log.ts +92 -0
- package/src/services/utils/server-interface.ts +172 -0
- package/src/services/utils/websocketmanager.ts +149 -0
- package/src/types/@esbuild.d.ts +1 -0
- package/src/types/@miqro/core.d.ts +2 -0
- package/src/types/@miqro/jsx.d.ts +2 -0
- package/src/types/@miqro/parser.d.ts +2 -0
- package/src/types/@miqro/query.d.ts +2 -0
- package/src/types/@miqro/request.d.ts +2 -0
- package/src/types/@miqro/test.d.ts +2 -0
- package/src/types/@miqro.d.ts +1 -0
- package/src/types/@types.d.ts +1 -0
- package/src/types/browser.globals.d.ts +9 -0
- package/src/types/globals.d.ts +2 -0
- package/src/types/jsx.globals.d.ts +37 -0
- package/src/types/miqro.d.ts +129 -0
- package/src/types/postject.d.ts +1 -0
- package/src/types/server.globals.d.ts +72 -0
- package/src/types.ts +222 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Logger, Router } from "@miqro/core";
|
|
2
|
+
import { importMiddlewareConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
|
+
import { getMiddlewareConfigPath } from "../common/paths.js";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { cwd } from "node:process";
|
|
7
|
+
import { MiddlewareConfig } from "../types.js";
|
|
8
|
+
|
|
9
|
+
export async function setupMiddleware(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]): Promise<MiddlewareConfig | null> {
|
|
10
|
+
const middlewarePath = getMiddlewareConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
11
|
+
|
|
12
|
+
if (middlewarePath) {
|
|
13
|
+
try {
|
|
14
|
+
const middewareModule = await importMiddlewareConfigModule(middlewarePath, logger);
|
|
15
|
+
logger.debug("setting up middleware from [%s]", join(service, basename(middlewarePath)));
|
|
16
|
+
if (middewareModule && middewareModule.middleware) {
|
|
17
|
+
for (const m of middewareModule.middleware) {
|
|
18
|
+
mainRouter.use(m);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (inflateDir && inflateSea) {
|
|
22
|
+
const inflatePath = resolve(inflateDir, service, "middleware.js");
|
|
23
|
+
mkdirSync(dirname(inflatePath), {
|
|
24
|
+
recursive: true
|
|
25
|
+
});
|
|
26
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
27
|
+
writeFileSync(inflatePath, await inflateJSX(middlewarePath, {
|
|
28
|
+
embemedJSX: false,
|
|
29
|
+
minify: false,
|
|
30
|
+
useExport: true,
|
|
31
|
+
logger
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
return middewareModule;
|
|
35
|
+
|
|
36
|
+
} catch (e) {
|
|
37
|
+
errors.push({
|
|
38
|
+
filePath: middlewarePath,
|
|
39
|
+
error: e
|
|
40
|
+
});
|
|
41
|
+
logger.error("error with " + middlewarePath);
|
|
42
|
+
logger.error(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { Logger } from "@miqro/core";
|
|
3
|
+
import { dirname, relative, resolve } from "node:path";
|
|
4
|
+
import { cwd } from "node:process";
|
|
5
|
+
|
|
6
|
+
import { importServerConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
7
|
+
import { getServerConfigPath } from "../common/paths.js";
|
|
8
|
+
import { ServerConfig } from "../types.js";
|
|
9
|
+
|
|
10
|
+
export interface ServerConfigMap {
|
|
11
|
+
[service: string]: ServerConfig | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function setupServerConfig(logger: Logger, servicePath: string, service: string, serverConfigMap: ServerConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
15
|
+
|
|
16
|
+
const serverPath = getServerConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
|
|
17
|
+
if (serverPath) {
|
|
18
|
+
try {
|
|
19
|
+
//logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
|
|
20
|
+
|
|
21
|
+
const serverConfig = await importServerConfigModule(serverPath, logger);
|
|
22
|
+
serverConfigMap[service] = serverConfig;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (inflateDir) {
|
|
26
|
+
const inflatePath = resolve(inflateDir, service, "server.js");
|
|
27
|
+
mkdirSync(dirname(inflatePath), {
|
|
28
|
+
recursive: true
|
|
29
|
+
});
|
|
30
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
31
|
+
writeFileSync(inflatePath, await inflateJSX(serverPath, {
|
|
32
|
+
embemedJSX: false,
|
|
33
|
+
minify: false,
|
|
34
|
+
useExport: true,
|
|
35
|
+
logger
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
errors.push({
|
|
40
|
+
filePath: serverPath,
|
|
41
|
+
error: e
|
|
42
|
+
});
|
|
43
|
+
logger.error("error with " + serverPath);
|
|
44
|
+
logger.error(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { importJSXFile } from "../common/jsx.js";
|
|
2
|
+
import { Logger } from "@miqro/core";
|
|
3
|
+
import { scanFiles } from "./setup-http.js";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
export async function setupTests(logger: Logger, servicePath: string) {
|
|
7
|
+
logger.debug("setting up tests from [%s]", servicePath);
|
|
8
|
+
const files = scanFiles(resolve(servicePath));
|
|
9
|
+
await Promise.allSettled(files.map((file) => {
|
|
10
|
+
switch (file.ext) {
|
|
11
|
+
case ".jsx":
|
|
12
|
+
case ".js":
|
|
13
|
+
case ".ts":
|
|
14
|
+
case ".tsx": {
|
|
15
|
+
switch (file.subExt) {
|
|
16
|
+
case ".test":
|
|
17
|
+
return importJSXFile(file.filePath, logger);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Logger } from "@miqro/core";
|
|
2
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
3
|
+
import { cwd } from "node:process";
|
|
4
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
import { importWSConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
7
|
+
import { getWSConfigPath } from "../common/paths.js";
|
|
8
|
+
import { WSConfig } from "../types.js";
|
|
9
|
+
|
|
10
|
+
export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<false | WSConfig> {
|
|
11
|
+
const wsPath = getWSConfigPath(servicePath); // resolve(process.cwd(), service, "ws.ts");
|
|
12
|
+
|
|
13
|
+
if (wsPath) {
|
|
14
|
+
try {
|
|
15
|
+
logger.debug("importing websocket socket for service [%s]", service);
|
|
16
|
+
const wsConfig = await importWSConfigModule(wsPath, logger);
|
|
17
|
+
if (wsConfig && wsConfigList.filter(c => c.path === wsConfig.path).length > 0) {
|
|
18
|
+
throw new Error(`ws path [${wsConfig.path}] already defined! from [${wsPath}]`);
|
|
19
|
+
} else if (wsConfigList) {
|
|
20
|
+
logger.debug("importing websocket on path [%s] from [%s]", wsConfig.path, join(service, "ws.ts"));
|
|
21
|
+
wsConfigList.push(wsConfig);
|
|
22
|
+
//wsMap[wsConfig.path] = { name: service, options: wsConfig };
|
|
23
|
+
}
|
|
24
|
+
if (inflateDir) {
|
|
25
|
+
const inflatePath = resolve(inflateDir, service, "ws.js");
|
|
26
|
+
mkdirSync(dirname(inflatePath), {
|
|
27
|
+
recursive: true
|
|
28
|
+
});
|
|
29
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
30
|
+
writeFileSync(inflatePath, await inflateJSX(wsPath, {
|
|
31
|
+
embemedJSX: false,
|
|
32
|
+
minify: false,
|
|
33
|
+
useExport: true,
|
|
34
|
+
logger
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return wsConfig;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
errors.push({
|
|
40
|
+
filePath: wsPath,
|
|
41
|
+
error: e
|
|
42
|
+
});
|
|
43
|
+
logger.error("error with " + wsPath);
|
|
44
|
+
logger.error(e);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Logger, Router } from "@miqro/core";
|
|
2
|
+
import { importDocConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
|
+
import { getDocConfigPath } from "../common/paths.js";
|
|
4
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { cwd } from "node:process";
|
|
7
|
+
import { getDocOutput } from "../bin/generate-doc.js";
|
|
8
|
+
import { RouteFileMap } from "./setup-http.js";
|
|
9
|
+
import { CONTENT_TYPE_MAP } from "../common/content-type.js";
|
|
10
|
+
|
|
11
|
+
export async function setupDoc(logger: Logger, servicePath: string, service: string, mainRouter: Router, fileMap: RouteFileMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
12
|
+
const docPath = getDocConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
13
|
+
|
|
14
|
+
if (docPath) {
|
|
15
|
+
try {
|
|
16
|
+
const docModule = await importDocConfigModule(docPath, logger);
|
|
17
|
+
logger.debug("setting up error handling from [%s]", join(service, basename(docPath)));
|
|
18
|
+
if (docModule && docModule.publish) {
|
|
19
|
+
const paths = Object.keys(docModule.publish);
|
|
20
|
+
for (const path of paths) {
|
|
21
|
+
const config = docModule.publish[path];
|
|
22
|
+
|
|
23
|
+
const body = await getDocOutput(mainRouter, fileMap, config.all, config.type);
|
|
24
|
+
mainRouter.get(path, async (_, res) => {
|
|
25
|
+
switch (config.type) {
|
|
26
|
+
case "MD": {
|
|
27
|
+
const contentType = CONTENT_TYPE_MAP[".md"];
|
|
28
|
+
return await res.asyncEnd({
|
|
29
|
+
headers: {
|
|
30
|
+
"content-type": contentType
|
|
31
|
+
},
|
|
32
|
+
status: 200,
|
|
33
|
+
body
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
case "JSON": {
|
|
37
|
+
return await res.json(body);
|
|
38
|
+
}
|
|
39
|
+
case "HTML": {
|
|
40
|
+
return await res.html(body);
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (inflateDir) {
|
|
48
|
+
const inflatePath = join(inflateDir, service, "static", path);
|
|
49
|
+
mkdirSync(dirname(inflatePath), {
|
|
50
|
+
recursive: true
|
|
51
|
+
});
|
|
52
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
53
|
+
writeFileSync(inflatePath, body);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} catch (e) {
|
|
59
|
+
errors.push({
|
|
60
|
+
filePath: docPath,
|
|
61
|
+
error: e
|
|
62
|
+
});
|
|
63
|
+
logger.error("error with " + docPath);
|
|
64
|
+
logger.error(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Router } from "@miqro/core";
|
|
2
|
+
import { describeFilePath } from "../../common/fs.js";
|
|
3
|
+
import { getRoutes } from "../../services/utils/get-route.js";
|
|
4
|
+
import { assertGlobalTampered } from "../../services/globals.js";
|
|
5
|
+
import { dirname, join, relative } from "node:path";
|
|
6
|
+
|
|
7
|
+
export async function appendAPIModule(router: Router, dir: string, filePath: string, module: any) {
|
|
8
|
+
const file = describeFilePath(filePath);
|
|
9
|
+
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
|
|
10
|
+
for (const r of routes) {
|
|
11
|
+
router.use(assertGlobalTampered);
|
|
12
|
+
router.use(module.handler, r.path, r.method as any, r.options);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/lib.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*export * from "@miqro/core";
|
|
2
|
+
export * from "@miqro/query";*/
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
|
|
5
|
+
export { ClusterWebSocketServer2 } from "./services/utils/cluster-ws.js";
|
|
6
|
+
export { ClusterCache } from "./services/utils/cluster-cache.js";
|
|
7
|
+
export { LocalCache } from "./services/utils/cache.js";
|
|
8
|
+
export { WebSocketManager, WebSocketManagerOptions } from "./services/utils/websocketmanager.js";
|
|
9
|
+
export { DBManager } from "./services/utils/db-manager.js";
|
|
10
|
+
export { LogProvider, LogProviderOptions } from "./services/utils/log.js";
|
|
11
|
+
export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
|
|
12
|
+
export { initGlobals, assertGlobalTampered } from "./services/globals.js";
|
|
13
|
+
export { appendAPIModule } from "./inflate/utils/sea-utils.js";
|
|
14
|
+
|
|
15
|
+
//exported for --inflate-sea
|
|
16
|
+
export { ServerInterfaceImpl, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
|
|
17
|
+
export { App, LoggerHandler, Router } from "@miqro/core";
|
|
18
|
+
export { migration } from "@miqro/query";
|
|
19
|
+
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Arguments, parseArguments } from "./common/arguments.js";
|
|
4
|
+
import { EXIT_CODES } from "./common/constants.js";
|
|
5
|
+
import { testMain } from "./bin/test.js";
|
|
6
|
+
import { compileSH } from "./bin/compile.js";
|
|
7
|
+
import { installTypings } from "./bin/types.js";
|
|
8
|
+
import { generateDocs } from "./bin/generate-doc.js";
|
|
9
|
+
import { Miqro } from "./services/app.js";
|
|
10
|
+
import { TEST_SOCKET } from "./common/paths.js";
|
|
11
|
+
import { Logger } from "@miqro/core";
|
|
12
|
+
|
|
13
|
+
async function main(args: Arguments) {
|
|
14
|
+
if (args.installTypes || args.installTSConfig) {
|
|
15
|
+
await installTypings(args, new Logger(""));
|
|
16
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
17
|
+
} else {
|
|
18
|
+
const app = new Miqro({
|
|
19
|
+
editor: args.editor,
|
|
20
|
+
name: args.name ? args.name : undefined,
|
|
21
|
+
port: args.test ? TEST_SOCKET : args.port,
|
|
22
|
+
services: args.services,
|
|
23
|
+
hotreload: args.test ? false : args.hotreload
|
|
24
|
+
});
|
|
25
|
+
// check arguments
|
|
26
|
+
if (args.generateDoc) {
|
|
27
|
+
// --generate-doc
|
|
28
|
+
const inflated = await app.inflate();
|
|
29
|
+
await generateDocs(args, app.logger, inflated);
|
|
30
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
31
|
+
} else if (args.migrateUp || args.migrateDown) {
|
|
32
|
+
// --migration-up and --migradtion-down
|
|
33
|
+
await app.migrate({
|
|
34
|
+
direction: args.migrateUp ? "up" : "down"
|
|
35
|
+
});
|
|
36
|
+
await app.dbManager.closeAll();
|
|
37
|
+
await app.dbManager.deleteAll();
|
|
38
|
+
await app.webSocketManager.disconnectAll();
|
|
39
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
40
|
+
} else if (args.test) {
|
|
41
|
+
// --test
|
|
42
|
+
await app.inflate();
|
|
43
|
+
await app.start();
|
|
44
|
+
await testMain(app);
|
|
45
|
+
await app.stop();
|
|
46
|
+
await app.dbManager.closeAll();
|
|
47
|
+
await app.webSocketManager.disconnectAll();
|
|
48
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
49
|
+
} else if (args.compile) {
|
|
50
|
+
// --compile
|
|
51
|
+
await app.inflate({
|
|
52
|
+
inflateDir: args.inflateDir,
|
|
53
|
+
inflateSea: true
|
|
54
|
+
});
|
|
55
|
+
await app.dbManager.closeAll();
|
|
56
|
+
await app.webSocketManager.disconnectAll();
|
|
57
|
+
await compileSH(args);
|
|
58
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
59
|
+
} else if (args.inflate) {
|
|
60
|
+
// --inflate and --inflate-sea
|
|
61
|
+
// loadApp with inflateDir arg to inflate inflatable files
|
|
62
|
+
await app.inflate({
|
|
63
|
+
inflateDir: args.inflateDir,
|
|
64
|
+
inflateSea: args.inflateSEA
|
|
65
|
+
});
|
|
66
|
+
await app.dbManager.closeAll();
|
|
67
|
+
await app.webSocketManager.disconnectAll();
|
|
68
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
69
|
+
} else {
|
|
70
|
+
// server
|
|
71
|
+
await app.inflate();
|
|
72
|
+
await app.start();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
// parse args
|
|
79
|
+
main(parseArguments()).catch(e => {
|
|
80
|
+
console.error(e);
|
|
81
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
82
|
+
});
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(e);
|
|
85
|
+
console.error(e.message);
|
|
86
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
87
|
+
}
|