Skip to content

Commit ef5c20a

Browse files
committed
Merge pull request #5 from mattking17/gruntify
Gruntify
2 parents 6b5d457 + c98328e commit ef5c20a

File tree

29 files changed

+2993
-25219
lines changed

29 files changed

+2993
-25219
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Gruntfile.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
var sys = require('sys');
2+
module.exports = function(grunt) {
3+
grunt.initConfig({
4+
pkg: grunt.file.readJSON('package.json'),
5+
watch: {
6+
js: {
7+
files: [
8+
'src/**/*.js',
9+
'test/**/*.*'
10+
],
11+
tasks: ['test'],
12+
options: { nospawn: true }
13+
}
14+
},
15+
qunit:{
16+
target: {
17+
src: ['test/**/*.html']
18+
},
19+
options: {
20+
'--web-security' : false,
21+
'--local-to-remote-url-access' : true,
22+
'--ignore-ssl-errors' : true
23+
}
24+
},
25+
clean: {
26+
test: ['test/net.js']
27+
},
28+
requirejs: {
29+
compile: {
30+
options: {
31+
almond: true,
32+
baseUrl: "src",
33+
optimize: "uglify",
34+
out: "./dist/net.js",
35+
include: ["net"],
36+
wrap: {
37+
startFile: ["./build/start.frag", "./build/license.frag"],
38+
endFile: "./build/end.frag"
39+
}
40+
}
41+
},
42+
compileForTest: {
43+
options: {
44+
almond: true,
45+
baseUrl: "src",
46+
out: "./test/net.js",
47+
optimize: 'none',
48+
include: ["net"],
49+
wrap: {
50+
startFile: ["./build/start.frag"],
51+
endFile: "./build/end.frag"
52+
}
53+
}
54+
}
55+
},
56+
// configure jshint task
57+
jshint: {
58+
options: {
59+
asi: false,
60+
bitwise: false,
61+
boss: false,
62+
browser: true,
63+
couch: false,
64+
curly: true,
65+
debug: false,
66+
devel: false,
67+
eqeqeq: true,
68+
eqnull: false,
69+
evil: false,
70+
expr: false,
71+
forin: false,
72+
globalstrict: true,
73+
globals: { "define": true },
74+
immed: true,
75+
jquery: true,
76+
latedef: true,
77+
laxbreak: false,
78+
loopfunc: false,
79+
mootools: false,
80+
newcap: false,
81+
noarg: true,
82+
node: false,
83+
noempty: false,
84+
nonew: true,
85+
nonstandard: true,
86+
nomen: false,
87+
onevar: false,
88+
passfail: false,
89+
plusplus: false,
90+
prototypejs: false,
91+
regexdash: true,
92+
regexp: false,
93+
rhino: false,
94+
undef: true,
95+
shadow: true,
96+
strict: false,
97+
sub: true,
98+
supernew: false,
99+
trailing: true,
100+
white: false,
101+
wsh: false,
102+
indent: 2,
103+
smarttabs: true
104+
},
105+
target: {
106+
src: ['src/**/*.js']
107+
}
108+
},
109+
connect: {
110+
server: {
111+
options: {
112+
port: 8000,
113+
base: './test',
114+
middleware: function(connect, options, middlewares) {
115+
middlewares.push(function(req, res, next) {
116+
if (req.url === '/data/test-json' && req.method === 'GET') {
117+
res.setHeader('Content-Type', 'application/json');
118+
res.end(JSON.stringify({abc: 123}));
119+
return true;
120+
} else {
121+
return next();
122+
}
123+
});
124+
middlewares.push(function(req, res, next) {
125+
if (req.url === '/data/test-bad-json' && req.method === 'GET') {
126+
res.setHeader('Content-Type', 'application/json');
127+
res.end('lllll');
128+
return true;
129+
} else {
130+
return next();
131+
}
132+
});
133+
middlewares.push(function(req, res, next) {
134+
if (req.url === '/data/test-empty-json' && req.method === 'GET') {
135+
res.setHeader('Content-Type', 'application/json');
136+
res.end('');
137+
return true;
138+
} else {
139+
return next();
140+
}
141+
});
142+
middlewares.push(function(req, res, next) {
143+
if (req.url === '/test-post' && req.method === 'POST') {
144+
res.setHeader('Content-Type', 'application/json');
145+
res.end(JSON.stringify({abc: 123}));
146+
return true;
147+
} else {
148+
return next();
149+
}
150+
});
151+
middlewares.push(function(req, res, next) {
152+
if (req.url === '/data/test' && req.method === 'GET') {
153+
res.end("Hi There");
154+
return true;
155+
} else {
156+
return next();
157+
}
158+
});
159+
middlewares.push(function(req, res, next) {
160+
if (req.url === '/data/test/weird-status' && req.method === 'GET') {
161+
res.statusCode = 444;
162+
res.end("Hi There");
163+
return true;
164+
} else {
165+
return next();
166+
}
167+
});
168+
middlewares.push(function(req, res, next) {
169+
if (req.url === '/data/test/server-error' && req.method === 'GET') {
170+
res.statusCode = 500;
171+
res.end("Hi There");
172+
return true;
173+
} else {
174+
return next();
175+
}
176+
});
177+
return middlewares;
178+
}
179+
}
180+
}
181+
}
182+
});
183+
184+
grunt.loadNpmTasks('grunt-contrib-connect');
185+
grunt.loadNpmTasks('grunt-requirejs');
186+
grunt.loadNpmTasks('grunt-contrib-jshint');
187+
grunt.loadNpmTasks('grunt-contrib-qunit');
188+
grunt.loadNpmTasks('grunt-contrib-watch');
189+
grunt.loadNpmTasks('grunt-contrib-clean');
190+
191+
grunt.registerTask('test', ['jshint', 'requirejs:compile', 'requirejs:compileForTest', 'qunit', 'clean']);
192+
grunt.registerTask('build', ['connect', 'jshint', 'requirejs:compile', 'qunit']);
193+
grunt.registerTask('default', ['connect', 'watch']);
194+
};

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ success function and fail function.
5454
// successful response
5555
},
5656
function(req) {
57-
// successful response
57+
// error response
5858
}
5959
);
6060

@@ -71,7 +71,7 @@ successive function will get back the data return from the previous set.
7171
return myObject;
7272
},
7373
function(req) {
74-
// successful response
74+
// error response
7575
}
7676
).then(
7777
function(myObject) {

0 commit comments

Comments
 (0)