wip fix
This commit is contained in:
parent
44a36b629c
commit
9b9e43baaf
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { apiContext } from "service-srv";
|
||||||
|
|
||||||
|
export const _ = {
|
||||||
|
url: "/deploy/**",
|
||||||
|
async api() {
|
||||||
|
const { req, res } = apiContext(this);
|
||||||
|
return "rukausfb";
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { createId } from "@paralleldrive/cuid2";
|
||||||
import { prepareApiRoutes } from "./server/api/api-scan";
|
import { prepareApiRoutes } from "./server/api/api-scan";
|
||||||
import { writeAsync } from "fs-jetpack";
|
import { writeAsync } from "fs-jetpack";
|
||||||
import { dir } from "dir";
|
import { dir } from "dir";
|
||||||
|
import { watchApiRoutes } from "./server/api/api-watch";
|
||||||
// import "../docker-prep";
|
// import "../docker-prep";
|
||||||
|
|
||||||
g.status = "init";
|
g.status = "init";
|
||||||
|
|
@ -57,15 +58,19 @@ if (!db) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await prepareApiRoutes();
|
||||||
|
|
||||||
if (!g.apiPrepared) {
|
if (!g.apiPrepared) {
|
||||||
await initSrv();
|
await initSrv();
|
||||||
await syncActionDefinition();
|
await syncActionDefinition();
|
||||||
g.log.info("WS Action defined");
|
g.log.info("WS Action defined");
|
||||||
await prepareApiRoutes();
|
|
||||||
await prepareAPITypes();
|
await prepareAPITypes();
|
||||||
g.log.info("API Prepared");
|
g.log.info("API Prepared");
|
||||||
g.apiPrepared = true;
|
g.apiPrepared = true;
|
||||||
|
|
||||||
|
if (g.mode === "dev") {
|
||||||
|
watchApiRoutes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g.parcel) {
|
if (!g.parcel) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { dir } from "dir";
|
||||||
|
import { watch } from "fs";
|
||||||
|
import { parseArgs } from "./parse-args";
|
||||||
|
import { g } from "utils/global";
|
||||||
|
export const watchApiRoutes = () => {
|
||||||
|
const root = dir.path(`app/srv/api`);
|
||||||
|
watch(root, { recursive: true }, async (e, filename) => {
|
||||||
|
if (filename && filename.endsWith(".ts")) {
|
||||||
|
const oldroute = g._api[filename];
|
||||||
|
if (oldroute) {
|
||||||
|
g.router.remove(oldroute.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
const importPath = dir.path(`app/srv/api/${filename}`);
|
||||||
|
delete require.cache[importPath];
|
||||||
|
const api = require(importPath);
|
||||||
|
let args: string[] = await parseArgs(importPath);
|
||||||
|
const route = {
|
||||||
|
url: api._.url,
|
||||||
|
args,
|
||||||
|
fn: api._.api,
|
||||||
|
path: importPath.substring(root.length + 1),
|
||||||
|
};
|
||||||
|
g._api[filename] = route;
|
||||||
|
g.router.insert(route.url.replace(/\*/gi, "**"), route);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { parseFile } from "@swc/core";
|
import { parseFile } from "@swc/core";
|
||||||
import { readAsync } from "fs-jetpack";
|
|
||||||
|
|
||||||
export const parseArgs = async (path: string) => {
|
export const parseArgs = async (path: string) => {
|
||||||
const res = await parseFile(path, { syntax: "typescript" });
|
const res = await parseFile(path, { syntax: "typescript" });
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ export const serveAPI = {
|
||||||
found = null;
|
found = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(found?.fn.toString());
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
const params = { ...found.params };
|
const params = { ...found.params };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { dir } from "dir";
|
||||||
|
import { context } from "esbuild";
|
||||||
|
|
||||||
|
const ctx = await context({
|
||||||
|
bundle: true,
|
||||||
|
absWorkingDir: dir.path(""),
|
||||||
|
entryPoints: [dir.path("app/web/src/nova/deploy/main.tsx")],
|
||||||
|
outdir: dir.path("app/static/deploy"),
|
||||||
|
splitting: true,
|
||||||
|
format: "esm",
|
||||||
|
jsx: "transform",
|
||||||
|
minify: true,
|
||||||
|
sourcemap: true,
|
||||||
|
logLevel: "error",
|
||||||
|
define: {
|
||||||
|
"process.env.NODE_ENV": `"production"`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.watch();
|
||||||
Loading…
Reference in New Issue