( filePath: string, state: WatchState, ctx: CmdRunContext, )
| 126 | } |
| 127 | |
| 128 | function handleFileChange( |
| 129 | filePath: string, |
| 130 | state: WatchState, |
| 131 | ctx: CmdRunContext, |
| 132 | ) { |
| 133 | const debounceDelay = ctx.flags.debounce || 5000; // Use configured debounce or 5s default |
| 134 | |
| 135 | state.pendingChanges.add(filePath); |
| 136 | |
| 137 | console.log(chalk.dim(`📝 File changed: ${filePath}`)); |
| 138 | |
| 139 | // Clear existing debounce timer |
| 140 | if (state.debounceTimer) { |
| 141 | clearTimeout(state.debounceTimer); |
| 142 | } |
| 143 | |
| 144 | // Set new debounce timer |
| 145 | state.debounceTimer = setTimeout(async () => { |
| 146 | if (state.isRunning) { |
| 147 | console.log( |
| 148 | chalk.yellow("⏳ Translation already in progress, skipping..."), |
| 149 | ); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | await triggerRetranslation(state, ctx); |
| 154 | }, debounceDelay); |
| 155 | } |
| 156 | |
| 157 | async function triggerRetranslation(state: WatchState, ctx: CmdRunContext) { |
| 158 | if (state.isRunning) return; |
no test coverage detected