1 | Nconf = require 'nconf'
|
2 | _ = require('underscore')._
|
3 |
|
4 | Fs = require 'fs'
|
5 | Path = require 'path'
|
6 |
|
7 | Funcster = require 'funcster'
|
8 |
|
9 | HipchatApi = require 'hipchat'
|
10 | GithubApi = require 'github'
|
11 | Winston = require 'winston'
|
12 | AWS = require 'aws-sdk'
|
13 |
|
14 | userHome = () ->
|
15 | process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
|
16 |
|
17 | envSuffix = () ->
|
18 | if process.env.NODE_ENV then "." + process.env.NODE_ENV + ".json" else ".json"
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | Nconf
|
24 | .env()
|
25 | .file('local', '.albot' + envSuffix())
|
26 | .file('home', userHome() + '/.albot' + envSuffix())
|
27 |
|
28 | Nconf
|
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 |
|
53 | hipchat = new HipchatApi Nconf.get('hipchat').token
|
54 |
|
55 | github = new GithubApi { version: "3.0.0", debug: Nconf.get("github").debug }
|
56 | github.authenticate { type: "oauth", token: Nconf.get("github").token }
|
57 |
|
58 | initLogger =
|
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 |
|
70 | initAws =
|
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 |
|
87 | module.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
|