MCPcopy
hub / github.com/tldraw/tldraw / writeImportBasedAssetDeclarationFile

Function writeImportBasedAssetDeclarationFile

internal/scripts/refresh-assets.ts:468–506  ·  view source on GitHub ↗
(
	importSuffix: string,
	fileName: string
)

Source from the content-addressed store, hash-verified

466}
467
468async function writeImportBasedAssetDeclarationFile(
469 importSuffix: string,
470 fileName: string
471): Promise<void> {
472 const codeFile = new CodeFile(`
473 // eslint-disable-next-line @typescript-eslint/triple-slash-reference
474 /// <reference path="./modules.d.ts" />
475 import { formatAssetUrl } from './utils.js'
476 `)
477
478 const fn = codeFile.appendFn(`
479 /**
480 * @param {AssetUrlOptions} [opts]
481 * @public
482 */
483 export function getAssetUrlsByImport(opts) {
484 `)
485
486 fn.append('return {')
487 for (const [type, assets] of Object.entries(collectedAssetUrls)) {
488 fn.append(`${type}: {`)
489 for (const [name, { file, hash }] of Object.entries(assets)) {
490 const variableName = codeFile.import(`./${file}${importSuffix}`)
491 const formattedUrl = fn.memo(file, `formatAssetUrl(${variableName}, opts)`)
492 const value = hash ? `${formattedUrl} + ${JSON.stringify('#' + hash)}` : formattedUrl
493 fn.append(`${JSON.stringify(name)}: ${value},`)
494 }
495 fn.append('},')
496 }
497 fn.append('}')
498
499 const codeFilePath = join(REPO_ROOT, 'packages', 'assets', fileName)
500 await writeCodeFile(
501 'internal/scripts/refresh-assets.ts',
502 'javascript',
503 codeFilePath,
504 codeFile.toString()
505 )
506}
507
508async function writeSelfHostedAssetDeclarationFile(): Promise<void> {
509 const codeFilePath = join(REPO_ROOT, 'packages', 'assets', 'selfHosted.js')

Callers 1

mainFunction · 0.85

Calls 7

appendFnMethod · 0.95
importMethod · 0.95
toStringMethod · 0.95
writeCodeFileFunction · 0.90
memoMethod · 0.80
appendMethod · 0.65
entriesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…