Skip to content

Commit

Permalink
Switch to args, lint code and clean up (rauchg#200)
Browse files Browse the repository at this point in the history
* Hide npm warnings

* Use args instead of commander

* Consitant naming

* Ignore stuff

* Put babel config into package.json

* Lint code

* Adjust code to get linted

* npm does this by default

* Proper task naming

* Proper name for build output

* Pin dependencies

* Updated eslint-config-default
  • Loading branch information
leo authored and rauchg committed Jun 17, 2016
1 parent 4ea80c4 commit c54b678
Show file tree
Hide file tree
Showing 20 changed files with 1,174 additions and 1,166 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
node
# build output
dist

# dependencies
node_modules

# logs
npm-debug.log
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

File renamed without changes.
File renamed without changes.
10 changes: 4 additions & 6 deletions Readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

# slackin

A little server that enables public access
to a Slack server. Like Freenode, but on Slack.
A little server that enables public access to a Slack server. Like Freenode, but on Slack.

It provides

Expand Down Expand Up @@ -136,16 +134,16 @@ By default logging is enabled.

## Developing

Slackin's server side code is written in ES6. It uses babel to transpile the
ES6 code to a format node understands. After cloning Slackin, you should
Slackin's server side code is written in ES6. It uses babel to transpile the
ES6 code to a format node understands. After cloning Slackin, you should
install the prerequisite node libraries with npm:

```bash
$ npm install
```

After the libraries install, the postinstall script will run `gulp` to invoke
babel on the source. It is important to run `gulp` manually after updating any
babel on the source. It is important to run `gulp` manually after updating any
files in lib/ to update the versions in node/.

## Credits
Expand Down
50 changes: 23 additions & 27 deletions bin/slackin
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
#!/usr/bin/env node

var pkg = require('./../package');
var program = require('commander');
var args = require('args');
var slackin = require('./../node').default;

program
.version(pkg.version)
.usage('[options] <team-id> <api-token>')
.option('-p, --port <port>', 'Port to listen on [$PORT or 3000]', require('hostenv').PORT || process.env.PORT || 3000)
.option('-h, --hostname <hostname>', 'Hostname to listen on [$HOSTNAME or 0.0.0.0]', require('hostenv').HOSTNAME || process.env.WEBSITE_HOSTNAME || '0.0.0.0')
.option('-c, --channels [<chan>]', 'One or more comma-separated channel names to allow single-channel guests [$SLACK_CHANNELS]', process.env.SLACK_CHANNELS)
.option('-c, --channel <chan>', 'Single channel guest invite (deprecated) [$SLACK_CHANNEL]', process.env.SLACK_CHANNEL)
.option('-i, --interval <int>', 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000)
.option('-P, --path <path>', 'Path to serve slackin under', '/')
.option('-s, --silent', 'Do not print out warns or errors')
.option('-C, --coc <coc>', 'Full URL to a CoC that needs to be agreed to')
.option('-c, --css <file>', 'Full URL to a custom CSS file to use on the main page')
.parse(process.argv);
args
.option(['p', 'port'], 'Port to listen on [$PORT or 3000]', require('hostenv').PORT || process.env.PORT || 3000)
.option(['h', 'hostname'], 'Hostname to listen on [$HOSTNAME or 0.0.0.0]', require('hostenv').HOSTNAME || process.env.WEBSITE_HOSTNAME || '0.0.0.0')
.option(['c', 'channels'], 'One or more comma-separated channel names to allow single-channel guests [$SLACK_CHANNELS]', process.env.SLACK_CHANNELS)
.option(['i', 'interval'], 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000)
.option(['P', 'path'], 'Path to serve slackin under', '/')
.option(['s', 'silent'], 'Do not print out warns or errors')
.option(['C', 'coc'], 'Full URL to a CoC that needs to be agreed to')
.option(['S', 'css'], 'Full URL to a custom CSS file to use on the main page');

var org = program.args[0] || process.env.SLACK_SUBDOMAIN;
var token = program.args[1] || process.env.SLACK_API_TOKEN;
var flags = args.parse(process.argv, {
value: '<team-id> <api-token>'
});

var org = args.sub[0] || process.env.SLACK_SUBDOMAIN;
var token = args.sub[1] || process.env.SLACK_API_TOKEN;

if (!org || !token) {
program.help();
args.showHelp();
} else {
program.org = org;
program.token = token;
flags.org = org;
flags.token = token;
}

// support deprecated option
if (!program.channels && program.channel) {
program.channels = program.channel;
}
var port = flags.port;
var hostname = flags.hostname;

var port = program.port;
var hostname = program.hostname;
slackin(program).listen(port, hostname, function(err){
slackin(flags).listen(port, hostname, function(err){
if (err) throw err;
if (!program.silent) console.log('%s – listening on %s:%d', new Date, hostname, port);
if (!flags.silent) console.log('%s – listening on %s:%d', new Date, hostname, port);
});
50 changes: 27 additions & 23 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
'use strict';

import gulp from 'gulp';
import babel from 'gulp-babel';
import rimraf from 'gulp-rimraf';
import gulp from 'gulp'
import babel from 'gulp-babel'
import rimraf from 'gulp-rimraf'

const paths = {
in_js: "lib/*.js",
in_assets: "lib/assets/*",
out_js: "node",
out_assets: "node/assets",
};
in: {
js: 'lib/*.js',
assets: 'lib/assets/*'
},
out: {
js: 'dist',
assets: 'dist/assets'
}
}

gulp.task('es6to5', () => {
return gulp.src(paths.in_js)
.pipe(babel())
.pipe(gulp.dest(paths.out_js));
});
gulp.task('transpile', () => {
return gulp.src(paths.in.js)
.pipe(babel())
.pipe(gulp.dest(paths.out.js))
})

gulp.task('copyassets', () => {
return gulp.src(paths.in_assets)
.pipe(gulp.dest(paths.out_assets));
});
gulp.task('assets', () => {
return gulp.src(paths.in.assets)
.pipe(gulp.dest(paths.out.assets))
})

gulp.task('clean', () => {
return gulp.src(paths.out_js, { read: false })
.pipe(rimraf());
});
return gulp.src(paths.out.js, {
read: false
})
.pipe(rimraf())
})

gulp.task('default', ['es6to5', 'copyassets']);
gulp.task('default', ['transpile', 'assets'])
Loading

0 comments on commit c54b678

Please sign in to comment.