Skip to content

Commit

Permalink
chore: follow standardjs guidelines
Browse files Browse the repository at this point in the history
- Extend the `standard` ESLint configuration
- Remove ESLint rules that are defined in the `standard` configuration
- Get rid of semi-colons

See: #1657
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Aug 3, 2017
1 parent 5c19b70 commit 3b19c07
Show file tree
Hide file tree
Showing 134 changed files with 5,353 additions and 5,407 deletions.
259 changes: 3 additions & 256 deletions .eslintrc.yml

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions lib/child-writer/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

'use strict';
'use strict'

const _ = require('lodash');
const _ = require('lodash')

/**
* @summary Get the explicit boolean form of an argument
Expand Down Expand Up @@ -44,19 +44,19 @@ const _ = require('lodash');
exports.getBooleanArgumentForm = (argumentName, value) => {
const prefix = _.attempt(() => {
if (!value) {
return '--no-';
return '--no-'
}

const SHORT_OPTION_LENGTH = 1;
const SHORT_OPTION_LENGTH = 1
if (_.size(argumentName) === SHORT_OPTION_LENGTH) {
return '-';
return '-'
}

return '--';
});
return '--'
})

return prefix + argumentName;
};
return prefix + argumentName
}

/**
* @summary Get CLI writer arguments
Expand Down Expand Up @@ -94,7 +94,7 @@ exports.getArguments = (options) => {
exports.getBooleanArgumentForm('unmount', options.unmountOnSuccess),
exports.getBooleanArgumentForm('check', options.validateWriteOnSuccess)

];
]

return argv;
};
return argv
}
6 changes: 3 additions & 3 deletions lib/child-writer/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

'use strict';
'use strict'

const path = require('path');
const path = require('path')

/**
* @summary Child writer constants
Expand All @@ -37,4 +37,4 @@ module.exports = {
*/
WRITER_PROXY_SCRIPT: path.join(__dirname, 'writer-proxy.js')

};
}
112 changes: 56 additions & 56 deletions lib/child-writer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*/

'use strict';

const EventEmitter = require('events').EventEmitter;
const _ = require('lodash');
const childProcess = require('child_process');
const ipc = require('node-ipc');
const rendererUtils = require('./renderer-utils');
const cli = require('./cli');
const CONSTANTS = require('./constants');
const EXIT_CODES = require('../shared/exit-codes');
const robot = require('../shared/robot');
'use strict'

const EventEmitter = require('events').EventEmitter
const _ = require('lodash')
const childProcess = require('child_process')
const ipc = require('node-ipc')
const rendererUtils = require('./renderer-utils')
const cli = require('./cli')
const CONSTANTS = require('./constants')
const EXIT_CODES = require('../shared/exit-codes')
const robot = require('../shared/robot')

/**
* @summary Perform a write
Expand Down Expand Up @@ -57,25 +57,25 @@ const robot = require('../shared/robot');
* });
*/
exports.write = (image, drive, options) => {
const emitter = new EventEmitter();
const emitter = new EventEmitter()

const argv = cli.getArguments({
entryPoint: rendererUtils.getApplicationEntryPoint(),
image,
device: drive.device,
validateWriteOnSuccess: options.validateWriteOnSuccess,
unmountOnSuccess: options.unmountOnSuccess
});
})

// There might be multiple Etcher instances running at
// the same time, therefore we must ensure each IPC
// server/client has a different name.
process.env.IPC_SERVER_ID = `etcher-server-${process.pid}`;
process.env.IPC_CLIENT_ID = `etcher-client-${process.pid}`;
process.env.IPC_SERVER_ID = `etcher-server-${process.pid}`
process.env.IPC_CLIENT_ID = `etcher-client-${process.pid}`

ipc.config.id = process.env.IPC_SERVER_ID;
ipc.config.silent = true;
ipc.serve();
ipc.config.id = process.env.IPC_SERVER_ID
ipc.config.silent = true
ipc.serve()

/**
* @summary Safely terminate the IPC server
Expand All @@ -91,11 +91,11 @@ exports.write = (image, drive, options) => {
// just stops receiving any further connections,
// but remains open if there are active ones.
_.each(ipc.server.sockets, (socket) => {
socket.destroy();
});
socket.destroy()
})

ipc.server.stop();
};
ipc.server.stop()
}

/**
* @summary Emit an error to the client
Expand All @@ -108,9 +108,9 @@ exports.write = (image, drive, options) => {
* emitError(new Error('foo bar'));
*/
const emitError = (error) => {
terminateServer();
emitter.emit('error', error);
};
terminateServer()
emitter.emit('error', error)
}

