1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-27 21:05:53 +00:00

Moved the development server into the gulpfile and added it to the "gulp watch" command for easier development. Updated readme to reflect changes.

This commit is contained in:
SirStendec 2015-02-08 04:06:56 -05:00
parent 19f7c5669e
commit 5e286098d1
4 changed files with 66 additions and 61 deletions

View file

@ -24,16 +24,14 @@ files for changes and re-build automatically with ```gulp watch```
FrankerFaceZ comes with a local development server that listens on port 8000
and it serves up local development copies of files, falling back to the CDN
when a local copy of a file isn't present. To start the server,
run ```npm test```
run ```gulp server```
For convenience, the server is run automatically along with ```gulp watch```
At this time, you will also need to use the included version of the Chrome
extension. Remove any existing copy of FrankerFaceZ from your browser and load
the unpacked extension in the ```Chrome Extension``` folder.
Once you're using that extension, use the command ```/ffz developer_mode on```
or ```/ffz developer_mode off``` in Twitch chat to toggle developer mode on or
off. You must then refresh the page for changes to take effect. If FFZ is not
working or the command otherwise fails to work, you can open the JavaScript
console on twitch.tv and run ```localStorage.ffzDebugMode = true;``` or
Use the command ```/ffz developer_mode on``` or ```/ffz developer_mode off```
in Twitch chat to toggle developer mode on or off. You must then refresh the
page for changes to take effect. If FFZ is not working or the command otherwise
fails to work, you can open the JavaScript console on twitch.tv and run
```localStorage.ffzDebugMode = true;``` or
```localStorage.ffzDebugMode = false;``` to enable or disable the feature.

View file

@ -1,3 +1,4 @@
// Dependencies
var fs = require('fs'),
gulp = require('gulp'),
browserify = require('gulp-browserify'),
@ -9,6 +10,16 @@ var fs = require('fs'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');
// Server Dependencies
var http = require("http"),
path = require("path"),
request = require("request"),
url = require("url");
var server_version = "0.1.1";
// Tasks
gulp.task('clean', function() {
return gulp.src('build', {read:false})
@ -33,8 +44,54 @@ gulp.task('scripts', ['prepare'], function() {
.on('error', util.log);
});
gulp.task('watch', ['default'], function() {
gulp.task('watch', ['default', 'server'], function() {
gulp.watch('src/**/*', ['default']);
});
gulp.task('default', ['scripts']);
// Server
gulp.task('server', function() {
http.createServer(function(req, res) {
var uri = url.parse(req.url).pathname,
lpath = path.join(uri).split(path.sep);
if ( uri == "/dev_server" ) {
util.log("[" + util.colors.cyan("HTTP") + "] " + util.colors.green("200") + " GET " + util.colors.magenta(uri));
res.writeHead(200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"});
return res.end(JSON.stringify({path: process.cwd(), version: server_version}));
}
if ( ! lpath[0] )
lpath.shift();
if ( lpath[0] == "script" )
lpath.shift();
else
lpath.splice(0, 0, "cdn");
var file = path.join(process.cwd(), lpath.join(path.sep));
fs.exists(file, function(exists) {
if ( ! exists ) {
util.log("[" + util.colors.cyan("HTTP") + "] " + util.colors.bold.blue("CDN") + " GET " + util.colors.magenta(uri));
return request.get("http://cdn.frankerfacez.com/" + uri).pipe(res);
}
if ( fs.lstatSync(file).isDirectory() ) {
util.log("[" + util.colors.cyan("HTTP") + "] " + util.colors.red("403") + " GET " + util.colors.magenta(uri));
res.writeHead(403, {"Access-Control-Allow-Origin": "*"});
res.write('403 Forbidden');
return res.end();
}
util.log("[" + util.colors.cyan("HTTP") + "] " + util.colors.green("200") + " GET " + util.colors.magenta(uri));
res.writeHead(200, {"Access-Control-Allow-Origin": "*"});
fs.createReadStream(file).pipe(res);
});
}).listen(8000);
util.log("[" + util.colors.cyan("HTTP") + "] Listening on Port: " + util.colors.magenta("8000"));
});

View file

@ -18,9 +18,6 @@
"gulp-util": "^3.0.2",
"request": "^2.51.0"
},
"scripts": {
"test": "node test/server.js"
},
"repository": {
"type": "git",
"url": "https://bitbucket.org/stendec/frankerfacez.git"

View file

@ -1,47 +0,0 @@
var version = "0.1.0";
var fs = require("fs"),
http = require("http"),
path = require("path"),
request = require("request"),
url = require("url");
http.createServer(function(req, res) {
var uri = url.parse(req.url).pathname,
lpath = path.join(uri).split(path.sep);
if ( uri == "/dev_server" ) {
console.log("[200] GET " + uri);
res.writeHead(200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"});
return res.end(JSON.stringify({path: process.cwd(), version: version}));
}
if ( ! lpath[0] )
lpath.shift();
if ( lpath[0] == "script" )
lpath.shift();
else
lpath.splice(0, 0, "cdn");
var file = path.join(process.cwd(), lpath.join(path.sep));
fs.exists(file, function(exists) {
if ( ! exists ) {
console.log("[CDN] GET " + uri);
return request.get("http://cdn.frankerfacez.com/" + uri).pipe(res);
}
if ( fs.lstatSync(file).isDirectory() ) {
console.log("[403] GET " + uri);
res.writeHead(403, {"Access-Control-Allow-Origin": "*"});
res.write('403 Forbidden');
return res.end();
}
console.log("[200] GET " + uri);
res.writeHead(200, {"Access-Control-Allow-Origin": "*"});
fs.createReadStream(file).pipe(res);
});
}).listen(8000);