Skip to content

Commit 934cd0c

Browse files
committed
init.
0 parents  commit 934cd0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1882
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.jsbeautifyrc
3+
.jshintignore
4+
.jshintrc
5+
jsconfig.json
6+
vsc-extension-quickstart.md

.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// A launch configuration that launches the extension inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false
12+
},
13+
{
14+
"name": "Launch Tests",
15+
"type": "extensionHost",
16+
"request": "launch",
17+
"runtimeExecutable": "${execPath}",
18+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
19+
"stopOnEntry": false
20+
}
21+
]
22+
}

.vscodeignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode/**
2+
typings/**
3+
test/**
4+
.gitignore
5+
.jsbeautifyrc
6+
.jshintignore
7+
.jshintrc
8+
jsconfig.json
9+
vsc-extension-quickstart.md

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# server README
2+
3+
This is the README for your extension "server". After writing up a brief description, we recommend including the following sections.
4+
5+
## Features
6+
7+
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
8+
9+
For example if there is an image subfolder under your extension project workspace:
10+
11+
\!\[feature X\]\(images/feature-x.png\)
12+
13+
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
14+
15+
## Requirements
16+
17+
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
18+
19+
## Extension Settings
20+
21+
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
22+
23+
For example:
24+
25+
This extension contributes the following settings:
26+
27+
* `myExtension.enable`: enable/disable this extension
28+
* `myExtension.thing`: set to `blah` to do something
29+
30+
## Known Issues
31+
32+
Calling out known issues can help limit users opening duplicate issues against your extension.
33+
34+
## Release Notes
35+
36+
Users appreciate release notes as you update your extension.
37+
38+
### 1.0.0
39+
40+
Initial release of ...
41+
42+
### 1.0.1
43+
44+
Fixed issue #.
45+
46+
### 1.1.0
47+
48+
Added features X, Y, and Z.
49+
50+
-----------------------------------------------------------------------------------------------------------
51+
52+
## Working with Markdown
53+
54+
**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
55+
56+
* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
57+
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
58+
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets
59+
60+
### For more information
61+
62+
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
63+
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
64+
65+
**Enjoy!**

developmentServer.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extentions": {
3+
"pre": ["liveReload", "mock"],
4+
"post": ["websocket"]
5+
},
6+
"middlewares": ["cors"],
7+
"processors": ["xml2json"]
8+
}

environment/index.js

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
const vscode = require('vscode'),
2+
window = vscode.window;
3+
4+
/**
5+
* Environment Class
6+
*
7+
* @class Environment
8+
* @author huk/2016.09.27
9+
*/
10+
class Environment {
11+
/**
12+
* Creates an instance of Environment.
13+
*
14+
* @param {any} channel
15+
*
16+
* @memberOf Environment
17+
*/
18+
constructor(channel) {
19+
this.console = window.createOutputChannel(channel);
20+
this.statusBar = window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1);
21+
}
22+
23+
log(message) {
24+
if (message) {
25+
this.console.appendLine(message);
26+
}
27+
}
28+
29+
/**
30+
*
31+
* @param {string} message
32+
*/
33+
info(message) {
34+
info(message);
35+
}
36+
37+
/**
38+
*
39+
* @param {string} message
40+
*/
41+
error(message) {
42+
error(message);
43+
}
44+
45+
show() {
46+
this.console.show();
47+
}
48+
49+
hide() {
50+
this.console.hide();
51+
this.statusBar.hide();
52+
}
53+
54+
appendStatusBar(port) {
55+
this.statusBar.command = 'server.openInBrowser';
56+
this.statusBar.tooltip = `Web server is hosting.\n\nClick here to open in browser`;
57+
this.statusBar.text = `$(server) Port ${port}`;
58+
this.statusBar.show();
59+
}
60+
61+
/**
62+
* get configuration from environment
63+
*
64+
* @returns
65+
*/
66+
getConfiguration() {
67+
return getVsConfiguration();
68+
}
69+
70+
getRootPath(){
71+
return getWorkPath();
72+
}
73+
74+
dispose() {
75+
this.console.dispose();
76+
this.statusBar.dispose();
77+
this.console = null;
78+
this.statusBar = null;
79+
}
80+
}
81+
82+
function info(message) {
83+
if (message) {
84+
vscode.window.showInformationMessage(message);
85+
}
86+
};
87+
88+
function error(message) {
89+
if (message) {
90+
vscode.window.showErrorMessage(message);
91+
}
92+
};
93+
94+
/**
95+
* get configuration from environment
96+
*
97+
* @returns
98+
*/
99+
function getVsConfiguration() {
100+
return vscode.workspace.getConfiguration('server') || {};
101+
}
102+
103+
function getWorkPath(){
104+
return vscode.workspace.rootPath;
105+
}
106+
107+
module.exports = {
108+
Environment: Environment,
109+
getRootPath: getWorkPath,
110+
getEnvironmentConfiguration: getVsConfiguration,
111+
error: error,
112+
info: info
113+
};

