wildpig 1.3.4 → 1.3.6

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/bin/cli.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import { build } from "../scripts/build";
3
3
  import { spawn } from "bun";
4
+ import fs from "node:fs";
4
5
  const command = process.argv[2];
5
6
 
6
7
  if(command === "start"){
@@ -26,7 +27,16 @@ if(command === "start"){
26
27
  if(command === "dev"){
27
28
  // 设置一些环境变量
28
29
  process.env.NODE_ENV = "development";
29
- await import("../scripts/server");
30
+ // 监测是否有node_modules/wildpig
31
+ const wildpigExist = fs.existsSync("./node_modules/wildpig");
32
+ const serverPath = wildpigExist ? "./node_modules/wildpig/scripts/server.ts" : "./scripts/server.ts";
33
+ spawn(["bun", "run", "--hot", serverPath], {
34
+ cwd: ".",
35
+ stdout: "inherit",
36
+ env: {
37
+ ...process.env
38
+ }
39
+ });
30
40
  }
31
41
 
32
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildpig",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "author": "eriktse",
5
5
  "main": "index.ts",
6
6
  "bin":{
package/scripts/server.ts CHANGED
@@ -17,10 +17,16 @@ const packageInfo = await getPackageInfo();
17
17
 
18
18
  const startHotServer = () => {
19
19
  let server = startServer();
20
- watch("src", {recursive: true}, async () => {
20
+ watch("src", {recursive: true}, async (event, filename) => {
21
+ // 只监测文件路径变化
22
+ if(event !== "rename")return;
23
+
21
24
  console.log(chalk.green("检测到src下文件路径变化(新增、删除或移动文件),重启服务..."));
22
25
  await server.stop();
23
- server = startServer();
26
+ setTimeout(() => {
27
+ server = startServer();
28
+ console.log(chalk.green("服务已重启"));
29
+ }, 500);
24
30
  })
25
31
  }
26
32
  startHotServer();