(filePath: string, contents: Buffer)
| 60 | } |
| 61 | |
| 62 | export async function writeFile(filePath: string, contents: Buffer) { |
| 63 | if (process.env.CI && !process.env.ALLOW_REFRESH_ASSETS_CHANGES) { |
| 64 | let existingContents: Buffer | null = null |
| 65 | try { |
| 66 | existingContents = await readFile(filePath) |
| 67 | } catch { |
| 68 | // Ignore |
| 69 | } |
| 70 | if (existingContents && !existingContents.equals(contents)) { |
| 71 | nicelog( |
| 72 | `Asset file ${relative( |
| 73 | REPO_ROOT, |
| 74 | filePath |
| 75 | )} has changed. Please run this script again and commit the changes.` |
| 76 | ) |
| 77 | nicelog('Contents before:') |
| 78 | nicelog(existingContents.toString('utf-8')) |
| 79 | nicelog('\nContents after:') |
| 80 | nicelog(contents.toString('utf-8')) |
| 81 | |
| 82 | process.exit(1) |
| 83 | } |
| 84 | } |
| 85 | await writeFileUnchecked(filePath, contents, 'utf-8') |
| 86 | } |
| 87 | |
| 88 | export async function writeJsonFile(filePath: string, contents: unknown) { |
| 89 | await writeStringFile(filePath, JSON.stringify(contents, null, '\t') + '\n') |
searching dependent graphs…