fix env
This commit is contained in:
parent
96dbca0e55
commit
2b9c84270f
|
|
@ -16,12 +16,13 @@
|
|||
"bun-types": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
"typescript": "^5.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"brotli-wasm": "^2.0.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"exit-hook": "^4.0.0",
|
||||
"firebase-admin": "^12.0.0",
|
||||
"prisma": "^5.8.1"
|
||||
"firebase-admin": "^12.2.0",
|
||||
"prisma": "^5.16.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import { apiContext } from "service-srv";
|
|||
import { deploy } from "utils/deploy";
|
||||
import { dir } from "utils/dir";
|
||||
import { g } from "utils/global";
|
||||
import { parse } from "utils/parse-env";
|
||||
import { genEnv, parseEnv } from "utils/parse-env";
|
||||
import { restartServer } from "utils/restart";
|
||||
|
||||
export const _ = {
|
||||
|
|
@ -68,12 +68,11 @@ export const _ = {
|
|||
case "db-update":
|
||||
if (action.url) {
|
||||
g.dburl = action.url;
|
||||
await Bun.write(
|
||||
dir("app/db/.env"),
|
||||
`\
|
||||
DATABASE_URL="${action.url}"
|
||||
`
|
||||
);
|
||||
const env = genEnv({
|
||||
...parseEnv(await Bun.file(dir(".env")).text()),
|
||||
DATABASE_URL: action.url,
|
||||
});
|
||||
await Bun.write(dir(".env"), env);
|
||||
}
|
||||
return "ok";
|
||||
case "db-gen":
|
||||
|
|
@ -88,9 +87,9 @@ DATABASE_URL="${action.url}"
|
|||
break;
|
||||
case "db-pull":
|
||||
{
|
||||
const env = await readAsync(dir("app/db/.env"));
|
||||
const env = await readAsync(dir(".env"));
|
||||
if (env) {
|
||||
const ENV = parse(env);
|
||||
const ENV = parseEnv(env);
|
||||
if (typeof ENV.DATABASE_URL === "string") {
|
||||
const type = ENV.DATABASE_URL.split("://").shift();
|
||||
if (type) {
|
||||
|
|
@ -194,7 +193,7 @@ export const downloadFile = async (
|
|||
_url.hostname = "127.0.0.1";
|
||||
}
|
||||
g.log.info(`Downloading ${url} to ${filePath}`);
|
||||
const res = await fetch(_url);
|
||||
const res = await fetch(_url as any);
|
||||
if (res.body) {
|
||||
const file = Bun.file(filePath);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { prepareAPITypes } from "./server/prep-api-ts";
|
|||
import { config } from "./utils/config";
|
||||
import { g } from "./utils/global";
|
||||
import { createLogger } from "./utils/logger";
|
||||
import { genEnv, parseEnv } from "utils/parse-env";
|
||||
|
||||
g.mode = process.argv.includes("dev") ? "dev" : "prod";
|
||||
g.datadir = g.mode === "prod" ? "../data" : ".data";
|
||||
|
|
@ -29,7 +30,8 @@ if (!(await existsAsync(dir("app/srv")))) {
|
|||
|
||||
if (!process.env.PORT) {
|
||||
g.port = 3000;
|
||||
await Bun.write(".env", `PORT=${g.port}`);
|
||||
const env = genEnv({ ...parseEnv(".env"), PORT: g.port });
|
||||
await Bun.write(".env", env);
|
||||
} else {
|
||||
g.port = parseInt(process.env.PORT);
|
||||
}
|
||||
|
|
@ -46,7 +48,6 @@ await config.init();
|
|||
|
||||
g.log.info(g.mode === "dev" ? "DEVELOPMENT" : "PRODUCTION");
|
||||
|
||||
|
||||
await deploy.init();
|
||||
if (g.mode === "dev") {
|
||||
await startDevWatcher();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import exitHook from "exit-hook";
|
|||
import { existsAsync } from "fs-jetpack";
|
||||
import { dir } from "utils/dir";
|
||||
import { checkPort, randomBetween } from "utils/ensure";
|
||||
import "dotenv/config";
|
||||
|
||||
let port = 0;
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ const main = {
|
|||
|
||||
console.log("Process Manager running at port:", port);
|
||||
|
||||
if (await existsAsync(dir("app/db/.env"))) {
|
||||
if (process.env.DATABASE_URL) {
|
||||
if (!(await existsAsync(dir("node_modules/.prisma")))) {
|
||||
try {
|
||||
await $({ cwd: dir(`app/db`) })`bun install`;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function removeQuotes(str: string) {
|
|||
}
|
||||
|
||||
/** Parse an envfile string. */
|
||||
export function parse(src: string): Data {
|
||||
export function parseEnv(src: string): Data {
|
||||
const result: Data = {};
|
||||
const lines = splitInLines(src);
|
||||
for (const line of lines) {
|
||||
|
|
@ -35,7 +35,7 @@ export function parse(src: string): Data {
|
|||
}
|
||||
|
||||
/** Turn an object into an envfile string. */
|
||||
export function stringify(obj: Input): string {
|
||||
export function genEnv(obj: Input): string {
|
||||
let result = "";
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (key) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { $ } from "execa";
|
|||
import { g } from "./global";
|
||||
|
||||
export const preparePrisma = async () => {
|
||||
if ((await existsAsync(dir("app/db/.env"))) && !g.db) {
|
||||
if (process.env.DATABASE_URL && !g.db) {
|
||||
try {
|
||||
if (g.mode !== "dev") {
|
||||
await $({ cwd: dir(`app/db`) })`bun prisma generate`;
|
||||
|
|
|
|||
Loading…
Reference in New Issue