forked from democracy-os-climate/hello
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
executable file
·259 lines (218 loc) · 6.52 KB
/
gulpfile.babel.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// generated on 2015-10-20 using generator-gulp-webapp 1.0.3
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import ftp from 'vinyl-ftp' ;
import del from 'del';
import {stream as wiredep} from 'wiredep';
import pngcrush from 'imagemin-pngcrush' ;
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
import fs from 'fs';
let info = JSON.parse(fs.readFileSync('./package.json'));
import jade from 'jade';
import phpjade from 'phpjade';
phpjade.init(jade);
gulp.task('styles', () => {
return gulp.src('app/styles/*.scss')
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.'],
}).on('error', $.sass.logError))
.pipe($.autoprefixer({browsers: ['last 1 version']}))
.pipe($.sourcemaps.write())
.pipe(gulp.dest('.tmp/styles'))
.pipe(reload({stream: true}));
});
function lint(files, options) {
return () => {
return gulp.src(files)
.pipe(reload({stream: true, once: true}))
.pipe($.eslint(options))
.pipe($.eslint.format())
.pipe($.if(!browserSync.active, $.eslint.failAfterError()));
};
}
gulp.task('lint', lint('app/scripts/**/*.js'));
gulp.task('html', ['views', 'styles'], () => {
const assets = $.useref.assets({searchPath: ['.tmp', '.tmp/includes', 'app', '.']});
return gulp.src(['app/*.html', '.tmp/**/*.html', '.tmp/**/*.php'])
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
.pipe(assets.restore())
.pipe($.useref())
.pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
.pipe(gulp.dest('dist'));
});
gulp.task('views', () => {
return gulp.src(['app/**/*.jade', '!app/layouts/**'])
.pipe($.jade({
jade: jade,
usestrip: true,
pretty: true,
prefunction: function(input,options) {
return input.replace(/###/, 'hello');
}
}))
.pipe($.if('*.php.html', $.rename({ extname: '' })))
.pipe(gulp.dest('.tmp'))
.pipe(reload({stream: true}));
});
gulp.task('images', () => {
return gulp.src('app/images/**/*')
.pipe($.if($.if.isFile, $.cache($.imagemin({
progressive: true,
interlaced: true,
// don't remove IDs from SVGs, they are often used
// as hooks for embedding and styling
svgoPlugins: [{cleanupIDs: false}],
use: [pngcrush({reduce: true})],
}))
.on('error', (err) => {
console.log(err);
this.end();
})))
.pipe(gulp.dest('.tmp/images'))
.pipe(gulp.dest('dist/images'));
});
gulp.task('fonts', () => {
return gulp.src(require('main-bower-files')({
filter: '**/*.{eot,svg,ttf,woff,woff2}',
}).concat('app/fonts/**/*'))
.pipe(gulp.dest('.tmp/fonts'))
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('extras', () => {
return gulp.src([
'app/**/*',
'!app/{layouts,layouts/**}',
'!app/{images,images/**}',
'!app/{fonts,fonts/**}',
'!app/**/*.html',
'!app/**/*.scss',
'!app/**/*.jade',
], {
dot: true,
}).pipe(gulp.dest('dist'));
});
gulp.task('clean', del.bind(null, ['.tmp', 'dist']));
gulp.task('clean:modules', del.bind(null, ['bower_components', 'node_modules']));
gulp.task('clean:all', ['clean', 'clean:modules'], () => {
console.log('you need to run the following command before the next build :');
console.log('npm install && bower install');
});
gulp.task('serve', ['views', 'styles', 'fonts', 'images'], () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['.tmp', 'app'],
routes: {
'/bower_components': 'bower_components',
},
'index': 'mockup.html',
},
});
gulp.watch([
'app/*.html',
'.tmp/**/*.html',
'app/scripts/**/*.js',
'app/images/**/*',
'.tmp/fonts/**/*',
]).on('change', reload);
gulp.watch('app/**/*.jade', ['views']);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
});
gulp.task('serve:dist', () => {
browserSync({
notify: false,
port: 9000,
server: {
baseDir: ['dist'],
'index': 'mockup.html',
},
});
});
// inject bower components
gulp.task('wiredep', () => {
gulp.src('app/styles/*.scss')
.pipe(wiredep({
ignorePath: /^(\.\.\/)+/,
}))
.pipe(gulp.dest('app/styles'));
gulp.src(['app/layouts/*.jade'])
.pipe(wiredep({
exclude: ['jquery', 'bootstrap-sass', 'modernizr'],
ignorePath: /^(\.\.\/)*\.\./,
}))
.pipe(gulp.dest('app/layouts/'));
});
let config = JSON.parse(fs.readFileSync('./.deployrc'));
function getDeployStream(configSet){
if(!fs.statSync('./.deployrc').isFile()) {
throw new $.util.PluginError({
plugin: 'deploy',
message: '.deployrc config file not found'
});
} else {
return ftp.create( {
host: configSet.host,
port: configSet.port,
user: configSet.user,
password: configSet.password,
log: $.util.log
});
}
}
gulp.task( 'deploy:prod', ['build'], () => {
let conn = getDeployStream(config.prod) ;
return gulp.src( 'dist/**' ,{
base: 'dist',
buffer: false
}).pipe( conn.dest( config.prod.path ) );
}) ;
gulp.task( 'deploy:dev', ['build'], () => {
let conn = getDeployStream(config.dev) ;
return gulp.src( 'dist/**' ,{
base: 'dist',
buffer: false
}).pipe( conn.dest( config.dev.path ) );
}) ;
gulp.task( 'deploy:watch', () => {
let conn = getDeployStream(config.dev) ;
let up = (file,base) => {
return gulp.src( [file], { base: base, buffer: false } )
.pipe( conn.newer( config.dev.path ) ) // only upload newer files
.pipe( conn.dest( config.dev.path ) )
;
};
gulp.watch(['.tmp/**/*']).on('change', (event) => {
console.log('Changes detected! Uploading file "' + event.path + '", ' + event.type);
return up(event.path,'.tmp') ;
});
gulp.watch([
'app/**/*',
'!app/{layouts,layouts/**}',
'!app/{images,images/**}',
'!app/{fonts,fonts/**}',
'!app/**/*.html',
'!app/**/*.scss',
'!app/**/*.jade',
]).on('change', (event) => {
console.log('Changes detected! Uploading file "' + event.path + '", ' + event.type);
return up(event.path,'app') ;
});
}) ;
gulp.task('build', ['lint', 'html', 'images', 'fonts', 'extras'], () => {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('default', ['clean'], () => {
gulp.start('build');
});