build-system/tasks/dist.js
/**
 * Precompilation steps required to build experiment js binaries.
 * @return {Promise<void>}
 */
Precompilation steps required to build experiment js binaries.
@return {Promise}
Precompilation steps required to build experiment js binaries . @return { Promise }
async function preBuildExperiments() {
  const expDir = 'tools/experiments';
  const htmlDestDir = 'dist.tools/experiments';
  const htmlSrcPath = `${expDir}/experiments.html`;
  const jsSrcPath = `${expDir}/experiments.js`;
  const html = await fs.readFile(htmlSrcPath, 'utf8');
  const minHtml = html
    .replace(
      '/dist.tools/experiments/experiments.js',
      `https://${hostname}/v0/experiments.js`
    )
    .replace(/\$internalRuntimeVersion\$/g, VERSION);
  await fs.outputFile(`${htmlDestDir}/experiments.cdn.html`, minHtml);
  await fs.copy(htmlSrcPath, `${htmlDestDir}/${path.basename(htmlSrcPath)}`);
  const jsDir = 'build/experiments/';
  const js = await fs.readFile(jsSrcPath, 'utf8');
  const builtName = 'experiments.max.js';
  await fs.outputFile(`${jsDir}/${builtName}`, js);
  const jsFiles = await fastGlob(`${expDir}/*.js`);
  await Promise.all(
    jsFiles.map((jsFile) => {
      return fs.copy(jsFile, `${jsDir}/${path.basename(jsFile)}`);
    })
  );
}
async function preBuildExperiments ( ) { const expDir = 'tools/experiments' ; const htmlDestDir = 'dist.tools/experiments' ; const htmlSrcPath = ` ${ expDir } ` ; const jsSrcPath = ` ${ expDir } ` ; const html = await fs . readFile ( htmlSrcPath , 'utf8' ) ; const minHtml = html . replace ( '/dist.tools/experiments/experiments.js' , ` ${ hostname } ` ) . replace ( / \$internalRuntimeVersion\$ / g , VERSION ) ; await fs . outputFile ( ` ${ htmlDestDir } ` , minHtml ) ; await fs . copy ( htmlSrcPath , ` ${ htmlDestDir } ${ path . basename ( htmlSrcPath ) } ` ) ; const jsDir = 'build/experiments/' ; const js = await fs . readFile ( jsSrcPath , 'utf8' ) ; const builtName = 'experiments.max.js' ; await fs . outputFile ( ` ${ jsDir } ${ builtName } ` , js ) ; const jsFiles = await fastGlob ( ` ${ expDir } ` ) ; await Promise . all ( jsFiles . map ( ( jsFile ) => { return fs . copy ( jsFile , ` ${ jsDir } ${ path . basename ( jsFile ) } ` ) ; } ) ) ; }
Precompilation steps required to build experiment js binaries.
Precompilation steps required to build experiment js binaries .
// Build HTML. // Build JS.