fix pub data
This commit is contained in:
parent
700cc0887c
commit
b9c5108384
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { $ } from "bun";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { dirAsync, readAsync, removeAsync, writeAsync } from "fs-jetpack";
|
import { dirAsync, readAsync, removeAsync, writeAsync } from "fs-jetpack";
|
||||||
import { apiContext } from "service-srv";
|
import { apiContext } from "service-srv";
|
||||||
|
|
@ -6,7 +7,6 @@ import { dir } from "utils/dir";
|
||||||
import { g } from "utils/global";
|
import { g } from "utils/global";
|
||||||
import { genEnv, parseEnv } from "utils/parse-env";
|
import { genEnv, parseEnv } from "utils/parse-env";
|
||||||
import { restartServer } from "utils/restart";
|
import { restartServer } from "utils/restart";
|
||||||
import { $ } from "bun";
|
|
||||||
|
|
||||||
export const _ = {
|
export const _ = {
|
||||||
url: "/_deploy",
|
url: "/_deploy",
|
||||||
|
|
@ -27,7 +27,7 @@ export const _ = {
|
||||||
| { type: "redeploy"; ts: string }
|
| { type: "redeploy"; ts: string }
|
||||||
) & {
|
) & {
|
||||||
id_site: string;
|
id_site: string;
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
const { res } = apiContext(this);
|
const { res } = apiContext(this);
|
||||||
|
|
||||||
|
|
@ -103,24 +103,24 @@ export const _ = {
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "${type}"
|
provider = "${type}"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
}`
|
}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Bun.write(
|
await Bun.write(
|
||||||
dir("app/db/.env"),
|
dir("app/db/.env"),
|
||||||
`DATABASE_URL=${ENV.DATABASE_URL}`
|
`DATABASE_URL=${ENV.DATABASE_URL}`,
|
||||||
);
|
);
|
||||||
await $`bun install`.cwd(dir("app/db"));
|
await $`bun install`.cwd(dir("app/db"));
|
||||||
await $`bun prisma db pull --force`.cwd(dir("app/db"));
|
await $`bun prisma db pull --force`.cwd(dir("app/db"));
|
||||||
await $`bun prisma generate`.cwd(dir("app/db"));
|
await $`bun prisma generate`.cwd(dir("app/db"));
|
||||||
await Bun.write(
|
await Bun.write(
|
||||||
dir(`${g.datadir}/db-ver`),
|
dir(`${g.datadir}/db-ver`),
|
||||||
Date.now().toString()
|
Date.now().toString(),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
@ -205,7 +205,7 @@ export const _ = {
|
||||||
export const downloadFile = async (
|
export const downloadFile = async (
|
||||||
url: string,
|
url: string,
|
||||||
filePath: string,
|
filePath: string,
|
||||||
progress?: (rec: number, total: number) => void
|
progress?: (rec: number, total: number) => void,
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const _url = new URL(url);
|
const _url = new URL(url);
|
||||||
|
|
@ -238,7 +238,7 @@ export const downloadFile = async (
|
||||||
if (progress) {
|
if (progress) {
|
||||||
progress(
|
progress(
|
||||||
receivedLength,
|
receivedLength,
|
||||||
parseInt(res.headers.get("content-length") || "0")
|
parseInt(res.headers.get("content-length") || "0"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { file } from "bun";
|
import { file } from "bun";
|
||||||
import { existsAsync, inspectAsync, listAsync } from "fs-jetpack";
|
import { inspectAsync, listAsync } from "fs-jetpack";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { createRouter } from "radix3";
|
import { createRouter } from "radix3";
|
||||||
|
import { prodIndex } from "utils/prod-index";
|
||||||
import { dir } from "../utils/dir";
|
import { dir } from "../utils/dir";
|
||||||
import { g } from "../utils/global";
|
import { g } from "../utils/global";
|
||||||
import { parseArgs } from "./parse-args";
|
import { parseArgs } from "./parse-args";
|
||||||
import { serveAPI } from "./serve-api";
|
import { serveAPI } from "./serve-api";
|
||||||
import { serveWeb } from "./serve-web";
|
import { serveWeb } from "./serve-web";
|
||||||
import { prodIndex } from "utils/prod-index";
|
|
||||||
|
|
||||||
export const createServer = async () => {
|
export const createServer = async () => {
|
||||||
g.router = createRouter({ strictTrailingSlash: true });
|
g.router = createRouter({ strictTrailingSlash: true });
|
||||||
|
|
@ -33,8 +33,8 @@ export const createServer = async () => {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
g.log.warn(
|
g.log.warn(
|
||||||
`Failed to import app/srv/api${importPath.substring(
|
`Failed to import app/srv/api${importPath.substring(
|
||||||
(root || path).length
|
(root || path).length,
|
||||||
)}`
|
)}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const f = file(importPath);
|
const f = file(importPath);
|
||||||
|
|
@ -92,6 +92,7 @@ export const createServer = async () => {
|
||||||
if (g.deploy.content) {
|
if (g.deploy.content) {
|
||||||
const core = g.deploy.content.code.core;
|
const core = g.deploy.content.code.core;
|
||||||
const site = g.deploy.content.code.site;
|
const site = g.deploy.content.code.site;
|
||||||
|
const pub = g.deploy.content.public;
|
||||||
|
|
||||||
let pathname = url.pathname;
|
let pathname = url.pathname;
|
||||||
if (url.pathname[0] === "/") pathname = pathname.substring(1);
|
if (url.pathname[0] === "/") pathname = pathname.substring(1);
|
||||||
|
|
@ -112,6 +113,7 @@ export const createServer = async () => {
|
||||||
|
|
||||||
if (core[pathname]) content = core[pathname];
|
if (core[pathname]) content = core[pathname];
|
||||||
else if (site[pathname]) content = site[pathname];
|
else if (site[pathname]) content = site[pathname];
|
||||||
|
else if (pub[pathname]) content = pub[pathname];
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
return await serveWeb({
|
return await serveWeb({
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ import {
|
||||||
removeAsync,
|
removeAsync,
|
||||||
writeAsync,
|
writeAsync,
|
||||||
} from "fs-jetpack";
|
} from "fs-jetpack";
|
||||||
|
import { decode } from "msgpackr";
|
||||||
|
import { createRouter } from "radix3";
|
||||||
|
import { startBrCompress } from "./br-load";
|
||||||
import { dir } from "./dir";
|
import { dir } from "./dir";
|
||||||
import { g } from "./global";
|
import { g } from "./global";
|
||||||
import { gunzipAsync } from "./gzip";
|
import { gunzipAsync } from "./gzip";
|
||||||
import { createRouter } from "radix3";
|
|
||||||
import { prodIndex } from "./prod-index";
|
|
||||||
import { startBrCompress } from "./br-load";
|
|
||||||
import { decode } from "msgpackr";
|
|
||||||
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
export const deploy = {
|
export const deploy = {
|
||||||
|
|
@ -33,19 +32,19 @@ export const deploy = {
|
||||||
g.deploy.content = decode(
|
g.deploy.content = decode(
|
||||||
await gunzipAsync(
|
await gunzipAsync(
|
||||||
new Uint8Array(
|
new Uint8Array(
|
||||||
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer()
|
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer(),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
g.deploy.content = JSON.parse(
|
g.deploy.content = JSON.parse(
|
||||||
decoder.decode(
|
decoder.decode(
|
||||||
await gunzipAsync(
|
await gunzipAsync(
|
||||||
new Uint8Array(
|
new Uint8Array(
|
||||||
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer()
|
await Bun.file(dir(`app/web/deploy/${ts}.gz`)).arrayBuffer(),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +98,7 @@ export const deploy = {
|
||||||
await removeAsync(dir(`app/web/server`));
|
await removeAsync(dir(`app/web/server`));
|
||||||
await dirAsync(dir(`app/web/server`));
|
await dirAsync(dir(`app/web/server`));
|
||||||
for (const [k, v] of Object.entries(
|
for (const [k, v] of Object.entries(
|
||||||
g.deploy.content.code.server
|
g.deploy.content.code.server,
|
||||||
)) {
|
)) {
|
||||||
await writeAsync(dir(`app/web/server/${k}`), v);
|
await writeAsync(dir(`app/web/server/${k}`), v);
|
||||||
}
|
}
|
||||||
|
|
@ -143,10 +142,10 @@ export const deploy = {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Downloading site deploy: ${this.config.site_id} [ts: ${this.config.deploy.ts}] ${base_url}`
|
`Downloading site deploy: ${this.config.site_id} [ts: ${this.config.deploy.ts}] ${base_url}`,
|
||||||
);
|
);
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${base_url}/prod-zip/${this.config.site_id}?ts=${Date.now()}&msgpack=1`
|
`${base_url}/prod-zip/${this.config.site_id}?ts=${Date.now()}&msgpack=1`,
|
||||||
);
|
);
|
||||||
const ts = Date.now();
|
const ts = Date.now();
|
||||||
|
|
||||||
|
|
@ -188,13 +187,13 @@ export const deploy = {
|
||||||
saveConfig() {
|
saveConfig() {
|
||||||
return Bun.write(
|
return Bun.write(
|
||||||
Bun.file(dir(`app/web/config.json`)),
|
Bun.file(dir(`app/web/config.json`)),
|
||||||
JSON.stringify(this.config, null, 2)
|
JSON.stringify(this.config, null, 2),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
has_gz() {
|
has_gz() {
|
||||||
if (this.config.deploy.ts) {
|
if (this.config.deploy.ts) {
|
||||||
return Bun.file(
|
return Bun.file(
|
||||||
dir(`app/web/deploy/${this.config.deploy.ts}.gz`)
|
dir(`app/web/deploy/${this.config.deploy.ts}.gz`),
|
||||||
).exists();
|
).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,5 @@ export const restartServer = () => {
|
||||||
if (g.mode === "dev") {
|
if (g.mode === "dev") {
|
||||||
$`bun ${g.mode}`;
|
$`bun ${g.mode}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue