miqro 6.1.2 → 6.1.4
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/editor.bundle.js +16 -0
- 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 +477 -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/types.js +8 -0
- package/build/esm/src/common/arguments.d.ts +7 -1
- package/build/esm/src/common/arguments.js +72 -10
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +33 -29
- package/build/esm/src/inflate/setup-ws.d.ts +1 -1
- package/build/esm/src/inflate/setup-ws.js +2 -2
- package/build/esm/src/main.js +3 -1
- package/build/esm/src/services/app.d.ts +2 -0
- package/build/esm/src/services/app.js +2 -2
- package/build/esm/src/services/utils/log-transport.d.ts +2 -2
- package/build/esm/src/services/utils/log-transport.js +8 -3
- package/build/esm/src/services/utils/server-interface.d.ts +1 -1
- package/build/esm/src/services/utils/server-interface.js +19 -14
- package/build/lib.cjs +23 -21
- 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 +481 -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/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +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 +29 -0
- package/src/cluster.ts +27 -0
- package/src/common/arguments.ts +576 -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 +55 -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 +115 -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 +49 -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 +89 -0
- package/src/services/app.ts +660 -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 +81 -0
- package/src/services/utils/log.ts +92 -0
- package/src/services/utils/server-interface.ts +179 -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,26 @@
|
|
|
1
|
+
import { APIRoute } from "@miqro/core";
|
|
2
|
+
import { AdminRequest } from "../../../../../common/admin-interface.js";
|
|
3
|
+
export interface ScannedFile {
|
|
4
|
+
filePath: string;
|
|
5
|
+
ext: string;
|
|
6
|
+
fileName: string;
|
|
7
|
+
name: string;
|
|
8
|
+
subExt: string;
|
|
9
|
+
subName: string;
|
|
10
|
+
language: string;
|
|
11
|
+
previewPath?: string;
|
|
12
|
+
dirs: string[];
|
|
13
|
+
apiPreview?: {
|
|
14
|
+
path: string;
|
|
15
|
+
method: string;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
18
|
+
declare const _default: APIRoute;
|
|
19
|
+
export default _default;
|
|
20
|
+
export declare function scanDir(req: AdminRequest, basePath?: string, ret?: ScannedFile[]): ScannedFile[];
|
|
21
|
+
export declare function getLanguage(filePath: string): string;
|
|
22
|
+
export declare function getPreview(req: AdminRequest, filePath: string): undefined | string;
|
|
23
|
+
export declare function getAPIPreview(req: any, filePath: string): undefined | {
|
|
24
|
+
path: string;
|
|
25
|
+
method: string;
|
|
26
|
+
}[];
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, extname, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
4
|
+
export default {
|
|
5
|
+
method: "GET",
|
|
6
|
+
path: "/scan",
|
|
7
|
+
description: "admin editor file scan endpoint",
|
|
8
|
+
middleware: [server.middleware.json()],
|
|
9
|
+
request: {
|
|
10
|
+
body: false
|
|
11
|
+
},
|
|
12
|
+
response: {
|
|
13
|
+
status: [200, 400]
|
|
14
|
+
},
|
|
15
|
+
handler: async (req, res) => {
|
|
16
|
+
const admin = req.editor;
|
|
17
|
+
const services = admin ? admin.getServices() : ["."];
|
|
18
|
+
return res.json({
|
|
19
|
+
files: scanDir(req),
|
|
20
|
+
services
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export function scanDir(req, basePath = BASE_PATH, ret = []) {
|
|
25
|
+
const admin = req.editor;
|
|
26
|
+
const services = admin ? admin.getServices() : ["."];
|
|
27
|
+
services.forEach(service => {
|
|
28
|
+
scanDirInternal(req, resolve(basePath, service), ret);
|
|
29
|
+
});
|
|
30
|
+
return ret;
|
|
31
|
+
}
|
|
32
|
+
function scanDirInternal(req, path = BASE_PATH, ret = []) {
|
|
33
|
+
if (!existsSync(path)) {
|
|
34
|
+
return ret;
|
|
35
|
+
}
|
|
36
|
+
const files = readdirSync(path);
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
if (shouldIgnoreFile(file)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const filePath = resolve(path, file);
|
|
42
|
+
if (statSync(filePath).isDirectory()) {
|
|
43
|
+
scanDirInternal(req, filePath, ret);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const ext = extname(filePath);
|
|
48
|
+
const fileName = basename(filePath);
|
|
49
|
+
const name = fileName.substring(0, fileName.length - ext.length);
|
|
50
|
+
const subExt = extname(name);
|
|
51
|
+
const subName = name.substring(0, name.length - subExt.length);
|
|
52
|
+
ret.push({
|
|
53
|
+
dirs: getFileDirs(relative(BASE_PATH, filePath)),
|
|
54
|
+
language: getLanguage(filePath),
|
|
55
|
+
filePath: relative(BASE_PATH, filePath),
|
|
56
|
+
ext,
|
|
57
|
+
fileName,
|
|
58
|
+
name,
|
|
59
|
+
subExt,
|
|
60
|
+
subName,
|
|
61
|
+
previewPath: getPreview(req, filePath),
|
|
62
|
+
apiPreview: getAPIPreview(req, filePath)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return ret;
|
|
67
|
+
}
|
|
68
|
+
function shouldIgnoreFile(file) {
|
|
69
|
+
return file === ".git" || file === ".types" || file === ".DS_Store" || file === "node_modules";
|
|
70
|
+
}
|
|
71
|
+
function getFileDirs(filePath) {
|
|
72
|
+
const dirs = [];
|
|
73
|
+
let dir = dirname(filePath);
|
|
74
|
+
while (dir !== sep && dir !== "" && dir !== "." && dir !== BASE_PATH) {
|
|
75
|
+
dirs.push(dir);
|
|
76
|
+
dir = dirname(dir);
|
|
77
|
+
}
|
|
78
|
+
return dirs.reverse().map(d => basename(d));
|
|
79
|
+
}
|
|
80
|
+
export function getLanguage(filePath) {
|
|
81
|
+
const ext = extname(filePath);
|
|
82
|
+
const fileName = basename(filePath);
|
|
83
|
+
switch (ext.toLocaleLowerCase()) {
|
|
84
|
+
case ".py":
|
|
85
|
+
return "python";
|
|
86
|
+
case ".sh":
|
|
87
|
+
return "bash";
|
|
88
|
+
case ".webmanifest":
|
|
89
|
+
case ".json":
|
|
90
|
+
return "json";
|
|
91
|
+
case ".xml":
|
|
92
|
+
return "xml";
|
|
93
|
+
case ".jsx":
|
|
94
|
+
case ".js":
|
|
95
|
+
return "javascript";
|
|
96
|
+
case ".tsx":
|
|
97
|
+
case ".ts":
|
|
98
|
+
case "d.ts":
|
|
99
|
+
return "typescript";
|
|
100
|
+
case ".htm":
|
|
101
|
+
case ".html":
|
|
102
|
+
return "html";
|
|
103
|
+
case ".scss":
|
|
104
|
+
case ".css":
|
|
105
|
+
return "css";
|
|
106
|
+
case ".md":
|
|
107
|
+
return "markdown";
|
|
108
|
+
case ".c":
|
|
109
|
+
return "c";
|
|
110
|
+
case ".h":
|
|
111
|
+
case ".cpp":
|
|
112
|
+
return "cpp";
|
|
113
|
+
case ".yml":
|
|
114
|
+
case ".yaml":
|
|
115
|
+
return "yaml";
|
|
116
|
+
case ".txt":
|
|
117
|
+
case ".log":
|
|
118
|
+
return "text";
|
|
119
|
+
default:
|
|
120
|
+
switch (fileName) {
|
|
121
|
+
case "dockerfile":
|
|
122
|
+
return "dockerfile";
|
|
123
|
+
case ".gitignore":
|
|
124
|
+
return "text";
|
|
125
|
+
}
|
|
126
|
+
return "text";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function getPreview(req, filePath) {
|
|
130
|
+
const admin = req.editor;
|
|
131
|
+
const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
|
|
132
|
+
if (inflateData) {
|
|
133
|
+
return inflateData.previewMethod === "html" ? inflateData.routes[0].path : undefined;
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
export function getAPIPreview(req, filePath) {
|
|
138
|
+
const admin = req.editor;
|
|
139
|
+
const inflateData = admin ? admin.getRouteFileMap()[filePath] : undefined;
|
|
140
|
+
if (inflateData) {
|
|
141
|
+
return inflateData.previewMethod === "api" ? inflateData.routes.map(r => {
|
|
142
|
+
return {
|
|
143
|
+
path: r.path,
|
|
144
|
+
method: r.method ? r.method : "GET"
|
|
145
|
+
};
|
|
146
|
+
}) : undefined;
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { getPath } from "./read.api.js";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
export default {
|
|
5
|
+
middleware: [server.middleware.json()],
|
|
6
|
+
method: "POST",
|
|
7
|
+
path: "/write",
|
|
8
|
+
description: "admin editor file write endpoint",
|
|
9
|
+
request: {
|
|
10
|
+
body: {
|
|
11
|
+
path: "string",
|
|
12
|
+
contents: "string",
|
|
13
|
+
override: "boolean?"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
response: {
|
|
17
|
+
status: [200, 400],
|
|
18
|
+
body: {
|
|
19
|
+
message: "string"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
handler: async (req, res) => {
|
|
23
|
+
const { path, contents, override } = req.body;
|
|
24
|
+
await writeFile(path, contents, override);
|
|
25
|
+
return res.json({
|
|
26
|
+
message: "OK"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
async function writeFile(path, contents, override) {
|
|
31
|
+
if (existsSync(getPath(path)) && !override) {
|
|
32
|
+
throw new Error("file already exists!");
|
|
33
|
+
}
|
|
34
|
+
mkdirSync(dirname(getPath(path)), {
|
|
35
|
+
recursive: true
|
|
36
|
+
});
|
|
37
|
+
writeFileSync(getPath(path), contents);
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
3
|
+
export default {
|
|
4
|
+
method: "POST",
|
|
5
|
+
path: "/reload",
|
|
6
|
+
description: "admin editor server reload endpoint. reloads the server without closing the port",
|
|
7
|
+
middleware: [],
|
|
8
|
+
request: {
|
|
9
|
+
body: false
|
|
10
|
+
},
|
|
11
|
+
response: {
|
|
12
|
+
status: [200, 400],
|
|
13
|
+
body: {
|
|
14
|
+
message: "string",
|
|
15
|
+
reloadString: "string",
|
|
16
|
+
migrations: "string[]",
|
|
17
|
+
errors: {
|
|
18
|
+
allowNull: true,
|
|
19
|
+
type: "array",
|
|
20
|
+
arrayType: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
filePath: "string",
|
|
23
|
+
error: "string"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
handler: async (req, res) => {
|
|
29
|
+
const errors = await req?.editor?.reload();
|
|
30
|
+
const parsedErrors = parseInflateErrors(errors);
|
|
31
|
+
return res.json({
|
|
32
|
+
message: "OK",
|
|
33
|
+
reloadString: req.uuid,
|
|
34
|
+
migrations: req?.editor?.getMigrations().map(m => m.name),
|
|
35
|
+
errors: parsedErrors ? parsedErrors : []
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export function parseInflateErrors(errors) {
|
|
40
|
+
return errors?.map(error => {
|
|
41
|
+
return {
|
|
42
|
+
filePath: relative(BASE_PATH, error.filePath),
|
|
43
|
+
error: error.error.message
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
3
|
+
export default {
|
|
4
|
+
method: "POST",
|
|
5
|
+
path: "/restart",
|
|
6
|
+
description: "admin editor server restart endpoint",
|
|
7
|
+
middleware: [server.middleware.json()],
|
|
8
|
+
request: {
|
|
9
|
+
body: false
|
|
10
|
+
},
|
|
11
|
+
response: {
|
|
12
|
+
status: [200, 400],
|
|
13
|
+
body: {
|
|
14
|
+
message: "string",
|
|
15
|
+
reloadString: "string",
|
|
16
|
+
migrations: "string[]",
|
|
17
|
+
errors: {
|
|
18
|
+
allowNull: true,
|
|
19
|
+
type: "array",
|
|
20
|
+
arrayType: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
filePath: "string",
|
|
23
|
+
error: "string"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
handler: async (req, res) => {
|
|
29
|
+
const errors = await req?.editor?.restart();
|
|
30
|
+
return res.json({
|
|
31
|
+
message: "OK",
|
|
32
|
+
reloadString: req.uuid,
|
|
33
|
+
migrations: req?.editor?.getMigrations().map(m => m.name),
|
|
34
|
+
errors: parseInflateErrors(errors)
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export function parseInflateErrors(errors) {
|
|
39
|
+
return errors?.map(error => {
|
|
40
|
+
return {
|
|
41
|
+
filePath: relative(BASE_PATH, error.filePath),
|
|
42
|
+
error: error.error.message
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { scanDir } from "./api/fs/scan.api.js";
|
|
2
|
+
import { HTMLEncode } from "../../../common/html-encode.js";
|
|
3
|
+
export default {
|
|
4
|
+
description: "ADMIN EDITOR GUI",
|
|
5
|
+
path: "/",
|
|
6
|
+
method: "GET",
|
|
7
|
+
handler: async (req, res) => {
|
|
8
|
+
const admin = req.editor;
|
|
9
|
+
const errors = admin ? admin.getInflateErrors() : [];
|
|
10
|
+
const files = scanDir(req);
|
|
11
|
+
const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
|
|
12
|
+
const services = admin ? admin.getServices() : ["."];
|
|
13
|
+
return res.html("<!DOCTYPE html>" + String(JSX.createElement("html", null,
|
|
14
|
+
JSX.createElement("head", null,
|
|
15
|
+
JSX.createElement("link", { rel: "stylesheet", href: "/admin/editor/style.css" })),
|
|
16
|
+
JSX.createElement("body", null,
|
|
17
|
+
JSX.createElement("script", { type: "module", src: "/admin/editor/editor.js" }),
|
|
18
|
+
JSX.createElement("editor-component", { disablelog: "true", disablepreview: "true", disablereload: "true", class: "main-container", reloadstring: `${req?.uuid}`, migrations: `${HTMLEncode(JSON.stringify(migrations))}`, services: `${HTMLEncode(JSON.stringify(services))}`, errors: `${HTMLEncode(JSON.stringify(errors))}`, files: `${HTMLEncode(JSON.stringify(files))}` },
|
|
19
|
+
JSX.createElement("noscript", null, "Enable JavaScript"))))));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { BASEEDITOR_PATH } from "./common/constants.js";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { relative, resolve } from "node:path";
|
|
5
|
+
import { ADMIN_EDITOR_AUTH_KEY, ADMIN_EDITOR_AUTH_QUERY } from "./auth.js";
|
|
6
|
+
//import { getEditorAdmin } from "./common/admin-interface.js";
|
|
7
|
+
const ADMIN_EDITOR_BROWSER_OPEN_KEY = "ADMIN_EDITOR_BROWSER_OPEN_KEY$$";
|
|
8
|
+
export default {
|
|
9
|
+
preload: (serverInterface, adminInterface) => {
|
|
10
|
+
//console.dir(server);
|
|
11
|
+
if (serverInterface?.isPrimaryWorker()) {
|
|
12
|
+
const cache = (adminInterface ? adminInterface.getCache() : serverInterface.cache);
|
|
13
|
+
if (!cache.has(ADMIN_EDITOR_AUTH_KEY)) {
|
|
14
|
+
const adminKEYPath = resolve(".admin_key");
|
|
15
|
+
if (existsSync(adminKEYPath)) {
|
|
16
|
+
serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", relative(process.cwd(), adminKEYPath));
|
|
17
|
+
cache.set(ADMIN_EDITOR_AUTH_KEY, readFileSync(adminKEYPath).toString().trim());
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
cache.set(ADMIN_EDITOR_AUTH_KEY, randomUUID());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
start: (serverInterface, adminInterface) => {
|
|
26
|
+
//console.dir(server);
|
|
27
|
+
const cache = (adminInterface ? adminInterface.getCache() : serverInterface.cache);
|
|
28
|
+
if (!cache.has(ADMIN_EDITOR_BROWSER_OPEN_KEY)) {
|
|
29
|
+
const KEY = cache.get(ADMIN_EDITOR_AUTH_KEY);
|
|
30
|
+
const adminPath = `${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`;
|
|
31
|
+
if (serverInterface?.isPrimaryWorker()) {
|
|
32
|
+
serverInterface.logger.log("\n\n\tADMIN_EDITOR\n\n\t%s\n\n", adminPath);
|
|
33
|
+
}
|
|
34
|
+
//const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
35
|
+
//const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
36
|
+
if (serverInterface.isPrimaryWorker()) {
|
|
37
|
+
cache.set(ADMIN_EDITOR_BROWSER_OPEN_KEY, true);
|
|
38
|
+
try {
|
|
39
|
+
serverInterface.openBrowser(`${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`);
|
|
40
|
+
//serverInterface.logger.log(`${OPEN} "${adminPath}"`);
|
|
41
|
+
//execSync(`${OPEN} "${adminPath}"`);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
serverInterface.logger.error(e.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LOG_SOCKET_PATH } from "./common/constants.js";
|
|
2
|
+
export default {
|
|
3
|
+
path: LOG_SOCKET_PATH,
|
|
4
|
+
validate(req) {
|
|
5
|
+
const admin = req.editor;
|
|
6
|
+
const cache = (admin ? admin.getCache() : req.server.cache);
|
|
7
|
+
const KEY = cache.get("AUTH_KEY");
|
|
8
|
+
const cookieToken = req.cookies["auth"];
|
|
9
|
+
return cookieToken === KEY ? true : false;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -16,5 +16,13 @@ export async function installTypings(args, logger) {
|
|
|
16
16
|
logger.error("tsconfig.json already exists!");
|
|
17
17
|
process.exit(EXIT_CODES.ABNORMAL);
|
|
18
18
|
}
|
|
19
|
+
if (args.installMiqroJSON && !existsSync("miqro.json")) {
|
|
20
|
+
logger.info("writing miqro.json");
|
|
21
|
+
writeFileSync("miqro.json", TEMPLATES["MIQROJSON"].template("", ""));
|
|
22
|
+
}
|
|
23
|
+
else if (args.installMiqroJSON) {
|
|
24
|
+
logger.error("miqro.json already exists!");
|
|
25
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
26
|
+
}
|
|
19
27
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
20
28
|
}
|
|
@@ -3,12 +3,18 @@ interface MiqroJSON {
|
|
|
3
3
|
port?: string | number;
|
|
4
4
|
inflateDir?: string;
|
|
5
5
|
name?: string;
|
|
6
|
+
browser?: string | boolean;
|
|
7
|
+
logFile?: string | boolean;
|
|
8
|
+
editor?: boolean;
|
|
6
9
|
}
|
|
7
10
|
export declare function importMiqroJSON(inFile: string): MiqroJSON;
|
|
8
11
|
export declare function getPORT(): string;
|
|
9
12
|
export interface Arguments {
|
|
10
|
-
name
|
|
13
|
+
name?: string;
|
|
14
|
+
browser?: string | boolean;
|
|
15
|
+
logFile?: string | boolean;
|
|
11
16
|
installTypes: boolean;
|
|
17
|
+
installMiqroJSON: boolean;
|
|
12
18
|
installTSConfig: boolean;
|
|
13
19
|
test: boolean;
|
|
14
20
|
port: string;
|
|
@@ -18,7 +18,10 @@ const MiqroJSONSchema = {
|
|
|
18
18
|
name: "string?",
|
|
19
19
|
services: "string[]?",
|
|
20
20
|
port: "number?|string?",
|
|
21
|
-
inflateDir: "string?"
|
|
21
|
+
inflateDir: "string?",
|
|
22
|
+
browser: "boolean?|string?",
|
|
23
|
+
logFile: "boolean?|string?",
|
|
24
|
+
editor: "boolean?"
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
27
|
export function importMiqroJSON(inFile) {
|
|
@@ -42,8 +45,11 @@ export function parseArguments() {
|
|
|
42
45
|
const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
|
|
43
46
|
const flags = {
|
|
44
47
|
name: null,
|
|
48
|
+
browser: null,
|
|
49
|
+
logFile: null,
|
|
45
50
|
hotreload: null,
|
|
46
51
|
miqroJSONPath: null,
|
|
52
|
+
installMiqroJSON: null,
|
|
47
53
|
disableMiqroJSON: null,
|
|
48
54
|
installTypes: null,
|
|
49
55
|
port: null,
|
|
@@ -130,7 +136,7 @@ export function parseArguments() {
|
|
|
130
136
|
console.error(usage);
|
|
131
137
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
132
138
|
}
|
|
133
|
-
const cPort = String(args[i + 1])
|
|
139
|
+
const cPort = String(args[i + 1]);
|
|
134
140
|
if (typeof cPort !== "string") {
|
|
135
141
|
console.error("bad arguments. --port must be a string.");
|
|
136
142
|
console.error(usage);
|
|
@@ -154,6 +160,36 @@ export function parseArguments() {
|
|
|
154
160
|
flags.name = cName;
|
|
155
161
|
i++;
|
|
156
162
|
continue;
|
|
163
|
+
case "--log-file":
|
|
164
|
+
if (flags.logFile !== null) {
|
|
165
|
+
console.error("bad arguments.");
|
|
166
|
+
console.error(usage);
|
|
167
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
168
|
+
}
|
|
169
|
+
const cLofFile = String(args[i + 1]);
|
|
170
|
+
if (typeof cLofFile !== "string") {
|
|
171
|
+
console.error("bad arguments. --port must be a string.");
|
|
172
|
+
console.error(usage);
|
|
173
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
174
|
+
}
|
|
175
|
+
flags.logFile = cLofFile;
|
|
176
|
+
i++;
|
|
177
|
+
continue;
|
|
178
|
+
case "--browser":
|
|
179
|
+
if (flags.browser !== null) {
|
|
180
|
+
console.error("bad arguments.");
|
|
181
|
+
console.error(usage);
|
|
182
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
183
|
+
}
|
|
184
|
+
const cBrowser = String(args[i + 1]);
|
|
185
|
+
if (typeof cBrowser !== "string") {
|
|
186
|
+
console.error("bad arguments. --port must be a string.");
|
|
187
|
+
console.error(usage);
|
|
188
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
189
|
+
}
|
|
190
|
+
flags.browser = cBrowser;
|
|
191
|
+
i++;
|
|
192
|
+
continue;
|
|
157
193
|
case "--generate-doc":
|
|
158
194
|
if (flags.generateDoc !== null) {
|
|
159
195
|
console.error("bad arguments.");
|
|
@@ -228,6 +264,14 @@ export function parseArguments() {
|
|
|
228
264
|
}
|
|
229
265
|
flags.editor = true;
|
|
230
266
|
continue;
|
|
267
|
+
case "--install-miqrojson":
|
|
268
|
+
if (flags.installMiqroJSON !== null) {
|
|
269
|
+
console.error("bad arguments. --install-miqrojson already set.");
|
|
270
|
+
console.error(usage);
|
|
271
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
272
|
+
}
|
|
273
|
+
flags.installMiqroJSON = true;
|
|
274
|
+
continue;
|
|
231
275
|
case "--inflate-sea":
|
|
232
276
|
if (flags.inflateSEA !== null) {
|
|
233
277
|
console.error("bad arguments. --inflate-sea already set.");
|
|
@@ -308,7 +352,6 @@ export function parseArguments() {
|
|
|
308
352
|
}
|
|
309
353
|
}
|
|
310
354
|
flags.inflate = flags.inflate ? flags.inflate : false;
|
|
311
|
-
flags.editor = flags.editor ? flags.editor : false;
|
|
312
355
|
flags.test = flags.test ? flags.test : false;
|
|
313
356
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
314
357
|
const miqroJSONPath = !flags.disableMiqroJSON ? flags.miqroJSONPath ? resolve(flags.miqroJSONPath) : getMiqroJSONPath() : false;
|
|
@@ -322,7 +365,7 @@ export function parseArguments() {
|
|
|
322
365
|
}
|
|
323
366
|
}
|
|
324
367
|
}
|
|
325
|
-
if (
|
|
368
|
+
if (flags.port === null) {
|
|
326
369
|
if (miqroRC.port) {
|
|
327
370
|
flags.port = String(miqroRC.port);
|
|
328
371
|
}
|
|
@@ -332,13 +375,29 @@ export function parseArguments() {
|
|
|
332
375
|
flags.inflateDir = miqroRC.inflateDir;
|
|
333
376
|
}
|
|
334
377
|
}
|
|
335
|
-
if (
|
|
378
|
+
if (flags.name === null) {
|
|
336
379
|
if (miqroRC.name) {
|
|
337
380
|
flags.name = miqroRC.name;
|
|
338
381
|
}
|
|
339
382
|
}
|
|
383
|
+
if (flags.logFile === null) {
|
|
384
|
+
if (miqroRC.logFile !== undefined) {
|
|
385
|
+
flags.logFile = miqroRC.logFile;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (flags.browser === null) {
|
|
389
|
+
if (miqroRC.browser !== undefined) {
|
|
390
|
+
flags.browser = miqroRC.browser;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (flags.editor === null) {
|
|
394
|
+
if (miqroRC.editor !== undefined) {
|
|
395
|
+
flags.editor = miqroRC.editor;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
340
398
|
}
|
|
341
|
-
|
|
399
|
+
flags.editor = flags.editor ? flags.editor : false;
|
|
400
|
+
if (services.length === 0 && (!flags.installTSConfig && !flags.installTypes && !flags.installMiqroJSON)) {
|
|
342
401
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
343
402
|
console.error(`bad arguments. missing --service argument`);
|
|
344
403
|
console.error(usage);
|
|
@@ -368,16 +427,16 @@ export function parseArguments() {
|
|
|
368
427
|
console.error("bad arguments. cannot use --inflate with --editor");
|
|
369
428
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
370
429
|
}
|
|
371
|
-
if (flags.inflate && (flags.installTypes || flags.installTSConfig)) {
|
|
372
|
-
console.error("bad arguments. cannot use --inflate with --install-types");
|
|
430
|
+
if (flags.inflate && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
431
|
+
console.error("bad arguments. cannot use --inflate with --install-types, --install-tsconfig or --install-miqrojson");
|
|
373
432
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
374
433
|
}
|
|
375
434
|
if (flags.inflateSEA && !flags.inflate) {
|
|
376
435
|
console.error("bad arguments. cannot use --inflate-sea without --inflate");
|
|
377
436
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
378
437
|
}
|
|
379
|
-
if (flags.editor && (flags.installTypes || flags.installTSConfig)) {
|
|
380
|
-
console.error("bad arguments. cannot use --editor with --install-
|
|
438
|
+
if (flags.editor && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
439
|
+
console.error("bad arguments. cannot use --editor with--install-types, --install-tsconfig or --install-miqrojson");
|
|
381
440
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
382
441
|
}
|
|
383
442
|
if (flags.test && (flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
|
|
@@ -403,11 +462,14 @@ export function parseArguments() {
|
|
|
403
462
|
const generateDocType = flags.generateDocType ? flags.generateDocType : "MD";
|
|
404
463
|
return {
|
|
405
464
|
name: flags.name ? flags.name : undefined,
|
|
465
|
+
browser: flags.browser !== null ? flags.browser : undefined,
|
|
466
|
+
logFile: flags.logFile !== null ? flags.logFile : undefined,
|
|
406
467
|
generateDocAll: flags.generateDocAll ? true : false,
|
|
407
468
|
hotreload: flags.hotreload ? true : false,
|
|
408
469
|
disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
|
|
409
470
|
miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
|
|
410
471
|
installTypes: flags.installTypes ? true : false,
|
|
472
|
+
installMiqroJSON: flags.installMiqroJSON ? true : false,
|
|
411
473
|
installTSConfig: flags.installTSConfig ? true : false,
|
|
412
474
|
inflate: flags.inflate,
|
|
413
475
|
port: flags.port ? flags.port : getPORT(),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const BIN_NAME = "miqro";
|
|
2
2
|
export declare const usage = "usage: miqro [...FLAGS] --service app/\n\n==examples==\n\nmiqro --watch --service front/\nPORT=8181 miqro --service api/ --service front/\nmiqro --test --service front/\nmiqro --inflate --service front/\nmiqro --generate-doc --generate-doc-out API.md --service front/\nCLUSTER_COUNT=10 miqro-cluster --service api/";
|
|
3
|
-
export declare const help = "\n==flags==\n\n-v, --version\
|
|
3
|
+
export declare const help = "\n==flags==\n\n-v, --version\n\toutputs the version number\n-h, --help\n\toutputs this page.\n--watch\n\tuse to enable the hot-reload functionality.\n--test\n\trun the tests for a service.\n--migrate-up\n\tmigrations up.\n--migrate-down\n\tmigrations down.\n--inflate\n\tinflates the application.\n--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.\n--editor\n\truns the application with a built-in editor.\n--generate-doc\n\tgenerates a documentation for the api endpoints of the service.\n--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.\n--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.\n--generate-doc-all\n\toutputs all the server routes in the documentation output.\n--compile\n\tinflates the application and tries to create a NODE SEA binary.\n--inflate-sea\n\tinflates the application with sea compilation scripts.\n--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.\n--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.\n--install-miqrojson\n\tcreates a default miqro.json file.\n--disable-miqrojson\n\tdisables the load of miqro.json file.\n--log-file\n\toverrides the default log file from LOG_FILE.\n--browser\n\toverrides the default browser from BROWSER.\n--config\n\toverrides the default miqro.json path.\n--port\n\toverrides the default port from PORT.\n--name\n\toverrides the default name of the server.\n\n==environment variables==\n\nPORT\n\toverride the default 8080 port.\nBROWSER\n\toverride the default browser. change to none to disable.\".\nLOG_FILE\n\toverride the default ./server.log file\nDB\n\tenable the server.db features\nDB_STORAGE\n\toverride the default local db location ./db.sqlite3\nDB_DIALECT\n\toverride the default node:sqlite\nDB_CONNECTION\n\toverride the default connection url\nCLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.\nJSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.\n";
|