function buildFrontend(patternlabGlobal) {
    const paths = patternlabGlobal.config.paths;

    const uikitPromises = _.map(patternlabGlobal.uikits, (uikit) => {
      //we need to make sure the patternlab object gets manipulated per uikit
      const patternlab = Object.assign({}, patternlabGlobal);

      resetUIBuilderState(patternlab);
      //determine which patterns should be included in the front-end rendering
      const styleguidePatterns = groupPatterns(patternlab, uikit);

      return new Promise((resolve) => {
        // set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
        const headerPromise = render(
          Pattern.createEmpty({ extendedTemplate: uikit.header }, patternlab),
          {
            cacheBuster: patternlab.cacheBuster,
          }
        )
          .then((headerPartial) => {
            const headFootData = patternlab.data;
            headFootData.patternLabHead = headerPartial;
            headFootData.cacheBuster = patternlab.cacheBuster;
            return render(patternlab.userHead, headFootData);
          })
          .catch((reason) => {
            console.log(reason);
            logger.error('error during header render()');
          });

        // set the pattern-specific footer by compiling the general-footer with data, and then adding it to the meta footer
        const footerPromise = render(
          Pattern.createEmpty({ extendedTemplate: uikit.footer }, patternlab),
          {
            patternData: '{}',
            cacheBuster: patternlab.cacheBuster,
          }
        )
          .then((footerPartial) => {
            const headFootData = patternlab.data;
            headFootData.patternLabFoot = footerPartial;
            return render(patternlab.userFoot, headFootData);
          })
          .catch((reason) => {
            console.log(reason);
            logger.error('error during footer render()');
          });

        return Promise.all([headerPromise, footerPromise]).then(
          (headFootPromiseResults) => {
            // build the viewall pages

            return buildViewAllPages(
              headFootPromiseResults[0],
              patternlab,
              styleguidePatterns,
              uikit
            )
              .then((allPatterns) => {
                // todo track down why we need to make this unique in the first place
                const uniquePatterns = uniqueAllPatterns(
                  allPatterns,
                  patternlab
                );

                // add the defaultPattern if we found one
                if (patternlab.defaultPattern) {
                  uniquePatterns.push(patternlab.defaultPattern);
                  addToPatternPaths(patternlab, patternlab.defaultPattern);
                }

                // build the main styleguide page
                return render(
                  Pattern.createEmpty(
                    {
                      extendedTemplate: uikit.viewAll,
                    },
                    patternlab
                  ),
                  {
                    partials: uniquePatterns,
                  },
                  {
                    patternSection: uikit.patternSection,
                    patternSectionSubgroup: uikit.patternSectionSubgroup,
                  }
                )
                  .then((styleguideHtml) => {
                    fs.outputFileSync(
                      path.resolve(
                        path.join(
                          process.cwd(),
                          uikit.outputDir,
                          paths.public.styleguide,
                          'html/styleguide.html'
                        )
                      ),
                      headFootPromiseResults[0] +
                        styleguideHtml +
                        headFootPromiseResults[1]
                    );

                    logger.info('Built Pattern Lab front end');

                    // move the index file from its asset location into public root
                    let patternlabSiteHtml;
                    try {
                      patternlabSiteHtml = fs.readFileSync(
                        path.resolve(
                          path.join(
                            uikit.modulePath,
                            paths.source.styleguide,
                            'index.html'
                          )
                        ),
                        'utf8'
                      );
                    } catch (err) {
                      logger.error(
                        `Could not load one or more styleguidekit assets from ${paths.source.styleguide}`
                      );
                    }
                    fs.outputFileSync(
                      path.resolve(
                        path.join(
                          process.cwd(),
                          uikit.outputDir,
                          paths.public.root,
                          'index.html'
                        )
                      ),
                      patternlabSiteHtml
                    );

                    //write out patternlab.data object to be read by the client
                    exportData(patternlab, uikit);
                    resolve();
                  })
                  .catch((reason) => {
                    console.log(reason);
                    logger.error('error during buildFrontend()');
                  });
              })
              .catch((reason) => {
                console.log(reason);
                logger.error('error during buildViewAllPages()');
              });
          }
        );
      });
    });
    return Promise.all(uikitPromises);
  }
