UNPKG

2.68 kBtext/coffeescriptView Raw
1Nconf = require 'nconf'
2_ = require('underscore')._
3
4Fs = require 'fs'
5Path = require 'path'
6
7Funcster = require 'funcster'
8
9HipchatApi = require 'hipchat'
10GithubApi = require 'github'
11Winston = require 'winston'
12AWS = require 'aws-sdk'
13
14userHome = () ->
15 process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
16
17envSuffix = () ->
18 if process.env.NODE_ENV then "." + process.env.NODE_ENV + ".json" else ".json"
19
20# env override everything
21# a local file comes second
22# then, if nothing is found here, a file in HOME is used
23Nconf
24 .env()
25 .file('local', '.albot' + envSuffix())
26 .file('home', userHome() + '/.albot' + envSuffix())
27
28Nconf
29 .defaults {
30 "nickname": "albot",
31 "aliases": {},
32 "disabledCommands": [],
33 "github": {
34 "repo_filter": "",
35 "gravatar": false,
36 "debug": false
37 },
38 "hipchat": {
39 "frequency": 6000
40 },
41 "deploy": {
42 "args": [],
43 "env": [],
44 "postProcessFile": ""
45 },
46 "amazon": {
47 "key": "",
48 "secret": "",
49 "region": "eu-west-1"
50 }
51 }
52
53hipchat = new HipchatApi Nconf.get('hipchat').token
54
55github = new GithubApi { version: "3.0.0", debug: Nconf.get("github").debug }
56github.authenticate { type: "oauth", token: Nconf.get("github").token }
57
58initLogger =
59 (verbose = false) ->
60 mode = if verbose then 'verbose' else 'info'
61
62 @logger = new Winston.Logger({
63 transports: [
64 new (Winston.transports.Console)({ level: mode })
65 ]
66 }).cli()
67
68 @logger
69
70initAws =
71 (aws) ->
72 if (aws?)
73 @aws = aws
74 else
75 credentials =
76 {
77 accessKeyId: Nconf.get("amazon").key,
78 secretAccessKey: Nconf.get("amazon").secret,
79 region: Nconf.get("amazon").region
80 }
81
82 AWS.config.update credentials
83 @aws = AWS
84
85 @aws
86
87module.exports =
88 Nconf: Nconf,
89 Nickname: Nconf.get('nickname'),
90 Github: {
91 Api: github,
92 Org: Nconf.get('github').organisation,
93 Filters: Nconf.get('github').repo_filters,
94 Gravatar: Nconf.get('github').gravatar
95 },
96 Hipchat: {
97 Rooms: hipchat.Rooms,
98 Channel: Nconf.get('hipchat').channel,
99 Frequency: Nconf.get('hipchat').frequency
100 },
101 Amazon: {
102 initAws: initAws,
103 aws: @aws || initAws()
104 },
105 Winston: {
106 initLogger: initLogger,
107 logger: @logger || initLogger()
108 },
109 Deploy: _.extend(Nconf.get('deploy'), {
110 postProcessFunction: if Nconf.get('deploy').postProcessFile then Funcster.deepDeserialize(
111 { __js_function: Nconf.get('deploy').postProcessFile },
112 { globals: { console: console } }
113 )
114 }),
115 Version: JSON.parse(Fs.readFileSync(Path.resolve(__dirname, '../package.json'), 'utf8')).version