This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
/
helpers.js
63 lines (50 loc) · 1.63 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
'use babel';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.spawnWorker = spawnWorker;
exports.showError = showError;
var _child_process = require('child_process');
var _child_process2 = _interopRequireDefault(_child_process);
var _processCommunication = require('process-communication');
var _path = require('path');
var _atom = require('atom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function spawnWorker() {
var env = Object.create(process.env);
delete env.NODE_PATH;
delete env.NODE_ENV;
delete env.OS;
var child = _child_process2.default.fork((0, _path.join)(__dirname, 'worker.js'), [], { env: env, silent: true });
var worker = (0, _processCommunication.createFromProcess)(child);
child.stdout.on('data', function (chunk) {
console.log('[Linter-ESLint] STDOUT', chunk.toString());
});
child.stderr.on('data', function (chunk) {
console.log('[Linter-ESLint] STDERR', chunk.toString());
});
return {
worker: worker,
subscription: new _atom.Disposable(function () {
worker.kill();
})
};
}
// eslint-disable-next-line import/no-extraneous-dependencies
function showError(givenMessage) {
var givenDetail = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var detail = void 0;
var message = void 0;
if (message instanceof Error) {
detail = message.stack;
message = message.message;
} else {
detail = givenDetail;
message = givenMessage;
}
atom.notifications.addError('[Linter-ESLint] ' + message, {
detail: detail,
dismissable: true
});
}