miqro 7.0.10 → 7.2.0
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/README.md +92 -24
- package/build/esm/editor/auth.js +1 -0
- package/build/esm/editor/auth.js.map +1 -0
- package/build/esm/editor/common/admin-interface.js +1 -0
- package/build/esm/editor/common/admin-interface.js.map +1 -0
- package/build/esm/editor/common/constants.js +1 -0
- package/build/esm/editor/common/constants.js.map +1 -0
- package/build/esm/editor/common/constants.server.js +1 -0
- package/build/esm/editor/common/constants.server.js.map +1 -0
- package/build/esm/editor/common/editor-index.js +1 -0
- package/build/esm/editor/common/editor-index.js.map +1 -0
- package/build/esm/editor/common/html-encode.js +1 -0
- package/build/esm/editor/common/html-encode.js.map +1 -0
- package/build/esm/editor/common/log-socket.js +1 -0
- package/build/esm/editor/common/log-socket.js.map +1 -0
- package/build/esm/editor/common/templates.js +1 -0
- package/build/esm/editor/common/templates.js.map +1 -0
- package/build/esm/editor/components/api-preview.js +1 -0
- package/build/esm/editor/components/api-preview.js.map +1 -0
- package/build/esm/editor/components/editor.js +1 -0
- package/build/esm/editor/components/editor.js.map +1 -0
- package/build/esm/editor/components/file-browser.js +1 -0
- package/build/esm/editor/components/file-browser.js.map +1 -0
- package/build/esm/editor/components/file-editor-toolbar.js +1 -0
- package/build/esm/editor/components/file-editor-toolbar.js.map +1 -0
- package/build/esm/editor/components/file-editor.js +1 -0
- package/build/esm/editor/components/file-editor.js.map +1 -0
- package/build/esm/editor/components/filter-query.js +1 -0
- package/build/esm/editor/components/filter-query.js.map +1 -0
- package/build/esm/editor/components/highlight-text-area.js +1 -0
- package/build/esm/editor/components/highlight-text-area.js.map +1 -0
- package/build/esm/editor/components/log-viewer.js +1 -0
- package/build/esm/editor/components/log-viewer.js.map +1 -0
- package/build/esm/editor/components/new-file.js +1 -0
- package/build/esm/editor/components/new-file.js.map +1 -0
- package/build/esm/editor/components/scroll-query.js +1 -0
- package/build/esm/editor/components/scroll-query.js.map +1 -0
- package/build/esm/editor/components/start-page.js +1 -0
- package/build/esm/editor/components/start-page.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +1 -0
- package/build/esm/editor/http/admin/editor/editor.js.map +1 -0
- package/build/esm/editor/http/admin/editor/index.api.js +1 -0
- package/build/esm/editor/http/admin/editor/index.api.js.map +1 -0
- package/build/esm/editor/server.js +1 -0
- package/build/esm/editor/server.js.map +1 -0
- package/build/esm/editor/ws.js +1 -0
- package/build/esm/editor/ws.js.map +1 -0
- package/build/esm/src/bin/compile.js +1 -0
- package/build/esm/src/bin/compile.js.map +1 -0
- package/build/esm/src/bin/doc-md.js +1 -0
- package/build/esm/src/bin/doc-md.js.map +1 -0
- package/build/esm/src/bin/generate-doc.js +1 -0
- package/build/esm/src/bin/generate-doc.js.map +1 -0
- package/build/esm/src/bin/test.d.ts +2 -1
- package/build/esm/src/bin/test.js +3 -2
- package/build/esm/src/bin/test.js.map +1 -0
- package/build/esm/src/bin/types.js +1 -0
- package/build/esm/src/bin/types.js.map +1 -0
- package/build/esm/src/cluster.js +1 -0
- package/build/esm/src/cluster.js.map +1 -0
- package/build/esm/src/common/arguments.d.ts +8 -0
- package/build/esm/src/common/arguments.js +78 -1
- package/build/esm/src/common/arguments.js.map +1 -0
- package/build/esm/src/common/assets.d.ts +1 -1
- package/build/esm/src/common/assets.js +2 -1
- package/build/esm/src/common/assets.js.map +1 -0
- package/build/esm/src/common/checksum.js +1 -0
- package/build/esm/src/common/checksum.js.map +1 -0
- package/build/esm/src/common/constants.d.ts +1 -0
- package/build/esm/src/common/constants.js +2 -0
- package/build/esm/src/common/constants.js.map +1 -0
- package/build/esm/src/common/content-type.js +1 -0
- package/build/esm/src/common/content-type.js.map +1 -0
- package/build/esm/src/common/esbuild.js +1 -0
- package/build/esm/src/common/esbuild.js.map +1 -0
- package/build/esm/src/common/exit.js +1 -0
- package/build/esm/src/common/exit.js.map +1 -0
- package/build/esm/src/common/fs.js +1 -0
- package/build/esm/src/common/fs.js.map +1 -0
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +7 -1
- package/build/esm/src/common/help.js.map +1 -0
- package/build/esm/src/common/jsx.d.ts +20 -16
- package/build/esm/src/common/jsx.js +34 -29
- package/build/esm/src/common/jsx.js.map +1 -0
- package/build/esm/src/common/jwt.js +1 -0
- package/build/esm/src/common/jwt.js.map +1 -0
- package/build/esm/src/common/paths.js +1 -0
- package/build/esm/src/common/paths.js.map +1 -0
- package/build/esm/src/common/watch.js +1 -0
- package/build/esm/src/common/watch.js.map +1 -0
- package/build/esm/src/inflate/inflate-sea.js +16 -15
- package/build/esm/src/inflate/inflate-sea.js.map +1 -0
- package/build/esm/src/inflate/inflate.d.ts +5 -1
- package/build/esm/src/inflate/inflate.js +6 -5
- package/build/esm/src/inflate/inflate.js.map +1 -0
- package/build/esm/src/inflate/md.js +1 -0
- package/build/esm/src/inflate/md.js.map +1 -0
- package/build/esm/src/inflate/setup-auth.d.ts +2 -2
- package/build/esm/src/inflate/setup-auth.js +3 -2
- package/build/esm/src/inflate/setup-auth.js.map +1 -0
- package/build/esm/src/inflate/setup-cors.d.ts +2 -2
- package/build/esm/src/inflate/setup-cors.js +3 -2
- package/build/esm/src/inflate/setup-cors.js.map +1 -0
- package/build/esm/src/inflate/setup-db.d.ts +3 -3
- package/build/esm/src/inflate/setup-db.js +6 -5
- package/build/esm/src/inflate/setup-db.js.map +1 -0
- package/build/esm/src/inflate/setup-error.d.ts +2 -2
- package/build/esm/src/inflate/setup-error.js +3 -2
- package/build/esm/src/inflate/setup-error.js.map +1 -0
- package/build/esm/src/inflate/setup-http.d.ts +7 -2
- package/build/esm/src/inflate/setup-http.js +54 -45
- package/build/esm/src/inflate/setup-http.js.map +1 -0
- package/build/esm/src/inflate/setup-log.d.ts +2 -2
- package/build/esm/src/inflate/setup-log.js +3 -2
- package/build/esm/src/inflate/setup-log.js.map +1 -0
- package/build/esm/src/inflate/setup-middleware.d.ts +2 -2
- package/build/esm/src/inflate/setup-middleware.js +3 -2
- package/build/esm/src/inflate/setup-middleware.js.map +1 -0
- package/build/esm/src/inflate/setup-server-config.d.ts +2 -2
- package/build/esm/src/inflate/setup-server-config.js +3 -2
- package/build/esm/src/inflate/setup-server-config.js.map +1 -0
- package/build/esm/src/inflate/setup-test.d.ts +2 -1
- package/build/esm/src/inflate/setup-test.js +3 -2
- package/build/esm/src/inflate/setup-test.js.map +1 -0
- package/build/esm/src/inflate/setup-ws.d.ts +2 -2
- package/build/esm/src/inflate/setup-ws.js +3 -2
- package/build/esm/src/inflate/setup-ws.js.map +1 -0
- package/build/esm/src/inflate/setup.doc.d.ts +2 -2
- package/build/esm/src/inflate/setup.doc.js +5 -4
- package/build/esm/src/inflate/setup.doc.js.map +1 -0
- package/build/esm/src/inflate/utils/sea-utils.js +1 -0
- package/build/esm/src/inflate/utils/sea-utils.js.map +1 -0
- package/build/esm/src/lib.js +1 -0
- package/build/esm/src/lib.js.map +1 -0
- package/build/esm/src/main.js +9 -2
- package/build/esm/src/main.js.map +1 -0
- package/build/esm/src/services/app.d.ts +5 -2
- package/build/esm/src/services/app.js +19 -6
- package/build/esm/src/services/app.js.map +1 -0
- package/build/esm/src/services/editor.js +1 -0
- package/build/esm/src/services/editor.js.map +1 -0
- package/build/esm/src/services/hot-reload.d.ts +1 -0
- package/build/esm/src/services/hot-reload.js +9 -5
- package/build/esm/src/services/hot-reload.js.map +1 -0
- package/build/esm/src/services/migrations.d.ts +3 -2
- package/build/esm/src/services/migrations.js +5 -4
- package/build/esm/src/services/migrations.js.map +1 -0
- package/build/esm/src/services/utils/admin-interface.js +1 -0
- package/build/esm/src/services/utils/admin-interface.js.map +1 -0
- package/build/esm/src/services/utils/cache.js +1 -0
- package/build/esm/src/services/utils/cache.js.map +1 -0
- package/build/esm/src/services/utils/cluster-cache.js +1 -0
- package/build/esm/src/services/utils/cluster-cache.js.map +1 -0
- package/build/esm/src/services/utils/cluster-ws.js +1 -0
- package/build/esm/src/services/utils/cluster-ws.js.map +1 -0
- package/build/esm/src/services/utils/db-manager.js +1 -0
- package/build/esm/src/services/utils/db-manager.js.map +1 -0
- package/build/esm/src/services/utils/get-route.js +1 -0
- package/build/esm/src/services/utils/get-route.js.map +1 -0
- package/build/esm/src/services/utils/jwt.js +1 -0
- package/build/esm/src/services/utils/jwt.js.map +1 -0
- package/build/esm/src/services/utils/log-transport.js +1 -0
- package/build/esm/src/services/utils/log-transport.js.map +1 -0
- package/build/esm/src/services/utils/log.js +1 -0
- package/build/esm/src/services/utils/log.js.map +1 -0
- package/build/esm/src/services/utils/middleware.js +1 -0
- package/build/esm/src/services/utils/middleware.js.map +1 -0
- package/build/esm/src/services/utils/server-interface.js +1 -0
- package/build/esm/src/services/utils/server-interface.js.map +1 -0
- package/build/esm/src/services/utils/websocketmanager.js +1 -0
- package/build/esm/src/services/utils/websocketmanager.js.map +1 -0
- package/build/esm/src/types.js +1 -0
- package/build/esm/src/types.js.map +1 -0
- package/build/lib.cjs +239 -150
- package/package.json +5 -5
- package/sea/install-esbuild.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/src/bin/test.ts +3 -2
- package/src/common/arguments.ts +92 -1
- package/src/common/assets.ts +2 -2
- package/src/common/constants.ts +1 -0
- package/src/common/help.ts +6 -1
- package/src/common/jsx.ts +41 -30
- package/src/inflate/inflate-sea.ts +15 -15
- package/src/inflate/inflate.ts +9 -5
- package/src/inflate/setup-auth.ts +3 -3
- package/src/inflate/setup-cors.ts +4 -3
- package/src/inflate/setup-db.ts +6 -6
- package/src/inflate/setup-error.ts +3 -3
- package/src/inflate/setup-http.ts +61 -45
- package/src/inflate/setup-log.ts +3 -3
- package/src/inflate/setup-middleware.ts +3 -3
- package/src/inflate/setup-server-config.ts +3 -3
- package/src/inflate/setup-test.ts +3 -3
- package/src/inflate/setup-ws.ts +3 -3
- package/src/inflate/setup.doc.ts +5 -5
- package/src/main.ts +8 -2
- package/src/services/app.ts +24 -9
- package/src/services/hot-reload.ts +9 -5
- package/src/services/migrations.ts +5 -5
package/src/inflate/setup-db.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger } from "@miqro/core";
|
|
2
2
|
import { Migration, migration } from "@miqro/query";
|
|
3
|
-
import { importDBConfigModule, importMigrationModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
|
+
import { importDBConfigModule, ImportJSXFileOptions, importMigrationModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
4
4
|
import { getDBConfigPath, getMigrationsPath, getServicePath } from "../common/paths.js";
|
|
5
5
|
import { dirname, extname, relative, resolve } from "node:path";
|
|
6
6
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -11,15 +11,15 @@ export interface MigrationModule extends Migration, NamedMigration {
|
|
|
11
11
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export async function inflateDBConfig(logger: Logger, service: string, dbConfigList: DBConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
14
|
+
export async function inflateDBConfig(logger: Logger, service: string, dbConfigList: DBConfig[] | undefined, inflateDir: string | undefined | false, options: ImportJSXFileOptions, errors: InflateError[]) {
|
|
15
15
|
const servicePath = getServicePath(service);
|
|
16
16
|
const dbConfigPath = getDBConfigPath(servicePath);
|
|
17
17
|
if (dbConfigPath) {
|
|
18
18
|
try {
|
|
19
19
|
//logger.debug("loading DBConfig for service[%s]", service);
|
|
20
|
-
const config = await importDBConfigModule(dbConfigPath, logger);
|
|
20
|
+
const config = await importDBConfigModule(dbConfigPath, options, logger);
|
|
21
21
|
if (config && dbConfigList && dbConfigList.filter(c => c.name === config.name).length > 0) {
|
|
22
|
-
throw new Error(`
|
|
22
|
+
throw new Error(`db name [${config.name}] already defined! error from [${dbConfigPath}]`);
|
|
23
23
|
} else if (config) {
|
|
24
24
|
//logger.debug("DBConfig [%s] loaded from service [%s]", config.name, service);
|
|
25
25
|
if (dbConfigList) {
|
|
@@ -62,7 +62,7 @@ export async function inflateDBConfig(logger: Logger, service: string, dbConfigL
|
|
|
62
62
|
return false;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export async function inflateDBMigrations(logger: Logger, service: string, dbName: string, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
65
|
+
export async function inflateDBMigrations(logger: Logger, service: string, dbName: string, inflateDir: string | undefined | false, options: ImportJSXFileOptions, errors: InflateError[]) {
|
|
66
66
|
const servicePath = getServicePath(service);
|
|
67
67
|
const migrationsFolderPath = getMigrationsPath(servicePath);
|
|
68
68
|
if (migrationsFolderPath) {
|
|
@@ -76,7 +76,7 @@ export async function inflateDBMigrations(logger: Logger, service: string, dbNam
|
|
|
76
76
|
for (const migrationName of serviceMigrations) {
|
|
77
77
|
const migrationPath = resolve(migrationsFolderPath, migrationName);
|
|
78
78
|
try {
|
|
79
|
-
const migrationModule = await importMigrationModule(migrationPath);
|
|
79
|
+
const migrationModule = await importMigrationModule(migrationPath, options, logger);
|
|
80
80
|
migrationModules.push({
|
|
81
81
|
name: migrationName,
|
|
82
82
|
service,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Logger, Router } from "@miqro/core";
|
|
2
|
-
import { importErrorConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
2
|
+
import { importErrorConfigModule, ImportJSXFileOptions, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
3
|
import { getErrorConfigPath } from "../common/paths.js";
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { cwd } from "node:process";
|
|
7
7
|
|
|
8
|
-
export async function setupError(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[]): Promise<void> {
|
|
8
|
+
export async function setupError(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, options: ImportJSXFileOptions, errors: InflateError[]): Promise<void> {
|
|
9
9
|
const errorPath = getErrorConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
10
10
|
|
|
11
11
|
if (errorPath) {
|
|
12
12
|
try {
|
|
13
|
-
const errorModule = await importErrorConfigModule(errorPath, logger);
|
|
13
|
+
const errorModule = await importErrorConfigModule(errorPath, options, logger);
|
|
14
14
|
logger.debug("setting up error handling from [%s]", join(service, basename(errorPath)));
|
|
15
15
|
if (errorModule && errorModule.catch) {
|
|
16
16
|
for (const m of errorModule.catch) {
|
|
@@ -3,7 +3,7 @@ import { existsSync, mkdir, readFile, readFileSync, readdirSync, statSync } from
|
|
|
3
3
|
import { dirname, join, relative, resolve as pathResolve } from "node:path";
|
|
4
4
|
|
|
5
5
|
import { CONTENT_TYPE_MAP, DEFAULT_CONTENT_TYPE } from "../common/content-type.js";
|
|
6
|
-
import { InflateError, importHTMLModule, importAPIRoute, inflateJSX, importJSONModule, JSONModuleValue, jsx2HTML } from "../common/jsx.js";
|
|
6
|
+
import { InflateError, importHTMLModule, importAPIRoute, inflateJSX, importJSONModule, JSONModuleValue, jsx2HTML, ImportJSXFileOptions } from "../common/jsx.js";
|
|
7
7
|
import { createNodeRuntime } from "@miqro/jsx-node";
|
|
8
8
|
import { getHotReloadScript } from "../services/hot-reload.js";
|
|
9
9
|
import { RuntimeURL } from "@miqro/jsx";
|
|
@@ -45,27 +45,27 @@ export interface StaticFileMap {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export async function setupHTTPRouter(server: ServerInterface, logger: Logger, hotreload: boolean, servicePath: string, service: string, routeFileMap: RouteFileMap, staticFileMap: StaticFileMap | null, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[], inflateParallel?: number) {
|
|
48
|
+
export async function setupHTTPRouter(importOptions: ImportJSXFileOptions, inflateOptions: InflateJSXFileOptions, server: ServerInterface, logger: Logger, hotreload: boolean, servicePath: string, service: string, routeFileMap: RouteFileMap, staticFileMap: StaticFileMap | null, inflateDir: string | undefined | false, inflateSea: boolean, errors: InflateError[], inflateParallel?: number) {
|
|
49
49
|
const mainRouter = new Router();
|
|
50
50
|
const apiRouterPath = getHTTPRouterPath(servicePath); //resolve(process.cwd(), service, "http");
|
|
51
51
|
let middlewareConfig: MiddlewareConfig | null = null;
|
|
52
52
|
|
|
53
|
-
await setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
53
|
+
await setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
54
54
|
|
|
55
|
-
await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
56
|
-
await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
57
|
-
middlewareConfig = await setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
55
|
+
await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
56
|
+
await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
57
|
+
middlewareConfig = await setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
58
58
|
|
|
59
59
|
if (apiRouterPath) {
|
|
60
60
|
logger.trace("setting up http routes from [%s]", service);
|
|
61
|
-
const { router: httpRouter } = await createRouterFromDirectory(server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea, inflateParallel);
|
|
61
|
+
const { router: httpRouter } = await createRouterFromDirectory(importOptions, inflateOptions, server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea, inflateParallel);
|
|
62
62
|
mainRouter.use(httpRouter);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const staticFilesPath = getStaticFilesPath(servicePath); //resolve(process.cwd(), service, "static");
|
|
66
66
|
if (staticFilesPath) {
|
|
67
67
|
logger.trace("setting up static file routes from [%s]", service);
|
|
68
|
-
const staticRouter = await createStaticRouterFromDirectory(service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap, inflateParallel);
|
|
68
|
+
const staticRouter = await createStaticRouterFromDirectory(inflateOptions, service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap, inflateParallel);
|
|
69
69
|
mainRouter.use(staticRouter);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -78,7 +78,7 @@ export async function setupHTTPRouter(server: ServerInterface, logger: Logger, h
|
|
|
78
78
|
return mainRouter;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
async function createStaticRoute(service: string, logger: Logger, router: Router, dir: string, file: ScannedFile, inflateDir?: string | undefined | false, routeFileMap?: RouteFileMap, staticFileMap?: StaticFileMap) {
|
|
81
|
+
async function createStaticRoute(inflateJSXOptions: InflateJSXFileOptions, service: string, logger: Logger, router: Router, dir: string, file: ScannedFile, inflateDir?: string | undefined | false, routeFileMap?: RouteFileMap, staticFileMap?: StaticFileMap) {
|
|
82
82
|
return new Promise<void>(async (resolve, reject) => {
|
|
83
83
|
try {
|
|
84
84
|
logger.trace("creating static route for [%s]", file.filePath);
|
|
@@ -100,8 +100,8 @@ async function createStaticRoute(service: string, logger: Logger, router: Router
|
|
|
100
100
|
previewMethod: "html"
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
if (inflateDir) {
|
|
104
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
103
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
104
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
105
105
|
mkdir(dirname(inflatePath), {
|
|
106
106
|
recursive: true
|
|
107
107
|
}, (err) => {
|
|
@@ -121,7 +121,7 @@ async function createStaticRoute(service: string, logger: Logger, router: Router
|
|
|
121
121
|
method: "GET",
|
|
122
122
|
path: normalizePath(path),
|
|
123
123
|
body: Buffer.from(body),
|
|
124
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
124
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : undefined
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -162,14 +162,14 @@ async function createStaticRoute(service: string, logger: Logger, router: Router
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
async function createStaticRouterFromDirectory(service: string, logger: Logger, dir: string, inflateDir: string | false | undefined, routeFileMap: RouteFileMap | undefined, staticFileMap: StaticFileMap | null, inflateParallel?: number): Promise<Router> {
|
|
165
|
+
async function createStaticRouterFromDirectory(inflateOptions: InflateJSXFileOptions, service: string, logger: Logger, dir: string, inflateDir: string | false | undefined, routeFileMap: RouteFileMap | undefined, staticFileMap: StaticFileMap | null, inflateParallel?: number): Promise<Router> {
|
|
166
166
|
const router = new Router();
|
|
167
167
|
const maxParallel = inflateParallel ? inflateParallel : 1;
|
|
168
168
|
logger.debug("loading static directory with parallel [%s]", maxParallel);
|
|
169
169
|
let tR = [];
|
|
170
170
|
const files = scanFiles(dir);
|
|
171
171
|
for (const file of files) {
|
|
172
|
-
tR.push(await createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap));
|
|
172
|
+
tR.push(await createStaticRoute(inflateOptions, service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap));
|
|
173
173
|
if (tR.length >= maxParallel) {
|
|
174
174
|
await Promise.all(tR);
|
|
175
175
|
tR = [];
|
|
@@ -182,7 +182,13 @@ async function createStaticRouterFromDirectory(service: string, logger: Logger,
|
|
|
182
182
|
return router;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
interface InflateJSXFileOptions {
|
|
186
|
+
noMinify?: boolean;
|
|
187
|
+
inflateOnlyAssets?: boolean;
|
|
188
|
+
inflateFlat?: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function createRouterFromDirectory(importOptions: ImportJSXFileOptions, inflateJSXOptions: InflateJSXFileOptions, server: ServerInterface, hotreload: boolean, service: string, logger: Logger, dir: string, errors: InflateError[] = [], routeFileMap: RouteFileMap = {}, staticFileMap: StaticFileMap | null = null, inflateDir: string | undefined | false, inflateSea: boolean, inflateParallel?: number): Promise<{
|
|
186
192
|
router: Router;
|
|
187
193
|
errors: InflateError[];
|
|
188
194
|
routeFileMap: RouteFileMap;
|
|
@@ -210,7 +216,12 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
210
216
|
return resolve();
|
|
211
217
|
case ".api": {
|
|
212
218
|
|
|
213
|
-
|
|
219
|
+
if (inflateJSXOptions.inflateOnlyAssets) {
|
|
220
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
221
|
+
return resolve();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const module = await importAPIRoute(file.filePath, importOptions, logger);
|
|
214
225
|
|
|
215
226
|
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName, module);
|
|
216
227
|
|
|
@@ -221,7 +232,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
221
232
|
previewMethod: "api"
|
|
222
233
|
};
|
|
223
234
|
|
|
224
|
-
const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
|
|
235
|
+
const inflatedCode = inflateDir && inflateSea && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined) ? await inflateJSX(file.filePath, {
|
|
225
236
|
// embemedJSX: false,
|
|
226
237
|
minify: false,
|
|
227
238
|
useExport: true,
|
|
@@ -243,7 +254,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
243
254
|
|
|
244
255
|
if (inflateDir && r.defaultInflatePath && inflateSea) {
|
|
245
256
|
const rPath = r.defaultInflatePath;
|
|
246
|
-
const inflatePath = join(inflateDir, service, "http", rPath + ".api.cjs");
|
|
257
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "http", rPath + ".api.cjs");
|
|
247
258
|
await mkdirASync(dirname(inflatePath), {
|
|
248
259
|
recursive: true
|
|
249
260
|
});
|
|
@@ -258,7 +269,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
258
269
|
return resolve();
|
|
259
270
|
}
|
|
260
271
|
case ".json": {
|
|
261
|
-
const module = await importJSONModule(file.filePath, logger);
|
|
272
|
+
const module = await importJSONModule(file.filePath, importOptions, logger);
|
|
262
273
|
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".json", module.apiOptions as Partial<APIRoute>);
|
|
263
274
|
|
|
264
275
|
routeFileMap[file.filePath] = {
|
|
@@ -274,12 +285,12 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
274
285
|
|
|
275
286
|
|
|
276
287
|
|
|
277
|
-
if (inflateDir) {
|
|
288
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
278
289
|
|
|
279
290
|
if (r.inflatePath) {
|
|
280
291
|
//if (r.method === "GET" || r.method === "get") {
|
|
281
292
|
const rPath = r.inflatePath;
|
|
282
|
-
const inflatePath = join(inflateDir, service, "static", rPath);
|
|
293
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", rPath);
|
|
283
294
|
await mkdirASync(dirname(inflatePath), {
|
|
284
295
|
recursive: true
|
|
285
296
|
});
|
|
@@ -301,7 +312,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
301
312
|
previewMethod: "html",
|
|
302
313
|
path: r.path,
|
|
303
314
|
body: Buffer.from(JSON_STATIC),
|
|
304
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
315
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", r.inflatePath) : undefined
|
|
305
316
|
}
|
|
306
317
|
}
|
|
307
318
|
}
|
|
@@ -326,7 +337,12 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
326
337
|
}
|
|
327
338
|
case ".html": {
|
|
328
339
|
|
|
329
|
-
|
|
340
|
+
if (inflateJSXOptions.inflateOnlyAssets) {
|
|
341
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
342
|
+
return resolve();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const module = await importHTMLModule(file.filePath, importOptions, logger);
|
|
330
346
|
|
|
331
347
|
const routes = getRoutes(join("/", dirname(relative(dir, file.filePath))), file.subName + ".html", module.apiOptions as Partial<APIRoute>);
|
|
332
348
|
|
|
@@ -341,12 +357,12 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
341
357
|
|
|
342
358
|
const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
|
|
343
359
|
|
|
344
|
-
if (inflateDir) {
|
|
360
|
+
if (inflateDir && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
345
361
|
|
|
346
362
|
if (r.inflatePath) {
|
|
347
363
|
//if (r.method === "GET" || r.method === "get") {
|
|
348
364
|
const rPath = r.inflatePath;
|
|
349
|
-
const inflatePath = join(inflateDir, service, "static", rPath);
|
|
365
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", rPath);
|
|
350
366
|
await mkdirASync(dirname(inflatePath), {
|
|
351
367
|
recursive: true
|
|
352
368
|
});
|
|
@@ -362,7 +378,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
362
378
|
//}
|
|
363
379
|
|
|
364
380
|
|
|
365
|
-
if (staticFileMap && inflateSea) {
|
|
381
|
+
if (staticFileMap && inflateSea && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
366
382
|
staticFileMap[file.filePath + r.method + r.path] = {
|
|
367
383
|
filePath: file.filePath,
|
|
368
384
|
contentType,
|
|
@@ -370,7 +386,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
370
386
|
previewMethod: "html",
|
|
371
387
|
path: r.path,
|
|
372
388
|
body: Buffer.from(HTML_STATIC),
|
|
373
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", r.inflatePath) : undefined
|
|
389
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", r.inflatePath) : undefined
|
|
374
390
|
}
|
|
375
391
|
}
|
|
376
392
|
}
|
|
@@ -397,7 +413,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
397
413
|
default: {
|
|
398
414
|
// allow fall-through when extension is .js and .ts because is a static route without embemedJSX
|
|
399
415
|
if (file.ext !== ".js" && file.ext !== ".ts") {
|
|
400
|
-
const code = await inflateJSX(file.filePath, {
|
|
416
|
+
const code = inflateJSXOptions.noMinify ? readFileSync(file.filePath).toString() : await inflateJSX(file.filePath, {
|
|
401
417
|
// embemedJSX: true,
|
|
402
418
|
minify: file.subExt === ".min" ? true : false,
|
|
403
419
|
useExport: true,
|
|
@@ -416,8 +432,8 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
416
432
|
previewMethod: "html"
|
|
417
433
|
};
|
|
418
434
|
|
|
419
|
-
if (inflateDir) {
|
|
420
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
435
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
436
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
421
437
|
await mkdirASync(dirname(inflatePath), {
|
|
422
438
|
recursive: true
|
|
423
439
|
});
|
|
@@ -433,7 +449,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
433
449
|
previewMethod: "html",
|
|
434
450
|
path,
|
|
435
451
|
body: Buffer.from(code),
|
|
436
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
452
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : undefined
|
|
437
453
|
}
|
|
438
454
|
}
|
|
439
455
|
}
|
|
@@ -469,8 +485,8 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
469
485
|
previewMethod: "html"
|
|
470
486
|
};
|
|
471
487
|
|
|
472
|
-
if (inflateDir) {
|
|
473
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
488
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
489
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
474
490
|
await mkdirASync(dirname(inflatePath), {
|
|
475
491
|
recursive: true
|
|
476
492
|
});
|
|
@@ -484,7 +500,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
484
500
|
previewMethod: "html",
|
|
485
501
|
path,
|
|
486
502
|
body: Buffer.from(code),
|
|
487
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
503
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : undefined
|
|
488
504
|
}
|
|
489
505
|
}
|
|
490
506
|
}
|
|
@@ -512,7 +528,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
512
528
|
}
|
|
513
529
|
case ".bundle":
|
|
514
530
|
case ".min": {
|
|
515
|
-
const code = await inflateJSX(file.filePath, {
|
|
531
|
+
const code = inflateJSXOptions.noMinify ? readFileSync(file.filePath).toString() : await inflateJSX(file.filePath, {
|
|
516
532
|
// embemedJSX: false,
|
|
517
533
|
minify: file.subExt === ".min" ? true : false,
|
|
518
534
|
useExport: true,
|
|
@@ -530,8 +546,8 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
530
546
|
previewMethod: "html"
|
|
531
547
|
};
|
|
532
548
|
|
|
533
|
-
if (inflateDir) {
|
|
534
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
549
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
550
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
535
551
|
await mkdirASync(dirname(inflatePath), {
|
|
536
552
|
recursive: true
|
|
537
553
|
});
|
|
@@ -545,7 +561,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
545
561
|
previewMethod: "html",
|
|
546
562
|
path,
|
|
547
563
|
body: Buffer.from(code),
|
|
548
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
564
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : undefined
|
|
549
565
|
}
|
|
550
566
|
}
|
|
551
567
|
}
|
|
@@ -588,8 +604,8 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
588
604
|
previewMethod: "html"
|
|
589
605
|
};
|
|
590
606
|
|
|
591
|
-
if (inflateDir) {
|
|
592
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
607
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === undefined)) {
|
|
608
|
+
const inflatePath = join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
593
609
|
await mkdirASync(dirname(inflatePath), {
|
|
594
610
|
recursive: true
|
|
595
611
|
});
|
|
@@ -603,7 +619,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
603
619
|
previewMethod: "html",
|
|
604
620
|
path,
|
|
605
621
|
body: Buffer.from(code),
|
|
606
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
622
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : undefined
|
|
607
623
|
}
|
|
608
624
|
}
|
|
609
625
|
}
|
|
@@ -622,7 +638,7 @@ async function createRouterFromDirectory(server: ServerInterface, hotreload: boo
|
|
|
622
638
|
}
|
|
623
639
|
}
|
|
624
640
|
}
|
|
625
|
-
await createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
|
|
641
|
+
await createStaticRoute(inflateJSXOptions, service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
|
|
626
642
|
return resolve();
|
|
627
643
|
|
|
628
644
|
}
|
|
@@ -684,16 +700,16 @@ export function scanFiles(path: string, ret: ScannedFile[] = []): ScannedFile[]
|
|
|
684
700
|
|
|
685
701
|
|
|
686
702
|
function getHTML(hotreload: boolean, req: ServerRequest, res: Response | null, url: RuntimeURL, basePath: string | undefined, out: JSX.Element): string {
|
|
687
|
-
let HTML = `<!DOCTYPE html>\n${jsx2HTML(out, createNodeRuntime({
|
|
703
|
+
let HTML = `<!DOCTYPE html>\n${hotreload ? `${getHotReloadScript()}\n` : ""}${jsx2HTML(out, createNodeRuntime({
|
|
688
704
|
url,
|
|
689
705
|
basePath
|
|
690
706
|
}))}`;
|
|
691
707
|
|
|
692
708
|
//console.log("GET_HTML[%s] [%o]", HTML, out);
|
|
693
709
|
|
|
694
|
-
if (hotreload) {
|
|
710
|
+
/*if (hotreload) {
|
|
695
711
|
HTML += getHotReloadScript()
|
|
696
|
-
}
|
|
712
|
+
}*/
|
|
697
713
|
return HTML;
|
|
698
714
|
}
|
|
699
715
|
|
package/src/inflate/setup-log.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from "@miqro/core";
|
|
2
|
-
import { importLogConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
2
|
+
import { ImportJSXFileOptions, importLogConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
3
|
import { getLogConfigPath } from "../common/paths.js";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -10,13 +10,13 @@ export interface LogConfigMap {
|
|
|
10
10
|
[service: string]: LogConfig | undefined;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async function setupLogConfig(logger: Logger, servicePath: string, service: string, logConfigMap: LogConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
13
|
+
export async function setupLogConfig(logger: Logger, servicePath: string, service: string, logConfigMap: LogConfigMap, inflateDir: string | undefined | false, options: ImportJSXFileOptions, errors: InflateError[]) {
|
|
14
14
|
const logPath = getLogConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
|
|
15
15
|
if (logPath) {
|
|
16
16
|
try {
|
|
17
17
|
//logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
|
|
18
18
|
|
|
19
|
-
const logConfig = await importLogConfigModule(logPath, logger);
|
|
19
|
+
const logConfig = await importLogConfigModule(logPath, options, logger);
|
|
20
20
|
logConfigMap[service] = logConfig;
|
|
21
21
|
|
|
22
22
|
if (inflateDir) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Logger, Router } from "@miqro/core";
|
|
2
|
-
import { importMiddlewareConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
2
|
+
import { ImportJSXFileOptions, importMiddlewareConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
3
3
|
import { getMiddlewareConfigPath } from "../common/paths.js";
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { cwd } from "node:process";
|
|
7
7
|
import { MiddlewareConfig } from "../types.js";
|
|
8
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> {
|
|
9
|
+
export async function setupMiddleware(logger: Logger, servicePath: string, service: string, mainRouter: Router, inflateDir: string | undefined | false, inflateSea: boolean, options: ImportJSXFileOptions, errors: InflateError[]): Promise<MiddlewareConfig | null> {
|
|
10
10
|
const middlewarePath = getMiddlewareConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
11
11
|
|
|
12
12
|
if (middlewarePath) {
|
|
13
13
|
try {
|
|
14
|
-
const middewareModule = await importMiddlewareConfigModule(middlewarePath, logger);
|
|
14
|
+
const middewareModule = await importMiddlewareConfigModule(middlewarePath, options, logger);
|
|
15
15
|
logger.debug("setting up middleware from [%s]", join(service, basename(middlewarePath)));
|
|
16
16
|
if (middewareModule && middewareModule.middleware) {
|
|
17
17
|
for (const m of middewareModule.middleware) {
|
|
@@ -3,7 +3,7 @@ import { Logger } from "@miqro/core";
|
|
|
3
3
|
import { dirname, relative, resolve } from "node:path";
|
|
4
4
|
import { cwd } from "node:process";
|
|
5
5
|
|
|
6
|
-
import { importServerConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
6
|
+
import { ImportJSXFileOptions, importServerConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
7
7
|
import { getServerConfigPath } from "../common/paths.js";
|
|
8
8
|
import { ServerConfig } from "../types.js";
|
|
9
9
|
|
|
@@ -11,14 +11,14 @@ export interface ServerConfigMap {
|
|
|
11
11
|
[service: string]: ServerConfig | undefined;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export async function setupServerConfig(logger: Logger, servicePath: string, service: string, serverConfigMap: ServerConfigMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
14
|
+
export async function setupServerConfig(logger: Logger, servicePath: string, service: string, serverConfigMap: ServerConfigMap, inflateDir: string | undefined | false, errors: InflateError[], options: ImportJSXFileOptions) {
|
|
15
15
|
|
|
16
16
|
const serverPath = getServerConfigPath(servicePath); // resolve(process.cwd(), service, "server.ts");
|
|
17
17
|
if (serverPath) {
|
|
18
18
|
try {
|
|
19
19
|
//logger.debug("setting up server config from [%s]", join(service, basename(serverPath)));
|
|
20
20
|
|
|
21
|
-
const serverConfig = await importServerConfigModule(serverPath, logger);
|
|
21
|
+
const serverConfig = await importServerConfigModule(serverPath, options, logger);
|
|
22
22
|
serverConfigMap[service] = serverConfig;
|
|
23
23
|
|
|
24
24
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { importJSXFile } from "../common/jsx.js";
|
|
1
|
+
import { importJSXFile, ImportJSXFileOptions } from "../common/jsx.js";
|
|
2
2
|
import { Logger } from "@miqro/core";
|
|
3
3
|
import { scanFiles } from "./setup-http.js";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
|
|
6
|
-
export async function setupTests(logger: Logger, servicePath: string) {
|
|
6
|
+
export async function setupTests(logger: Logger, servicePath: string, options: ImportJSXFileOptions) {
|
|
7
7
|
logger.debug("setting up tests from [%s]", servicePath);
|
|
8
8
|
const files = scanFiles(resolve(servicePath));
|
|
9
9
|
await Promise.allSettled(files.map((file) => {
|
|
@@ -14,7 +14,7 @@ export async function setupTests(logger: Logger, servicePath: string) {
|
|
|
14
14
|
case ".tsx": {
|
|
15
15
|
switch (file.subExt) {
|
|
16
16
|
case ".test":
|
|
17
|
-
return importJSXFile(file.filePath, logger);
|
|
17
|
+
return importJSXFile(file.filePath, options, logger);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/inflate/setup-ws.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { dirname, join, relative, resolve } from "node:path";
|
|
|
3
3
|
import { cwd } from "node:process";
|
|
4
4
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
5
5
|
|
|
6
|
-
import { importWSConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
6
|
+
import { ImportJSXFileOptions, importWSConfigModule, InflateError, inflateJSX } from "../common/jsx.js";
|
|
7
7
|
import { getWSConfigPath } from "../common/paths.js";
|
|
8
8
|
import { WSConfig } from "../types.js";
|
|
9
9
|
|
|
10
|
-
export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<void> {
|
|
10
|
+
export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[], options: ImportJSXFileOptions): Promise<void> {
|
|
11
11
|
const wsPath = getWSConfigPath(servicePath); // resolve(process.cwd(), service, "ws.ts");
|
|
12
12
|
|
|
13
13
|
if (wsPath) {
|
|
14
14
|
try {
|
|
15
15
|
logger.debug("importing websocket socket for service [%s]", service);
|
|
16
|
-
const wsConfig = await importWSConfigModule(wsPath, logger);
|
|
16
|
+
const wsConfig = await importWSConfigModule(wsPath, options, logger);
|
|
17
17
|
if (wsConfig && wsConfigList.filter(c => c.path === wsConfig.path).length > 0) {
|
|
18
18
|
throw new Error(`ws path [${wsConfig.path}] already defined! from [${wsPath}]`);
|
|
19
19
|
} else if (wsConfigList) {
|
package/src/inflate/setup.doc.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger, Router } from "@miqro/core";
|
|
2
|
-
import { importDocConfigModule,
|
|
2
|
+
import { importDocConfigModule, ImportJSXFileOptions, InflateError } from "../common/jsx.js";
|
|
3
3
|
import { getDocConfigPath } from "../common/paths.js";
|
|
4
4
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
@@ -8,12 +8,12 @@ import { getDocOutput } from "../bin/generate-doc.js";
|
|
|
8
8
|
import { RouteFileMap, StaticFileMap } from "./setup-http.js";
|
|
9
9
|
import { CONTENT_TYPE_MAP } from "../common/content-type.js";
|
|
10
10
|
|
|
11
|
-
export async function setupDoc(logger: Logger, servicePath: string, service: string, mainRouter: Router, fileMap: RouteFileMap, staticFileMap: StaticFileMap, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
11
|
+
export async function setupDoc(logger: Logger, servicePath: string, service: string, mainRouter: Router, fileMap: RouteFileMap, staticFileMap: StaticFileMap, inflateDir: string | undefined | false, errors: InflateError[], options: ImportJSXFileOptions, inflateFlat: boolean) {
|
|
12
12
|
const docPath = getDocConfigPath(servicePath); //resolve(process.cwd(), service, "auth.ts");
|
|
13
13
|
|
|
14
14
|
if (docPath) {
|
|
15
15
|
try {
|
|
16
|
-
const docModule = await importDocConfigModule(docPath, logger);
|
|
16
|
+
const docModule = await importDocConfigModule(docPath, options, logger);
|
|
17
17
|
logger.debug("setting up error handling from [%s]", join(service, basename(docPath)));
|
|
18
18
|
if (docModule && docModule.publish) {
|
|
19
19
|
const paths = Object.keys(docModule.publish);
|
|
@@ -47,7 +47,7 @@ export async function setupDoc(logger: Logger, servicePath: string, service: str
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
if (inflateDir) {
|
|
50
|
-
const inflatePath = join(inflateDir, service, "static", path);
|
|
50
|
+
const inflatePath = join(inflateDir, !inflateFlat ? service : "", "static", path);
|
|
51
51
|
mkdirSync(dirname(inflatePath), {
|
|
52
52
|
recursive: true
|
|
53
53
|
});
|
|
@@ -72,7 +72,7 @@ export async function setupDoc(logger: Logger, servicePath: string, service: str
|
|
|
72
72
|
method: "GET",
|
|
73
73
|
path,
|
|
74
74
|
body: Buffer.from(body),
|
|
75
|
-
inflatePath: inflateDir ? join(inflateDir, service, "static", path) : undefined
|
|
75
|
+
inflatePath: inflateDir ? join(inflateDir, !inflateFlat ? service : "", "static", path) : undefined
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
package/src/main.ts
CHANGED
|
@@ -26,7 +26,9 @@ async function main(args: Arguments) {
|
|
|
26
26
|
watch: args.test ? false : args.watch,
|
|
27
27
|
https: args.test ? false : args.https,
|
|
28
28
|
serverOptions: args.serverOptions,
|
|
29
|
-
httpRedirect: args.test ? undefined : args.httpsRedirect
|
|
29
|
+
httpRedirect: args.test ? undefined : args.httpsRedirect,
|
|
30
|
+
noBuild: args.noBuild,
|
|
31
|
+
noMinify: args.noMinify
|
|
30
32
|
});
|
|
31
33
|
// check arguments
|
|
32
34
|
if (args.generateDoc) {
|
|
@@ -51,7 +53,9 @@ async function main(args: Arguments) {
|
|
|
51
53
|
inflateParallel: args.inflateParallel
|
|
52
54
|
});
|
|
53
55
|
await app.start();
|
|
54
|
-
await testMain(app
|
|
56
|
+
await testMain(app, {
|
|
57
|
+
noBuild: args.noBuild
|
|
58
|
+
});
|
|
55
59
|
await app.stop();
|
|
56
60
|
await app.dbManager.closeAll();
|
|
57
61
|
await app.webSocketManager.disconnectAll();
|
|
@@ -71,6 +75,8 @@ async function main(args: Arguments) {
|
|
|
71
75
|
// --inflate and --inflate-sea
|
|
72
76
|
// loadApp with inflateDir arg to inflate inflatable files
|
|
73
77
|
await app.inflate({
|
|
78
|
+
inflateOnlyAssets: args.inflateOnlyAssets,
|
|
79
|
+
inflateFlat: args.inflateFlat,
|
|
74
80
|
inflateDir: args.inflateDir,
|
|
75
81
|
inflateSea: args.inflateSEA,
|
|
76
82
|
inflateParallel: args.inflateParallel
|