UNPKG

2.06 kBtext/coffeescriptView Raw
1require 'coffee-errors'
2
3util = require 'util'
4path = require 'path'
5yeoman = require 'yeoman-generator'
6GitHubApi = require 'github'
7
8githubUserInfo = (name, cb) ->
9 proxy = process.env.http_proxy or process.env.HTTP_PROXY or process.env.https_proxy or process.env.HTTPS_PROXY or null
10 githubOptions = version: '3.0.0'
11
12 if proxy
13 proxy = url.parse proxy
14
15 githubOptions.proxy =
16 host: proxy.hostname
17 port: proxy.port
18
19 github = new GitHubApi githubOptions
20
21 github.user.getFrom user: name, (err, res) ->
22 throw err if err
23 cb JSON.parse JSON.stringify res
24
25class CoffeeModuleGenerator extends yeoman.generators.Base
26 constructor: (args, options, config) ->
27 super
28 @currentYear = (new Date()).getFullYear()
29 @on 'end', => @installDependencies skipInstall: options['skip-install']
30 @pkg = JSON.parse @readFileAsString path.join __dirname, '../package.json'
31
32 askFor: ->
33 done = @async()
34
35 # have Yeoman greet the user.
36 console.log @yeoman
37
38 prompts = [
39 name: 'githubUser'
40 message: 'Would you mind telling me your username on GitHub?'
41 default: 'someuser'
42 ,
43 name: 'moduleName'
44 message: 'What\'s the name of your module?'
45 default: @_.slugify(@appname)
46 ]
47
48 @prompt prompts, (props) =>
49 @githubUser = props.githubUser
50 @appname = props.moduleName
51 @slug = @_.slugify @appname
52 done()
53
54 userInfo: ->
55 done = @async()
56
57 githubUserInfo @githubUser, (res) =>
58 @realname = res.name
59 @email = res.email
60 @githubUrl = res.html_url
61 done()
62
63 projectfiles: ->
64 @template '_package.json', 'package.json'
65 @template '_travis.yml', '.travis.yml'
66 @template 'gulpfile.js'
67 @template 'gulpfile.coffee'
68 @template 'README.md'
69 @template 'LICENSE'
70
71 gitfiles: ->
72 @copy '_gitignore', '.gitignore'
73
74 app: ->
75 @template 'src/index.coffee', "src/#{@appname}.coffee"
76
77 tests: ->
78 @mkdir 'test'
79 @template 'test/spec.coffee', "test/#{@appname}.spec.coffee"
80
81module.exports = CoffeeModuleGenerator