forked from tbranyen/backbone-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 'reload' task, along with node server support, Issue tbranyen#10
- Loading branch information
Showing
5 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Reload Task Client script | ||
* | ||
* Created by webxl | ||
* Date: 1/11/12 | ||
* | ||
*/ | ||
|
||
$(function() { | ||
|
||
var reloader = function Reloader() { | ||
|
||
var url = 'ws://localhost:8000'; | ||
|
||
return { | ||
isSocketConnected:function () { | ||
return this.socket && this.socket.readyState === WebSocket.OPEN; | ||
}, | ||
connect:function () { | ||
if (this.isSocketConnected()) { | ||
return; | ||
} | ||
if (this.connectTimeout) { | ||
clearTimeout(this.connectTimeout); | ||
} | ||
this.socket = new WebSocket(url); | ||
|
||
this.socket.onmessage = function (msg) { | ||
this.close(); | ||
window.document.location.reload(); | ||
} | ||
// Todo: reconnect support | ||
} | ||
}; | ||
|
||
}(); | ||
|
||
setTimeout(function() { reloader.connect(); }, 3000); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// ============================================================================ | ||
// TASKS | ||
// ============================================================================ | ||
|
||
task.registerBasicTask("reload", "Reload connected clients.", function (data, name) { | ||
// Minify CSS. | ||
var errorcount = fail.errorcount; | ||
var files = file.expand(data); | ||
file.write(name, task.helper('reload', files)); | ||
|
||
// Fail task if there were errors. | ||
if (fail.errorcount > errorcount) { | ||
return false; | ||
} | ||
|
||
// Otherwise, print a success message. | ||
log.writeln("File \"" + name + "\" created."); | ||
}); | ||
|
||
// ============================================================================ | ||
// HELPERS | ||
// ============================================================================ | ||
|
||
task.registerHelper("reload", function (files) { | ||
var http = require('http'); | ||
|
||
var fileData = JSON.stringify(files); | ||
|
||
var options = { | ||
host:'localhost', | ||
port:8000, | ||
method:'POST', | ||
path:'/reload', | ||
headers:{ | ||
'Content-Type':'application/x-www-form-urlencoded', | ||
'Content-Length':fileData.length | ||
} | ||
}; | ||
|
||
var post_req = http.request(options, | ||
function (proxyResponse) {}).on('error', function (e) { | ||
console.log("Got error: " + e.message); | ||
}); | ||
|
||
post_req.write(fileData); | ||
post_req.end(); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters