( groupKey: string, assets: readonly MaterializedAsset[], )
| 84 | } |
| 85 | |
| 86 | export function materializeEmbeddedAssetGroup( |
| 87 | groupKey: string, |
| 88 | assets: readonly MaterializedAsset[], |
| 89 | ): MaterializedAssetGroup { |
| 90 | const hash = createHash('sha256') |
| 91 | for (const asset of assets) { |
| 92 | hash.update(asset.relativePath) |
| 93 | hash.update(readFileSync(resolveEmbeddedAssetPath(asset.embeddedPath))) |
| 94 | } |
| 95 | |
| 96 | const baseDir = join( |
| 97 | tmpdir(), |
| 98 | 'ncode-native-assets', |
| 99 | `${sanitizeGroupKey(groupKey)}-${hash.digest('hex').slice(0, 16)}`, |
| 100 | ) |
| 101 | const paths: Record<string, string> = {} |
| 102 | |
| 103 | for (const asset of assets) { |
| 104 | const targetPath = join(baseDir, asset.relativePath) |
| 105 | paths[asset.relativePath] = targetPath |
| 106 | if (!existsSync(targetPath)) { |
| 107 | writeAtomically( |
| 108 | targetPath, |
| 109 | Buffer.from(readFileSync(resolveEmbeddedAssetPath(asset.embeddedPath))), |
| 110 | asset.mode, |
| 111 | ) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return { |
| 116 | baseDir, |
| 117 | paths, |
| 118 | } |
| 119 | } |
no test coverage detected