-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
105 lines (88 loc) · 2.72 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
'use strict';
const gulp = require( 'gulp' );
const sass = require( 'gulp-sass' );
const browserSync = require( 'browser-sync' );
const browserify = require( 'browserify' );
const source = require( 'vinyl-source-stream' );
const imagemin = require('gulp-imagemin');
const cache = require('gulp-cache');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const srcPaths = {
jsPath: [ 'public/**/*.js', '!public/third-party.js' ],
thirdPartyJsPath: 'public/third-party.js',
compsPath: 'public/components/**/*',
imagesPath: 'public/images/**',
stylesPath: 'public/styles/**/*.scss'
};
const distPaths = {
root: 'dist/',
scriptsPath: 'dist/scripts',
compsPath: 'dist/components',
imagesPath: 'dist/images',
stylesPath: 'dist/styles',
htmlPath: 'dist/index.html'
}
gulp.task( 'serve', () => {
browserSync.init( {
open: false,
proxy: "localhost:8080"
} );
gulp.watch( srcPaths.jsPath, [ 'concatScripts', browserSync.reload ] );
gulp.watch( srcPaths.thirdPartyJsPath, [ 'compileThirdParty', browserSync.reload ] );
gulp.watch( srcPaths.imagesPath, [ 'imageMin' ] );
gulp.watch( srcPaths.stylesPath, [ 'sassCompile' ] );
gulp.watch( srcPaths.compsPath, ['copyComponents', browserSync.reload ] );
gulp.watch( distPaths.htmlPath, [ browserSync.reload ] );
});
gulp.task( 'concatScripts', () => {
return gulp.src( srcPaths.jsPath )
.pipe( concat( 'main.js' ) )
.pipe( gulp.dest( distPaths.scriptsPath ) )
});
gulp.task( 'compileThirdParty', () => {
return browserify( srcPaths.thirdPartyJsPath )
.bundle()
.pipe( source( 'third-party.js' ) )
.pipe( gulp.dest( distPaths.scriptsPath ) );
});
gulp.task( 'sassCompile', () => {
return gulp.src( srcPaths.stylesPath )
.pipe(sass().on('error', sass.logError))
.pipe( gulp.dest( distPaths.stylesPath ) )
.pipe( browserSync.stream() );
});
gulp.task('imageMin', () => {
gulp.src( srcPaths.imagesPath )
.pipe( cache(
imagemin ( {
optimizationLevel: 3,
progressive: true,
interlaced: true
} ) ) )
.pipe( gulp.dest( distPaths.imagesPath ) );
});
gulp.task( 'copyComponents', () => {
return gulp.src( srcPaths.compsPath )
.pipe( gulp.dest( distPaths.compsPath ) );
});
gulp.task( 'default', [ 'serve' ] );
gulp.task( 'pre-test', () => {
const testFiles = [
'app/**/*.js',
'!app/server.js',
'!app/routes/*.js',
'!app/db/*.js',
'!app/config.js'
];
return gulp.src( testFiles )
.pipe( istanbul( { includeUntested: true } ) )
.pipe( istanbul.hookRequire() );
});
gulp.task( 'test', [ 'pre-test' ], () => {
return gulp.src('test/**/*.js')
.pipe( mocha() )
.pipe( istanbul.writeReports() );
});