* Precompilation steps required to build experiment js binaries. * @return {Promise }
()
| 300 | * @return {Promise<void>} |
| 301 | */ |
| 302 | async function preBuildExperiments() { |
| 303 | const expDir = 'tools/experiments'; |
| 304 | const htmlDestDir = 'dist.tools/experiments'; |
| 305 | const htmlSrcPath = `${expDir}/experiments.html`; |
| 306 | const jsSrcPath = `${expDir}/experiments.js`; |
| 307 | |
| 308 | // Build HTML. |
| 309 | const html = await fs.readFile(htmlSrcPath, 'utf8'); |
| 310 | const minHtml = html |
| 311 | .replace( |
| 312 | '/dist.tools/experiments/experiments.js', |
| 313 | `https://${hostname}/v0/experiments.js` |
| 314 | ) |
| 315 | .replace(/\$internalRuntimeVersion\$/g, VERSION); |
| 316 | await fs.outputFile(`${htmlDestDir}/experiments.cdn.html`, minHtml); |
| 317 | await fs.copy(htmlSrcPath, `${htmlDestDir}/${path.basename(htmlSrcPath)}`); |
| 318 | |
| 319 | // Build JS. |
| 320 | const jsDir = 'build/experiments/'; |
| 321 | const js = await fs.readFile(jsSrcPath, 'utf8'); |
| 322 | const builtName = 'experiments.max.js'; |
| 323 | await fs.outputFile(`${jsDir}/${builtName}`, js); |
| 324 | const jsFiles = await fastGlob(`${expDir}/*.js`); |
| 325 | await Promise.all( |
| 326 | jsFiles.map((jsFile) => { |
| 327 | return fs.copy(jsFile, `${jsDir}/${path.basename(jsFile)}`); |
| 328 | }) |
| 329 | ); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Build "Login Done" page. |