-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodemon.js
More file actions
38 lines (35 loc) · 1.1 KB
/
nodemon.js
File metadata and controls
38 lines (35 loc) · 1.1 KB
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
import nodemon from "nodemon";
import { execSync } from "child_process";
nodemon({
ext: 'js ts', // 监控的文件扩展名
watch: ["myserver.ts", "src/**"], // 监控的目录
exec: 'tsx myserver.ts',
ignore: ["node_modules", "dist"],
env: {
"NODE_ENV": "development"
},
verbose: true, // 开启详细日志
});
nodemon
.on('start', () => {
console.log('App has started');
})
.on('change', (files) => {
// files 是变更文件的路径数组(可能多个文件同时变更)
console.log('检测到文件变更:', files);
})
.on('quit', () => {
console.log('App has quit');
process.exit();
})
.on('restart', (files) => {
console.log('App restarted due to: ', files);
const targetDir = ["backend/events", "backend/hooks", "backend/middlewares", "backend/routes"];
if (containsAny(files, targetDir)) {
console.log("autoloadindex start!");
execSync("tsx ./scripts/autoloadindex.ts");
}
});
function containsAny(sourceList, targetList) {
return targetList.some(target => sourceList.some(source => source.includes(target)));
}