Skip to content
Open
Show file tree
Hide file tree
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
29 changes: 23 additions & 6 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
this.tools = [ require('./atom-build') ];
this.linter = null;

this.detectConsoleEncoding();
this.setupTargetManager();
this.setupBuildView();
this.setupErrorMatcher();
Expand Down Expand Up @@ -47,6 +48,21 @@ export default {
atom.packages.onDidActivateInitialPackages(() => this.targetManager.refreshTargets());
},

detectConsoleEncoding() {
this.encoding = 'utf8';

if (process.platform === 'win32') {
// On windows, `chcp` commnad prints current console codepage.
// see: https://ss64.com/nt/chcp.html
require('child_process').exec('chcp', (err, stdout, stderr) => {
if (stdout) {
const i = stdout.lastIndexOf(':');
this.encoding = 'cp' + stdout.slice(i + 1).trim();
}
});
}
},

setupTargetManager() {
const TargetManager = require('./target-manager');
this.targetManager = new TargetManager();
Expand Down Expand Up @@ -161,14 +177,15 @@ export default {
);
}

const iconv = require('iconv-lite');
let stdout = '';
let stderr = '';
this.child.stdout.setEncoding('utf8');
this.child.stderr.setEncoding('utf8');
this.child.stdout.on('data', d => (stdout += d));
this.child.stderr.on('data', d => (stderr += d));
this.child.stdout.pipe(this.buildView.terminal);
this.child.stderr.pipe(this.buildView.terminal);
const decodeStdout = this.child.stdout.pipe(iconv.decodeStream(this.encoding));
const decodeStderr = this.child.stderr.pipe(iconv.decodeStream(this.encoding));
decodeStdout.on('data', d => (stdout += d));
decodeStderr.on('data', d => (stderr += d));
decodeStdout.pipe(this.buildView.terminal);
decodeStderr.pipe(this.buildView.terminal);
this.child.killSignals = (target.killSignals || [ 'SIGINT', 'SIGTERM', 'SIGKILL' ]).slice();

this.child.on('error', (err) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"cross-spawn": "^4.0.2",
"cson-parser": "^1.3.0",
"getmac": "^1.0.7",
"iconv-lite": "^0.4.23",
"js-yaml": "^3.4.6",
"term.js": "https://github.com/jeremyramin/term.js/tarball/de1635fc2695e7d8165012d3b1d007d7ce60eea2",
"tree-kill": "^1.0.0",
Expand Down