all files / app/ index.coffee

79.63% Statements 43/54
41.67% Branches 5/12
90.91% Functions 10/11
82.98% Lines 39/47
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                                                            
require 'coffee-errors'
 
htmlWiring = require 'html-wiring'
_          = require 'lodash'
path       = require 'path'
yeoman     = require 'yeoman-generator'
 
helpers    = require './helpers'
 
class OctobluSentinelGenerator extends yeoman.Base
  constructor: (args, options) ->
    super
    @option 'github-user'
    @currentYear = (new Date()).getFullYear()
    {@realname, @githubUrl} = options
    @skipInstall = options['skip-install']
    @githubUser  = options['github-user']
    @pkg = JSON.parse htmlWiring.readFileAsString path.join __dirname, '../package.json'
 
  initializing: =>
    @appname = _.kebabCase @appname
    @noSentinel = _.replace @appname, /^sentinel-/, ''
    I@env.error 'appname must start with "sentinel-", exiting.' unless _.startsWith @appname, 'sentinel-'
 
  prompting: =>
    Ireturn if @githubUser?
    done = @async()
 
    prompts = [
      name: 'githubUser'
      message: 'Would you mind telling me your username on GitHub?'
      default: 'octoblu'
    ]
 
    @prompt(prompts).then (props) =>
      @githubUser = props.githubUser
      done()
 
  userInfo: =>
    Ereturn if @realname? and @githubUrl?
 
    done = @async()
 
    helpers.githubUserInfo @githubUser, (error, res) =>
      @env.error error if error?
      @realname = res.name
      @email = res.email
      @githubUrl = res.html_url
      done()
 
  configuring: =>
    @copy '_gitignore', '.gitignore'
 
  writing: =>
    filePrefix     = _.kebabCase @noSentinel
    instancePrefix = _.camelCase @noSentinel
    classPrefix    = _.upperFirst instancePrefix
    constantPrefix = _.toUpper _.snakeCase @noSentinel
 
    context = {@appname, @githubUrl, @realname, constantPrefix}
 
    @template '_package.json', 'package.json', context
    @template '_travis.yml', '.travis.yml', context
    @template '_README.md', 'README.md', context
    @template '_LICENSE', 'LICENSE', context
    @template '_command.js', 'command.js', context
    @template '_helpers.js', 'helpers.js', context
 
  install: =>
    Ereturn if @skipInstall
    @installDependencies npm: true, bower: false
 
  end: =>
    Ereturn if @skipInstall
 
module.exports = OctobluSentinelGenerator