const fs = require('fs')
const path = require('path')
const chalk = require('chalk')

/**
 * Start web service
 * @param {Object} options
 */
function runWeb(options) {
  if (!checkWebEnv(process.cwd())) {
    console.log()
    console.log(chalk.red('  Not available web environment !'))
    console.log()
    console.log(`  You should run ${chalk.blue('weexpack init')} first`)
    return
  }

  console.log()
  console.log(` => ${chalk.blue.bold('Starting web service')}`)

  install()
  startServer()
}

/**
 * Check web environment
 * @param {Strng} cwd
 */
function checkWebEnv(cwd) {
  return fs.existsSync(path.join(cwd, 'package.json'))
      && fs.existsSync(path.join(cwd, 'web'))
}

/**
 * Install npm dependencies
 */
function install() {
}

/**
 * Start a web server
 */
function startServer() {
}

module.exports = runWeb

@@ -77,16 +77,63 @@
 'chalk')
+%0Aconst child_process = require('child_process')
 %0A%0A/**%0A *
@@ -795,65 +795,400 @@
 ) %7B%0A
-%7D%0A%0A/**%0A * Start a web server%0A */%0Afunction startServer() %7B
+  console.log(%60    installing npm packages ...%60)%0A  child_process.execSync('cnpm install')%0A%7D%0A%0A/**%0A * Start a web server%0A */%0Afunction startServer() %7B%0A  console.log(%60    start server%60)%0A%0A  child_process.execSync('npm run build & npm run serve')%0A%0A  console.log()%0A  console.log(%60 =%3E $%7Bchalk.green('server is running')%7D%60)%0A  console.log(%60    see %7Bchalk.cyan('http://localhost:8080/web/index.html')%7D%60)
 %0A%7D%0A%0A

enable to run web service