Skip to content

Commit 7655a6a

Browse files
committed
added CI build with beautify and linting
1 parent 83cff95 commit 7655a6a

File tree

7 files changed

+132
-47
lines changed

7 files changed

+132
-47
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*.js]
4+
indent_style=tab
5+
trim_trailing_whitespace=true

.eslintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"plugins": [
6+
"nodeca"
7+
],
8+
"rules": {
9+
"strict": 0,
10+
"camelcase": 0,
11+
"curly": 0,
12+
"indent": [0, "tab"],
13+
"nodeca/indent": [2, "tabs", 1],
14+
"eol-last": 2,
15+
"no-shadow": 0,
16+
"no-redeclare": 2,
17+
"no-extra-bind": 2,
18+
"no-empty": 0,
19+
"no-process-exit": 2,
20+
"no-underscore-dangle": 0,
21+
"no-use-before-define": 0,
22+
"no-unused-vars": 0,
23+
"consistent-return": 0,
24+
"no-inner-declarations": 2,
25+
"no-loop-func": 2,
26+
"space-before-function-paren": [2, "never"]
27+
}
28+
}

.jsbeautifyrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"js": {
3+
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
4+
"brace_style": "collapse",
5+
"break_chained_methods": false,
6+
"e4x": true,
7+
"eval_code": false,
8+
"end_with_newline": true,
9+
"indent_char": "\t",
10+
"indent_level": 0,
11+
"indent_size": 1,
12+
"indent_with_tabs": true,
13+
"jslint_happy": false,
14+
"jslint_happy_align_switch_case": true,
15+
"space_after_anon_function": false,
16+
"keep_array_indentation": false,
17+
"keep_function_indentation": false,
18+
"max_preserve_newlines": 2,
19+
"preserve_newlines": true,
20+
"space_before_conditional": false,
21+
"space_in_paren": false,
22+
"unescape_strings": false,
23+
"wrap_line_length": 0
24+
}
25+
}

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- node
5+
script: npm run travis

bin/webpack-dev-server.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,48 @@ var webpack = require("webpack");
1818

1919
var optimist = require("optimist")
2020

21-
.usage("webpack-dev-server " + require("../package.json").version + "\n" +
22-
"Usage: http://webpack.github.io/docs/webpack-dev-server.html")
21+
.usage("webpack-dev-server " + require("../package.json").version + "\n" +
22+
"Usage: http://webpack.github.io/docs/webpack-dev-server.html")
2323

24-
.boolean("lazy").describe("lazy")
24+
.boolean("lazy").describe("lazy")
2525

26-
.boolean("stdin").describe("stdin", "close when stdin ends")
26+
.boolean("stdin").describe("stdin", "close when stdin ends")
2727

28-
.boolean("info").describe("info").default("info", true)
28+
.boolean("info").describe("info").default("info", true)
2929

30-
.boolean("quiet").describe("quiet")
30+
.boolean("quiet").describe("quiet")
3131

32-
.boolean("inline").describe("inline", "Inline the webpack-dev-server logic into the bundle.")
32+
.boolean("inline").describe("inline", "Inline the webpack-dev-server logic into the bundle.")
3333

34-
.boolean("https").describe("https")
34+
.boolean("https").describe("https")
3535

36-
.string("key").describe("key", "Path to a SSL key.")
36+
.string("key").describe("key", "Path to a SSL key.")
3737

38-
.string("cert").describe("cert", "Path to a SSL certificate.")
38+
.string("cert").describe("cert", "Path to a SSL certificate.")
3939

40-
.string("cacert").describe("cacert", "Path to a SSL CA certificate.")
40+
.string("cacert").describe("cacert", "Path to a SSL CA certificate.")
4141

42-
.string("content-base").describe("content-base", "A directory or URL to serve HTML content from.")
42+
.string("content-base").describe("content-base", "A directory or URL to serve HTML content from.")
4343

44-
.string("content-base-target").describe("content-base-target", "Proxy requests to this target.")
44+
.string("content-base-target").describe("content-base-target", "Proxy requests to this target.")
4545

46-
.boolean("history-api-fallback").describe("history-api-fallback", "Fallback to /index.html for Single Page Applications.")
46+
.boolean("history-api-fallback").describe("history-api-fallback", "Fallback to /index.html for Single Page Applications.")
4747

48-
.boolean("compress").describe("compress", "enable gzip compression")
48+
.boolean("compress").describe("compress", "enable gzip compression")
4949

50-
.boolean("open").describe("open", "Open default browser")
50+
.boolean("open").describe("open", "Open default browser")
5151

52-
.describe("port", "The port").default("port", 8080)
52+
.describe("port", "The port").default("port", 8080)
5353

