Skip to content

Commit 2ba7835

Browse files
author
Giedrius Grabauskas
committed
Updated typescript. Handled openBrowser in other platforms.
1 parent f814e23 commit 2ba7835

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"rollup-plugin-typescript": "0.7.7",
3535
"rollup-watch": "2.5.0",
3636
"tslint": "3.14.0",
37-
"typescript": "2.0.0",
37+
"typescript": "^2.1.4",
3838
"typings": "2.0.0"
3939
},
4040
"peerDependencies": {

src/server.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { RequestHandler } from 'express-serve-static-core';
44
import Logger from './utils/logger';
55
import Configuration from './configuration/configuration';
66
import { spawn } from 'child_process';
7+
import { exec } from 'child_process';
8+
import * as path from "path";
79
import * as connectLiveReload from 'connect-livereload';
810
import * as tinyLr from 'tiny-lr';
911
import ActionsEmitter, { } from './utils/actions-emitter';
@@ -73,7 +75,28 @@ export default class ServerStarter {
7375

7476
private openBrowser(serverUrl: string) {
7577
if (!this.isQuiet) {
76-
spawn('explorer', [serverUrl]);
78+
let opener = '';
79+
switch (process.platform) {
80+
case 'darwin':
81+
opener = 'open';
82+
break;
83+
case 'win32':
84+
opener = 'start ""';
85+
break;
86+
default:
87+
opener = path.join(__dirname, '../vendor/xdg-open');
88+
break;
89+
}
90+
91+
if (process.env.SUDO_USER) {
92+
opener = `sudo -u ${process.env.SUDO_USER} ${opener}`;
93+
}
94+
try {
95+
exec(`opener "${serverUrl}"`);
96+
} catch (error) {
97+
Logger.error("Error with openBrowser.", error);
98+
Logger.info("Please create new issue here: https://github.com/quatrocode/simplr-gulp/issues");
99+
}
77100
}
78101
}
79102

0 commit comments

Comments
 (0)