wildpig 1.3.6 → 1.3.7
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/build/built-api-routes.ts +3 -9
- package/package.json +1 -1
- package/scripts/apiRoutes.ts +5 -1
- package/scripts/packageStatic.ts +7 -1
- package/scripts/server.ts +12 -10
|
@@ -5,12 +5,9 @@ import {
|
|
|
5
5
|
} from "#/src/api/hello/index";
|
|
6
6
|
import {
|
|
7
7
|
GET as GET2,
|
|
8
|
-
} from "#/src/api/hello/[id]/index";
|
|
9
|
-
import {
|
|
10
|
-
GET as GET3,
|
|
11
8
|
} from "#/src/api/server-data/hello/[id]/index";
|
|
12
9
|
import {
|
|
13
|
-
GET as
|
|
10
|
+
GET as GET3,
|
|
14
11
|
} from "#/src/api/server-data/home/index";
|
|
15
12
|
|
|
16
13
|
export default {
|
|
@@ -18,13 +15,10 @@ export default {
|
|
|
18
15
|
GET: (req: any) => middleware(req, GET1),
|
|
19
16
|
POST: (req: any) => middleware(req, POST1),
|
|
20
17
|
},
|
|
21
|
-
"/api/hello/:id": {
|
|
22
|
-
GET: (req: any) => middleware(req, GET2),
|
|
23
|
-
},
|
|
24
18
|
"/api/server-data/hello/:id": {
|
|
25
|
-
GET: (req: any) => middleware(req,
|
|
19
|
+
GET: (req: any) => middleware(req, GET2),
|
|
26
20
|
},
|
|
27
21
|
"/api/server-data/home": {
|
|
28
|
-
GET: (req: any) => middleware(req,
|
|
22
|
+
GET: (req: any) => middleware(req, GET3),
|
|
29
23
|
},
|
|
30
24
|
}
|
package/package.json
CHANGED
package/scripts/apiRoutes.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { readdirSync, statSync, writeFileSync } from "fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const __dirname = import.meta.dirname;
|
|
4
|
+
|
|
5
|
+
|
|
2
6
|
import { middleware } from "@/api/middleware";
|
|
3
7
|
|
|
4
8
|
const getFilePaths = (dir: string) => {
|
|
@@ -64,7 +68,7 @@ export const packageApiRoutes = async () => {
|
|
|
64
68
|
routesText += `\t},\n`;
|
|
65
69
|
}
|
|
66
70
|
routesText += "}";
|
|
67
|
-
writeFileSync("
|
|
71
|
+
writeFileSync(path.resolve(__dirname, "../build/built-api-routes.ts"), importsText + "\n" + routesText);
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
/**
|
package/scripts/packageStatic.ts
CHANGED
|
@@ -5,14 +5,20 @@ import path from "node:path";
|
|
|
5
5
|
const __dirname = import.meta.dirname;
|
|
6
6
|
|
|
7
7
|
export const packageStatic = async () => {
|
|
8
|
+
const targetPublicPath = path.resolve(__dirname, "../dist/public");
|
|
9
|
+
if(fs.existsSync(targetPublicPath)) {
|
|
10
|
+
fs.rmSync(targetPublicPath, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
fs.mkdirSync(targetPublicPath);
|
|
8
13
|
/** 打包js */
|
|
9
14
|
await Bun.build({
|
|
10
15
|
entrypoints: [path.resolve(__dirname, "../public/render.tsx")],
|
|
11
|
-
outdir:
|
|
16
|
+
outdir: targetPublicPath,
|
|
12
17
|
format: "esm",
|
|
13
18
|
minify: true,
|
|
14
19
|
});
|
|
15
20
|
|
|
21
|
+
if(!fs.existsSync("./dist/public"))fs.mkdirSync("./dist/public");
|
|
16
22
|
/** 打包ico */
|
|
17
23
|
fs.copyFileSync("./public/favicon.ico", "./dist/public/favicon.ico");
|
|
18
24
|
}
|
package/scripts/server.ts
CHANGED
|
@@ -17,17 +17,19 @@ const packageInfo = await getPackageInfo();
|
|
|
17
17
|
|
|
18
18
|
const startHotServer = () => {
|
|
19
19
|
let server = startServer();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if(isDev){
|
|
21
|
+
watch("src", {recursive: true}, async (event, filename) => {
|
|
22
|
+
// 只监测文件路径变化
|
|
23
|
+
if(event !== "rename")return;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
console.log(chalk.green("检测到src下文件路径变化(新增、删除或移动文件),重启服务..."));
|
|
26
|
+
await server.stop();
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
server = startServer();
|
|
29
|
+
console.log(chalk.green("服务已重启"));
|
|
30
|
+
}, 500);
|
|
31
|
+
})
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
34
|
startHotServer();
|
|
33
35
|
|