MCPcopy Index your code
hub / github.com/tldraw/tldraw / writeSelfHostedAssetDeclarationFile

Function writeSelfHostedAssetDeclarationFile

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

Source from the content-addressed store, hash-verified

506}
507
508async function writeSelfHostedAssetDeclarationFile(): Promise<void> {
509 const codeFilePath = join(REPO_ROOT, 'packages', 'assets', 'selfHosted.js')
510 const codeFile = new CodeFile(`
511 // eslint-disable-next-line @typescript-eslint/triple-slash-reference
512 /// <reference path="./modules.d.ts" />
513 import { formatAssetUrl } from './utils.js'
514 `)
515
516 const fn = codeFile.appendFn(`
517 /**
518 * @param {AssetUrlOptions} [opts]
519 * @public
520 */
521 export function getAssetUrls(opts) {
522 `)
523
524 fn.append('return {')
525 for (const [type, assets] of Object.entries(collectedAssetUrls)) {
526 fn.append(`${type}: {`)
527 for (const [name, { file, hash }] of Object.entries(assets)) {
528 const href = JSON.stringify(`./${file}`)
529 const formattedUrl = fn.memo(file, `formatAssetUrl(${href}, opts)`)
530 const value = hash ? `${formattedUrl} + ${JSON.stringify('#' + hash)}` : formattedUrl
531 fn.append(`${JSON.stringify(name)}: ${value},`)
532 }
533 fn.append('},')
534 }
535 fn.append('}')
536
537 await writeCodeFile(
538 'internal/scripts/refresh-assets.ts',
539 'javascript',
540 codeFilePath,
541 codeFile.toString()
542 )
543}
544
545async function writeAssetDeclarationDTSFile() {
546 let dts = `

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…