extend/ajax.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
(function () {
2+
var READY_STATE_COMPLTETED = 4,
3+
RealXHRSend = XMLHttpRequest.prototype.send,
4+
RealXHROpen = XMLHttpRequest.prototype.open;
5+
var cache = [];
6+
7+
function isString(value) {
8+
return typeof value === 'string';
9+
}
10+
/**
11+
*
12+
* Open(string method,string url,boolean asynch,String username,string password)
13+
*/
14+
/**
15+
*
16+
*/
17+
XMLHttpRequest.prototype.open = function () {
18+
if (arguments.length >= 2 && isString(arguments[0]) && isString(arguments[1])) {
19+
cache.push({
20+
method: arguments[0],
21+
url: arguments[2]
22+
});
23+
}
24+
25+
RealXHROpen.apply(this, arguments);
26+
};
27+
28+
/**
29+
* Override send method
30+
*/
31+
XMLHttpRequest.prototype.send = function () {
32+
var item = cache.pop();
33+
if (!item.request && arguments.length) {
34+
item.request = arguments[0];
35+
}
36+
// fireCallbacks(requestCallbacks,this);
37+
if (this.addEventListener) {
38+
var self = this;
39+
this.addEventListener("readystatechange", function () {
40+
if (this.readyState === READY_STATE_COMPLTETED) {
41+
item.response = this.responseText;
42+
console.log(item);
43+
}
44+
// fireResponseCallbacksIfCompleted(self);
45+
}, false);
46+
} else {
47+
var realOnReadyStateChange = this.onreadystatechange;
48+
if (realOnReadyStateChange) {
49+
this.onreadystatechange = function () {
50+
realOnReadyStateChange();
51+
};
52+
}
53+
}
54+
55+
RealXHRSend.apply(this, arguments);
56+
};
57+
58+
})();

extend/websocket.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function () {
2+
var cache = [];
3+
sendMethod = WebSocket.prototype.send;
4+
WebSocket.prototype.send = function () {
5+
cache.push({
6+
url: this.url,
7+
request: arguments[0]
8+
});
9+
if (this.addEventListener) {
10+
this.addEventListener('message', function (e) {
11+
var item = cache.pop();
12+
if (!item.response && e && e.data) {
13+
item.response = e.data;
14+
}
15+
console.log(item);
16+
}, false);
17+
}
18+
19+
sendMethod.apply(this,arguments);
20+
}
21+
22+
})();

extension.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const vscode = require('vscode'),
2+
{
3+
Environment,
4+
info,
5+
error
6+
} = require('./environment'),
7+
Server = require('./server');
8+
9+
function activate(context) {
10+
let environment;
11+
const app = new Server();
12+
13+
context.subscriptions.push(vscode.commands.registerCommand('server.start', () => {
14+
if (!vscode.workspace.rootPath) {
15+
error('No folders are open')
16+
} else {
17+
environment = new Environment('DevelopmentServer');
18+
app.start(environment)
19+
.then(message => {
20+
if (message) {
21+
info(message);
22+
}
23+
}, error => {
24+
if (error && error.message) {
25+
environment.error(error.message);
26+
}
27+
});
28+
}
29+
}));
30+
31+
context.subscriptions.push(vscode.commands.registerCommand('server.stop', () => {
32+
app.stop()
33+
.then(message => {
34+
if (message) {
35+
environment.info(message);
36+
}
37+
}, error => {
38+
if (error && error.message) {
39+
environment.error(error.message);
40+
}
41+
})
42+
.then(() => {
43+
environment.dispose();
44+
environment = null;
45+
});
46+
}));
47+
48+
context.subscriptions.push(vscode.commands.registerCommand('server.openInBrowser', () => {
49+
if (app.server) {
50+
app.open();
51+
} else {
52+
utilis.error('Development server is not running');
53+
}
54+
}));
55+
}
56+
57+
exports.activate = activate;
58+
59+
// this method is called when your extension is deactivated
60+
function deactivate() {}
61+
exports.deactivate = deactivate;

0 commit comments

Comments
 (0)