Skip to content

Commit

Permalink
chore: prettier standard
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw committed Apr 13, 2020
1 parent 0ceb864 commit 94e2c46
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 113 deletions.
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ const doAuthorization = !!(program.user && program.password);
const doSecure = !!(program.key && program.certificate);
const sessionSecret = String(+new Date()) + Math.random();
const files = program.args.join(' ');
const filesNamespace = crypto
.createHash('md5')
.update(files)
.digest('hex');
const filesNamespace = crypto.createHash('md5').update(files).digest('hex');
const urlPath = program.urlPath.replace(/\/$/, ''); // remove trailing slash

if (program.daemonize) {
daemonize(__filename, program, {
doAuthorization,
doSecure
doSecure,
});
} else {
/**
Expand All @@ -59,7 +56,12 @@ if (program.daemonize) {
}
appBuilder
.static(path.join(__dirname, 'web', 'assets'))
.index(path.join(__dirname, 'web', 'index.html'), files, filesNamespace, program.theme);
.index(
path.join(__dirname, 'web', 'index.html'),
files,
filesNamespace,
program.theme
);

const builder = serverBuilder();
if (doSecure) {
Expand All @@ -86,7 +88,10 @@ if (program.daemonize) {
if (!sessionIdEncoded) {
return next(new Error('Session cookie not provided'), false);
}
const sessionId = cookieParser.signedCookie(sessionIdEncoded, sessionSecret);
const sessionId = cookieParser.signedCookie(
sessionIdEncoded,
sessionSecret
);
if (sessionId) {
return next(null);
}
Expand Down Expand Up @@ -121,7 +126,7 @@ if (program.daemonize) {
* When connected send starting data
*/
const tailer = tail(program.args, {
buffer: program.number
buffer: program.number,
});

const filesSocket = io.of(`/${filesNamespace}`).on('connection', (socket) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/connect_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ConnectBuilder.prototype.index = function index(
this.app.use(this.urlPath, (req, res) => {
fs.readFile(path, (err, data) => {
res.writeHead(200, {
'Content-Type': 'text/html'
'Content-Type': 'text/html',
});
res.end(
data
Expand All @@ -61,7 +61,7 @@ ConnectBuilder.prototype.session = function sessionf(secret) {
expressSession({
secret,
resave: false,
saveUninitialized: true
saveUninitialized: true,
})
);
return this;
Expand Down
6 changes: 3 additions & 3 deletions lib/daemonize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fs = require('fs');

const defaultOptions = {
doAuthorization: false,
doSecure: false
doSecure: false,
};

module.exports = (script, params, opts) => {
Expand All @@ -23,7 +23,7 @@ module.exports = (script, params, opts) => {
'-l',
params.lines,
'-t',
params.theme
params.theme,
];

if (options.doAuthorization) {
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = (script, params, opts) => {

const proc = daemon.daemon(script, args, {
stdout: logFile,
stderr: logFile
stderr: logFile,
});

fs.writeFileSync(params.pidPath, proc.pid);
Expand Down
35 changes: 30 additions & 5 deletions lib/options_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ program
.version(require('../package.json').version)
.usage('[options] [file ...]')
.helpOption('--help')
.option('-h, --host <host>', 'listening host, default 0.0.0.0', String, '0.0.0.0')
.option(
'-h, --host <host>',
'listening host, default 0.0.0.0',
String,
'0.0.0.0'
)
.option('-p, --port <port>', 'listening port, default 9001', Number, 9001)
.option('-n, --number <number>', 'starting lines number, default 10', Number, 10)
.option('-l, --lines <lines>', 'number on lines stored in browser, default 2000', Number, 2000)
.option('-t, --theme <theme>', 'name of the theme (default, dark)', String, 'default')
.option(
'-n, --number <number>',
'starting lines number, default 10',
Number,
10
)
.option(
'-l, --lines <lines>',
'number on lines stored in browser, default 2000',
Number,
2000
)
.option(
'-t, --theme <theme>',
'name of the theme (default, dark)',
String,
'default'
)
.option('-d, --daemonize', 'run as daemon')
.option(
'-U, --user <username>',
Expand Down Expand Up @@ -46,7 +66,12 @@ program
String,
'/dev/null'
)
.option('--url-path <path>', 'URL path for the browser application, default /', String, '/')
.option(
'--url-path <path>',
'URL path for the browser application, default /',
String,
'/'
)
.option('--ui-hide-topbar', 'hide topbar (log file name and search box)')
.option('--ui-no-indent', "don't indent log lines")
.option(
Expand Down
6 changes: 4 additions & 2 deletions lib/server_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ ServerBuilder.prototype.build = function build() {
if (this._key && this._cert) {
const options = {
key: this._key,
cert: this._cert
cert: this._cert,
};
return https.createServer(options, this._callback).listen(this._port, this._host);
return https
.createServer(options, this._callback)
.listen(this._port, this._host);
}

return http.createServer(this._callback).listen(this._port, this._host);
Expand Down
4 changes: 3 additions & 1 deletion lib/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Stats.prototype.timeEnd = function timeEnd(category, action, cb) {
return;
}

this.tracker.timing(category, action, Date.now() - this.timer[category][action]).send(cb);
this.tracker
.timing(category, action, Date.now() - this.timer[category][action])
.send(cb);
};

module.exports = (enabled, opts) => new Stats(enabled, opts);
4 changes: 2 additions & 2 deletions lib/tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Tail(path, opts) {
events.EventEmitter.call(this);

const options = opts || {
buffer: 0
buffer: 0,
};
this._buffer = new CBuffer(options.buffer);

Expand Down Expand Up @@ -52,7 +52,7 @@ function Tail(path, opts) {
stream = tailStream.createReadStream(path.join(), {
encoding: 'utf8',
start: options.buffer,
tail: true
tail: true,
});
}
}
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"devDependencies": {
"eslint": "~6.8.0",
"eslint-config-airbnb-base": "~14.0.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "~2.20.0",
"jsdom": "~11.12.0",
"mocha": "~5.2.0",
Expand All @@ -55,17 +56,14 @@
]
},
"eslintConfig": {
"extends": "airbnb-base",
"extends": [
"airbnb-base",
"prettier"
],
"rules": {
"no-console": "off",
"strict": "off",
"implicit-arrow-linebreak": "off",
"comma-dangle": [
"error",
{
"functions": "never"
}
]
"implicit-arrow-linebreak": "off"
},
"env": {
"node": true
Expand Down
23 changes: 13 additions & 10 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('browser application', () => {
filterInput: window.document.querySelector('#filter'),
pauseBtn: window.document.querySelector('#pauseBtn'),
topbar: window.document.querySelector('.topbar'),
body: window.document.querySelector('body')
body: window.document.querySelector('body'),
});
}

Expand Down Expand Up @@ -43,9 +43,10 @@ describe('browser application', () => {

beforeEach((done) => {
io = new events.EventEmitter();
const html = '<title></title><body><div class="topbar"></div>'
+ '<div class="log"></div><button type="button" id="pauseBtn"></button>'
+ '<input type="test" id="filter"/></body>';
const html =
'<title></title><body><div class="topbar"></div>' +
'<div class="log"></div><button type="button" id="pauseBtn"></button>' +
'<input type="test" id="filter"/></body>';
const ansiup = fs.readFileSync('./web/assets/ansi_up.js', 'utf-8');
const src = fs.readFileSync('./web/assets/app.js', 'utf-8');

Expand All @@ -58,7 +59,7 @@ describe('browser application', () => {

initApp();
done();
}
},
});
});

Expand All @@ -70,7 +71,9 @@ describe('browser application', () => {
log.childNodes[0].textContent.should.be.equal('test');
log.childNodes[0].className.should.be.equal('line');
log.childNodes[0].tagName.should.be.equal('DIV');
log.childNodes[0].innerHTML.should.be.equal('<p class="inner-line">test</p>');
log.childNodes[0].innerHTML.should.be.equal(
'<p class="inner-line">test</p>'
);
});

it('should select line when clicked', () => {
Expand Down Expand Up @@ -124,8 +127,8 @@ describe('browser application', () => {
io.emit('options:highlightConfig', {
words: {
foo: 'background: black',
bar: 'background: black'
}
bar: 'background: black',
},
});
io.emit('line', 'foo bar');

Expand All @@ -138,8 +141,8 @@ describe('browser application', () => {
it('should highlight line', () => {
io.emit('options:highlightConfig', {
lines: {
line: 'background: black'
}
line: 'background: black',
},
});
io.emit('line', 'line1');

Expand Down
Loading

0 comments on commit 94e2c46

Please sign in to comment.