(db: Db, file: ChangedFile)
| 500 | * @param file The ChangedFile object containing status and path. |
| 501 | */ |
| 502 | export async function processFileUpdate(db: Db, file: ChangedFile): Promise<void> { |
| 503 | const { status, filepath, oldFilepath } = file; |
| 504 | |
| 505 | const locale = getLocaleFromFilepath(filepath); |
| 506 | const isTranslation = locale !== null && locale !== 'en'; |
| 507 | |
| 508 | if (isTranslation) { |
| 509 | switch (status) { |
| 510 | case 'A': |
| 511 | await _handleTranslationFileAdded(db, filepath); |
| 512 | break; |
| 513 | case 'M': |
| 514 | await _handleTranslationFileModified(db, filepath); |
| 515 | break; |
| 516 | case 'R': |
| 517 | // delete+add rather than diff: simpler and correct since a rename implies |
| 518 | // a collection change, and translation docs are cheap to recreate. |
| 519 | if (oldFilepath) await _handleTranslationFileDeleted(db, oldFilepath); |
| 520 | await _handleTranslationFileAdded(db, filepath); |
| 521 | break; |
| 522 | case 'D': |
| 523 | await _handleTranslationFileDeleted(db, filepath); |
| 524 | break; |
| 525 | default: |
| 526 | console.log(`\nSkipping translation file ${filepath} with unhandled status ${status}.`); |
| 527 | } |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | switch (status) { |
| 532 | case 'A': |
| 533 | await _handleFileAdded(db, filepath); |
| 534 | break; |
| 535 | case 'M': |
| 536 | await _handleFileModified(db, filepath); |
| 537 | break; |
| 538 | case 'R': |
| 539 | if (!oldFilepath) { |
| 540 | console.error( |
| 541 | `Error: Renamed file status 'R' requires 'oldFilepath' for ${filepath}. Skipping.` |
| 542 | ); |
| 543 | return; |
| 544 | } |
| 545 | await _handleFileRenamed(db, filepath, oldFilepath); |
| 546 | break; |
| 547 | case 'D': |
| 548 | await _handleFileDeleted(db, filepath); |
| 549 | break; |
| 550 | default: |
| 551 | console.log(`\nSkipping file ${filepath} with unhandled status ${status}.`); |
| 552 | } |
| 553 | } |
no test coverage detected