-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
executable file
·171 lines (132 loc) · 3.88 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
167
168
169
170
171
var gulp = require('gulp') ;
var browserSync = require('browser-sync');
var inlinesource = require('gulp-inline-source');
var prompt = require('gulp-prompt');
var url = require('url-regexp');
var plugins = require('gulp-load-plugins')();
var cssFiles = [
'node_modules/font-awesome/css/font-awesome.min.css'
] ;
var fontFiles = [
'node_modules/bootstrap/dist/fonts/*',
'node_modules/font-awesome/fonts/*'
] ;
var jsFiles = [
'node_modules/jquery/dist/jquery.js',
'node_modules/jquery/dist/jquery.min.map',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/imagesloaded/imagesloaded.pkgd.js',
'node_modules/holderjs/holder.js'
] ;
var jsLibFiles = [
'js/lib/jquery.js',
'js/lib/bootstrap.js',
'js/lib/ie10-viewport-bug-workaround.js',
'js/lib/imagesloaded.pkgd.js',
'js/lib/jquery.balancetext.js',
'js/lib/jquery.slabtext.js'
] ;
var distFiles = [
'css/**/*.min.css',
'css/**/*.map',
'js/**/*.min.js',
'js/**/*.map',
'fonts/*',
'img/**/*',
'*.html',
'screenshot*.png',
'sitemap.xml'
] ;
gulp.task('copy-css', function(){
return gulp.src(cssFiles)
.pipe(gulp.dest('css')) ;
}) ;
gulp.task('copy-js', function(){
return gulp.src(jsFiles)
.pipe(gulp.dest('js/lib')) ;
}) ;
gulp.task('copy-fonts', function(){
return gulp.src(fontFiles)
.pipe(gulp.dest('fonts')) ;
}) ;
gulp.task('js', function () {
return gulp.src(['js/*.js', '!js/*.min.js','!js/phantom.js'])
.pipe(plugins.uglify())
.pipe(plugins.rename({ extname: '.min.js' }))
.pipe(gulp.dest('js'));
});
gulp.task('bundle-js',['copy-js'], function(){
return gulp.src(jsLibFiles)
.pipe(plugins.uglify())
.pipe(plugins.concat('bundle.min.js'))
.pipe(gulp.dest('js/lib')) ;
} ) ;
gulp.task('less', function() {
return gulp.src(['less/*.less','!less/*.inc.less'])
.pipe(plugins.less())
.pipe(gulp.dest('css'))
.pipe(plugins.autoprefixer({ cascade: false }))
.pipe(plugins.minifyCss())
.pipe(plugins.rename({ extname: '.min.css' }))
.pipe(gulp.dest('css'));
});
gulp.task('sitemap', function () {
return gulp.src('*.html')
.pipe(prompt.prompt({
type: 'input',
name: 'url',
message: 'Enter site URL for sitemap.xml :',
default: 'http://www.democracyos.eu',
validate: function(siteUrl){
if (!siteUrl || !/[^\s]+/.test(siteUrl)) {
siteUrl = 'http://www.democracyos.eu' ;
}
if(!url.validate(siteUrl)){
return 'This is not a valid URL : ' + siteUrl ;
}
return true;
}
}, function(res){
//value is in res.url
console.log('actual sitemap : ' + res.url) ;
return gulp.src('*.html')
.pipe(plugins.sitemap({
siteUrl: res.url
}))
.pipe(gulp.dest('.'));
}));
});
gulp.task('phantom', function(){
return gulp.src('js/phantom.js')
.pipe(plugins.phantom())
.pipe(gulp.dest('.'));
});
gulp.task('build', ['copy-css','copy-fonts','bundle-js','js','less']);
gulp.task('seo', ['sitemap'] , function () {
gulp.src('img/**/*.@(jpg|jpeg|gif|png)')
.pipe(plugins.image())
.pipe(gulp.dest('img'));
gulp.src(['*.html','!*.min.html'])
.pipe(inlinesource())
.pipe(plugins.rename({ extname: '.min.html' }))
.pipe(gulp.dest('.'));
});
gulp.task('dist', ['build'], function(){
return gulp.src(distFiles)
.pipe(plugins.copy('dist')) ;
});
gulp.task('less-reload', ['less'], browserSync.reload );
gulp.task('js-reload', ['js'], browserSync.reload );
gulp.task('live', ['build'], function() {
browserSync({
server: './'
});
gulp.watch('less/*.less', ['less-reload']);
gulp.watch(['js/*.js','!js/*.min.js'], ['js-reload']);
gulp.watch('*.html').on('change', browserSync.reload);
});
gulp.task('watch', ['build'], function() {
gulp.watch('less/*.less', ['less']);
gulp.watch(['js/*.js','!js/*.min.js'], ['js']);
});
gulp.task('default', ['build']);