Files
img-bed/schedule-build.js
2026-01-01 23:55:35 +08:00

34 lines
1017 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { exec } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 设置定时间隔毫秒这里设置为1小时3600000毫秒
const INTERVAL_MS = 5000; // 1秒
function runBuild() {
console.log(`[${new Date().toISOString()}] 开始执行 npm run build`);
exec('npm run build', { cwd: __dirname }, (error, stdout, stderr) => {
if (error) {
console.error(`[${new Date().toISOString()}] 执行失败: ${error.message}`);
return;
}
if (stderr) {
console.error(`[${new Date().toISOString()}] 标准错误: ${stderr}`);
}
console.log(`[${new Date().toISOString()}] 执行成功: ${stdout}`);
});
}
// 立即执行一次
runBuild();
// 设置定时器,每隔指定时间执行一次
setInterval(runBuild, INTERVAL_MS);
console.log(`定时任务已启动,每 ${INTERVAL_MS / 1000 / 60} 分钟执行一次 npm run build`);