miqro 7.0.1 → 7.0.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 +71 -0
- package/build/esm/editor/common/templates.d.ts +11 -0
- package/build/esm/editor/common/templates.js +477 -0
- package/build/esm/editor/components/api-preview.d.ts +11 -0
- package/build/esm/editor/components/api-preview.js +92 -0
- package/build/esm/editor/components/editor.d.ts +16 -0
- package/build/esm/editor/components/editor.js +367 -0
- package/build/esm/editor/components/file-browser.d.ts +37 -0
- package/build/esm/editor/components/file-browser.js +127 -0
- package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
- package/build/esm/editor/components/file-editor-toolbar.js +95 -0
- package/build/esm/editor/components/file-editor.d.ts +32 -0
- package/build/esm/editor/components/file-editor.js +61 -0
- package/build/esm/editor/components/filter-query.d.ts +1 -0
- package/build/esm/editor/components/filter-query.js +23 -0
- package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
- package/build/esm/editor/components/highlight-text-area.js +127 -0
- package/build/esm/editor/components/log-viewer.d.ts +6 -0
- package/build/esm/editor/components/log-viewer.js +71 -0
- package/build/esm/editor/components/new-file.d.ts +10 -0
- package/build/esm/editor/components/new-file.js +119 -0
- package/build/esm/editor/components/scroll-query.d.ts +7 -0
- package/build/esm/editor/components/scroll-query.js +22 -0
- package/build/esm/editor/components/start-page.d.ts +13 -0
- package/build/esm/editor/components/start-page.js +32 -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 +30 -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 +50 -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 +40 -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 +150 -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 +39 -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 +46 -0
- package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +8 -0
- package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
- package/build/esm/editor/http/admin/editor/index.api.js +22 -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/inflate/inflate-sea.js +8 -1
- package/build/esm/src/services/app.js +7 -2
- package/build/lib.cjs +14 -3
- 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 +87 -0
- package/editor/common/templates.ts +481 -0
- package/editor/components/api-preview.tsx +118 -0
- package/editor/components/editor.tsx +496 -0
- package/editor/components/file-browser.tsx +311 -0
- package/editor/components/file-editor-toolbar.tsx +194 -0
- package/editor/components/file-editor.tsx +125 -0
- package/editor/components/filter-query.tsx +26 -0
- package/editor/components/highlight-text-area.tsx +148 -0
- package/editor/components/log-viewer.tsx +113 -0
- package/editor/components/new-file.tsx +172 -0
- package/editor/components/scroll-query.tsx +25 -0
- package/editor/components/start-page.tsx +52 -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 +10 -0
- package/editor/http/admin/editor/index.api.tsx +42 -0
- package/editor/server.ts +57 -0
- package/editor/ws.ts +15 -0
- package/package.json +2 -2
- 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 +34 -0
- package/src/cluster.ts +27 -0
- package/src/common/arguments.ts +762 -0
- package/src/common/assets.ts +148 -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 +102 -0
- package/src/common/exit.ts +91 -0
- package/src/common/fs.ts +82 -0
- package/src/common/help.ts +60 -0
- package/src/common/jsx.ts +562 -0
- package/src/common/jwt.ts +85 -0
- package/src/common/paths.ts +107 -0
- package/src/common/watch.ts +88 -0
- package/src/inflate/inflate-sea.ts +244 -0
- package/src/inflate/inflate.ts +101 -0
- package/src/inflate/md.ts +25 -0
- package/src/inflate/setup-auth.ts +41 -0
- package/src/inflate/setup-cors.ts +41 -0
- package/src/inflate/setup-db.ts +117 -0
- package/src/inflate/setup-error.ts +44 -0
- package/src/inflate/setup-http.ts +704 -0
- package/src/inflate/setup-log.ts +45 -0
- package/src/inflate/setup-middleware.ts +47 -0
- package/src/inflate/setup-server-config.ts +48 -0
- package/src/inflate/setup-test.ts +23 -0
- package/src/inflate/setup-ws.ts +50 -0
- package/src/inflate/setup.doc.ts +92 -0
- package/src/inflate/utils/sea-utils.ts +14 -0
- package/src/lib.ts +34 -0
- package/src/main.ts +101 -0
- package/src/services/app.ts +703 -0
- package/src/services/editor.tsx +101 -0
- package/src/services/globals.ts.ignore +186 -0
- package/src/services/hot-reload.ts +51 -0
- package/src/services/migrations.ts +68 -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 +202 -0
- package/src/services/utils/db-manager.ts +92 -0
- package/src/services/utils/get-route.ts +70 -0
- package/src/services/utils/jwt.ts +25 -0
- package/src/services/utils/log-transport.ts +81 -0
- package/src/services/utils/log.ts +92 -0
- package/src/services/utils/middleware.ts +10 -0
- package/src/services/utils/server-interface.ts +122 -0
- package/src/services/utils/websocketmanager.ts +157 -0
- package/src/types.ts +307 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Logger } from "@miqro/core";
|
|
2
|
+
import { importLogConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
|
+
import { getLogConfigPath } from "../common/paths.js";
|
|
4
|
+
import { dirname, relative, resolve } from "node:path";
|
|
5
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { cwd } from "node:process";
|
|
7
|
+
import { LogConfig } from "../types.js";
|
|
8
|
+
|
|
9
|
+
export interface LogConfigMap {
|
|
10
|
+
[service: string]: LogConfig | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function setupLogConfig(logger: Logger, servicePath: string, service: string, logConfigMap: LogConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
14
|
+
const logPath = getLogConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
|
|
15
|
+
if (logPath) {
|
|
16
|
+
try {
|
|
17
|
+
//logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
|
|
18
|
+
|
|
19
|
+
const logConfig = await importLogConfigModule(logPath, logger);
|
|
20
|
+
logConfigMap[service] = logConfig;
|
|
21
|
+
|
|
22
|
+
if (inflateDir) {
|
|
23
|
+
const inflatePath = resolve(inflateDir, service, "log.cjs");
|
|
24
|
+
mkdirSync(dirname(inflatePath), {
|
|
25
|
+
recursive: true
|
|
26
|
+
});
|
|
27
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
28
|
+
writeFileSync(inflatePath, await inflateJSX(logPath, {
|
|
29
|
+
// embemedJSX: false,
|
|
30
|
+
minify: false,
|
|
31
|
+
useExport: true,
|
|
32
|
+
platform: "node",
|
|
33
|
+
logger
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
errors.push({
|
|
38
|
+
filePath: logPath,
|
|
39
|
+
error: e
|
|
40
|
+
});
|
|
41
|
+
logger.error("error with " + logPath);
|
|
42
|
+
logger.error(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.cjs");
|
|
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
|
+
platform: "node",
|
|
31
|
+
useExport: true,
|
|
32
|
+
logger
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
return middewareModule;
|
|
36
|
+
|
|
37
|
+
} catch (e) {
|
|
38
|
+
errors.push({
|
|
39
|
+
filePath: middlewarePath,
|
|
40
|
+
error: e
|
|
41
|
+
});
|
|
42
|
+
logger.error("error with " + middlewarePath);
|
|
43
|
+
logger.error(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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.cjs");
|
|
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
|
+
platform: "node",
|
|
35
|
+
useExport: true,
|
|
36
|
+
logger
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
errors.push({
|
|
41
|
+
filePath: serverPath,
|
|
42
|
+
error: e
|
|
43
|
+
});
|
|
44
|
+
logger.error("error with " + serverPath);
|
|
45
|
+
logger.error(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -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,50 @@
|
|
|
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<void> {
|
|
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
|
+
|
|
25
|
+
if (inflateDir) {
|
|
26
|
+
const inflatePath = resolve(inflateDir, service, "ws.cjs");
|
|
27
|
+
mkdirSync(dirname(inflatePath), {
|
|
28
|
+
recursive: true
|
|
29
|
+
});
|
|
30
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
31
|
+
writeFileSync(inflatePath, await inflateJSX(wsPath, {
|
|
32
|
+
// embemedJSX: false,
|
|
33
|
+
minify: false,
|
|
34
|
+
platform: "node",
|
|
35
|
+
useExport: true,
|
|
36
|
+
logger
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
//return wsConfigList;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
errors.push({
|
|
42
|
+
filePath: wsPath,
|
|
43
|
+
error: e
|
|
44
|
+
});
|
|
45
|
+
logger.error("error with " + wsPath);
|
|
46
|
+
logger.error(e);
|
|
47
|
+
//return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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, StaticFileMap } 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, staticFileMap: StaticFileMap, 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 contentType = config.type === "MD" ? CONTENT_TYPE_MAP[".md"] :
|
|
24
|
+
config.type === "JSON" ? CONTENT_TYPE_MAP[".json"] : CONTENT_TYPE_MAP[".html"];
|
|
25
|
+
|
|
26
|
+
const body = await getDocOutput(mainRouter, fileMap, config.all, config.type);
|
|
27
|
+
mainRouter.get(path, async (_, res) => {
|
|
28
|
+
switch (config.type) {
|
|
29
|
+
case "MD": {
|
|
30
|
+
return await res.asyncEnd({
|
|
31
|
+
headers: {
|
|
32
|
+
"content-type": contentType
|
|
33
|
+
},
|
|
34
|
+
status: 200,
|
|
35
|
+
body
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
case "JSON": {
|
|
39
|
+
return await res.json(body);
|
|
40
|
+
}
|
|
41
|
+
case "HTML": {
|
|
42
|
+
return await res.html(body);
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (inflateDir) {
|
|
50
|
+
const inflatePath = join(inflateDir, service, "static", path);
|
|
51
|
+
mkdirSync(dirname(inflatePath), {
|
|
52
|
+
recursive: true
|
|
53
|
+
});
|
|
54
|
+
logger.log("writing [%s]", relative(cwd(), inflatePath));
|
|
55
|
+
writeFileSync(inflatePath, body);
|
|
56
|
+
|
|
57
|
+
fileMap[docPath + path] = {
|
|
58
|
+
routes: [{
|
|
59
|
+
method: "GET",
|
|
60
|
+
path
|
|
61
|
+
}],
|
|
62
|
+
service,
|
|
63
|
+
filePath: docPath,
|
|
64
|
+
previewMethod: "html"
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (staticFileMap) {
|
|
68
|
+
staticFileMap[docPath + path] = {
|
|
69
|
+
contentType,
|
|
70
|
+
filePath: docPath,
|
|
71
|
+
previewMethod: "html",
|
|
72
|
+
method: "GET",
|
|
73
|
+
path,
|
|
74
|
+
body: Buffer.from(body),
|
|
75
|
+
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} catch (e) {
|
|
83
|
+
errors.push({
|
|
84
|
+
filePath: docPath,
|
|
85
|
+
error: e
|
|
86
|
+
});
|
|
87
|
+
logger.error("error with " + docPath);
|
|
88
|
+
logger.error(e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
@@ -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,34 @@
|
|
|
1
|
+
import { Component, enableDebugLog, Fragment, Props, createElement as realCreateElement } from "@miqro/jsx";
|
|
2
|
+
import { jsx2HTML } from "./common/jsx.js";
|
|
3
|
+
|
|
4
|
+
/*export * from "@miqro/core";
|
|
5
|
+
export * from "@miqro/query";*/
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
|
|
8
|
+
export { ClusterWebSocketServer2 } from "./services/utils/cluster-ws.js";
|
|
9
|
+
export { ClusterCache } from "./services/utils/cluster-cache.js";
|
|
10
|
+
export { LocalCache } from "./services/utils/cache.js";
|
|
11
|
+
export { WebSocketManager, WebSocketManagerOptions } from "./services/utils/websocketmanager.js";
|
|
12
|
+
export { DBManager } from "./services/utils/db-manager.js";
|
|
13
|
+
export { LogProvider, LogProviderOptions } from "./services/utils/log.js";
|
|
14
|
+
export { Miqro, MiqroOptions, ServerRequestHandler } from "./services/app.js";
|
|
15
|
+
// export { initGlobals, assertGlobalTampered } from "./services/globals.js";
|
|
16
|
+
export { jsx2HTML } from "./common/jsx.js";
|
|
17
|
+
|
|
18
|
+
//exported for --inflate-sea
|
|
19
|
+
export { appendAPIModule } from "./inflate/utils/sea-utils.js";
|
|
20
|
+
export { createServerInterface, ServerInterfaceImplOptions } from "./services/utils/server-interface.js";
|
|
21
|
+
export { App, LoggerHandler, Router } from "@miqro/core";
|
|
22
|
+
export { migration } from "@miqro/query";
|
|
23
|
+
export { middleware } from "./services/utils/middleware.js";
|
|
24
|
+
export { jwt } from "./services/utils/jwt.js";
|
|
25
|
+
export const JSX = {
|
|
26
|
+
createElement: (...args: [tag: string | Component | typeof Fragment, attributes: Props | null | undefined, ...children: Array<any>]) => {
|
|
27
|
+
const ret = realCreateElement(...args);
|
|
28
|
+
ret.toString = () => jsx2HTML(ret)
|
|
29
|
+
return ret;
|
|
30
|
+
},
|
|
31
|
+
Fragment,
|
|
32
|
+
enableDebugLog
|
|
33
|
+
}
|
|
34
|
+
export * as jsx from "@miqro/jsx";
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
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.install || args.installTSConfig || args.installMiqroJSON) {
|
|
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
|
+
browser: args.browser,
|
|
24
|
+
logFile: args.logFile,
|
|
25
|
+
hotreload: args.test ? false : args.hotreload,
|
|
26
|
+
watch: args.test ? false : args.watch,
|
|
27
|
+
https: args.test ? false : args.https,
|
|
28
|
+
serverOptions: args.serverOptions,
|
|
29
|
+
httpRedirect: args.test ? undefined : args.httpsRedirect
|
|
30
|
+
});
|
|
31
|
+
// check arguments
|
|
32
|
+
if (args.generateDoc) {
|
|
33
|
+
// --generate-doc
|
|
34
|
+
const inflated = await app.inflate({
|
|
35
|
+
inflateParallel: args.inflateParallel
|
|
36
|
+
});
|
|
37
|
+
await generateDocs(args, app.logger, inflated);
|
|
38
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
39
|
+
} else if (args.migrateUp || args.migrateDown) {
|
|
40
|
+
// --migration-up and --migradtion-down
|
|
41
|
+
await app.migrate({
|
|
42
|
+
direction: args.migrateUp ? "up" : "down"
|
|
43
|
+
});
|
|
44
|
+
await app.dbManager.closeAll();
|
|
45
|
+
await app.dbManager.deleteAll();
|
|
46
|
+
await app.webSocketManager.disconnectAll();
|
|
47
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
48
|
+
} else if (args.test) {
|
|
49
|
+
// --test
|
|
50
|
+
await app.inflate({
|
|
51
|
+
inflateParallel: args.inflateParallel
|
|
52
|
+
});
|
|
53
|
+
await app.start();
|
|
54
|
+
await testMain(app);
|
|
55
|
+
await app.stop();
|
|
56
|
+
await app.dbManager.closeAll();
|
|
57
|
+
await app.webSocketManager.disconnectAll();
|
|
58
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
59
|
+
} else if (args.compile) {
|
|
60
|
+
// --compile
|
|
61
|
+
await app.inflate({
|
|
62
|
+
inflateDir: args.inflateDir,
|
|
63
|
+
inflateSea: true,
|
|
64
|
+
inflateParallel: args.inflateParallel
|
|
65
|
+
});
|
|
66
|
+
await app.dbManager.closeAll();
|
|
67
|
+
await app.webSocketManager.disconnectAll();
|
|
68
|
+
await compileSH(args);
|
|
69
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
70
|
+
} else if (args.inflate) {
|
|
71
|
+
// --inflate and --inflate-sea
|
|
72
|
+
// loadApp with inflateDir arg to inflate inflatable files
|
|
73
|
+
await app.inflate({
|
|
74
|
+
inflateDir: args.inflateDir,
|
|
75
|
+
inflateSea: args.inflateSEA,
|
|
76
|
+
inflateParallel: args.inflateParallel
|
|
77
|
+
});
|
|
78
|
+
await app.dbManager.closeAll();
|
|
79
|
+
await app.webSocketManager.disconnectAll();
|
|
80
|
+
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
81
|
+
} else {
|
|
82
|
+
// server
|
|
83
|
+
await app.inflate({
|
|
84
|
+
inflateParallel: args.inflateParallel
|
|
85
|
+
});
|
|
86
|
+
await app.start();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// parse args
|
|
93
|
+
main(parseArguments()).catch(e => {
|
|
94
|
+
console.error(e);
|
|
95
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
96
|
+
});
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error(e);
|
|
99
|
+
console.error(e.message);
|
|
100
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
101
|
+
}
|