Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
closes #228: browsersync
Browse files Browse the repository at this point in the history
  • Loading branch information
gruppjo committed Sep 3, 2015
1 parent 8ec3a39 commit 13c283a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 57 deletions.
20 changes: 18 additions & 2 deletions generators/app/templates/gulp/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
var gulp = require('gulp');
var path = require('path');
var paths = gulp.paths;
var options = gulp.options;
// plugins
var $ = require('gulp-load-plugins')();
// modules
var Server = require('karma').Server;
var bs = require('browser-sync');

// KARMA
function runKarma (singleRun, done) {
new Server({
configFile: path.join(__dirname, '/../karma.conf.js'),
Expand All @@ -26,6 +29,7 @@ gulp.task('karma:auto', ['linting'], function (done) {
runKarma(false, done);
});

// PROTRACTOR
// Downloads the selenium webdriver
var webdriverUpdate = 'webdriver_update';
var webdriverStandalone = 'webdriver_standalone';
Expand All @@ -42,9 +46,21 @@ function runProtractor (done) {
throw err;
})
.on('end', function () {
bs.exit();
done();
});
}

gulp.task('protractor', ['serve-no-open', 'linting', 'webdriver-update'], runProtractor);
gulp.task('protractor-build', ['serve-build-no-open', 'linting', 'webdriver-update'], runProtractor);
gulp.task('protractor', ['serve', 'linting', 'webdriver-update'], function (done) {
runProtractor(done);
});

var protractorBuildDeps = ['serve-build', 'webdriver-update'];
if (options.build !== false) {
protractorBuildDeps.push('build');
}
gulp.task('protractor-build', protractorBuildDeps, function (done) {
gulp.start('linting');

runProtractor(done);
});
92 changes: 43 additions & 49 deletions generators/app/templates/gulp/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,51 @@
var gulp = require('gulp');
var paths = gulp.paths;
var options = gulp.options;
// plugins
var $ = require('gulp-load-plugins')();
// modules
var http = require('http');
var connect = require('connect');
var opn = require('opn');
var serveStatic = require('serve-static');
var connectLiveReload = require('connect-livereload');
var bs = require('browser-sync').create();

var createConnectServer = function (paths) {
return function () {
var app = connect()
.use(connectLiveReload({port: 35729}));
for (var key in paths) {
app.use(serveStatic(paths[key]));
var bsInit = function (paths, openOverride) {
var bsOptions = {
server: {
baseDir: paths
}
http.createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
};
};

var open = function () {
if (options.open !== false) {
opn('http://localhost:9000');
if (options.open === false) {
bsOptions.open = false;
}
if (openOverride !== undefined) {
bsOptions.open = openOverride;
}
bs.init(bsOptions);
};

// WATCH
gulp.task('watch', ['serve', 'linting'], function () {
$.livereload.listen();
gulp.task('watch', ['inject-all'], function () {

gulp.watch([
'app/index.html',
'.tmp/*/styles/*.css', // each module's css
'app/*/assets/**/*'
].concat(paths.jsFiles)
.concat(paths.templates),
function (event) {
// browser sync server
bsInit(['app', '.tmp']);

var watchFiles = paths.jsFiles
.concat([
'app/index.html',
'.tmp/*/styles/*.css', // each module's css
'app/*/assets/**/*'
])
.concat(paths.templates);

// start linting and watching
gulp.start('linting');
gulp.watch(watchFiles, function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
if (event.type === 'changed') {
$.livereload.reload();
bs.reload();
gulp.start('linting');
}
else { // added or deleted
// inject in index (implicitly reloads)
gulp.start('inject-all');
}
});

// watch for changes in scss
gulp.watch('app/*/styles/**/*.scss', ['styles']);
// watch for changes in environment files and new config files
Expand All @@ -65,23 +58,24 @@ gulp.task('watch', ['serve', 'linting'], function () {
'app/*/constants/*config-const.js'
], ['environment']);
});
gulp.task('serve', ['connect', 'inject-all'], open);
gulp.task('serve-no-open', ['connect', 'inject-all']);
gulp.task('connect', createConnectServer(['app', '.tmp']));

// WATCH-BUILD
gulp.task('watch-build', ['serve-build'], function () {
$.livereload.listen();

gulp.watch(paths.dist + '/**/*', function () {
$.livereload.reload();
var watchBuildDeps = [];
if (options.build !== false) {
watchBuildDeps.push('build');
}
gulp.task('watch-build', watchBuildDeps, function () {
bsInit(paths.dist);
gulp.watch(paths.dist + '**/*', function () {
bs.reload();
});
});

var serveBuildDependencies = ['connect-build'];
if (options.build !== false) {
serveBuildDependencies.push('build');
}
gulp.task('serve-build', serveBuildDependencies, open);
gulp.task('serve-build-no-open', serveBuildDependencies);
gulp.task('connect-build', createConnectServer([paths.dist]));
// SERVE TASKS
gulp.task('serve', ['inject-all'], function () {
bsInit(['app', '.tmp'], false);
});
gulp.task('serve-build', ['build'], function () {
bsInit(['app', '.tmp'], false);
});

6 changes: 1 addition & 5 deletions generators/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"node": ">=0.10.0"
},
"devDependencies": {
"browser-sync": "^2.8.3",
"chalk": "^1.1.0",
"connect": "^3.4.0",
"connect-livereload": "^0.5.3",
"cordova": "5.2.0",
"del": "^2.0.0",
"elementtree": "^0.1.6",
Expand All @@ -22,7 +21,6 @@
"gulp-jscs": "^2.0.0",
"gulp-jshint": "^1.11.0",
"gulp-jsonlint": "^1.1.0",
"gulp-livereload": "^3.8.0",
"gulp-load-plugins": "^1.0.0-rc",
"gulp-minify-html": "^1.0.3",
"gulp-natural-sort": "^0.1.0",
Expand All @@ -45,12 +43,10 @@
"lodash": "^3.10.1",
"main-bower-files": "^2.9.0",
"minimist": "^1.2.0",
"opn": "^3.0.2",
"path": "^0.11.14",
"phantomjs": "^1.9.17",
"plist": "^1.1.0",
"require-dir": "^0.3.0",
"serve-static": "^1.10.0",
"vinyl-paths": "^2.0.0",
"wiredep": "^2.2.2",
"xml2js": "^0.4.9"
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports.config = {
'browserName': 'chrome'
},

baseUrl: 'http://localhost:9000',
baseUrl: 'http://localhost:3000',

// Spec patterns are relative to the current working directly when
// protractor is called.
Expand Down

0 comments on commit 13c283a

Please sign in to comment.