-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
166 lines (146 loc) · 4.69 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// gulpfile.js
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var nodemon = require('gulp-nodemon');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
var stylus = require('gulp-stylus');
var uglifyCSS = require('gulp-uglifycss');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var bases = {
app: './src/',
dist: './dist/'
}
var path = {
app: 'app.js',
start: 'bin/www',
scripts: ['scripts/','scripts/**.js'],
stylus: ['styles/','styles/**.styl'],
routes: ['routes/','routes/**.js'],
views: ['views/','views/**.jade'],
js: ['public/js/','public/js/**.js'],
css: ['public/css/','public/css/**.css'],
bundle: 'public/js/bundle.js'
}
gulp.task('default', function () {
gutil.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
gutil.log('PLEASE USE:');
gutil.log('gulp dev - to start on development');
gutil.log('gulp pro - to start on production');
gutil.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
});
gulp.task('clean', function(){
return gulp.src(bases.dist)
.pipe(clean());
});
gulp.task('copy',['clean'], function(){
// Copy app.js
gulp.src(bases.app + path.app)
.pipe(gulp.dest(bases.dist));
gutil.log('Gulp copied app.js')
// Copy server
gulp.src(bases.app + path.start)
.pipe(gulp.dest(bases.dist + 'bin'));
gutil.log('Gulp copied server files')
// Copy routes
gulp.src(bases.app + path.routes[1])
.pipe(gulp.dest(bases.dist + path.routes[0]))
gutil.log('Gulp copied routes')
// Copy views
gulp.src(bases.app + path.views[1])
.pipe(gulp.dest(bases.dist + path.views[0]))
gutil.log('Gulp copied views')
});
gulp.task('js',['clean', 'copy'], function(){
// all scripts get browser- and uglyfied
return gulp.src(bases.app + path.scripts[1])
.pipe(concat('bundle.js'))
.pipe(gulp.dest(bases.dist + path.js[0]))
.on('end', function(){ gutil.log('Gulp piped scripts to bundle.js') });
});
gulp.task('jspublish', ['clean', 'copy', 'js'], function(){
// browserify resolves all requirements
return browserify(bases.dist + path.bundle)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(bases.dist + path.js[0]))
.on('end', function(){ gutil.log('Gulp\'s bundle.js got browserified') });
});
gulp.task('uglify', ['clean', 'copy', 'js', 'jspublish'], function(){
return gulp.src(bases.dist + path.bundle)
.pipe(uglify())
.pipe(gulp.dest(bases.dist + path.js[0]))
})
gulp.task('css',['clean', 'copy'], function(){
return gulp.src(bases.app + path.stylus[1])
.pipe(stylus())
.pipe(concat('style.css'))
.pipe(uglifyCSS())
.pipe(gulp.dest(bases.dist + path.css[0]))
.on('end', function(){ gutil.log('Gulp piped styles to style.css')});
})
gulp.task('pro', ['clean', 'copy', 'js', 'jspublish', 'css', 'uglify'], function(cb){
var started = false;
return nodemon({
script: bases.dist + path.start
}).on('start', function () {
// to avoid nodemon being started multiple times
if (!started) {
cb();
started = true;
}
gutil.log('Gulp started production server')
});
});
gulp.task('dev', ['scripts', 'styles', 'browserify', 'browser-sync']);
gulp.task('browser-sync', ['scripts', 'styles', 'browserify', 'nodemon'], function() {
browserSync.init(null, {
proxy: "http://localhost:5000",
browser: "google chrome",
port: 7000,
});
gulp.watch(bases.app + path.stylus[1], ['styles']);
gulp.watch(bases.app + path.scripts[1], ['scripts', 'browserify']);
gulp.watch('**/*.*').on('change', browserSync.reload);
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: bases.app + path.start
}).on('start', function () {
// to avoid nodemon being started multiple times
if (!started) {
cb();
started = true;
}
gutil.log('Gulp started development server')
});
});
gulp.task('scripts', function(){
// all scripts get browser- and uglyfied
return gulp.src(bases.app + path.scripts[1])
.pipe(concat('bundle.js'))
.pipe(gulp.dest(bases.app + path.js[0]))
.on('end', function(){ gutil.log('Gulp piped scripts to bundle.js') });
});
gulp.task('browserify', ['scripts'], function(){
// browserify resolves all requirements
return browserify(bases.app + path.bundle)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(bases.app + path.js[0]))
.on('end', function(){ gutil.log('Gulp\'s bundle.js got browserified') });
});
gulp.task('styles', function(){
// all styles get bundled and uglyfied
return gulp.src(bases.app + path.stylus[1])
.pipe(stylus())
.pipe(concat('style.css'))
.pipe(uglifyCSS())
.pipe(gulp.dest(bases.app + path.css[0]))
.on('end', function(){ gutil.log('Gulp piped styles to style.css')});
});