| 506 | } |
| 507 | |
| 508 | async 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 | |
| 545 | async function writeAssetDeclarationDTSFile() { |
| 546 | let dts = ` |