| 429 | |
| 430 | // 6. ASSET DECLARATION FILES |
| 431 | async 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 | |
| 468 | async function writeImportBasedAssetDeclarationFile( |
| 469 | importSuffix: string, |