-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
114 lines (100 loc) · 2.53 KB
/
gulpfile.babel.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
import autoprefixer from 'autoprefixer';
import browserSync from 'browser-sync';
import cleanCSS from 'gulp-clean-css';
import gulp from 'gulp';
import GulpRunner from 'gulp-run';
import minimist from 'minimist';
import sass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import postcss from 'gulp-postcss';
// parse command line options
// [--env dev (default) | prod]
const options = minimist(process.argv);
const env = options.env || 'dev';
// Environment-based configurations for CleanCss
// https://github.com/jakubpawlowicz/clean-css
const cleanCssConfig = {
dev: {
compatibility: '*',
level: 2,
format: 'beautify'
},
prod: {
compatibility: '*',
level: 2
}
};
/*
* gulp environment
* Prints the environment setting.
*/
export const environment = () => console.log(`${env}`);
/*
* gulp pretty
* Run Prettier to autoformat code.
*/
export const pretty = () => {
return GulpRunner('npm run pretty').exec();
};
/*
* gulp basic
* Compile the basic site
*/
gulp.task('basic', ['sass'], () => {
return GulpRunner('lsst-report-html').exec();
});
gulp.task('serve', ['sass', 'basic'], () => {
browserSync.init({
server: {
baseDir: 'test-sites/basic'
}
});
gulp.watch('scss/**/*.scss', ['sass']);
gulp.watch('uservice_nbreport/publish/templates/report-html/*.{css,jinja}', [
'browser-sync-reload'
]);
});
/*
* gulp sass
* Compile the sass
*/
const sassTask = () => {
let stream = gulp
.src('scss/app.scss')
// Initialize sourcemaps
.pipe(sourcemaps.init())
// Compile sass synchronously
.pipe(sass.sync().on('error', sass.logError))
// Autoprefix with default configs
.pipe(postcss([autoprefixer()]))
// Clean CSS
.pipe(cleanCSS(cleanCssConfig[env]));
if (env === 'dev') {
// Write out sourcemaps
stream.pipe(sourcemaps.write());
}
stream.pipe(gulp.dest('uservice_nbreport/publish/templates/report-html'));
stream.pipe(browserSync.stream());
return stream;
};
gulp.task('sass', sassTask);
/*
* gulp watch
* Watch for source changes and rebuild any assets
*/
const watchTask = () => {
gulp.watch('scss/*.scss', ['sass']);
};
gulp.task('watch', watchTask);
// Reload Browser Sync (synchronously)
// This task depends on the "basic" build task to make sure that the
// reload is always done *after* the site is compiled.
gulp.task('browser-sync-reload', ['basic'], done => {
browserSync.reload();
done();
});
/*
* gulp
* Default task that compiles assets and watches for additional changes.
*/
gulp.task('default', ['sass', 'watch']);