Guest User

Untitled

a guest
Dec 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1.  
  2. # First Run Callback
  3. firstRunCallback: (data,next) ->
  4. # Prepare
  5. consoleInterface = @
  6. commander = @commander
  7. docpad = @docpad
  8. balUtil = require('bal-util')
  9.  
  10. # Log
  11. 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) ->
  12. if ok
  13. commands = [
  14. ['git','config','--get','user.name']
  15. ['git','config','--get','user.email']
  16. ['git','config','--get','github.user']
  17. ]
  18. balUtil.spawnMultiple commands, (err,results) ->
  19. # Fetch
  20. name = results[0][1]
  21. email = results[1][1]
  22. username = results[2][1]
  23.  
  24. # Fallbacks
  25. tasks = new balUtil.Group (err) ->
  26. console.log "Sweet! We've subscribed you to our newsletter. You're looking super sexy today!"
  27. return next()
  28.  
  29. # Name Fallback
  30. tasks.push (complete) ->
  31. return complete() if name
  32. consoleInterface.prompt "Awesome! So, what is your name?", (result) ->
  33. name = result
  34. complete()
  35.  
  36. # Email Fallback
  37. tasks.push (complete) ->
  38. return complete() if email
  39. consoleInterface.prompt "Amazing! and your email?", (result) ->
  40. email = result
  41. complete()
  42.  
  43. # Username Fallback
  44. tasks.push (complete) ->
  45. return complete() if username
  46. consoleInterface.prompt "Groovey! and what username would you like for our cloud services when they come?", (result) ->
  47. username = result
  48. complete()
  49.  
  50. # Run fallbacks
  51. tasks.sync()
  52. else
  53. next()
  54.  
  55. # Chain
  56. @
  57.  
  58. # Prompt for input
  59. prompt: (message,next) ->
  60. # Prepare
  61. consoleInterface = @
  62. commander = @commander
  63.  
  64. # Log
  65. commander.prompt message+' ', (result) ->
  66. # Parse
  67. unless result.trim() # no value
  68. return consoleInterface.prompt(message,next)
  69.  
  70. # Forward
  71. return next(result)
  72.  
  73. # Chain
  74. @
  75.  
  76. # Confirm an option
  77. confirm: (message,fallback,next) ->
  78. # Prepare
  79. consoleInterface = @
  80. commander = @commander
  81.  
  82. # Log
  83. commander.prompt message+' ', (ok) ->
  84. # Parse
  85. unless ok.trim() # no value
  86. if fallback? # has default value
  87. ok = fallback # set to default value
  88. else # otherwise try again
  89. return consoleInterface.confirm(message,fallback,next)
  90. else # parse the value
  91. ok = /^y|yes|ok|true$/i.test(ok)
  92.  
  93. # Forward
  94. return next(ok)
  95.  
  96. # Chain
  97. @
Add Comment
Please, Sign In to add comment