Skip to content

Commit

Permalink
feat(cli): implement --inspect|-i flags for start (resolve #91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Paniontko authored and epaminond committed Jun 24, 2018
1 parent 50a1d3a commit e209ea1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/core/botpress/src/botpress.js
Expand Up @@ -130,7 +130,7 @@ const validateBotfile = botfile => {
}

class botpress {
constructor({ botfile }) {
constructor({ botfile, options = {} }) {
this.version = getBotpressVersion()
/**
* The project location, which is the folder where botfile.js located
Expand All @@ -152,6 +152,14 @@ class botpress {
this.stats = stats(this.botfile)

this.interval = null

/*
Check --inspect flag
*/

const opts = options.opts()

this.hasInspectMode = opts.inspect || opts.i
}

/**
Expand Down Expand Up @@ -376,6 +384,18 @@ class botpress {
const server = createServer(this)
server.start().then(srv => {
this.stopServer = srv && srv.stop

if (this.hasInspectMode) {
const serverPID = process.pid
const inspectSignal = 'SIGUSR1'

if (process.platform === 'win32') {
process._debugProcess(serverPID)
} else {
process.kill(serverPID, inspectSignal)
}
}

events.emit('ready')
for (const mod of _.values(loadedModules)) {
mod.handlers.ready && mod.handlers.ready(this, mod.configuration, createHelpers)
Expand Down
1 change: 1 addition & 0 deletions packages/core/botpress/src/cli/index.js
Expand Up @@ -43,6 +43,7 @@ program
collectArgs,
[]
)
.option('-i, --inspect', 'Inspect bot with "debugger"')
.action(start)

program
Expand Down
2 changes: 1 addition & 1 deletion packages/core/botpress/src/cli/start.js
Expand Up @@ -91,7 +91,7 @@ module.exports = (projectPath, options) => {
setTimeout(() => process.exit(), 100)
})
} else {
const bot = new Botpress({ botfile })
const bot = new Botpress({ botfile, options })
bot.start()
}
}

0 comments on commit e209ea1

Please sign in to comment.