-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
183 lines (161 loc) · 5.85 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
172
173
174
175
176
177
178
179
180
181
182
183
// packages installed
var gulp = require('gulp'),
fs = require('fs'),
gulpif = require('gulp-if'), // condtionally run task
plumber = require('gulp-plumber'), // prevent pipe breaking
browserSync = require('browser-sync').create(),
bower = require('gulp-bower'), // gulp bower
concat = require('gulp-concat'), // concat files
cssmin = require('gulp-minify-css'), // minify css
rename = require('gulp-rename'), // rename file
runSequence = require('run-sequence').use(gulp), // runs gulp tasks in order
sass = require('gulp-sass'), //css preprocesser
uglify = require('gulp-uglify'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('autoprefixer'), // minify js
requireDir = require('require-dir'),// allows me to use another directory for gulp tasks
del= require ('del'); // delete
// Using project_pages_tasks to store seperate tasks that are apart of my build out
requireDir('./project_pages_tasks', {recurese:true});
// Accessing config.json to get paths to files
function setVars () {
// config.json file
configFile = 'config.json';
// parse strings from config.json to object
configJSON = JSON.parse(fs.readFileSync(configFile));
// Accessing paths object in config.json
paths = configJSON.paths;
// how long error message will pop up
errorTimeout = 1000;
}
// call setVars
setVars();
// Tasks
// bower
gulp.task('bower',function(){
// runs bower install
return bower();
});
// install bower, run build and start browser-sync
gulp.task('install', function(){
// runSequence waits for one task to complete then b4 moving to the next task.
// notice here `install` makes a callback to the `bower` function
runSequence('bower','install');
});
// start up browserSync
gulp.task('sync',function(){
// start browserSync
browserSync.init({
// Accessing paths.destination obj in config.json which contains html
server: paths.main_dest.html
});
});
var notify = require('gulp-notify');
var beep = require('beepbeep');
// error handeler function
var onError = function(err){
notify.onError({
title: "Task Error",
message: "<%= error.message %>",
sound: "Sosumi"
})(err);
this.emit('end');
};
// watch main page js files
gulp.watch(paths.watcher_main.js_main,['js_main_task']);
// watch main page scss file
// comment out when not running main
gulp.watch(paths.watcher_main.styles_main,['styles_main_task']);
// project 2 styles
gulp.watch(paths.watcher_projects.watcher_proj11.styles_proj11,['proj11_styles']);
// watch main page html
gulp.watch(paths.watcher_main.html,['reload']);
// reload browser on html or script adjustment
gulp.task('reload', function(){
browserSync.reload();
});
// Scripts Main Task
gulp.task('js_main_task',function(){
return gulp.src(paths.source.main_page_source.js_main)
.pipe(plumber({errorHandler: onError}))
// plumber finds errors in stream and
// notifys me in terminal
.pipe(concat('site.js')) // concating js files to main.js
.pipe(gulp.dest(paths.main_dest.js_main)) // save in dest
.pipe(uglify()) // minify js
.pipe(rename({ // rename with file with .min
suffix:'.min'
}))
.pipe(gulp.dest(paths.main_dest.js_main))
.pipe(notify({ message: 'js_main task finished'})),
browserSync.reload();
});
// Particle
gulp.task('particles_task', function(){
return gulp.src(paths.source.particles.js)
.pipe(plumber({errorHandler: onError}))
// plumber finds errors in stream and
// notifys me in terminal
.pipe(gulp.dest(paths.particles_dest.js_particles)) // save in dest
.pipe(uglify()) // minify js
.pipe(rename({ // rename with file with .min
suffix:'.min'
}))
.pipe(gulp.dest(paths.main_dest.js_main))
.pipe(notify({ message: 'particle task finished'})),
browserSync.reload();
});
// Styles Main
gulp.task('styles_main_task',function(){
return gulp.src(paths.source.main_page_source.styles_main)
.pipe(plumber({
// plumber finds errors in stream
errorHandler: onError}))
.pipe(sourcemaps.init()) // source maps
.pipe(postcss([ autoprefixer({ browsers: ['> 1%','last 2 versions'] }) ]))
.pipe(sass())
.pipe(gulp.dest(paths.main_dest.styles_main))
.pipe(cssmin()) // min css
.pipe(rename({ // rename file to site.min.css
suffix:'.min'
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.main_dest.styles_main))
.pipe(notify({ message: 'styles_main_task finished' }))
// .pipe(browserSync.stream({match:'**/*.css'}));
.pipe(browserSync.stream());
});
// Project Styles Task Injection
// Change paths to desired project when working on css for that project
// paths.source.project_pgs_src.proj_#.styles_proj#
gulp.task('proj11_styles',function(){
// source to project 11 scss
return gulp.src(paths.source.project_pgs_src.proj_11.styles_proj11)
.pipe(plumber({
// plumber finds errors in stream
errorHandler: onError}))
.pipe(sourcemaps.init()) // source maps
.pipe(sass())
.pipe(gulp.dest(paths.project_pages_dest.proj11_dest.styles_proj11))
.pipe(cssmin()) // min css
.pipe(rename({ // rename file to site.min.css
suffix:'.min'
}))
// destination for compiled css for project 11
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.project_pages_dest.proj11_dest.styles_proj11))
.pipe(notify({ message: 'proj11_styles task finished' }))
.pipe(browserSync.stream());
});
//default task
gulp.task('main',function(){
// call runSequence to make sure our tasks are
// perfromed in the correct order
runSequence('js_main_task','styles_main_task','sync');
});
gulp.task('project_styles',function(){
// call runSequence to make sure our tasks are
// assign project page #
runSequence('proj11_styles','sync');
});