-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
67 lines (60 loc) · 2.22 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
const { src, dest, parallel } = require('gulp')
const concat = require('gulp-concat')
const iife = require('gulp-iife')
const insert = require('gulp-insert')
const rename = require('gulp-rename')
const sass = require('gulp-sass')(require('sass'))
const uglify = require('gulp-uglify')
// silence deprecation warnings due to old gulp plugins
const process = require('process')
process.removeAllListeners('warning')
const settings = {
dest: 'build',
src: {
additionalhtml: ['additionalhtml/*.js'],
head: ['additionalhtmlhead/*.js'],
mobile: ['mobile-css/index.scss']
}
}
function moodleMobile() {
return src(settings.src.mobile, { sourcemaps: false })
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(rename('mobile.css'))
.pipe(dest(settings.dest))
}
function addlhtml() {
return src(settings.src.additionalhtml)
.pipe(concat('footer.js'))
.pipe(iife())
.pipe(uglify())
.pipe(insert.prepend(`<script async src="https://www.googletagmanager.com/gtag/js?id=G-9KK2VCY0TM"></script><script>\n// minified ${new Date().toLocaleString()} - see https://github.com/cca/moodle-styles\n`))
.pipe(insert.append('\n</script>'))
.pipe(dest(settings.dest))
}
// same as above but no GTM script & don't minify
function addlhtmlDev() {
return src(settings.src.additionalhtml)
.pipe(concat('footer.js'))
.pipe(iife())
.pipe(insert.prepend(`<script>\n// updated ${new Date().toLocaleString()} - see https://github.com/cca/moodle-styles\n`))
.pipe(insert.append('\n</script>'))
.pipe(dest(settings.dest))
}
// defunct since we have no additionalhtmlhead js anymore
function head() {
return src(settings.src.head)
.pipe(concat('head.js'))
.pipe(iife())
.pipe(uglify())
.pipe(insert.prepend(`<script>\n// minified ${new Date().toLocaleString()} - see https://github.com/cca/moodle-styles\n`))
.pipe(insert.append('\n</script>'))
.pipe(dest(settings.dest))
}
// by default, do all builds in parallel
module.exports = {
addlhtml: addlhtml,
addlhtmlDev: addlhtmlDev,
default: parallel([moodleMobile]),
head: head,
mobile: moodleMobile,
}