src/core.js
/**
 * Compiles all templates according to configurations and outputs html.
 */
Compiles all templates according to configurations and outputs html.
Compiles all templates according to configurations and outputs html .
async function gen(opts = {}) {
  const { watching = '', ext, watchMode } = opts;
  globalConfig.watchMode = watchMode || false;
  globalConfig.build.dry
  && consola.log('Dry run in', `"${globalConfig.build.mode}" mode`);
  setupLocales(); 
  const triggerAll = ext === null || ext === '.html';
  const triggers = {
    all: triggerAll,
    js: triggerAll || ext === '.js' || ext === '.mjs',
    css: triggerAll || ext === '.css',
    html: triggerAll || ext === '.html'
  };
  triggers.html && (globalSearchList = []); 
  const publicOutPath = vpath(globalConfig.output.path).full;
  const cleaned = triggers.all && await del([`${publicOutPath}/**`, `!${publicOutPath}`]);
  debugLog('cleaned output dir', cleaned);
  const assetsPath = triggers.all && vpath([globalConfig.cwd, 'assets']);
  const stylePath = triggers.css && vpath([globalConfig.cwd, 'style']);
  const scriptPath = triggers.js && vpath([globalConfig.cwd, 'script']);
  const staticPath = triggers.all && vpath([globalConfig.cwd, 'static']);
  const assets = triggers.all && getDirPaths(assetsPath.full, 'full');
  const styles = triggers.css && getDirPaths(stylePath.full, 'full');
  const script = triggers.js && getDirPaths(scriptPath.full, 'full');
  const staticAssets = triggers.all && getDirPaths(staticPath.full, 'full');
  cheers.config({
    watchMode: globalConfig.watchMode,
    cwd: globalConfig.cwd,
    output: globalConfig.output,
    plugins: globalConfig.plugins,
    assets: globalConfig.assets,
    build: globalConfig.build,
    site: globalConfig.site
  });
  const getProcState = p => {
    const proc_all = 1;
    const proc_watched = 2;
    const proc_ignore = 3;
    return ['', 'ready'].includes(watching) || triggerAll
      ? proc_all
      : p.endsWith(watching) ? proc_watched
        : proc_ignore;
  };
  triggers.all && cheers.transform('assets', assets.map(p => ({ path: p })));
  triggers.css && cheers.transform('style', styles.map(p => ({ path: p, procState: getProcState(p) })));
  triggers.js && cheers.transform('script', script.map(p => ({ path: p, procState: getProcState(p) })));
  triggers.all && cheers.transform('static', staticAssets.map(p => ({ path: p })));
  debugLog('Watching', `"${watching}"`);
  const run = () => {
    const promises = pagination.map(pageTransform());
    return Promise.all(promises);
  };
  triggers.html && await run();
}
async function gen ( opts = { } ) { const { watching = '' , ext , watchMode } = opts ; globalConfig . watchMode = watchMode || false ; globalConfig . build . dry && consola . log ( 'Dry run in' , ` ${ globalConfig . build . mode } ` ) ; setupLocales ( ) ; const triggerAll = ext === null || ext === '.html' ; const triggers = { all : triggerAll , js : triggerAll || ext === '.js' || ext === '.mjs' , css : triggerAll || ext === '.css' , html : triggerAll || ext === '.html' } ; triggers . html && ( globalSearchList = [ ] ) ; const publicOutPath = vpath ( globalConfig . output . path ) . full ; const cleaned = triggers . all && await del ( [ ` ${ publicOutPath } ` , ` ${ publicOutPath } ` ] ) ; debugLog ( 'cleaned output dir' , cleaned ) ; const assetsPath = triggers . all && vpath ( [ globalConfig . cwd , 'assets' ] ) ; const stylePath = triggers . css && vpath ( [ globalConfig . cwd , 'style' ] ) ; const scriptPath = triggers . js && vpath ( [ globalConfig . cwd , 'script' ] ) ; const staticPath = triggers . all && vpath ( [ globalConfig . cwd , 'static' ] ) ; const assets = triggers . all && getDirPaths ( assetsPath . full , 'full' ) ; const styles = triggers . css && getDirPaths ( stylePath . full , 'full' ) ; const script = triggers . js && getDirPaths ( scriptPath . full , 'full' ) ; const staticAssets = triggers . all && getDirPaths ( staticPath . full , 'full' ) ; cheers . config ( { watchMode : globalConfig . watchMode , cwd : globalConfig . cwd , output : globalConfig . output , plugins : globalConfig . plugins , assets : globalConfig . assets , build : globalConfig . build , site : globalConfig . site } ) ; const getProcState = p => { const proc_all = 1 ; const proc_watched = 2 ; const proc_ignore = 3 ; return [ '' , 'ready' ] . includes ( watching ) || triggerAll ? proc_all : p . endsWith ( watching ) ? proc_watched : proc_ignore ; } ; triggers . all && cheers . transform ( 'assets' , assets . map ( p => ( { path : p } ) ) ) ; triggers . css && cheers . transform ( 'style' , styles . map ( p => ( { path : p , procState : getProcState ( p ) } ) ) ) ; triggers . js && cheers . transform ( 'script' , script . map ( p => ( { path : p , procState : getProcState ( p ) } ) ) ) ; triggers . all && cheers . transform ( 'static' , staticAssets . map ( p => ( { path : p } ) ) ) ; debugLog ( 'Watching' , ` ${ watching } ` ) ; const run = ( ) => { const promises = pagination . map ( pageTransform ( ) ) ; return Promise . all ( promises ) ; } ; triggers . html && await run ( ) ; }
Compiles all templates according to configurations and outputs html.
Compiles all templates according to configurations and outputs html .
// format locales as needed at this stage // build triggeres // reset search list on every build // clean output dir /* eslint-disable camelcase */ /* eslint-enable camelcase */