-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
135 lines (116 loc) · 3.96 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
/**
* gulpfile.js
* Based heavily on "Getting started with gulp" by Mark Goodyear
*
* @link https://markgoodyear.com/2014/01/getting-started-with-gulp/
*/
//Required NPM modules
var fs = require('fs'),
gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
notify = require("gulp-notify"),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
del = require('del'),
livereload = require('gulp-livereload'),
sassOpt = {
errLogToConsole: true,
outputStyle: 'expanded'
},
jsFiles = [
'src/scripts/libs/Chart.js',
'src/scripts/libs/angular.js',
'src/scripts/libs/angular-animate.js',
'src/scripts/envelope.js',
'src/scripts/web-audio-components.js',
'src/scripts/app.js'
];
//Sass task. Compiles and auto prefixes sass files
gulp.task('styles', function() {
return gulp.src('src/styles/sass/main.scss')
.pipe(sass(sassOpt).on('error', sass.logError))
//Set auto prefixer to look back 2 versions
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
//Save this file to the css director
.pipe(gulp.dest('public/css'))
//Append min to file name
.pipe(rename({suffix: '.min'}))
//Minify the file
.pipe(minifycss())
//Save the minified file
.pipe(gulp.dest('public/css'))
//Notification of completed task
.pipe(notify({ message: 'Sass task complete' }));
});
//Javascript task. Concentrates the files and minifies them
gulp.task('javascript', function() {
return gulp.src(jsFiles)
//Checks for jshintrc (jsHint config file)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
//Concentrates javascript files into app.js
.pipe(concat('app.js'))
//Saves concat file
.pipe(gulp.dest('public/js'))
//Appeds .min to name of files
.pipe(rename({suffix: '.min'}))
//Minifys the file
.pipe(uglify())
//Saves file into dist file directory
.pipe(gulp.dest('public/js'))
//Notification of completed task
.pipe(notify({ message: 'Javascript task complete' }));
});
gulp.task('move-html', function() {
gulp.src('src/**/*.html')
.pipe(gulp.dest('public'))
.pipe(notify({ message: '.html files moved', onLast: true }));
});
gulp.task('move-svg', function() {
gulp.src('src/svg/**/*')
.pipe(gulp.dest('public/svg'))
.pipe(notify({ message: '.svgs moved', onLast: true }));
});
gulp.task('move-fonts', function() {
gulp.src('src/fonts/**/*.{ttf,woff,woff2,eot,svg}')
.pipe(gulp.dest('public/fonts'))
.pipe(notify({ message: 'Fonts moved', onLast: true }));
});
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('public/images'))
.pipe(notify({ message: 'Images optimised', onLast: true }));
});
gulp.task('clean', function() {
return Promise.all([
del(['public/*'])
]);
});
//Main gulp task that runs each indvidual task.
gulp.task('default',['clean'], function() {
gulp.start('styles', 'javascript', 'images', 'move-html', 'move-svg', 'move-fonts');
});
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('src/styles/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('src/scripts/**/*.js', ['javascript']);
// Watch .js && update docs
// gulp.watch('src/scripts/**/*.js', ['javascript', 'docs']);
// Watch image files
gulp.watch('src/images/**/*', ['images']);
// Watch html files
gulp.watch('src/**/*.html', ['move-html']);
// Watch for new svg or fonts
gulp.watch('src/svg/**/*', ['move-svg']);
gulp.watch('src/fonts/**/*', ['move-fonts']);
livereload.listen();
gulp.watch(['public/**']).on('change', livereload.changed);
});