({
rootPath,
translationFilePaths,
mappingFilePath,
logger,
}: MigrateFilesOptions)
| 28 | |
| 29 | /** Migrates the legacy message IDs based on the passed in configuration. */ |
| 30 | export function migrateFiles({ |
| 31 | rootPath, |
| 32 | translationFilePaths, |
| 33 | mappingFilePath, |
| 34 | logger, |
| 35 | }: MigrateFilesOptions) { |
| 36 | const fs = getFileSystem(); |
| 37 | const absoluteMappingPath = fs.resolve(rootPath, mappingFilePath); |
| 38 | const mapping = JSON.parse(fs.readFile(absoluteMappingPath)) as MigrationMapping; |
| 39 | |
| 40 | if (Object.keys(mapping).length === 0) { |
| 41 | logger.warn( |
| 42 | `Mapping file at ${absoluteMappingPath} is empty. Either there are no messages ` + |
| 43 | `that need to be migrated, or the extraction step failed to find them.`, |
| 44 | ); |
| 45 | } else { |
| 46 | translationFilePaths.forEach((path) => { |
| 47 | const absolutePath = fs.resolve(rootPath, path); |
| 48 | const sourceCode = fs.readFile(absolutePath); |
| 49 | fs.writeFile(absolutePath, migrateFile(sourceCode, mapping)); |
| 50 | }); |
| 51 | } |
| 52 | } |
no test coverage detected
searching dependent graphs…