UNPKG

hapi.app

Version:

HAPI application generator

53 lines (44 loc) 1.39 kB
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 [cwd, params] = 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 = -> # colors caused problems with a themed terminal prompt.colors = false prompt.message = "HAPI setup" # bit nicer than successive colons 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"