/**
   * The main entry point for ui_builder
   * @param patternlabGlobal - global data store
   * @returns {Promise} a promise fulfilled when build is complete
   */
The main entry point for ui_builder
@param patternlabGlobal - global data store
@returns {Promise} a promise fulfilled when build is complete
The main entry point for ui_builder @param patternlabGlobal - global data store @returns { Promise } a promise fulfilled when build is complete
function buildFrontend(patternlabGlobal) {
    const paths = patternlabGlobal.config.paths;
    const uikitPromises = _.map(patternlabGlobal.uikits, (uikit) => {
      const patternlab = Object.assign({}, patternlabGlobal);
      resetUIBuilderState(patternlab);
      const styleguidePatterns = groupPatterns(patternlab, uikit);
      return new Promise((resolve) => {
        const headerPromise = render(
          Pattern.createEmpty({ extendedTemplate: uikit.header }, patternlab),
          {
            cacheBuster: patternlab.cacheBuster,
          }
        )
          .then((headerPartial) => {
            const headFootData = patternlab.data;
            headFootData.patternLabHead = headerPartial;
            headFootData.cacheBuster = patternlab.cacheBuster;
            return render(patternlab.userHead, headFootData);
          })
          .catch((reason) => {
            console.log(reason);
            logger.error('error during header render()');
          });
        const footerPromise = render(
          Pattern.createEmpty({ extendedTemplate: uikit.footer }, patternlab),
          {
            patternData: '{}',
            cacheBuster: patternlab.cacheBuster,
          }
        )
          .then((footerPartial) => {
            const headFootData = patternlab.data;
            headFootData.patternLabFoot = footerPartial;
            return render(patternlab.userFoot, headFootData);
          })
          .catch((reason) => {
            console.log(reason);
            logger.error('error during footer render()');
          });
        return Promise.all([headerPromise, footerPromise]).then(
          (headFootPromiseResults) => {
            return buildViewAllPages(
              headFootPromiseResults[0],
              patternlab,
              styleguidePatterns,
              uikit
            )
              .then((allPatterns) => {
                const uniquePatterns = uniqueAllPatterns(
                  allPatterns,
                  patternlab
                );
                if (patternlab.defaultPattern) {
                  uniquePatterns.push(patternlab.defaultPattern);
                  addToPatternPaths(patternlab, patternlab.defaultPattern);
                }
                return render(
                  Pattern.createEmpty(
                    {
                      extendedTemplate: uikit.viewAll,
                    },
                    patternlab
                  ),
                  {
                    partials: uniquePatterns,
                  },
                  {
                    patternSection: uikit.patternSection,
                    patternSectionSubgroup: uikit.patternSectionSubgroup,
                  }
                )
                  .then((styleguideHtml) => {
                    fs.outputFileSync(
                      path.resolve(
                        path.join(
                          process.cwd(),
                          uikit.outputDir,
                          paths.public.styleguide,
                          'html/styleguide.html'
                        )
                      ),
                      headFootPromiseResults[0] +
                        styleguideHtml +
                        headFootPromiseResults[1]
                    );
                    logger.info('Built Pattern Lab front end');
                    let patternlabSiteHtml;
                    try {
                      patternlabSiteHtml = fs.readFileSync(
                        path.resolve(
                          path.join(
                            uikit.modulePath,
                            paths.source.styleguide,
                            'index.html'
                          )
                        ),
                        'utf8'
                      );
                    } catch (err) {
                      logger.error(
                        `Could not load one or more styleguidekit assets from ${paths.source.styleguide}`
                      );
                    }
                    fs.outputFileSync(
                      path.resolve(
                        path.join(
                          process.cwd(),
                          uikit.outputDir,
                          paths.public.root,
                          'index.html'
                        )
                      ),
                      patternlabSiteHtml
                    );
                    exportData(patternlab, uikit);
                    resolve();
                  })
                  .catch((reason) => {
                    console.log(reason);
                    logger.error('error during buildFrontend()');
                  });
              })
              .catch((reason) => {
                console.log(reason);
                logger.error('error during buildViewAllPages()');
              });
          }
        );
      });
    });
    return Promise.all(uikitPromises);
  }
