-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
143 lines (119 loc) · 4.05 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
//var imageop = require('gulp-image-optimization');
//var clean = require('gulp-clean');
var asciify = require('asciify');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var gutil = require('gulp-util');
var serverPort = 8085;
// dirs prefix
var sourcesRoot = 'src/';
var develRoot = '_devel/';
var distRoot = '_dist/';
var workingRoot = develRoot;
var releasing = false;
// files configuration
var FILES = {
sassToStart: sourcesRoot + 'css/style.scss',
sassToWatch: sourcesRoot + 'css/**/*.scss',
js: sourcesRoot + 'js/*',
thirdPartyToBundle: sourcesRoot + 'js/third-party/*.js',
thirdPartyProvided: sourcesRoot + 'js/provided/*.js',
images: sourcesRoot + 'img/**',
html: sourcesRoot + '*.html',
copy: [
sourcesRoot + '**/*.woff',
sourcesRoot + '**/*.ttf',
sourcesRoot + '**/*.woff2',
sourcesRoot + '**/*.eot',
sourcesRoot + '**/*.mp4',
sourcesRoot + '**/*.swf'
]
};
//Sass task se sourcemaps, prefixerem a minifikaci
gulp.task('sass', function () {
return gulp.src(FILES.sassToStart)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({ style: 'expanded' }).on('error', sass.logError))
.pipe(autoprefixer('last 2 version'))
.pipe(cleanCSS())
.pipe(sourcemaps.write())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(workingRoot + 'css'))
.pipe(connect.reload());
});
// Devel tasks
gulp.task('server', function() {
connect.server({
livereload: true,
root: [workingRoot],
port: serverPort
});
});
//js stejne jako third-party se sourcemaps a uglify
gulp.task('js', function() {
gulp.src([FILES.js, '!'+sourcesRoot + 'js/provided', '!'+sourcesRoot + 'js/third-party'])
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(workingRoot + 'js'))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(workingRoot + 'js'))
.pipe(connect.reload());
});
gulp.task('html', function(){
gulp.src(FILES.html, { base: '' })
.pipe(gulp.dest(workingRoot)).pipe(connect.reload())
;
});
gulp.task('copy', function(){
gulp.src(FILES.copy, { base: '' })
.pipe(gulp.dest(workingRoot)).pipe(connect.reload())
;
});
gulp.task('third-party', function() {
gulp.src(FILES.thirdPartyToBundle)
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(uglify())
.pipe(rename('third-party.min.js'))
.pipe(gulp.dest(workingRoot + 'js/third-party'))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(workingRoot + 'js/third-party'))
.pipe(connect.reload());
gulp.src(FILES.thirdPartyProvided, { base: '' })
.pipe(gulp.dest(workingRoot+"/js/provided")).pipe(connect.reload())
});
// watch for dev server
gulp.task('watch', function () {
gulp.watch(FILES.sassToWatch, ['sass']);
gulp.watch(FILES.js, ['js']);
//gulp.watch(FILES.images, ['images']);
gulp.watch(FILES.html, ['html']);
gulp.watch(FILES.copy, ['copy']);
});
gulp.task('devel', ['server', 'sass', 'js', 'third-party', 'html', 'copy', 'watch'], function() {
asciify('Watching changes', {color:'yellow', font: 'smshadow'}, function(err, res){ console.log(res); });
});
gulp.task('configure-release', function() {
workingRoot = distRoot;
releasing = true;
});
gulp.task('release', ['configure-release', 'sass', 'js', 'third-party', 'copy', 'html'], function() {
asciify('Releasing', {color:'yellow', font: 'smshadow'}, function(err, res){ console.log(res); });
});
gulp.task('default', function() {
gutil.log('\n\n\n' + 'Usage: gulp ' + gutil.colors.red('<command>') + '\n'
+ '\n' + 'Where ' + gutil.colors.red('<command>') + 'if one of:' + '\n'
+ '\t ' + gutil.colors.green('devel') + ' - start server on port: ' + serverPort + ' and live reload your changes' + '\n'
+ '\t ' + gutil.colors.green('release') + ' - builds and copies to ' + distRoot
);
});