Skip to content

Commit 72d08ab

Browse files
committed
append open method.
1 parent 239da1d commit 72d08ab

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ refrence
33
.jsbeautifyrc
44
.jshintignore
55
.jshintrc
6+
.vscode
67
jsconfig.json
7-
vsc-extension-quickstart.md
8+
vsc-extension-quickstart.md
9+
devServer-0.0.1.vsix

environment/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class Environment {
5252
}
5353

5454
appendStatusBar(port) {
55-
this.statusBar.command = 'server.openInBrowser';
56-
this.statusBar.tooltip = `Web server is hosting.\n\nClick here to open in browser`;
55+
this.statusBar.command = 'server.open';
56+
this.statusBar.tooltip = `Click here to open html in browser`;
5757
this.statusBar.text = `$(server) Port ${port}`;
5858
this.statusBar.show();
5959
}

extension.js

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ function activate(context) {
5858
}
5959
});
6060
}));
61+
62+
context.subscriptions.push(vscode.commands.registerCommand('server.open', () => {
63+
app.open();
64+
}));
6165
}
6266

6367
exports.activate = activate;

package.json

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
{
22
"name": "devServer",
3-
"displayName": "webServer",
3+
"displayName": "devServer",
44
"description": "a light weight express server for development,which support livereload,websocket,mock test and auto complie css.",
55
"version": "0.0.1",
6-
"publisher": "huke",
6+
"publisher": "ihuke",
77
"engines": {
88
"vscode": "^1.4.0"
99
},
10+
"Repository": {
11+
"type": "git",
12+
"url": "https://github.com/ihuke/developmentServer.git"
13+
},
1014
"categories": [
1115
"Other"
1216
],
1317
"activationEvents": [
1418
"onCommand:server.start",
1519
"onCommand:server.stop",
16-
"onCommand:server.restart"
20+
"onCommand:server.restart",
21+
"onCommand:server.open"
1722
],
1823
"main": "./extension",
1924
"contributes": {
2025
"commands": [{
21-
"command": "server.start",
22-
"title": "Server: Start"
23-
}, {
24-
"command": "server.stop",
25-
"title": "Server: Stop"
26-
}, {
27-
"command": "server.restart",
28-
"title": "Server: Restart"
29-
}]
26+
"command": "server.start",
27+
"title": "devServer: Start"
28+
},
29+
{
30+
"command": "server.stop",
31+
"title": "devServer: Stop"
32+
},
33+
{
34+
"command": "server.restart",
35+
"title": "devServer: Restart"
36+
}
37+
]
3038
},
3139
"scripts": {
3240
"postinstall": "node ./node_modules/vscode/bin/install"
@@ -39,7 +47,6 @@
3947
"gaze": "^1.1.1",
4048
"less": "^2.7.1",
4149
"open": "0.0.5",
42-
"socket.io": "^1.4.8",
4350
"ws": "^1.1.1",
4451
"xml2js": "^0.4.17"
4552
},

server/index.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = class Server {
1717
/**
1818
* initilize
1919
*
20-
* @param {Environment environment
20+
* @param {Environment} environment
2121
*/
2222
initilize(environment) {
2323
this.environment = environment;
@@ -43,7 +43,7 @@ module.exports = class Server {
4343
} = this.config;
4444

4545
if (this.server) {
46-
const message = 'Development server already started';
46+
const message = 'devServer already started';
4747
this.environment.log(message)
4848
reject(new Error(message));
4949
} else {
@@ -53,15 +53,14 @@ module.exports = class Server {
5353
app.use(express.static(directory));
5454
this.server = app.listen(port, () => {
5555
this.environment.appendStatusBar(port);
56-
this.environment.log(`Development server start on port ${port}\n\nhost path:${directory}`);
56+
this.environment.log(`devServer start on port ${port}\n\nhost path:${directory}`);
5757
this.environment.show();
5858
this.registePostExtentions(app, this.server);
59-
// this.supportWebSocket(this.server);
60-
resolve(`Development server start on port ${port}`);
59+
resolve(`devServer start on port ${port}`);
6160
this.open();
6261
})
6362
.on('error', error => {
64-
this.environment.log(`Failed to start development server due to ${error.message}`);
63+
this.environment.log(`Failed to start devServer due to ${error.message}`);
6564
reject(error);
6665
this.server = null;
6766
})
@@ -82,13 +81,13 @@ module.exports = class Server {
8281
stop() {
8382
return new Promise((resolve, reject) => {
8483
if (this.server) {
85-
this.environment.log(`Development server is stopping`);
84+
this.environment.log(`devServer is stopping`);
8685
this.server.close(() => {
8786
this.dispose();
88-
resolve('Development server stopped');
87+
resolve('devServer stopped');
8988
});
9089
} else {
91-
reject(new Error('Development server is not running!'));
90+
reject(new Error('devServer is not running!'));
9291
}
9392
});
9493
}

0 commit comments

Comments
 (0)