hapi.app
Version:
HAPI application generator
64 lines (51 loc) • 1.93 kB
text/coffeescript
exec = require("child_process").exec
path = require "path"
fs = require "fs"
wrench = require "wrench"
async = require "async"
tools = require "../src/tools"
appTemplateFolder = path.join(__dirname,"../templates")
app = ->
checkArguments(arguments)
[folderName, callback] = arguments
folderPath = path.join process.cwd(), folderName
checkFolderAvailability(folderPath)
async.series [
(cb) -> createAppFolder(folderPath, cb),
(cb) -> bundleTotem(folderPath, cb),
(cb) -> installNpms(folderPath, cb),
(cb) -> completeCommand(folderName, cb)
], callback or ->
createAppFolder = (folderPath, cb) ->
console.log "Creating application folder: #{folderPath}"
wrench.copyDirRecursive appTemplateFolder, folderPath, cb
bundleTotem = (folderPath, cb) ->
console.log "Bundling Totem ..."
tools.bundleTotem folderPath, cb
installNpms = (folderPath, cb) ->
console.log "Installing npm packages for new app ..."
tools.installNpms folderPath, cb
completeCommand = (folderName, cb) ->
console.log """Congratulations! Your app folder has been created.
Now you need to set it up!
Run the following commands:
cd #{folderName}
hapi setup"""
cb?()
checkArguments = (args) ->
unless correctNumberOfArguments(args)
throw new Error "wrong number of arguments"
unless callbackArgumentIsFunction(args)
throw new Error "invalid argument: #{callbackArgument(args)}"
checkFolderAvailability = (folderPath) ->
if fs.existsSync folderPath
throw new Error "Folder #{folderPath} already exists"
callbackArgument = (args) ->
args[1]
correctNumberOfArguments = (args) ->
0 < args.length < 3
callbackArgumentIsFunction = (args) ->
return true if args.length < 2
typeof callbackArgument(args) is "function"
module.exports.command = app
module.exports.help = "app path creates a new HAPI app"