function buildFrontend ( patternlabGlobal ) { const paths = patternlabGlobal . config . paths ; const uikitPromises = _ . map ( patternlabGlobal . uikits , ( uikit ) => { const patternlab = Object . assign ( { } , patternlabGlobal ) ; resetUIBuilderState ( patternlab ) ; const styleguidePatterns = groupPatterns ( patternlab , uikit ) ; return new Promise ( ( resolve ) => { const headerPromise = render ( Pattern . createEmpty ( { extendedTemplate : uikit . header } , patternlab ) , { cacheBuster : patternlab . cacheBuster , } ) . then ( ( headerPartial ) => { const headFootData = patternlab . data ; headFootData . patternLabHead = headerPartial ; headFootData . cacheBuster = patternlab . cacheBuster ; return render ( patternlab . userHead , headFootData ) ; } ) . catch ( ( reason ) => { console . log ( reason ) ; logger . error ( 'error during header render()' ) ; } ) ; const footerPromise = render ( Pattern . createEmpty ( { extendedTemplate : uikit . footer } , patternlab ) , { patternData : '{}' , cacheBuster : patternlab . cacheBuster , } ) . then ( ( footerPartial ) => { const headFootData = patternlab . data ; headFootData . patternLabFoot = footerPartial ; return render ( patternlab . userFoot , headFootData ) ; } ) . catch ( ( reason ) => { console . log ( reason ) ; logger . error ( 'error during footer render()' ) ; } ) ; return Promise . all ( [ headerPromise , footerPromise ] ) . then ( ( headFootPromiseResults ) => { return buildViewAllPages ( headFootPromiseResults [ 0 ] , patternlab , styleguidePatterns , uikit ) . then ( ( allPatterns ) => { const uniquePatterns = uniqueAllPatterns ( allPatterns , patternlab ) ; if ( patternlab . defaultPattern ) { uniquePatterns . push ( patternlab . defaultPattern ) ; addToPatternPaths ( patternlab , patternlab . defaultPattern ) ; } return render ( Pattern . createEmpty ( { extendedTemplate : uikit . viewAll , } , patternlab ) , { partials : uniquePatterns , } , { patternSection : uikit . patternSection , patternSectionSubgroup : uikit . patternSectionSubgroup , } ) . then ( ( styleguideHtml ) => { fs . outputFileSync ( path . resolve ( path . join ( process . cwd ( ) , uikit . outputDir , paths . public . styleguide , 'html/styleguide.html' ) ) , headFootPromiseResults [ 0 ] + styleguideHtml + headFootPromiseResults [ 1 ] ) ; logger . info ( 'Built Pattern Lab front end' ) ; let patternlabSiteHtml ; try { patternlabSiteHtml = fs . readFileSync ( path . resolve ( path . join ( uikit . modulePath , paths . source . styleguide , 'index.html' ) ) , 'utf8' ) ; } catch ( err ) { logger . error ( ` ${ paths . source . styleguide } ` ) ; } fs . outputFileSync ( path . resolve ( path . join ( process . cwd ( ) , uikit . outputDir , paths . public . root , 'index.html' ) ) , patternlabSiteHtml ) ; exportData ( patternlab , uikit ) ; resolve ( ) ; } ) . catch ( ( reason ) => { console . log ( reason ) ; logger . error ( 'error during buildFrontend()' ) ; } ) ; } ) . catch ( ( reason ) => { console . log ( reason ) ; logger . error ( 'error during buildViewAllPages()' ) ; } ) ; } ) ; } ) ; } ) ; return Promise . all ( uikitPromises ) ; }
The main entry point for ui_builder
 @param patternlabGlobal - global data store
 @returns {Promise} a promise fulfilled when build is complete
The main entry point for ui_builder @param patternlabGlobal - global data store @returns { Promise } a promise fulfilled when build is complete
//we need to make sure the patternlab object gets manipulated per uikit //determine which patterns should be included in the front-end rendering // set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header // set the pattern-specific footer by compiling the general-footer with data, and then adding it to the meta footer // build the viewall pages // todo track down why we need to make this unique in the first place // add the defaultPattern if we found one // build the main styleguide page // move the index file from its asset location into public root //write out patternlab.data object to be read by the client