src/modules/render.js
/**
 * Checks that both consolidate and the required engine are installed
 */
Checks that both consolidate and the required engine are installed
Checks that both consolidate and the required engine are installed
function checkInstall (opts) {
  return new Promise((resolve, reject) => {
    getTemplate(opts)
      .then(template => {
        let engines = conf.get(ENGINE_KEY)
        let engine = engines.find(engine => {
          return engine.extensions.find(ext => ext === template.ext)
        })
        if (opts.engine) {
          engine = engines.find(engine => engine.name === opts.engine)
        }
        if (!engine) {
          reject(new EngineError('Can not find engine to use'))
          return
        }
        let templates = store(opts.dataDir || null)
        Promise.all([
          templates.checkInstall(engine.module),
          templates.checkInstall('consolidate')
        ])
          .then(res => {
            Promise.resolve()
              .then(() => {
                return res[ 1 ] ? Promise.resolve() : installConsolidate(opts)
              })
              .then(() => {
                return res[ 0 ] ? Promise.resolve() : installModule(opts, engine)
              })
              .then(res => resolve(true))
              .catch(reject)
          })
          .catch(err => {
            reject(err)
          })
      })
  })
}
function checkInstall ( opts ) { return new Promise ( ( resolve , reject ) => { getTemplate ( opts ) . then ( template => { let engines = conf . get ( ENGINE_KEY ) let engine = engines . find ( engine => { return engine . extensions . find ( ext => ext === template . ext ) } ) if ( opts . engine ) { engine = engines . find ( engine => engine . name === opts . engine ) } if ( ! engine ) { reject ( new EngineError ( 'Can not find engine to use' ) ) return } let templates = store ( opts . dataDir || null ) Promise . all ( [ templates . checkInstall ( engine . module ) , templates . checkInstall ( 'consolidate' ) ] ) . then ( res => { Promise . resolve ( ) . then ( ( ) => { return res [ 1 ] ? Promise . resolve ( ) : installConsolidate ( opts ) } ) . then ( ( ) => { return res [ 0 ] ? Promise . resolve ( ) : installModule ( opts , engine ) } ) . then ( res => resolve ( true ) ) . catch ( reject ) } ) . catch ( err => { reject ( err ) } ) } ) } ) }
Checks that both consolidate and the required engine are installed
Checks that both consolidate and the required engine are installed
// Grab the engine first // Grab an engine if specified // @TODO pretty ugly but so is this whole render code