forked from helsingborg-stad/api-event-manager-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·217 lines (192 loc) · 7.11 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
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
//
// GULPFILE.JS - Reactified
// Author: Nikolas Ramstedt ([email protected])
//
// Commands:
// "gulp" - Build and watch task combined
// "gulp build" - Build assets
// "gulp watch" - Watch for file changes and build changed files
//
const gulp = require('gulp');
const sass = require('gulp-sass');
const terser = require('gulp-terser');
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const plumber = require('gulp-plumber');
const rev = require('gulp-rev');
const revDel = require('rev-del');
const runSequence = require('run-sequence');
const sourcemaps = require('gulp-sourcemaps');
const notifier = require('node-notifier');
const del = require('del');
const eslint = require('gulp-eslint');
const streamify = require('gulp-streamify');
//Dependecies required to compile ES6 Scripts
const browserify = require('browserify');
const reactify = require('reactify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const babelify = require('babelify');
const es = require('event-stream');
//Dependecies required to compile non React script
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const jshint = require('gulp-jshint');
// ==========================================================================
// Default Task
// ==========================================================================
gulp.task('default', function(callback) {
runSequence('build', 'watch', callback);
});
// ==========================================================================
// Build Tasks
// ==========================================================================
gulp.task('build', function(callback) {
runSequence('clean:dist', ['sass', 'scripts', 'img'], 'revision', callback);
});
gulp.task('build:sass', function(callback) {
runSequence('sass', 'revision', callback);
});
gulp.task('build:scripts', function(callback) {
runSequence('scripts', 'revision', callback);
});
// ==========================================================================
// Watch Task
// ==========================================================================
gulp.task('watch', function() {
gulp.watch(['source/js/**/*.js', 'source/js/**/*.jsx'], ['build:scripts']);
gulp.watch('source/sass/**/*.scss', ['build:sass']);
gulp.watch('source/img/**/*.*', ['build:img']);
});
// ==========================================================================
// SASS Task
// ==========================================================================
gulp.task('sass', function() {
var filePath = 'source/sass/';
var files = ['event-manager-integration.scss', 'event-manager-integration-admin.scss'];
var tasks = files.map(function(entry) {
return gulp
.src(filePath + entry)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(
sass().on('error', function(err) {
console.log(err.message);
notifier.notify({
title: 'SASS Compile Error',
message: err.message,
});
})
)
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/css'))
.pipe(cleanCSS({ debug: true }))
.pipe(gulp.dest('dist/.tmp/css'));
});
return es.merge.apply(null, tasks);
});
// ==========================================================================
// Scripts Task
// ==========================================================================
gulp.task('scripts', function() {
gulp.src(['source/js/admin/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(
jshint.reporter('fail').on('error', function(err) {
this.pipe(jshint.reporter('default'));
notifier.notify({
title: 'JS Compile Error',
message: err.message,
});
})
)
.pipe(concat('event-integration-admin.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/js'))
.pipe(
uglify().on('error', function(err) {
return;
})
)
.pipe(gulp.dest('dist/.tmp/js'));
gulp.src(['source/js/front/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(jshint())
.pipe(
jshint.reporter('fail').on('error', function(err) {
this.pipe(jshint.reporter('default'));
notifier.notify({
title: 'JS Compile Error',
message: err.message,
});
})
)
.pipe(concat('event-integration-front.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/js'))
.pipe(
uglify().on('error', function(err) {
return;
})
)
.pipe(gulp.dest('dist/.tmp/js'));
var filePath = 'source/js/';
var files = ['Module/Event/Index.js'];
var tasks = files.map(function(entry) {
return (
browserify({
entries: [filePath + entry],
debug: true,
})
.transform([babelify])
.bundle()
.on('error', function(err) {
console.log(err.message);
notifier.notify({
title: 'Compile Error',
message: err.message,
});
this.emit('end');
})
.pipe(source(entry)) // Converts To Vinyl Stream
.pipe(buffer()) // Converts Vinyl Stream To Vinyl Buffer
// Gulp Plugins Here!
.pipe(sourcemaps.init())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/js'))
.pipe(terser())
.pipe(gulp.dest('dist/.tmp/js'))
);
});
return es.merge.apply(null, tasks);
});
// ==========================================================================
// Images
// ==========================================================================
var filePath = 'source/img/*.*';
gulp.task('img', function() {
gulp.src(filePath).pipe(gulp.dest('dist/img'));
});
// ==========================================================================
// Revision Task
// ==========================================================================
gulp.task('revision', function() {
return gulp
.src(['./dist/.tmp/**/*'])
.pipe(rev())
.pipe(gulp.dest('./dist'))
.pipe(rev.manifest('rev-manifest.json', { merge: true }))
.pipe(revDel({ dest: './dist' }))
.pipe(gulp.dest('./dist'));
});
// ==========================================================================
// Clean Task
// ==========================================================================
gulp.task('clean:dist', function() {
return del.sync('dist');
});