-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
135 lines (116 loc) · 2.94 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
var argv = require('minimist')(process.argv.slice(2));
var concat = require('gulp-concat');
var gulp = require('gulp');
var gulpif = require('gulp-if');
// Is the current build running on travis?
var onTravis = !!process.env.TRAVIS;
// The paths
var paths = {
src: {
cs: {
scss: 'src/css/cs/**/*.scss',
js: './src/js/cs/main.js'
},
loadFiles: './src/js/loadfiles/**/*.js'
},
dist: {
main: 'dist',
images: 'dist/uc_images'
}
};
// The file names
var names = {
dist: {
css: 'sis_cs.css',
js: 'sis_cs.js',
loadFiles: 'sis_loadfiles.js'
}
};
/**
* CSS Task
* - autoprefix
* - contact
* - sassify
*/
gulp.task('css', function() {
// Automatically add browser prefixes (e.g. -webkit) when necessary
var autoprefixer = require('gulp-autoprefixer');
// Convert the .scss files into .css
var sass = require('gulp-sass');
return gulp.src(paths.src.cs.scss)
.pipe(sass())
.pipe(autoprefixer({
cascade: false
}))
// Combine the files
.pipe(concat(names.dist.css))
// Output to the correct directory
.pipe(gulp.dest(paths.dist.main));
});
/**
* Run the CSS Linter on the CSS files
*/
gulp.task('css-lint', function() {
var scsslint = require('gulp-scss-lint');
return gulp.src(paths.src.cs.scss)
.pipe(scsslint())
// Only fail the build when running on Travis
.pipe(gulpif(onTravis, scsslint.failReporter()));
});
gulp.task('load-files', function() {
var uglify = require('gulp-uglify');
return gulp.src(paths.src.loadFiles)
// Combine the files
.pipe(concat(names.dist.loadFiles))
// Minify the file
.pipe(uglify())
// Output to the correct directory
.pipe(gulp.dest(paths.dist.main));
});
// Setup the JavaScript task
var gutil = require('gulp-util');
var browserify = require('browserify');
var watchify = require('watchify');
var bundler = browserify({
entries: paths.src.cs.js,
transform: 'brfs'
});
// Only watch when needed
if (argv.watch) {
var watcher = watchify(bundler);
watcher.on('update', bundleJs);
watcher.on('log', gutil.log);
}
/**
* Bundle the JavaScript
*/
function bundleJs() {
var source = require('vinyl-source-stream');
return bundler.bundle()
// Log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
// Name the output file
.pipe(source(names.dist.js))
// Output to the correct directory
.pipe(gulp.dest(paths.dist.main));
};
gulp.task('js', bundleJs);
/**
* Build Clean task
* Remove all the files generated by the build
*/
gulp.task('build-clean', function(callback) {
var del = require('del');
del(
[
paths.dist.main
], callback);
});
gulp.task('lint', ['css-lint']);
gulp.task('build', ['css', 'js', 'load-files']);
if (argv.watch) {
gulp.watch(paths.src.cs.scss, ['css']);
gulp.watch(paths.src.loadFiles, ['load-files']);
}
gulp.task('default', ['build-clean', 'build']);
gulp.task('prod', ['build-clean', 'build', 'lint']);