-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathgulpfile.js
110 lines (96 loc) · 3.28 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var header = require('gulp-header');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var connect = require('gulp-connect');
var zip = require('gulp-zip');
var del = require('del');
var paths = {
html: '*.html',
sass: 'client/sass/**/*.scss',
scripts: ['client/js/**/*.js', '!client/external/**/*.js'],
jslib: ['client/jslib/**/*.js'],
images: 'client/img/**/*'
};
var timestamp = function() {
var curDate = new Date();
var Year = curDate.getFullYear().toString().slice(-2);
var Month = ('0' + (curDate.getMonth() + 1)).slice(-2);
var Day = ('0' + curDate.getDate()).slice(-2);
var Hours = ("0" + curDate.getHours()).slice(-2);
var Minutes = ("0" + curDate.getMinutes()).slice(-2);
return FullDate = Year + Month + Day + Hours + Minutes;
};
var pkg = require('./package.json');
var banner = ['/**',
' * @Author - <%= pkg.author %>',
' * @version - ' + timestamp(),
' */',
''].join('\n');
// Not all tasks need to use streams
// A gulpfile is just another node program and you can use any package available on npm
gulp.task('clean', function(cb) {
// You can use multiple globbing patterns as you would with `gulp.src`
del(['build/js','build/css'], cb);
});
var html = function() {
return gulp.src(paths.html)
.pipe(connect.reload());
};
gulp.task('html-watch', html);
var css = function() {
return gulp.src(paths.sass)
//.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}))
//.pipe(sourcemaps.write())
.pipe(header(banner, { pkg : pkg }))
.pipe(gulp.dest('build/css'))
.pipe(connect.reload());
};
gulp.task('css', ['clean'], css);
gulp.task('css-watch', css);
var scripts = function() {
return gulp.src(paths.scripts)
//.pipe(sourcemaps.init())
//.pipe(coffee())
.pipe(uglify())
.pipe(concat('app.min.js'))
//.pipe(sourcemaps.write())
.pipe(header(banner, { pkg : pkg }))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload());
};
gulp.task('scripts', ['clean'], scripts);
gulp.task('scripts-watch', scripts);
var jslibrary = function() {
return gulp.src(paths.jslib)
.pipe(uglify())
.pipe(concat('lib.min.js'))
.pipe(header(banner, { pkg : pkg }))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload());
};
gulp.task('jslibrary', ['clean'], jslibrary);
gulp.task('jslibrary-watch', jslibrary);
// Rerun the task when a file changes
gulp.task('connect', function () {
connect.server({
port: 8090,
livereload: true
});
});
gulp.task('watch', function() {
gulp.watch(paths.html, ['html-watch']);
gulp.watch(paths.sass, ['css-watch']);
gulp.watch(paths.scripts, ['scripts-watch']);
gulp.watch(paths.jslib, ['jslibrary-watch']);
});
gulp.task('zip', function(){
return gulp.src('build/**')
.pipe(zip('app_'+ timestamp() +'.zip'))
.pipe(gulp.dest('zip'));
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['connect','watch', 'css', 'scripts', 'jslibrary']);