MCPcopy
hub / github.com/tldraw/tldraw / writeUrlBasedAssetDeclarationFile

Function writeUrlBasedAssetDeclarationFile

internal/scripts/refresh-assets.ts:431–466  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

429
430// 6. ASSET DECLARATION FILES
431async function writeUrlBasedAssetDeclarationFile() {
432 const codeFilePath = join(REPO_ROOT, 'packages', 'assets', 'urls.js')
433 const codeFile = new CodeFile(`
434 // eslint-disable-next-line @typescript-eslint/triple-slash-reference
435 /// <reference path="./modules.d.ts" />
436 import { formatAssetUrl } from './utils.js'
437 `)
438
439 const fn = codeFile.appendFn(`
440 /**
441 * @param {AssetUrlOptions} [opts]
442 * @public
443 */
444 export function getAssetUrlsByMetaUrl(opts) {
445 `)
446
447 fn.append('return {')
448 for (const [type, assets] of Object.entries(collectedAssetUrls)) {
449 fn.append(`${type}: {`)
450 for (const [name, { file, hash }] of Object.entries(assets)) {
451 const href = JSON.stringify(`./${file}`)
452 const fileUrl = fn.memo(file, `formatAssetUrl(new URL(${href}, import.meta.url).href, opts)`)
453 const value = hash ? `${fileUrl} + ${JSON.stringify('#' + hash)}` : fileUrl
454 fn.append(`${JSON.stringify(name)}: ${value},`)
455 }
456 fn.append('},')
457 }
458 fn.append('}')
459
460 await writeCodeFile(
461 'internal/scripts/refresh-assets.ts',
462 'javascript',
463 codeFilePath,
464 codeFile.toString()
465 )
466}
467
468async function writeImportBasedAssetDeclarationFile(
469 importSuffix: string,

Callers 1

mainFunction · 0.85

Calls 6

appendFnMethod · 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…