Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
feat(serve): add support for defining ext for watch & remove domain
Browse files Browse the repository at this point in the history
fix #96
  • Loading branch information
thetutlage committed Jul 15, 2018
1 parent 649e3fd commit f6ec54c
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions src/Commands/Serve/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

const path = require('path')
const { exec } = require('child_process')
const { Command } = require('../../../lib/ace')

/**
Expand All @@ -32,9 +31,9 @@ class Serve extends Command {
serve
{ --dev : Start development server }
{ -w, --watch=@value : A custom set of only files to watch },
{ -e, --ext=@value : A custom set of extensions to watch },
{ -p, --polling : Use polling to find file changes. Also required when using Docker }
{ --debug?=@value: Start server in debug mode }
{ -d, --domain=@value: Register hotel .dev domain. Value must be in (name@url) format }
`
}

Expand Down Expand Up @@ -100,23 +99,6 @@ class Serve extends Command {
this.error('Application crashed, make sure to kill all related running process, fix the issue and re-run the app')
}

/**
* Listening for app start
*
* @method onStart
*
* @return {void}
*/
onStart (name, url) {
if (name && url) {
exec(`hotel add ${url} --name=${name}`, (error, stdout, stderr) => {
if (!error && !stderr) {
this.info(`Proxying app to http://${name}.dev`)
}
})
}
}

/**
* Listening for on quite event
*
Expand All @@ -126,10 +108,7 @@ class Serve extends Command {
*
* @return {void}
*/
onQuit (name, url) {
if (name && url) {
exec(`hotel rm --name=${name}`)
}
onQuit () {
process.exit(0)
}

Expand All @@ -143,7 +122,7 @@ class Serve extends Command {
*
* @return {void}
*/
async handle (args, { dev, watch, debug, polling, domain }) {
async handle (args, { dev, watch, debug, polling, ext }) {
const acePath = path.join(process.cwd(), 'ace')
const appFile = path.join(process.cwd(), 'server.js')
const exists = await this.pathExists(acePath)
Expand All @@ -166,7 +145,7 @@ class Serve extends Command {
* The file extensions only when dev mode
* is true
*/
const ext = dev ? 'js json' : 'null'
ext = ext || (dev ? 'js json' : 'null')

/**
* Directories to watch
Expand Down Expand Up @@ -203,20 +182,13 @@ class Serve extends Command {

this.started(dev, debug)

/**
* Reading app name and url to register it with hotel. It is the job of the
* user to install hotel cli.
*/
const [name, url] = typeof (domain) === 'string' && domain ? domain.split('@') : [null, null]

/**
* Listeners
*/
nodemon
.on('start', () => (this.onStart(name, url)))
.on('restart', this.onRestart.bind(this))
.on('crash', this.onCrash.bind(this))
.on('quit', () => (this.onQuit(name, url)))
.on('quit', () => (this.onQuit()))
}
}

Expand Down

0 comments on commit f6ec54c

Please sign in to comment.