/**
* @summary Bridge robot message to the child writer caller
Expand All @@ -127,91 +127,91 @@ exports.write = (image, drive, options) => {
const bridgeRobotMessage = (message) => {
const parsedMessage = _.attempt(() => {
if (robot.isMessage(message)) {
return robot.parseMessage(message);
return robot.parseMessage(message)
}

// Don't be so strict. If a message doesn't look like
// a robot message, then make the child writer log it
// for debugging purposes.
return robot.parseMessage(robot.buildMessage(robot.COMMAND.LOG, {
message
}));
});
}))
})

if (_.isError(parsedMessage)) {
emitError(parsedMessage);
return;
emitError(parsedMessage)
return
}

try {
// These are lighweight accessor methods for
// the properties of the parsed message
const messageCommand = robot.getCommand(parsedMessage);
const messageData = robot.getData(parsedMessage);
const messageCommand = robot.getCommand(parsedMessage)
const messageData = robot.getData(parsedMessage)

// The error object is decomposed by the CLI for serialisation
// purposes. We compose it back to an `Error` here in order
// to provide better encapsulation.
if (messageCommand === robot.COMMAND.ERROR) {
emitError(robot.recomposeErrorMessage(parsedMessage));
emitError(robot.recomposeErrorMessage(parsedMessage))
} else if (messageCommand === robot.COMMAND.LOG) {
// If the message data is an object and it contains a
// message string then log the message string only.
if (_.isPlainObject(messageData) && _.isString(messageData.message)) {
console.log(messageData.message);
console.log(messageData.message)
} else {
console.log(messageData);
console.log(messageData)
}
} else {
emitter.emit(messageCommand, messageData);
emitter.emit(messageCommand, messageData)
}
} catch (error) {
emitError(error);
emitError(error)
}
};
}

ipc.server.on('error', emitError);
ipc.server.on('message', bridgeRobotMessage);
ipc.server.on('error', emitError)
ipc.server.on('message', bridgeRobotMessage)

ipc.server.on('start', () => {
const child = childProcess.fork(CONSTANTS.WRITER_PROXY_SCRIPT, argv, {
silent: true,
env: process.env
});
})

child.stdout.on('data', (data) => {
console.info(`WRITER: ${data.toString()}`);
});
console.info(`WRITER: ${data.toString()}`)
})

child.stderr.on('data', (data) => {
bridgeRobotMessage(data.toString());
bridgeRobotMessage(data.toString())

// This function causes the `close` event to be emitted
child.kill();
});
child.kill()
})

child.on('error', emitError);
child.on('error', emitError)

child.on('close', (code) => {
terminateServer();
terminateServer()

if (code === EXIT_CODES.CANCELLED) {
return emitter.emit('done', {
cancelled: true
});
})
}

// We shouldn't emit the `done` event manually here
// since the writer process will take care of it.
if (code === EXIT_CODES.SUCCESS || code === EXIT_CODES.VALIDATION_ERROR) {
return null;
return null
}

return emitError(new Error(`Child process exited with error code: ${code}`));
});
});
return emitError(new Error(`Child process exited with error code: ${code}`))
})
})

ipc.server.start();
ipc.server.start()

return emitter;
};
return emitter
}
20 changes: 10 additions & 10 deletions lib/child-writer/renderer-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

'use strict';
'use strict'

/**
* This file is only meant to be loaded by the renderer process.
*/

const path = require('path');
const isRunningInAsar = require('electron-is-running-in-asar');
const electron = require('electron');
const CONSTANTS = require('./constants');
const path = require('path')
const isRunningInAsar = require('electron-is-running-in-asar')
const electron = require('electron')
const CONSTANTS = require('./constants')

/**
* @summary Get application entry point
Expand All @@ -37,14 +37,14 @@ const CONSTANTS = require('./constants');
*/
exports.getApplicationEntryPoint = () => {
if (isRunningInAsar()) {
return path.join(process.resourcesPath, 'app.asar');
return path.join(process.resourcesPath, 'app.asar')
}

const ENTRY_POINT_ARGV_INDEX = 1;
const relativeEntryPoint = electron.remote.process.argv[ENTRY_POINT_ARGV_INDEX];
const ENTRY_POINT_ARGV_INDEX = 1
const relativeEntryPoint = electron.remote.process.argv[ENTRY_POINT_ARGV_INDEX]

// On GNU/Linux, `pkexec` resolves relative paths
// from `/root`, therefore we pass an absolute path,
// in order to be on the safe side.
return path.join(CONSTANTS.PROJECT_ROOT, relativeEntryPoint);
};
return path.join(CONSTANTS.PROJECT_ROOT, relativeEntryPoint)
}
8 changes: 4 additions & 4 deletions lib/child-writer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

'use strict';
'use strict'

const _ = require('lodash');
const _ = require('lodash')

/**
* @summary Split stringified object lines
Expand All @@ -41,5 +41,5 @@ exports.splitObjectLines = (lines) => {
.split(/((?:[^\n"']|"[^"]*"|'[^']*')+)/)
.map(_.trim)
.reject(_.isEmpty)
.value();
};
.value()
}
Loading

0 comments on commit 3b19c07

Please sign in to comment.