wildpig 1.5.8 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +11 -0
- package/package.json +3 -2
- package/scripts/build.ts +2 -1
- package/scripts/devServer.ts +18 -18
- package/scripts/prodServer.ts +8 -9
package/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
let wildpigServer: Bun.Server<undefined>;
|
|
3
|
+
if( process.env.NODE_ENV !== 'production') {
|
|
4
|
+
wildpigServer = await import("./scripts/devServer") as any;
|
|
5
|
+
}else{
|
|
6
|
+
wildpigServer = await import("./scripts/prodServer") as any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
wildpigServer
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wildpig",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.10",
|
|
4
4
|
"author": "eriktse",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"dev": "wildpig dev",
|
|
32
32
|
"build": "wildpig build",
|
|
33
|
-
"start": "wildpig start"
|
|
33
|
+
"start": "wildpig start",
|
|
34
|
+
"local-publish": "yalc publish"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/scripts/build.ts
CHANGED
package/scripts/devServer.ts
CHANGED
|
@@ -98,6 +98,22 @@ const getPackageInfo = async () => {
|
|
|
98
98
|
}
|
|
99
99
|
const packageInfo = await getPackageInfo();
|
|
100
100
|
|
|
101
|
+
export const startServer = async () => {
|
|
102
|
+
// 确保重启后可以重新拿到路由
|
|
103
|
+
const apiModules = await getApiRouteModules("dev") as any;
|
|
104
|
+
const server = Bun.serve({
|
|
105
|
+
port,
|
|
106
|
+
hostname,
|
|
107
|
+
routes:{
|
|
108
|
+
...apiModules,
|
|
109
|
+
"/*": viteHandler(apiModules),
|
|
110
|
+
},
|
|
111
|
+
development: true,
|
|
112
|
+
})
|
|
113
|
+
afterStart();
|
|
114
|
+
return server;
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
/** 启动后的描述性文字 */
|
|
102
118
|
const afterStart = () => {
|
|
103
119
|
// 启动后的文字
|
|
@@ -112,23 +128,7 @@ console.log(chalk.green(" Strong & Fast Fullstack Framework\n"));
|
|
|
112
128
|
console.log(chalk.green("✨ WildPig is running on port " + env.PORT || 3000));
|
|
113
129
|
console.log(chalk.yellow("💻 Wildpig is Running in development mode."));
|
|
114
130
|
console.log(chalk.green("⚡ Vite server is running on port " + viteServer.config.server?.port));
|
|
115
|
-
console.log(chalk.green(`🔗 Click to debug in Browser: http
|
|
131
|
+
console.log(chalk.green(`🔗 Click to debug in Browser: http://localhost:${port}`));
|
|
116
132
|
}
|
|
117
133
|
|
|
118
|
-
export const
|
|
119
|
-
// 确保重启后可以重新拿到路由
|
|
120
|
-
const apiModules = await getApiRouteModules("dev") as any;
|
|
121
|
-
console.log(apiModules)
|
|
122
|
-
const server = Bun.serve({
|
|
123
|
-
port,
|
|
124
|
-
hostname,
|
|
125
|
-
routes:{
|
|
126
|
-
...apiModules,
|
|
127
|
-
"/*": viteHandler(apiModules),
|
|
128
|
-
},
|
|
129
|
-
development: true,
|
|
130
|
-
})
|
|
131
|
-
afterStart();
|
|
132
|
-
return server;
|
|
133
|
-
}
|
|
134
|
-
startServer();
|
|
134
|
+
export const wildpigServer = await startServer();
|
package/scripts/prodServer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getApiRouteModules } from "./apiRoutes";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { matchRoutes } from "react-router";
|
|
4
|
-
import
|
|
4
|
+
import packageJson from "../package.json";
|
|
5
5
|
|
|
6
6
|
// 用户代码
|
|
7
7
|
const pageRoutes = (await import("@/router/routes"!)).default as WildPigRouteObject[];
|
|
@@ -13,7 +13,6 @@ const port = env.PORT || 3000;
|
|
|
13
13
|
const hostname = env.HOST || env.HOSTNAME || "localhost";
|
|
14
14
|
|
|
15
15
|
const getPackageInfo = async () => {
|
|
16
|
-
const packageJson = await Bun.file(path.resolve(__dirname, "../package.json")).json();
|
|
17
16
|
return packageJson;
|
|
18
17
|
}
|
|
19
18
|
const packageInfo = await getPackageInfo();
|
|
@@ -31,7 +30,7 @@ console.log(chalk.blue.bgGreen(` 🐗 WildPig version ${packageInfo?.ver
|
|
|
31
30
|
console.log(chalk.green(" Strong & Fast Fullstack Framework\n"));
|
|
32
31
|
console.log(chalk.green("✨ WildPig is running on port " + env.PORT || 3000));
|
|
33
32
|
console.log(chalk.green("💻 Wildpig is Running in production mode."));
|
|
34
|
-
console.log(chalk.green(`🔗 Click to
|
|
33
|
+
console.log(chalk.green(`🔗 Click to play in Browser: http://localhost:${port}`));
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
|
|
@@ -39,7 +38,7 @@ console.log(chalk.green(`🔗 Click to debug in Browser: http://${hostname}:${po
|
|
|
39
38
|
export const startServer = async () => {
|
|
40
39
|
// 确保重启后可以重新拿到路由
|
|
41
40
|
const apiModules = await getApiRouteModules("prod") as any;
|
|
42
|
-
|
|
41
|
+
const server = Bun.serve({
|
|
43
42
|
port,
|
|
44
43
|
hostname,
|
|
45
44
|
routes:{
|
|
@@ -95,7 +94,7 @@ export const startServer = async () => {
|
|
|
95
94
|
// 2. 获取渲染函数
|
|
96
95
|
const { render } = await import("../entry/server"!);
|
|
97
96
|
// 3. 获取应用程序 HTML
|
|
98
|
-
const appHtml = await render(request)
|
|
97
|
+
const appHtml = await render(request, serverData);
|
|
99
98
|
|
|
100
99
|
// 4. 注入渲染后的应用程序 HTML 到模板中。
|
|
101
100
|
const html = template
|
|
@@ -113,9 +112,9 @@ export const startServer = async () => {
|
|
|
113
112
|
},
|
|
114
113
|
development: false,
|
|
115
114
|
|
|
116
|
-
})
|
|
115
|
+
});
|
|
116
|
+
afterStart();
|
|
117
|
+
return server;
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
startServer();
|
|
121
|
-
afterStart();
|
|
120
|
+
export const wildpigServer = await startServer();
|