2020-03-31 11:06:58 +00:00
|
|
|
const pkg = require('./package.json')
|
|
|
|
const path = require('path')
|
|
|
|
const glob = require('glob')
|
|
|
|
const yargs = require('yargs')
|
2020-03-31 11:23:51 +00:00
|
|
|
const colors = require('colors')
|
2020-03-31 11:06:58 +00:00
|
|
|
const webpack = require('webpack-stream')
|
|
|
|
const { runQunitPuppeteer, printResultSummary, printFailedTests } = require('node-qunit-puppeteer')
|
|
|
|
|
2018-03-11 13:15:17 +00:00
|
|
|
const gulp = require('gulp')
|
2020-03-31 11:06:58 +00:00
|
|
|
const tap = require('gulp-tap')
|
2020-03-03 20:01:35 +00:00
|
|
|
const zip = require('gulp-zip')
|
|
|
|
const sass = require('gulp-sass')
|
|
|
|
const header = require('gulp-header')
|
2018-05-14 18:01:59 +00:00
|
|
|
const eslint = require('gulp-eslint')
|
2018-03-11 13:15:17 +00:00
|
|
|
const uglify = require('gulp-uglify')
|
|
|
|
const rename = require('gulp-rename')
|
|
|
|
const minify = require('gulp-clean-css')
|
|
|
|
const connect = require('gulp-connect')
|
2020-03-03 20:01:35 +00:00
|
|
|
const autoprefixer = require('gulp-autoprefixer')
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-03-05 10:35:20 +00:00
|
|
|
const root = yargs.argv.root || '.'
|
|
|
|
const port = yargs.argv.port || 8000
|
|
|
|
|
2020-03-03 20:01:35 +00:00
|
|
|
const license = `/*!
|
|
|
|
* reveal.js <%= pkg.version %> (<%= new Date().toDateString() %>)
|
|
|
|
* <%= pkg.homepage %>
|
|
|
|
* MIT licensed
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
|
|
|
|
*/\n`
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-03-06 17:59:09 +00:00
|
|
|
|
2020-03-16 13:30:36 +00:00
|
|
|
const swallowError = function(error) {
|
|
|
|
console.log(error.toString())
|
|
|
|
this.emit('end')
|
|
|
|
}
|
|
|
|
|
2020-03-07 09:44:02 +00:00
|
|
|
gulp.task('js', () => gulp.src(['./js/index.js'])
|
2020-03-31 11:23:51 +00:00
|
|
|
.pipe(webpack(require('./webpack.config.js')))
|
2020-03-16 13:30:36 +00:00
|
|
|
.on('error', swallowError)
|
2020-03-03 20:01:35 +00:00
|
|
|
.pipe(header(license, {pkg: pkg}))
|
|
|
|
.pipe(rename('reveal.min.js'))
|
2020-03-06 18:58:40 +00:00
|
|
|
.pipe(gulp.dest('./dist')))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
|
|
|
gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.{sass,scss}'])
|
|
|
|
.pipe(sass())
|
2020-03-06 18:58:40 +00:00
|
|
|
.pipe(gulp.dest('./dist/theme')))
|
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
gulp.task('css-core', gulp.series(
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-03-06 18:58:40 +00:00
|
|
|
() => gulp.src(['css/reveal.scss'])
|
|
|
|
.pipe(sass())
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(gulp.dest('./dist')),
|
|
|
|
() => gulp.src(['dist/reveal.css'])
|
2020-03-31 11:23:51 +00:00
|
|
|
.pipe(minify({compatibility: 'ie9'}))
|
2020-03-06 18:58:40 +00:00
|
|
|
.pipe(header(license, {pkg: pkg}))
|
|
|
|
.pipe(gulp.dest('./dist'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
))
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-03-13 18:53:46 +00:00
|
|
|
gulp.task('css', gulp.parallel('css-themes', 'css-core'))
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-03-31 11:06:58 +00:00
|
|
|
gulp.task('test-qunit', function() {
|
|
|
|
|
|
|
|
let testFiles = glob.sync('test/*.html' )
|
|
|
|
|
2020-03-31 12:06:38 +00:00
|
|
|
let totalTests = 0;
|
|
|
|
let failingTests = 0;
|
|
|
|
|
|
|
|
let tests = Promise.all( testFiles.map( filename => {
|
2020-03-31 11:06:58 +00:00
|
|
|
return new Promise( ( resolve, reject ) => {
|
|
|
|
runQunitPuppeteer({
|
|
|
|
targetUrl: `file://${path.join(__dirname, filename)}`,
|
2020-04-07 07:57:28 +00:00
|
|
|
timeout: 20000,
|
2020-04-07 07:05:56 +00:00
|
|
|
redirectConsole: false,
|
2020-03-31 11:06:58 +00:00
|
|
|
puppeteerArgs: ['--allow-file-access-from-files']
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
if( result.stats.failed > 0 ) {
|
2020-03-31 12:06:38 +00:00
|
|
|
console.log(`${'!'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red);
|
|
|
|
// printResultSummary(result, console);
|
2020-03-31 11:06:58 +00:00
|
|
|
printFailedTests(result, console);
|
|
|
|
}
|
2020-03-31 12:06:38 +00:00
|
|
|
else {
|
|
|
|
console.log(`${'✔'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.green);
|
|
|
|
}
|
|
|
|
|
|
|
|
totalTests += result.stats.total;
|
|
|
|
failingTests += result.stats.failed;
|
2020-03-31 11:06:58 +00:00
|
|
|
|
|
|
|
resolve();
|
|
|
|
})
|
2020-03-31 12:06:38 +00:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
2020-03-31 11:06:58 +00:00
|
|
|
reject();
|
|
|
|
});
|
|
|
|
} )
|
2020-03-31 12:06:38 +00:00
|
|
|
} ) );
|
|
|
|
|
|
|
|
return new Promise( ( resolve, reject ) => {
|
|
|
|
|
|
|
|
tests.then( () => {
|
|
|
|
if( failingTests > 0 ) {
|
|
|
|
reject( new Error(`${failingTests}/${totalTests} tests failed`.red) );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log(`${'✔'} Passed ${totalTests} tests`.green.bold);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.catch( () => {
|
|
|
|
reject();
|
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|
2020-03-31 11:06:58 +00:00
|
|
|
} )
|
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
gulp.task('test', gulp.series(
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-03-31 11:06:58 +00:00
|
|
|
() => gulp.src(['./js/**', 'gulpfile.js']).pipe(eslint()).pipe(eslint.format()),
|
|
|
|
'test-qunit'
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
))
|
2018-03-11 13:15:17 +00:00
|
|
|
|
|
|
|
gulp.task('default', gulp.series(gulp.parallel('js', 'css'), 'test'))
|
|
|
|
|
2020-04-07 08:05:16 +00:00
|
|
|
gulp.task('build', gulp.parallel('js', 'css'))
|
2020-04-07 08:00:28 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
gulp.task('package', gulp.series('default', () =>
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
gulp.src([
|
2018-03-11 13:15:17 +00:00
|
|
|
'./index.html',
|
2020-03-06 18:58:40 +00:00
|
|
|
'./dist/**',
|
2018-03-11 13:15:17 +00:00
|
|
|
'./lib/**',
|
|
|
|
'./images/**',
|
|
|
|
'./plugin/**',
|
|
|
|
'./**.md'
|
|
|
|
]).pipe(zip('reveal-js-presentation.zip')).pipe(gulp.dest('./'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
))
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2018-05-14 18:01:59 +00:00
|
|
|
gulp.task('serve', () => {
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-03-11 13:15:17 +00:00
|
|
|
connect.server({
|
2020-03-05 10:35:20 +00:00
|
|
|
root: root,
|
|
|
|
port: port,
|
2020-03-11 07:13:53 +00:00
|
|
|
host: '0.0.0.0',
|
2020-03-05 10:35:20 +00:00
|
|
|
livereload: true
|
2018-03-11 13:15:17 +00:00
|
|
|
})
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-03-07 17:29:00 +00:00
|
|
|
gulp.watch(['js/**'], gulp.series('js', 'test'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-04-06 09:22:54 +00:00
|
|
|
gulp.watch(['test/*.html'], gulp.series('test'))
|
|
|
|
|
2020-03-03 20:01:35 +00:00
|
|
|
gulp.watch([
|
|
|
|
'css/theme/source/*.{sass,scss}',
|
2018-03-11 16:52:37 +00:00
|
|
|
'css/theme/template/*.{sass,scss}',
|
|
|
|
], gulp.series('css-themes'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-03-13 18:53:46 +00:00
|
|
|
gulp.watch([
|
|
|
|
'css/reveal.scss',
|
|
|
|
'css/print/*.{sass,scss,css}'
|
|
|
|
], gulp.series('css-core'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2018-03-11 13:15:17 +00:00
|
|
|
})
|