写了一些日常辅助脚本:定时备份数据、批量重命名截图、调用 Windows 通知中心。用 node-schedule 和 node-notifier 很方便。
定时备份
const schedule = require('node-schedule');
// 每天凌晨 3 点备份
schedule.scheduleJob('0 3 * * *', () => {
backupData();
});
批量重命名
客户发来的截图文件名混乱,用正则提取日期和号码,统一格式。
const files = fs.readdirSync('./screenshots');
files.forEach(file => {
const newName = file.replace(/IMG_(\d{8})/, 'screenshot_$1');
fs.renameSync(file, newName);
});
Windows 通知
充值完成时弹出系统通知,不用盯着窗口。
const notifier = require('node-notifier');
notifier.notify({
title: '充值完成',
message: '号码 13800138000 已到账',
icon: './logo.png'
});