* Materialise a bundle into a freshly-created directory so the harness * server can serve it. Accepts either a directory (copied) or one of * the bundled archive shapes (zip / war / jar — unzip-extractable).
(input, dest)
| 94 | * the bundled archive shapes (zip / war / jar — unzip-extractable). |
| 95 | */ |
| 96 | function materializeBundle(input, dest) { |
| 97 | fs.mkdirSync(dest, { recursive: true }); |
| 98 | const stat = fs.statSync(input); |
| 99 | if (stat.isDirectory()) { |
| 100 | copyTree(input, dest); |
| 101 | return; |
| 102 | } |
| 103 | const ext = path.extname(input).toLowerCase(); |
| 104 | if (ext === '.zip' || ext === '.war' || ext === '.jar') { |
| 105 | const result = nodeSpawnSync('unzip', ['-qq', input, '-d', dest], { encoding: 'utf8' }); |
| 106 | if (result.status !== 0) { |
| 107 | throw new Error(`unzip failed for ${input}: status=${result.status} stderr=${result.stderr}`); |
| 108 | } |
| 109 | return; |
| 110 | } |
| 111 | throw new Error(`Unsupported bundle input: ${input}`); |
| 112 | } |
| 113 | |
| 114 | function copyTree(src, dst) { |
| 115 | fs.mkdirSync(dst, { recursive: true }); |
no test coverage detected