generated from forge42dev/open-source-stack
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tsup.config.ts
70 lines (60 loc) · 1.79 KB
/
tsup.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import fs from "node:fs";
import path from "node:path";
import { defineConfig } from "tsup";
export default defineConfig([
{
entry: [
"src/adapters/node.ts",
"src/adapters/bun.ts",
"src/adapters/cloudflare.ts",
"src/dev.ts",
"src/middleware.ts",
"src/http.ts",
],
outDir: "dist",
format: ["esm"],
clean: true,
dts: true,
external: [
// virtual module provided by React Router at build time
"virtual:react-router/server-build",
],
onSuccess: async () => {
setupExamples();
},
},
{
entry: ["src/cli.ts"],
outDir: "dist",
format: ["esm"],
onSuccess: async () => {
const banner = "#!/usr/bin/env node\n";
const cliFilePath = "dist/cli.js";
const originalContent = fs.readFileSync(cliFilePath, "utf-8");
fs.writeFileSync(cliFilePath, banner + originalContent);
fs.chmodSync(cliFilePath, "755");
},
},
]);
function setupExamples() {
const adapters = fs.readdirSync("examples");
for (const adapter of adapters) {
const adapterPath = path.join("examples", adapter);
if (!fs.statSync(adapterPath).isDirectory()) {
continue;
}
const examples = fs.readdirSync(adapterPath);
for (const example of examples) {
const examplePath = path.join(adapterPath, example);
if (!fs.statSync(examplePath).isDirectory()) {
continue;
}
const moduleDir = path.join(examplePath, "node_modules", "react-router-hono-server");
fs.rmSync(moduleDir, { recursive: true, force: true });
fs.mkdirSync(moduleDir, { recursive: true });
fs.symlinkSync(path.resolve("dist"), path.join(moduleDir, "dist"), "junction");
// Copy package.json
fs.copyFileSync("package.json", path.join(moduleDir, "package.json"));
}
}
}