Skip to content

Commit c54b678

Browse files
leorauchg
authored andcommitted
Switch to args, lint code and clean up (rauchg#200)
* 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
1 parent 4ea80c4 commit c54b678

20 files changed

+1174
-1166
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
node
1+
# build output
2+
dist
3+
4+
# dependencies
25
node_modules
6+
7+
# logs
8+
npm-debug.log

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

History.md renamed to HISTORY.md

File renamed without changes.

LICENSE renamed to LICENSE.md

File renamed without changes.

Readme.md renamed to README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
21
# slackin
32

4-
A little server that enables public access
5-
to a Slack server. Like Freenode, but on Slack.
3+
A little server that enables public access to a Slack server. Like Freenode, but on Slack.
64

75
It provides
86

@@ -136,16 +134,16 @@ By default logging is enabled.
136134

137135
## Developing
138136

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

143141
```bash
144142
$ npm install
145143
```
146144

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

151149
## Credits

bin/slackin

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
#!/usr/bin/env node
22

33
var pkg = require('./../package');
4-
var program = require('commander');
4+
var args = require('args');
55
var slackin = require('./../node').default;
66

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

21-
var org = program.args[0] || process.env.SLACK_SUBDOMAIN;
22-
var token = program.args[1] || process.env.SLACK_API_TOKEN;
17+
var flags = args.parse(process.argv, {
18+
value: '<team-id> <api-token>'
19+
});
20+
21+
var org = args.sub[0] || process.env.SLACK_SUBDOMAIN;
22+
var token = args.sub[1] || process.env.SLACK_API_TOKEN;
2323

2424
if (!org || !token) {
25-
program.help();
25+
args.showHelp();
2626
} else {
27-
program.org = org;
28-
program.token = token;
27+
flags.org = org;
28+
flags.token = token;
2929
}
3030

31-
// support deprecated option
32-
if (!program.channels && program.channel) {
33-
program.channels = program.channel;
34-
}
31+
var port = flags.port;
32+
var hostname = flags.hostname;
3533

36-
var port = program.port;
37-
var hostname = program.hostname;
38-
slackin(program).listen(port, hostname, function(err){
34+
slackin(flags).listen(port, hostname, function(err){
3935
if (err) throw err;
40-
if (!program.silent) console.log('%s – listening on %s:%d', new Date, hostname, port);
36+
if (!flags.silent) console.log('%s – listening on %s:%d', new Date, hostname, port);
4137
});

gulpfile.babel.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
'use strict';
2-
3-
import gulp from 'gulp';
4-
import babel from 'gulp-babel';
5-
import rimraf from 'gulp-rimraf';
1+
import gulp from 'gulp'
2+
import babel from 'gulp-babel'
3+
import rimraf from 'gulp-rimraf'
64

75
const paths = {
8-
in_js: "lib/*.js",
9-
in_assets: "lib/assets/*",
10-
out_js: "node",
11-
out_assets: "node/assets",
12-
};
6+
in: {
7+
js: 'lib/*.js',
8+
assets: 'lib/assets/*'
9+
},
10+
out: {
11+
js: 'dist',
12+
assets: 'dist/assets'
13+
}
14+
}
1315

14-
gulp.task('es6to5', () => {
15-
return gulp.src(paths.in_js)
16-
.pipe(babel())
17-
.pipe(gulp.dest(paths.out_js));
18-
});
16+
gulp.task('transpile', () => {
17+
return gulp.src(paths.in.js)
18+
.pipe(babel())
19+
.pipe(gulp.dest(paths.out.js))
20+
})
1921

20-
gulp.task('copyassets', () => {
21-
return gulp.src(paths.in_assets)
22-
.pipe(gulp.dest(paths.out_assets));
23-
});
22+
gulp.task('assets', () => {
23+
return gulp.src(paths.in.assets)
24+
.pipe(gulp.dest(paths.out.assets))
25+
})
2426

2527
gulp.task('clean', () => {
26-
return gulp.src(paths.out_js, { read: false })
27-
.pipe(rimraf());
28-
});
28+
return gulp.src(paths.out.js, {
29+
read: false
30+
})
31+
.pipe(rimraf())
32+
})
2933

30-
gulp.task('default', ['es6to5', 'copyassets']);
34+
gulp.task('default', ['transpile', 'assets'])

0 commit comments

Comments
 (0)