aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
blob: 8cdab0473c83d53a2381d052f5845a0f76dd2972 (plain)
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
const pkg = require('./package.json')
const path = require('path')
const glob = require('glob')
const colors = require('colors')
const yargs = require('yargs')
const webpack = require('webpack-stream')
const { runQunitPuppeteer, printResultSummary, printFailedTests } = require('node-qunit-puppeteer')

const gulp = require('gulp')
const tap = require('gulp-tap')
const zip = require('gulp-zip')
const sass = require('gulp-sass')
const babel = require('gulp-babel')
const header = require('gulp-header')
const eslint = require('gulp-eslint')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const minify = require('gulp-clean-css')
const connect = require('gulp-connect')
const autoprefixer = require('gulp-autoprefixer')

const root = yargs.argv.root || '.'
const port = yargs.argv.port || 8000

const license = `/*!
* reveal.js <%= pkg.version %> (<%= new Date().toDateString() %>)
* <%= pkg.homepage %>
* MIT licensed
*
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
*/\n`


const swallowError = function(error) {
  console.log(error.toString())
  this.emit('end')
}

gulp.task('js', () => gulp.src(['./js/index.js'])
        .pipe(babel({ presets: ['@babel/preset-env'] }))
        .pipe(webpack({ mode: 'production' }))
        .on('error', swallowError)
        .pipe(header(license, {pkg: pkg}))
        .pipe(rename('reveal.min.js'))
        .pipe(gulp.dest('./dist')))

gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.{sass,scss}'])
        .pipe(sass())
        .pipe(gulp.dest('./dist/theme')))

gulp.task('css-core', gulp.series(

    () => gulp.src(['css/reveal.scss'])
        .pipe(sass())
        .pipe(autoprefixer())
        .pipe(gulp.dest('./dist')),
    () => gulp.src(['dist/reveal.css'])
        .pipe(minify({
            compatibility: 'ie9'
        }))
        .pipe(header(license, {pkg: pkg}))
        .pipe(gulp.dest('./dist'))

))

gulp.task('css', gulp.parallel('css-themes', 'css-core'))

gulp.task('test-qunit', function() {

    let testFiles = glob.sync('test/*.html' )

    return Promise.all( testFiles.map( filename => {
        return new Promise( ( resolve, reject ) => {
            runQunitPuppeteer({
                targetUrl: `file://${path.join(__dirname, filename)}`,
                timeout: 10000,
                redirectConsole: true,
                puppeteerArgs: ['--allow-file-access-from-files']
            })
                .then(result => {
                    console.log(`\n\n${('Testing '+filename+'...').bold.blue}`);
                    printResultSummary(result, console);
                    if( result.stats.failed > 0 ) {
                        printFailedTests(result, console);
                    }

                    resolve();
                })
                .catch(ex => {
                    console.error(ex);
                    reject();
                });
        } )
    } ) )
} )

gulp.task('test', gulp.series(

    () => gulp.src(['./js/**', 'gulpfile.js']).pipe(eslint()).pipe(eslint.format()),
    'test-qunit'

))

gulp.task('default', gulp.series(gulp.parallel('js', 'css'), 'test'))

gulp.task('package', gulp.series('default', () =>

    gulp.src([
        './index.html',
        './dist/**',
        './lib/**',
        './images/**',
        './plugin/**',
        './**.md'
    ]).pipe(zip('reveal-js-presentation.zip')).pipe(gulp.dest('./'))

))

gulp.task('serve', () => {

    connect.server({
        root: root,
        port: port,
        host: '0.0.0.0',
        livereload: true
    })

    gulp.watch(['js/**'], gulp.series('js', 'test'))

    gulp.watch([
        'css/theme/source/*.{sass,scss}',
        'css/theme/template/*.{sass,scss}',
    ], gulp.series('css-themes'))

    gulp.watch([
        'css/reveal.scss',
        'css/print/*.{sass,scss,css}'
    ], gulp.series('css-core'))

})