packages/heml/src/bin/commands/develop.js
function startDevServer (directory, port = 3000) {
  let url
  const app = express()
  const { reload } = reloadServer(app)
  let preview = ''

  app.get('/', (req, res) => res.send(preview))
  app.use(express.static(directory))

  function update ({ html, errors, metadata }) {
    let status = errors.length ? chalk.red('failed') : chalk.green('success')
    preview = errors.length
      ? buildErrorPage(errors)
      : html.replace('</body>', '<script src="/reload/reload.js"></script></body>')

    renderCLI({ url, status, time: metadata.time, size: metadata.size })
    reload()
  }

  return new Promise((resolve, reject) => {
    getPort({ port }).then((availablePort) => {
      url = `http://localhost:${availablePort}`

      app.listen(availablePort, () => resolve({ update, url, app }))
    })

    process.on('uncaughtException', reject)
  })
}
function startDevServer (directory, port = 3000) {
  let url
  const app = express()
  const { reload } = reloadServer(app)
  let preview = ''

  app.get('/', (req, res) => res.send(preview))
  app.use(express.static(directory))

  function update ({ html, errors, metadata }) {
    let status = errors.length ? chalk.red('failed') : chalk.green('success')
    preview = errors.length
      ? buildErrorPage(errors)
      : html.replace('</body>', '<script src="/reload/reload.js"></script></body>')

    renderCLI({ url, status, time: metadata.time, size: metadata.size })
    reload()
  }

  return new Promise((resolve, reject) => {
    getPort({ port }).then((availablePort) => {
      url = `http://localhost:${availablePort}`

      app.listen(availablePort, () => resolve({ update, url, app }))
    })

    process.on('uncaughtException', reject)
  })
}
function startDevServer ( directory , port = 3000 ) { let url const app = express ( ) const { reload } = reloadServer ( app ) let preview = '' app . get ( '/' , ( req , res ) => res . send ( preview ) ) app . use ( express . static ( directory ) ) function update ( { html , errors , metadata } ) { let status = errors . length ? chalk . red ( 'failed' ) : chalk . green ( 'success' ) preview = errors . length ? buildErrorPage ( errors ) : html . replace ( '</body>' , '<script src="/reload/reload.js"></script></body>' ) renderCLI ( { url , status , time : metadata . time , size : metadata . size } ) reload ( ) } return new Promise ( ( resolve , reject ) => { getPort ( { port } ) . then ( ( availablePort ) => { url = ` ${ availablePort } ` app . listen ( availablePort , ( ) => resolve ( { update , url , app } ) ) } ) process . on ( 'uncaughtException' , reject ) } ) }
Launches a server that reloads when the update function is called
@param  {String} defaultPreview  the default content for when the sever loads
@return {Object}                 { server, port, update }
Launches a server that reloads when the update function is called