From a1bfbb8f868829d5190d8a2ec7d5ecdb19031984 Mon Sep 17 00:00:00 2001 From: vrde Date: Mon, 8 Jun 2015 15:24:58 +0200 Subject: [PATCH] [wip] add server to serve app --- gulpfile.js | 38 ++++++++++++--------- index.html | 4 +-- js/app.js | 2 +- js/components/ascribe_media/media_player.js | 4 +-- js/components/header.js | 2 +- package.json | 9 +++-- sass/ascribe-fonts/ascribe-fonts.scss | 12 +++---- server.js | 18 ++++++++++ 8 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 server.js diff --git a/gulpfile.js b/gulpfile.js index 6e5697bb..b4a1af04 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -15,6 +15,9 @@ var sass = require('gulp-sass'); var concat = require('gulp-concat'); var _ = require('lodash'); var eslint = require('gulp-eslint'); +var argv = require('yargs').argv; +var server = require('./server.js').app; + var config = { bootstrapDir: './node_modules/bootstrap-sass' @@ -23,17 +26,20 @@ var config = { gulp.task('build', function() { bundle(false); }); - -gulp.task('serve', ['browser-sync', 'lint:watch', 'sass', 'sass:watch', 'copy'], function() { + +gulp.task('serve', ['browser-sync', 'run-server', 'lint:watch', 'sass', 'sass:watch', 'copy'], function() { bundle(true); }); +gulp.task('run-server', function() { + server.listen(4000); +}); + gulp.task('browser-sync', function() { browserSync({ - server: { - baseDir: "." - }, - port: process.env.PORT || 3000 + files: ['build/css/*.css', 'build/js/*.js'], + proxy: 'http://localhost:4000', + port: 3000 }); }); @@ -47,7 +53,7 @@ gulp.task('sass', function () { }).on('error', sass.logError)) .pipe(sourcemaps.write('./maps')) .pipe(gulp.dest('./build/css')) - .pipe(browserSync.stream());; + .pipe(browserSync.stream()); }); gulp.task('sass:watch', function () { @@ -55,13 +61,13 @@ gulp.task('sass:watch', function () { }); gulp.task('copy', function () { - var files = [ + var staticAssets = [ './fonts/**/*', './img/**/*' ]; - gulp.src(files, {base: './'}) - .pipe(gulp.dest('build')); + gulp.src(staticAssets, {base: './'}) + .pipe(gulp.dest('./build')); gulp.src(config.bootstrapDir + '/assets/fonts/**/*') .pipe(gulp.dest('./build/fonts')); @@ -86,7 +92,7 @@ gulp.task('lint:watch', function () { function bundle(watch) { var bro; - + if (watch) { bro = watchify(browserify('./js/app.js', // Assigning debug to have sourcemaps @@ -101,11 +107,11 @@ function bundle(watch) { debug: true }); } - + bro.transform(babelify.configure({ compact: false })); - + function rebundle(bundler, watch) { return bundler.bundle() .on('error', notify.onError('Error: <%= error.message %>')) @@ -115,9 +121,9 @@ function bundle(watch) { loadMaps: true })) // loads map from browserify file .pipe(sourcemaps.write()) // writes .map file - .pipe(gulp.dest('./build')) + .pipe(gulp.dest('./build/js')) .pipe(browserSync.stream()); } - + return rebundle(bro); -} \ No newline at end of file +} diff --git a/index.html b/index.html index 320dfa89..5a80b431 100644 --- a/index.html +++ b/index.html @@ -6,11 +6,11 @@ ascribe - +
- + diff --git a/js/app.js b/js/app.js index ca2df1c6..e3fc3229 100644 --- a/js/app.js +++ b/js/app.js @@ -47,7 +47,7 @@ fetch.defaults({ } }); -Router.run(routes, Router.HashLocation, (AscribeApp) => { +Router.run(routes, Router.HistoryLocation, (AscribeApp) => { React.render( , document.getElementById('main') diff --git a/js/components/ascribe_media/media_player.js b/js/components/ascribe_media/media_player.js index 55188568..b0002de0 100644 --- a/js/components/ascribe_media/media_player.js +++ b/js/components/ascribe_media/media_player.js @@ -46,8 +46,8 @@ let Image = React.createClass({ this.inject('http://code.jquery.com/jquery-2.1.4.min.js') .then(() => Promise.all([ - this.inject('node_modules/shmui/shmui.css'), - this.inject('node_modules/shmui/jquery.shmui.js') + this.inject('/static/thirdparty/shmui/shmui.css'), + this.inject('/static/thirdparty/shmui/jquery.shmui.js') ]).then(() => { window.jQuery('.shmui-ascribe').shmui(); })); }, diff --git a/js/components/header.js b/js/components/header.js index d46dd4b2..3df56afb 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -38,7 +38,7 @@ let Header = React.createClass({ return (