-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
118 lines (107 loc) · 3.31 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Load Gulp and your plugins
var gulp = require('gulp');
var connect = require('gulp-connect');
var stylus = require('gulp-stylus');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var notify = require('gulp-notify');
var shell = require('child_process');
// Define paths
var paths = {
tests : 'tests/bdd/js/tests/*.js',
dist : './public',
html : '**/*.html',
css : 'src/stylus/**/*',
js : 'src/js/**/*.js'
};
// Connect task
gulp.task('connect', function() {
connect.server({
root: [ __dirname + '/' ],
port: 9001,
livereload: true
});
});
// HTML task
gulp.task('html', function() {
gulp.src( paths.html )
.pipe( connect.reload() );
});
// JS task
gulp.task('js', function() {
gulp.src([
'src/js/modules/**/*.js',
'src/js/models/**/*.js',
'src/js/controllers/**/*.js',
'src/js/app.js'
])
.pipe( jshint() )
.pipe( jshint.reporter( 'default' ) )
.pipe( concat( 'main.js' ) )
.pipe( uglify() )
.pipe( gulp.dest( paths.dist + '/js' ) )
.pipe( notify( 'JS OK!' ) )
.pipe( connect.reload() );
});
// Stylus task
gulp.task('stylus', function() {
gulp.src( 'src/stylus/*.styl' )
.pipe( plumber() )
.pipe(
stylus({
use: [ 'nib' ],
set: [ 'compress' ]
})
)
.pipe( gulp.dest( paths.dist + '/css' ) )
.pipe( notify( 'CSS OK!' ) )
.pipe( connect.reload() );
});
// TDD (Mocha)
gulp.task('tdd', function() {
gulp.src( paths.tests )
.pipe( plumber() )
.pipe( mocha({ reporter : 'spec' }) )
.pipe( notify( 'Tests OK!' ) );
});
// Watch task
gulp.task('watch', function() {
// gulp.watch( paths.tests, ['tdd'] );
gulp.watch( paths.css, ['stylus'] );
gulp.watch( paths.html, ['html'] );
var jsWatcher = gulp.watch( [ paths.js, paths.tests ], ['js'] );
jsWatcher.on('change', function(e) {
var filename = e.path.split('/').pop();
var bars = '\n================================================';
console.log('%s\n \u2192 File: %s was %s, runing tasks...%s', bars, filename, e.type, bars);
});
});
gulp.task( 'deploy', function(done) {
console.log( 'Deploying...' );
var ghPagesRegex = /gh-pages/;
var actualBranchRegex = /^\*\s(\w+)/m;
shell.exec( 'git branch', function(stdin, stdout, stderr) {
console.log( 'Exec git branch to get actual branch' );
var createGhPages = 'git checkout -b gh-pages';
var actualBranch = stdout.match( actualBranchRegex )[1];
if( ghPagesRegex.test( stdout ) )
createGhPages = 'git checkout gh-pages';
console.log( 'Now, deploy to gh-pages' );
shell.exec([
createGhPages,
'git merge ' + actualBranch,
'git push origin gh-pages',
'git checkout ' + actualBranch
].join( '&&' ), function(stdin, stdout, stderr) {
console.log(stdout);
console.log( 'Done!' );
done();
});
});
});
// Server task
gulp.task( 'server', ['connect', 'watch'] );
gulp.task( 'default', [ 'server' ] );