Skip to content

Code style improvements #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lib/Local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var childProcess = require('child_process'),
const childProcess = require('child_process'),
os = require('os'),
fs = require('fs'),
path = require('path'),
Expand All @@ -9,7 +9,7 @@ var childProcess = require('child_process'),

function Local(){
this.sanitizePath = function(rawPath) {
var doubleQuoteIfRequired = this.windows && !rawPath.match(/"[^"]+"/) ? '"' : '';
const doubleQuoteIfRequired = this.windows && !rawPath.match(/"[^"]+"/) ? '"' : '';
return doubleQuoteIfRequired + rawPath + doubleQuoteIfRequired;
};

Expand All @@ -22,12 +22,9 @@ function Local(){
this.opcode = 'start';
this.exitCallback;

this.errorRegex = /\*\*\* Error: [^\r\n]*/i;
this.doneRegex = /Press Ctrl-C to exit/i;

this.start = function(options, callback){
this.userArgs = [];
var that = this;
const that = this;
this.addArgs(options);

if(typeof options['onlyCommand'] !== 'undefined')
Expand All @@ -53,16 +50,18 @@ function Local(){
}
}

var data = {};
if(stdout)
let data;
if(!!stdout)
data = JSON.parse(stdout);
else if(stderr)
data = JSON.parse(stderr);
else
else {
callback(new LocalError('No output received'));
return;
}

if(data['state'] != 'connected'){
callback(new LocalError(data['message']['message']));
if(data.state !== 'connected'){
callback(new LocalError(data.message.message));
} else {
that.pid = data['pid'];
that.isProcessRunning = true;
Expand All @@ -85,8 +84,8 @@ function Local(){
};

this.addArgs = function(options){
for(var key in options){
var value = options[key];
for(const key in options){
const value = options.key;

switch(key){
case 'key':
Expand Down Expand Up @@ -192,7 +191,7 @@ function Local(){
this.getBinaryPath = function(callback){
if(typeof(this.binaryPath) == 'undefined'){
this.binary = new LocalBinary();
var conf = {};
let conf = {};
if(this.proxyHost && this.proxyPort){
conf.proxyHost = this.proxyHost;
conf.proxyPort = this.proxyPort;
Expand All @@ -205,7 +204,7 @@ function Local(){
};

this.getBinaryArgs = function(){
var args = ['--daemon', this.opcode, '--log-file', this.logfile];
const args = ['--daemon', this.opcode, '--log-file', this.logfile];
if(this.key) {
args.push('--key');
args.push(this.key);
Expand Down Expand Up @@ -254,16 +253,16 @@ function Local(){
args.push('--verbose');
args.push(this.verboseFlag.toString());
}
for(var i in this.userArgs){
for(const i in this.userArgs){
args.push(this.userArgs[i]);
}
return args;
};

this.killAllProcesses = function(callback){
psTree(this.pid, (err, children) => {
var childPids = children.map(val => val.PID);
var killChecker = setInterval(() => {
const childPids = children.map(val => val.PID);
const killChecker = setInterval(() => {
if(childPids.length === 0) {
clearInterval(killChecker);
try {
Expand All @@ -278,7 +277,7 @@ function Local(){
callback();
}
}
for(var i in childPids) {
for(const i in childPids) {
try {
process.kill(childPids[i]);
} catch(err) {
Expand Down