fix
This commit is contained in:
parent
cd856a75f3
commit
72c9212d9e
|
|
@ -12,6 +12,10 @@ import { config } from "./utils/config";
|
||||||
import { g } from "./utils/global";
|
import { g } from "./utils/global";
|
||||||
import { createLogger } from "./utils/logger";
|
import { createLogger } from "./utils/logger";
|
||||||
|
|
||||||
|
if (process.argv[process.argv.length - 1] === "skip_types") {
|
||||||
|
g.skip_build_types = true;
|
||||||
|
}
|
||||||
|
|
||||||
let db_env: any = {};
|
let db_env: any = {};
|
||||||
try {
|
try {
|
||||||
db_env = parseEnv(await Bun.file(dir("app/db/.env")).text());
|
db_env = parseEnv(await Bun.file(dir("app/db/.env")).text());
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ if (process.env.DATABASE_URL) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const startMain = () => {
|
const startMain = (argv?: string) => {
|
||||||
return Bun.spawn({
|
return Bun.spawn({
|
||||||
cmd: ["bun", "run", "pkgs/index.ts"],
|
cmd: ["bun", "run", "pkgs/index.ts", argv].filter((e) => e) as string[],
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
|
|
@ -49,7 +49,7 @@ const startMain = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
subprocess.kill();
|
subprocess.kill();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
main.process = startMain();
|
main.process = startMain("skip_types");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onExit(subprocess, exitCode, signalCode, error) {
|
onExit(subprocess, exitCode, signalCode, error) {
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,25 @@ import { dir } from "../utils/dir";
|
||||||
import { g } from "../utils/global";
|
import { g } from "../utils/global";
|
||||||
|
|
||||||
export const prepareAPITypes = async () => {
|
export const prepareAPITypes = async () => {
|
||||||
const out: string[] = [];
|
if (!g.skip_build_types) {
|
||||||
for (const [k, v] of Object.entries(g.api)) {
|
const out: string[] = [];
|
||||||
const name = k.substring(0, k.length - 3).replace(/\W/gi, "_");
|
for (const [k, v] of Object.entries(g.api)) {
|
||||||
|
const name = k.substring(0, k.length - 3).replace(/\W/gi, "_");
|
||||||
|
|
||||||
let p = {
|
let p = {
|
||||||
path: `"app/srv/api/${v.path}"`,
|
path: `"app/srv/api/${v.path}"`,
|
||||||
handler: `"./api/${v.path.substring(0, v.path.length - 3)}"`,
|
handler: `"./api/${v.path.substring(0, v.path.length - 3)}"`,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!(await existsAsync(dir(p.path)))) {
|
if (!(await existsAsync(dir(p.path)))) {
|
||||||
p.path = `"pkgs/api/${v.path}"`;
|
p.path = `"pkgs/api/${v.path}"`;
|
||||||
p.handler = `"../../pkgs/api/${v.path.substring(0, v.path.length - 3)}"`;
|
p.handler = `"../../pkgs/api/${v.path.substring(
|
||||||
}
|
0,
|
||||||
|
v.path.length - 3
|
||||||
|
)}"`;
|
||||||
|
}
|
||||||
|
|
||||||
out.push(`\
|
out.push(`\
|
||||||
export const ${name} = {
|
export const ${name} = {
|
||||||
name: "${name}",
|
name: "${name}",
|
||||||
url: "${v.url}",
|
url: "${v.url}",
|
||||||
|
|
@ -26,31 +30,32 @@ export const ${name} = {
|
||||||
args: ${JSON.stringify(v.args)},
|
args: ${JSON.stringify(v.args)},
|
||||||
handler: import(${p.handler})
|
handler: import(${p.handler})
|
||||||
}`);
|
}`);
|
||||||
}
|
|
||||||
await Bun.write(dir(`app/srv/exports.ts`), out.join(`\n`));
|
|
||||||
|
|
||||||
const targetFile = dir("app/srv/exports.d.ts");
|
|
||||||
spawnSync(
|
|
||||||
[
|
|
||||||
dir("node_modules/.bin/tsc"),
|
|
||||||
dir("app/srv/exports.ts"),
|
|
||||||
"--declaration",
|
|
||||||
"--emitDeclarationOnly",
|
|
||||||
"--outFile",
|
|
||||||
targetFile,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
cwd: dir(`node_modules/.bin`),
|
|
||||||
}
|
}
|
||||||
);
|
await Bun.write(dir(`app/srv/exports.ts`), out.join(`\n`));
|
||||||
|
|
||||||
let res = await readAsync(targetFile);
|
const targetFile = dir("app/srv/exports.d.ts");
|
||||||
if (res) {
|
spawnSync(
|
||||||
res = res.replace('export * from "@prisma/client";', "");
|
[
|
||||||
res = res.replace("server: Server;", "");
|
dir("node_modules/.bin/tsc"),
|
||||||
res = res.replace(`import { PrismaClient } from "app/db/db";`, "");
|
dir("app/srv/exports.ts"),
|
||||||
res = res.replace(`db: PrismaClient;`, "");
|
"--declaration",
|
||||||
await Bun.write(targetFile, res);
|
"--emitDeclarationOnly",
|
||||||
|
"--outFile",
|
||||||
|
targetFile,
|
||||||
|
],
|
||||||
|
{
|
||||||
|
cwd: dir(`node_modules/.bin`),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let res = await readAsync(targetFile);
|
||||||
|
if (res) {
|
||||||
|
res = res.replace('export * from "@prisma/client";', "");
|
||||||
|
res = res.replace("server: Server;", "");
|
||||||
|
res = res.replace(`import { PrismaClient } from "app/db/db";`, "");
|
||||||
|
res = res.replace(`db: PrismaClient;`, "");
|
||||||
|
await Bun.write(targetFile, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await getContent("load.js.dev");
|
await getContent("load.js.dev");
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ export const g = global as unknown as {
|
||||||
log: Logger;
|
log: Logger;
|
||||||
firebaseInit: boolean;
|
firebaseInit: boolean;
|
||||||
firebase: admin.app.App;
|
firebase: admin.app.App;
|
||||||
|
skip_build_types: boolean;
|
||||||
main: {
|
main: {
|
||||||
process: null | Subprocess;
|
process: null | Subprocess;
|
||||||
restart: {
|
restart: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue