Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
121 lines (108 loc) 路 5.31 KB
/
Copy pathgulpfile.js
File metadata and controls
121 lines (108 loc) 路 5.31 KB
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
"use strict";
var gulp = require('gulp');
const terser = require('gulp-uglify');
const sass = require('gulp-sass')(require('sass'));
const flatten = require('gulp-flatten');
const autoprefixer = require('autoprefixer')
const postcss = require('gulp-postcss')
const sourcemaps = require('gulp-sourcemaps');
const browsersync = require('browser-sync').create();
const { exec } = require("child_process");
const spawn = require('child_process').spawn;
const cssnano = require('cssnano');
const con = require('gulp-concat');
const gulpif = require('gulp-if');
// Inline sourcemaps made the built stylesheets about 5x larger, so only the watch tasks (local development) keep them
let devBuild = false;
function fonts(done) {
return gulp.src('node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.*', { encoding: false })
.pipe(gulp.dest('pipeline/built_assets/fonts'))
.pipe(browsersync.stream());
}
function styles(done) {
const bs_select = ["tom-select.bootstrap5.css"]
const fullcalendar = ["skeleton.css", "theme.css", "palette.css"]
return gulp.src(['pipeline/source_assets/scss/**/*.scss',
'node_modules/fullcalendar/skeleton.css',
'node_modules/fullcalendar/themes/classic/theme.css',
'node_modules/fullcalendar/themes/classic/palette.css',
'node_modules/tom-select/dist/css/tom-select.bootstrap5.css',
'node_modules/easymde/dist/easymde.min.css'
])
.pipe(gulpif(devBuild, sourcemaps.init()))
// Bootstrap 4's SCSS can only be consumed via @import (its partials share global variables),
// so that one deprecation stays silenced until we move to a Sass-module-aware framework.
// quietDeps hides the remaining deprecations raised inside third-party stylesheets.
.pipe(sass({
loadPaths: ['.'],
quietDeps: true,
silenceDeprecations: ['import'],
}).on('error', sass.logError))
.pipe(gulpif(function(file) { return bs_select.includes(file.relative);}, con('selects.css')))
.pipe(gulpif(function(file) { return file.path.includes('node_modules/fullcalendar/') && fullcalendar.includes(file.relative);}, con('main.css')))
.pipe(postcss([ autoprefixer(), cssnano() ]))
.pipe(gulpif(devBuild, sourcemaps.write()))
.pipe(gulp.dest('pipeline/built_assets/css'))
.pipe(browsersync.stream());
}
function scripts() {
const dest = 'pipeline/built_assets/js';
const base_scripts = ["src.js", "konami.js"];
const bs_select = ["tom-select.complete.js", "autocompleter.js"]
const interaction = ["html5sortable.min.js", "interaction.js"]
return gulp.src([/* Bootstrap bundle includes Popper */
'node_modules/bootstrap/dist/js/bootstrap.bundle.js',
'node_modules/html5sortable/dist/html5sortable.min.js',
'node_modules/clipboard/dist/clipboard.min.js',
'node_modules/moment/moment.js',
'node_modules/fullcalendar/all/global.js',
'node_modules/fullcalendar/themes/classic/global.js',
'node_modules/tom-select/dist/js/tom-select.complete.js',
'node_modules/easymde/dist/easymde.min.js',
'node_modules/konami/konami.js',
// With its source map, which the minified file points to and collectstatic insists on finding
'node_modules/chart.js/dist/chart.umd.min.js',
'node_modules/chart.js/dist/chart.umd.min.js.map',
'pipeline/source_assets/js/**/*.js',])
.pipe(gulpif(function(file) { return base_scripts.includes(file.relative);}, con('base.js')))
.pipe(gulpif(function(file) { return bs_select.includes(file.relative);}, con('selects.js')))
.pipe(gulpif(function(file) { return interaction.includes(file.relative);}, con('interaction.js')))
.pipe(gulpif(function(file) { return file.path.includes('node_modules/fullcalendar/');}, con('main.js')))
.pipe(gulpif(function(file) { return ["bootstrap.bundle.js", "helpers.js"].includes(file.relative);}, con('jpop.js')))
.pipe(flatten())
// Only minify if filename does not already denote it as minified
.pipe(gulpif(function(file) { return file.path.indexOf("min") === -1;},terser()))
.pipe(gulp.dest(dest))
.pipe(browsersync.stream());
}
function browserSync(done) {
spawn('python', ['manage.py', 'runserver'], {stdio: 'inherit'});
browsersync.init({
notify: true,
open: false,
port: 8001,
proxy: '127.0.0.1:8000'
});
done();
}
function browserSyncReload(done) {
browsersync.reload();
done();
}
function watchFiles() {
gulp.watch("pipeline/source_assets/scss/**/*.scss", styles);
gulp.watch("pipeline/source_assets/js/**/*.js", scripts);
gulp.watch("**/templates/*.html", browserSyncReload);
}
// Rebuild the bundles when the sources change (used by the `assets` service in compose.override.yml)
function watchSources() {
gulp.watch("pipeline/source_assets/scss/**/*.scss", styles);
gulp.watch("pipeline/source_assets/js/**/*.js", scripts);
}
exports.build = gulp.parallel(styles, scripts, fonts);
exports.watch = gulp.parallel(watchFiles, browserSync);
function enableSourcemaps(done) {
devBuild = true;
done();
}
exports.watchAssets = gulp.series(enableSourcemaps, exports.build, watchSources);