54-
55-
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");
54+
.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");
5655

5756
require("webpack/bin/config-optimist")(optimist);
5857

5958
var argv = optimist.argv;
6059

61-
var wpOpt = require("webpack/bin/convert-argv")(optimist, argv, { outputFilename: "/bundle.js" });
60+
var wpOpt = require("webpack/bin/convert-argv")(optimist, argv, {
61+
outputFilename: "/bundle.js"
62+
});
6263
var firstWpOpt = Array.isArray(wpOpt) ? wpOpt[0] : wpOpt;
6364

6465
var options = wpOpt.devServer || firstWpOpt.devServer || {};
@@ -106,7 +107,9 @@ if(argv["content-base"]) {
106107
else if(!/^(https?:)?\/\//.test(options.contentBase))
107108
options.contentBase = path.resolve(options.contentBase);
108109
} else if(argv["content-base-target"]) {
109-
options.contentBase = { target: argv["content-base-target"] };
110+
options.contentBase = {
111+
target: argv["content-base-target"]
112+
};
110113
} else if(!options.contentBase) {
111114
options.contentBase = process.cwd();
112115
}
@@ -186,6 +189,6 @@ new Server(webpack(wpOpt), options).listen(options.port, options.host, function(
186189
console.log("content is served from " + options.contentBase);
187190
if(options.historyApiFallback)
188191
console.log("404s will fallback to %s", options.historyApiFallback.index || "/index.html");
189-
if (options.open)
192+
if(options.open)
190193
open(uri);
191194
});

lib/Server.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Server(compiler, options) {
1515
// Default options
1616
if(!options) options = {};
1717

18-
if (options.lazy && !options.filename) {
18+
if(options.lazy && !options.filename) {
1919
throw new Error("'filename' option must be set in lazy mode.");
2020
}
2121

@@ -72,6 +72,7 @@ function Server(compiler, options) {
7272
res.write('<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>');
7373
var path = this.middleware.getFilenameFromUrl(options.publicPath || "/");
7474
var fs = this.middleware.fileSystem;
75+
7576
function writeDirectory(baseUrl, basePath) {
7677
var content = fs.readdirSync(basePath);
7778
res.write("<ul>");
@@ -111,14 +112,14 @@ function Server(compiler, options) {
111112

112113
var features = {
113114
compress: function() {
114-
if (options.compress) {
115+
if(options.compress) {
115116
// Enable gzip compression.
116117
app.use(compress());
117118
}
118-
}.bind(this),
119+
},
119120

120121
proxy: function() {
121-
if (options.proxy) {
122+
if(options.proxy) {
122123
/**
123124
* Assume a proxy configuration specified as:
124125
* proxy: 'a url'
@@ -139,17 +140,16 @@ function Server(compiler, options) {
139140
* 'context': 'target'
140141
* }
141142
*/
142-
if(!Array.isArray(options.proxy)) {
143-
options.proxy = Object.keys(options.proxy).map(function (context) {
143+
if(!Array.isArray(options.proxy)) {
144+
options.proxy = Object.keys(options.proxy).map(function(context) {
144145
var proxyOptions;
145146

146147
if(typeof options.proxy[context] === 'string') {
147148
proxyOptions = {
148149
context: context,
149150
target: options.proxy[target]
150151
};
151-
}
152-
else {
152+
} else {
153153
proxyOptions = options.proxy[context];
154154
proxyOptions.context = context;
155155
}
@@ -167,7 +167,7 @@ function Server(compiler, options) {
167167
* }
168168
* ]
169169
*/
170-
options.proxy.forEach(function (proxyConfig) {
170+
options.proxy.forEach(function(proxyConfig) {
171171
var context = proxyConfig.context || proxyConfig.path;
172172

173173
app.use(function(req, res, next) {
@@ -183,14 +183,14 @@ function Server(compiler, options) {
183183
}, httpProxyMiddleware(context, proxyConfig));
184184
});
185185
}
186-
}.bind(this),
186+
},
187187

188188
historyApiFallback: function() {
189-
if (options.historyApiFallback) {
189+
if(options.historyApiFallback) {
190190
// Fall back to /index.html if nothing else matches.
191191
app.use(historyApiFallback(typeof options.historyApiFallback === 'object' ? options.historyApiFallback : null));
192192
}
193-
}.bind(this),
193+
},
194194

195195
contentBase: function() {
196196
if(options.contentBase !== false) {
@@ -215,15 +215,15 @@ function Server(compiler, options) {
215215
'Location': contentBase + req.path + (req._parsedUrl.search || "")
216216
});
217217
res.end();
218-
}.bind(this));
218+
});
219219
} else if(typeof contentBase === "number") {
220220
// Redirect every request to the port contentBase
221221
app.get("*", function(req, res) {
222222
res.writeHead(302, {
223223
'Location': "//localhost:" + contentBase + req.path + (req._parsedUrl.search || "")
224224
});
225225
res.end();
226-
}.bind(this));
226+
});
227227
} else {
228228
// route content request
229229
app.get("*", express.static(contentBase), serveIndex(contentBase));
@@ -247,7 +247,7 @@ function Server(compiler, options) {
247247
setup: function() {
248248
if(typeof options.setup === "function")
249249
options.setup(app);
250-
}.bind(this)
250+
}
251251
};
252252

253253
var defaultFeatures = ["setup", "headers", "middleware"];
@@ -266,9 +266,9 @@ function Server(compiler, options) {
266266
features[feature]();
267267
}, this);
268268

269-
if (options.https) {
269+
if(options.https) {
270270
// for keep supporting CLI parameters
271-
if (typeof options.https === 'boolean') {
271+
if(typeof options.https === 'boolean') {
272272
options.https = {
273273
key: options.key,
274274
cert: options.cert,
@@ -307,7 +307,7 @@ Server.prototype.listen = function() {
307307
var sockServer = sockjs.createServer({
308308
// Limit useless logs
309309
log: function(severity, line) {
310-
if (severity === "error") {
310+
if(severity === "error") {
311311
console.log(line);
312312
}
313313
}
@@ -318,7 +318,7 @@ Server.prototype.listen = function() {
318318
// Remove the connection when it's closed
319319
conn.on("close", function() {
320320
var connIndex = this.sockets.indexOf(conn);
321-
if (connIndex >= 0) {
321+
if(connIndex >= 0) {
322322
this.sockets.splice(connIndex, 1);
323323
}
324324
}.bind(this));
@@ -344,7 +344,10 @@ Server.prototype.close = function() {
344344

345345
Server.prototype.sockWrite = function(sockets, type, data) {
346346
sockets.forEach(function(sock) {
347-
sock.write(JSON.stringify({type: type, data: data}));
347+
sock.write(JSON.stringify({
348+
type: type,
349+
data: data
350+
}));
348351
});
349352
}
350353

@@ -359,14 +362,22 @@ Server.prototype.serveMagicHtml = function(req, res, next) {
359362
res.write('.js');
360363
res.write(req._parsedUrl.search || "");
361364
res.end('"></script></body></html>');
362-
} catch(e) { return next(); }
365+
} catch(e) {
366+
return next();
367+
}
363368
}
364369

365370
// send stats to a socket or multiple sockets
366371
Server.prototype._sendStats = function(sockets, stats, force) {
367-
if(!force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every(function(asset) {
368-
return !asset.emitted;
369-
})) return this.sockWrite(sockets, "still-ok");
372+
if(!force &&
373+
stats &&
374+
(!stats.errors || stats.errors.length === 0) &&
375+
stats.assets &&
376+
stats.assets.every(function(asset) {
377+
return !asset.emitted;
378+
})
379+
)
380+
return this.sockWrite(sockets, "still-ok");
370381
this.sockWrite(sockets, "hash", stats.hash);
371382
if(stats.errors.length > 0)
372383
this.sockWrite(sockets, "errors", stats.errors);

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
"http-proxy-middleware": "~0.9.0"
2323
},
2424
"devDependencies": {
25+
"beautify-lint": "^1.0.4",
2526
"css-loader": "~0.23.0",
27+
"eslint": "^1.10.3",
28+
"eslint-plugin-nodeca": "^1.0.3",
2629
"file-loader": "~0.8.4",
2730
"jade": "^1.11.0",
2831
"jade-loader": "~0.8.0",
32+
"jsbeautify": "^0.3.6",
2933
"less": "^2.5.1",
3034
"less-loader": "~2.2.0",
3135
"style-loader": "~0.13.0",
@@ -47,6 +51,10 @@
4751
"ssl/"
4852
],
4953
"scripts": {
50-
"prepublish": "webpack ./client/live.js client/live.bundle.js --colors --config client/webpack.config.js -p && webpack ./client/index.js client/index.bundle.js --colors --config client/webpack.config.js -p"
54+
"prepublish": "webpack ./client/live.js client/live.bundle.js --colors --config client/webpack.config.js -p && webpack ./client/index.js client/index.bundle.js --colors --config client/webpack.config.js -p",
55+
"lint": "eslint lib test",
56+
"beautify-lint": "beautify-lint lib/**.js bin/**.js",
57+
"beautify": "beautify-rewrite lib/**.js bin/**.js",
58+
"travis": "npm run lint && npm run beautify-lint && node lib/Server.js"
5159
}
5260
}

0 commit comments

Comments
 (0)