Make debug scripts cross platform

This commit is contained in:
2026-07-07 10:30:58 +08:00
parent 4f184c9e86
commit c2fe56cae9
2 changed files with 30 additions and 8 deletions

View File

@@ -2,6 +2,8 @@
* 单任务调试入口
*
* 示例:
* node debugTask.js dailyTrending --keep-open
* node debugTask.js updateProject --keep-open --dry-run
* TASK=dailyTrending DEBUG_TASK=true DEBUG_KEEP_OPEN=true node debugTask.js
* TASK=updateProject DEBUG_TASK=true DEBUG_KEEP_OPEN=true DEBUG_DRY_RUN=true node debugTask.js
*/
@@ -52,15 +54,35 @@ const taskMap = {
},
};
function getArgs() {
const args = process.argv.slice(2);
const taskArg = args.find((arg) => !arg.startsWith('--'));
const flags = new Set(args.filter((arg) => arg.startsWith('--')));
return {
taskKey: process.env.TASK || taskArg,
help: flags.has('--help') || flags.has('-h'),
keepOpen: process.env.DEBUG_KEEP_OPEN === 'true' || flags.has('--keep-open'),
pauseEachStep: process.env.DEBUG_PAUSE_EACH_STEP === 'true' || flags.has('--pause-each-step'),
dryRun: process.env.DEBUG_DRY_RUN === 'true' || flags.has('--dry-run'),
};
}
function printUsage() {
logger.info('用法: TASK=<taskName> node debugTask.js');
logger.info('用法: node debugTask.js <taskName> [--keep-open] [--pause-each-step] [--dry-run]');
logger.info('兼容用法: TASK=<taskName> node debugTask.js');
logger.info('可用任务:');
Object.keys(taskMap).forEach((key) => logger.info(` ${key}`));
logger.info('常用参数: DEBUG_KEEP_OPEN=true DEBUG_PAUSE_EACH_STEP=true DEBUG_DRY_RUN=true');
}
async function main() {
const taskKey = process.env.TASK;
const args = getArgs();
if (args.help) {
printUsage();
return;
}
const taskKey = args.taskKey;
const task = taskMap[taskKey];
if (!task) {
@@ -101,9 +123,9 @@ async function main() {
logger.info(`===== 执行单任务: ${task.name} =====`);
await task.handler(page, {
debugTask: true,
keepOpen: process.env.DEBUG_KEEP_OPEN === 'true',
pauseEachStep: process.env.DEBUG_PAUSE_EACH_STEP === 'true',
dryRun: process.env.DEBUG_DRY_RUN === 'true',
keepOpen: args.keepOpen,
pauseEachStep: args.pauseEachStep,
dryRun: args.dryRun,
});
logger.divider();