hapi.app
Version:
HAPI application generator
53 lines (44 loc) • 1.39 kB
text/coffeescript
fs = require "fs"
prompt = require "prompt"
tools = require "../src/tools"
DEFAULT_PORT = 9294
SERVER_CONFIG_FILENAME = "hapi.config.json"
defaultCwd = "."
setup = ->
if arguments.length > 0
[] = arguments
return completeCommand cwd, params
setupPrompt()
getPromptInput (err, params) ->
throw err if err
completeCommand defaultCwd, params
completeCommand = (cwd, params) ->
tools.checkInHapiApp cwd
writeServerConfig(cwd, params)
setupPrompt = ->
prompt.colors = false
prompt.message = "HAPI setup"
prompt.delimiter = " > "
getPromptInput = (callback) ->
prompt.start()
prompt.get [
'endPoint',
'clientId',
'appSecret',
{ name: "PORT", default: DEFAULT_PORT, type: "number" }
], callback
writeServerConfig = (cwd, config) ->
setup =
base:
endPoint: config.endPoint
assignConfigVariables: ["clientId"]
development:
clientId: config.clientId
appSecret: config.appSecret
PORT: config.PORT
fileContent = JSON.stringify(setup, null, 4)
fs.writeFileSync "#{cwd}/#{SERVER_CONFIG_FILENAME}", fileContent
module.exports.command = setup
module.exports.help = "setup sets up a HAPI app"