|
|
|
# First Run Callback |
|
firstRunCallback: (data,next) -> |
|
# Prepare |
|
consoleInterface = @ |
|
commander = @commander |
|
docpad = @docpad |
|
balUtil = require('bal-util') |
|
|
|
# Log |
|
consoleInterface.confirm "Thanks for installing DocPad. As DocPad moves very very fast, would you like to subscribe to our newsletter and stay up to date with the latest releases and tutorials? [Y/n]", true, (ok) -> |
|
if ok |
|
commands = [ |
|
['git','config','--get','user.name'] |
|
['git','config','--get','user.email'] |
|
['git','config','--get','github.user'] |
|
] |
|
balUtil.spawnMultiple commands, (err,results) -> |
|
# Fetch |
|
name = results[0][1] |
|
email = results[1][1] |
|
username = results[2][1] |
|
|
|
# Fallbacks |
|
tasks = new balUtil.Group (err) -> |
|
console.log "Sweet! We've subscribed you to our newsletter. You're looking super sexy today!" |
|
return next() |
|
|
|
# Name Fallback |
|
tasks.push (complete) -> |
|
return complete() if name |
|
consoleInterface.prompt "Awesome! So, what is your name?", (result) -> |
|
name = result |
|
complete() |
|
|
|
# Email Fallback |
|
tasks.push (complete) -> |
|
return complete() if email |
|
consoleInterface.prompt "Amazing! and your email?", (result) -> |
|
email = result |
|
complete() |
|
|
|
# Username Fallback |
|
tasks.push (complete) -> |
|
return complete() if username |
|
consoleInterface.prompt "Groovey! and what username would you like for our cloud services when they come?", (result) -> |
|
username = result |
|
complete() |
|
|
|
# Run fallbacks |
|
tasks.sync() |
|
else |
|
next() |
|
|
|
# Chain |
|
@ |
|
|
|
# Prompt for input |
|
prompt: (message,next) -> |
|
# Prepare |
|
consoleInterface = @ |
|
commander = @commander |
|
|
|
# Log |
|
commander.prompt message+' ', (result) -> |
|
# Parse |
|
unless result.trim() # no value |
|
return consoleInterface.prompt(message,next) |
|
|
|
# Forward |
|
return next(result) |
|
|
|
# Chain |
|
@ |
|
|
|
# Confirm an option |
|
confirm: (message,fallback,next) -> |
|
# Prepare |
|
consoleInterface = @ |
|
commander = @commander |
|
|
|
# Log |
|
commander.prompt message+' ', (ok) -> |
|
# Parse |
|
unless ok.trim() # no value |
|
if fallback? # has default value |
|
ok = fallback # set to default value |
|
else # otherwise try again |
|
return consoleInterface.confirm(message,fallback,next) |
|
else # parse the value |
|
ok = /^y|yes|ok|true$/i.test(ok) |
|
|
|
# Forward |
|
return next(ok) |
|
|
|
# Chain |
|
@ |