-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to require slack-irc as a node module
- Loading branch information
ekmartin
committed
May 22, 2015
1 parent
1af1145
commit 979208f
Showing
9 changed files
with
96 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
#!/usr/bin/env node | ||
|
||
var program = require('commander'); | ||
var checkEnv = require('check-env'); | ||
var createBots = require('./lib/helpers').createBots; | ||
var logger = require('winston'); | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
logger.level = 'debug'; | ||
} | ||
|
||
program | ||
.version('1.1.0') | ||
.option('-c, --config <path>', | ||
'Sets the path to the config file, otherwise read from the env variable CONFIG_FILE.' | ||
) | ||
.parse(process.argv); | ||
|
||
// If no config option is given, try to use the env variable: | ||
if (!program.config) checkEnv(['CONFIG_FILE']); | ||
else process.env.CONFIG_FILE = program.config; | ||
/* istanbul ignore next*/ | ||
if (!module.parent) { | ||
require('./lib/cli')(); | ||
} | ||
|
||
createBots(); | ||
module.exports = createBots; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env node | ||
|
||
var program = require('commander'); | ||
var path = require('path'); | ||
var checkEnv = require('check-env'); | ||
var createBots = require('./helpers').createBots; | ||
|
||
function run() { | ||
program | ||
.version(require('../package.json').version) | ||
.option('-c, --config <path>', | ||
'Sets the path to the config file, otherwise read from the env variable CONFIG_FILE.' | ||
) | ||
.parse(process.argv); | ||
|
||
// If no config option is given, try to use the env variable: | ||
if (!program.config) checkEnv(['CONFIG_FILE']); | ||
else process.env.CONFIG_FILE = program.config; | ||
|
||
var configFile = require(path.resolve(process.cwd(), process.env.CONFIG_FILE)); | ||
|
||
createBots(configFile); | ||
} | ||
|
||
module.exports = run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* jshint expr: true */ | ||
var chai = require('chai'); | ||
var sinon = require('sinon'); | ||
var sinonChai = require('sinon-chai'); | ||
var rewire = require('rewire'); | ||
var cli = rewire('../lib/cli'); | ||
var testConfig = require('./fixtures/test-config.json'); | ||
var singleTestConfig = require('./fixtures/single-test-config.json'); | ||
|
||
chai.should(); | ||
chai.use(sinonChai); | ||
|
||
describe('CLI', function() { | ||
before(function() { | ||
this.createBotsStub = sinon.stub(); | ||
cli.__set__('createBots', this.createBotsStub); | ||
}); | ||
|
||
afterEach(function() { | ||
this.createBotsStub.reset(); | ||
}); | ||
|
||
it('should be possible to give the config as an env var', function() { | ||
process.env.CONFIG_FILE = process.cwd() + '/test/fixtures/test-config.json'; | ||
process.argv = ['node', 'index.js']; | ||
cli(); | ||
this.createBotsStub.should.have.been.calledWith(testConfig); | ||
}); | ||
|
||
it('should be possible to give the config as an option', function() { | ||
delete process.env.CONFIG_FILE; | ||
process.argv = ['node', 'index.js', | ||
'--config', process.cwd() + '/test/fixtures/single-test-config.json']; | ||
cli(); | ||
this.createBotsStub.should.have.been.calledWith(singleTestConfig); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters