MCPcopy Index your code
hub / github.com/ampproject/amphtml / preBuildExperiments

Function preBuildExperiments

build-system/tasks/dist.js:302–330  ·  view source on GitHub ↗

* Precompilation steps required to build experiment js binaries. * @return {Promise }

()

Source from the content-addressed store, hash-verified

300 * @return {Promise<void>}
301 */
302async 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.

Callers 1

prebuildFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected