-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite-plugin-run-scripts.js
More file actions
35 lines (29 loc) · 1.11 KB
/
vite-plugin-run-scripts.js
File metadata and controls
35 lines (29 loc) · 1.11 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
import { exec } from 'child_process';
export function runScriptsPlugin() {
return {
name: 'run-scripts',
configureServer(server) {
if (process.argv.includes('--run-scripts')) {
const runScript = () => {
console.log('Running scripts...');
const script = exec('node .github/scripts/generate-summaries.mjs');
script.stdout.on('data', (data) => {
console.log(`[scripts] ${data}`);
});
script.stderr.on('data', (data) => {
console.error(`[scripts] ${data}`);
});
script.on('close', (code) => {
console.log(`[scripts] exited with code ${code}`);
});
};
runScript();
server.watcher.on('change', (path) => {
if (path.includes('/blog/')) {
runScript();
}
});
}
},
};
}