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.
Files changed (148) hide show
  1. package/build/esm/editor/auth.d.ts +6 -0
  2. package/build/esm/editor/auth.js +41 -0
  3. package/build/esm/editor/common/admin-interface.d.ts +36 -0
  4. package/build/esm/editor/common/admin-interface.js +44 -0
  5. package/build/esm/editor/common/constants.d.ts +4 -0
  6. package/build/esm/editor/common/constants.js +20 -0
  7. package/build/esm/editor/common/constants.server.d.ts +2 -0
  8. package/build/esm/editor/common/constants.server.js +4 -0
  9. package/build/esm/editor/common/editor-index.d.ts +2 -0
  10. package/build/esm/editor/common/editor-index.js +14 -0
  11. package/build/esm/editor/common/html-encode.d.ts +1 -0
  12. package/build/esm/editor/common/html-encode.js +14 -0
  13. package/build/esm/editor/common/log-socket.d.ts +15 -0
  14. package/build/esm/editor/common/log-socket.js +71 -0
  15. package/build/esm/editor/common/templates.d.ts +11 -0
  16. package/build/esm/editor/common/templates.js +477 -0
  17. package/build/esm/editor/components/api-preview.d.ts +11 -0
  18. package/build/esm/editor/components/api-preview.js +92 -0
  19. package/build/esm/editor/components/editor.d.ts +16 -0
  20. package/build/esm/editor/components/editor.js +367 -0
  21. package/build/esm/editor/components/file-browser.d.ts +37 -0
  22. package/build/esm/editor/components/file-browser.js +127 -0
  23. package/build/esm/editor/components/file-editor-toolbar.d.ts +22 -0
  24. package/build/esm/editor/components/file-editor-toolbar.js +95 -0
  25. package/build/esm/editor/components/file-editor.d.ts +32 -0
  26. package/build/esm/editor/components/file-editor.js +61 -0
  27. package/build/esm/editor/components/filter-query.d.ts +1 -0
  28. package/build/esm/editor/components/filter-query.js +23 -0
  29. package/build/esm/editor/components/highlight-text-area.d.ts +11 -0
  30. package/build/esm/editor/components/highlight-text-area.js +127 -0
  31. package/build/esm/editor/components/log-viewer.d.ts +6 -0
  32. package/build/esm/editor/components/log-viewer.js +71 -0
  33. package/build/esm/editor/components/new-file.d.ts +10 -0
  34. package/build/esm/editor/components/new-file.js +119 -0
  35. package/build/esm/editor/components/scroll-query.d.ts +7 -0
  36. package/build/esm/editor/components/scroll-query.js +22 -0
  37. package/build/esm/editor/components/start-page.d.ts +13 -0
  38. package/build/esm/editor/components/start-page.js +32 -0
  39. package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +3 -0
  40. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +30 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +5 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +50 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +4 -0
  44. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +40 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +26 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +150 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +3 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +39 -0
  49. package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +10 -0
  50. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +46 -0
  51. package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +10 -0
  52. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +46 -0
  53. package/build/esm/editor/http/admin/editor/editor.d.ts +1 -0
  54. package/build/esm/editor/http/admin/editor/editor.js +8 -0
  55. package/build/esm/editor/http/admin/editor/index.api.d.ts +3 -0
  56. package/build/esm/editor/http/admin/editor/index.api.js +22 -0
  57. package/build/esm/editor/server.d.ts +3 -0
  58. package/build/esm/editor/server.js +49 -0
  59. package/build/esm/editor/ws.d.ts +3 -0
  60. package/build/esm/editor/ws.js +11 -0
  61. package/build/esm/src/inflate/inflate-sea.js +8 -1
  62. package/build/esm/src/services/app.js +7 -2
  63. package/build/lib.cjs +14 -3
  64. package/editor/auth.ts +51 -0
  65. package/editor/common/admin-interface.ts +84 -0
  66. package/editor/common/constants.server.ts +5 -0
  67. package/editor/common/constants.ts +21 -0
  68. package/editor/common/editor-index.tsx +17 -0
  69. package/editor/common/html-encode.ts +14 -0
  70. package/editor/common/log-socket.tsx +87 -0
  71. package/editor/common/templates.ts +481 -0
  72. package/editor/components/api-preview.tsx +118 -0
  73. package/editor/components/editor.tsx +496 -0
  74. package/editor/components/file-browser.tsx +311 -0
  75. package/editor/components/file-editor-toolbar.tsx +194 -0
  76. package/editor/components/file-editor.tsx +125 -0
  77. package/editor/components/filter-query.tsx +26 -0
  78. package/editor/components/highlight-text-area.tsx +148 -0
  79. package/editor/components/log-viewer.tsx +113 -0
  80. package/editor/components/new-file.tsx +172 -0
  81. package/editor/components/scroll-query.tsx +25 -0
  82. package/editor/components/start-page.tsx +52 -0
  83. package/editor/http/admin/editor/api/fs/delete.api.tsx +32 -0
  84. package/editor/http/admin/editor/api/fs/read.api.tsx +55 -0
  85. package/editor/http/admin/editor/api/fs/rename.api.tsx +41 -0
  86. package/editor/http/admin/editor/api/fs/scan.api.tsx +181 -0
  87. package/editor/http/admin/editor/api/fs/write.api.tsx +41 -0
  88. package/editor/http/admin/editor/api/server/reload.api.ts +53 -0
  89. package/editor/http/admin/editor/api/server/restart.api.tsx +52 -0
  90. package/editor/http/admin/editor/editor.tsx +10 -0
  91. package/editor/http/admin/editor/index.api.tsx +42 -0
  92. package/editor/server.ts +57 -0
  93. package/editor/ws.ts +15 -0
  94. package/package.json +2 -2
  95. package/src/bin/compile.ts +35 -0
  96. package/src/bin/doc-md.ts +210 -0
  97. package/src/bin/generate-doc.ts +64 -0
  98. package/src/bin/test.ts +92 -0
  99. package/src/bin/types.ts +34 -0
  100. package/src/cluster.ts +27 -0
  101. package/src/common/arguments.ts +762 -0
  102. package/src/common/assets.ts +148 -0
  103. package/src/common/checksum.ts +58 -0
  104. package/src/common/constants.ts +18 -0
  105. package/src/common/content-type.ts +84 -0
  106. package/src/common/esbuild.ts +102 -0
  107. package/src/common/exit.ts +91 -0
  108. package/src/common/fs.ts +82 -0
  109. package/src/common/help.ts +60 -0
  110. package/src/common/jsx.ts +562 -0
  111. package/src/common/jwt.ts +85 -0
  112. package/src/common/paths.ts +107 -0
  113. package/src/common/watch.ts +88 -0
  114. package/src/inflate/inflate-sea.ts +244 -0
  115. package/src/inflate/inflate.ts +101 -0
  116. package/src/inflate/md.ts +25 -0
  117. package/src/inflate/setup-auth.ts +41 -0
  118. package/src/inflate/setup-cors.ts +41 -0
  119. package/src/inflate/setup-db.ts +117 -0
  120. package/src/inflate/setup-error.ts +44 -0
  121. package/src/inflate/setup-http.ts +704 -0
  122. package/src/inflate/setup-log.ts +45 -0
  123. package/src/inflate/setup-middleware.ts +47 -0
  124. package/src/inflate/setup-server-config.ts +48 -0
  125. package/src/inflate/setup-test.ts +23 -0
  126. package/src/inflate/setup-ws.ts +50 -0
  127. package/src/inflate/setup.doc.ts +92 -0
  128. package/src/inflate/utils/sea-utils.ts +14 -0
  129. package/src/lib.ts +34 -0
  130. package/src/main.ts +101 -0
  131. package/src/services/app.ts +703 -0
  132. package/src/services/editor.tsx +101 -0
  133. package/src/services/globals.ts.ignore +186 -0
  134. package/src/services/hot-reload.ts +51 -0
  135. package/src/services/migrations.ts +68 -0
  136. package/src/services/utils/admin-interface.ts +37 -0
  137. package/src/services/utils/cache.ts +88 -0
  138. package/src/services/utils/cluster-cache.ts +230 -0
  139. package/src/services/utils/cluster-ws.ts +202 -0
  140. package/src/services/utils/db-manager.ts +92 -0
  141. package/src/services/utils/get-route.ts +70 -0
  142. package/src/services/utils/jwt.ts +25 -0
  143. package/src/services/utils/log-transport.ts +81 -0
  144. package/src/services/utils/log.ts +92 -0
  145. package/src/services/utils/middleware.ts +10 -0
  146. package/src/services/utils/server-interface.ts +122 -0
  147. package/src/services/utils/websocketmanager.ts +157 -0
  148. 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
+ }