MCPcopy
hub / github.com/tldraw/tldraw / writeFile

Function writeFile

internal/scripts/lib/file.ts:62–86  ·  view source on GitHub ↗
(filePath: string, contents: Buffer)

Source from the content-addressed store, hash-verified

60}
61
62export 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
88export async function writeJsonFile(filePath: string, contents: unknown) {
89 await writeStringFile(filePath, JSON.stringify(contents, null, '\t') + '\n')

Callers 8

copyEmbedIconsFunction · 0.90
copyFontsFunction · 0.90
copyTranslationsFunction · 0.90
storeAssetFunction · 0.85
storeAssetFunction · 0.85
snapshotTestFunction · 0.85
snapshotTestFunction · 0.85
writeStringFileFunction · 0.85

Calls 3

nicelogFunction · 0.90
equalsMethod · 0.65
toStringMethod · 0.65

Tested by 2

snapshotTestFunction · 0.68
snapshotTestFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…