-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (90 loc) · 2.7 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
'use strict';
const gulp = require('gulp'),
fs = require('fs'),
del = require('del'),
inject = require('gulp-inject-string'),
htmlValidator = require('gulp-w3c-html-validator'),
embedTemplates = require('gulp-angular-embed-templates'),
sourcemaps = require('gulp-sourcemaps'),
useref = require('gulp-useref'),
lazypipe = require('lazypipe'),
gulpif = require('gulp-if'),
terser = require('gulp-terser'),
minifyCss = require('gulp-clean-css'),
npmDist = require('gulp-npm-dist'),
livereload = require('gulp-livereload');
/**
* Config
*/
const googleAnalyticsSnippetFile = '.ga-snip.html';
const rootDest = './dist';
const watchAllSrc = './src/**/*.{html,php,css,pl,cgi,js}';
const paths = {
htdocs: {
src: './src/**/*.{html,php,pl,cgi}',
dest: './dist/**/*.{html,php,pl,cgi}',
opts: { }
},
js: {
src: './src/**/*.js',
dest: './dist/**/*.js',
opts: { }
},
css: {
src: './src/**/*.{css}',
dest: './dist/**/*.{css}',
opts: { }
}
};
var gaSnippet = "";
if( fs.existsSync( googleAnalyticsSnippetFile ) ){
gaSnippet = fs.readFileSync(googleAnalyticsSnippetFile, 'utf8');
}
/**
* Task Streams
*/
gulp.task('clean', function(){
return del(rootDest);
});
gulp.task('clean:postbuild', function(){
return del(rootDest + '/views');
});
gulp.task('build', function(){
return gulp.src(paths.htdocs.src)
.pipe(gulpif('index.html', inject.replace('<!-- gulp-inject-google-analytics -->', gaSnippet )))
.pipe(useref({}, lazypipe().pipe(sourcemaps.init, { loadMaps: true })))
.pipe(gulpif('blackjack.min.js', embedTemplates()))
.pipe(gulpif('*.js', terser()))
.pipe(gulpif('*.css', minifyCss()))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest(rootDest));
});
// Excludes sourcemaps
gulp.task('build-prod', function(){
return gulp.src(paths.htdocs.src)
.pipe(useref())
.pipe(gulpif('*.js', embedTemplates()))
.pipe(gulpif('*.js', terser()))
.pipe(gulpif('*.css', minifyCss()))
.pipe(gulp.dest(rootDest));
});
gulp.task('validate-html', function() {
//return gulp.src(paths.htdocs.src)
// views fail... and won't ever pass..
return gulp.src('src/index.html')
.pipe(htmlValidator())
.pipe(htmlValidator.reporter());
});
// Copy dependencies to ./dest/resources
gulp.task('copy:libs', function() {
return gulp.src(npmDist(), {base:'./node_modules'})
.pipe(gulp.dest(rootDest + '/resources'));
});
gulp.task('copy:devlibs', function() {
return gulp.src(npmDist({copyUnminified: true}), {base:'./node_modules'})
.pipe(gulp.dest( './src' + '/resources'));
});
/**
* Default task
*/
gulp.task('default', gulp.series('clean','validate-html','copy:devlibs','build','clean:postbuild'));