2020-03-31 13:06:58 +02:00
|
|
|
const pkg = require('./package.json')
|
|
|
|
const path = require('path')
|
|
|
|
const glob = require('glob')
|
|
|
|
const yargs = require('yargs')
|
2020-03-31 13:23:51 +02:00
|
|
|
const colors = require('colors')
|
2020-04-16 14:51:34 +02:00
|
|
|
const qunit = require('node-qunit-puppeteer')
|
|
|
|
|
|
|
|
const {rollup} = require('rollup');
|
|
|
|
const {terser} = require('rollup-plugin-terser');
|
|
|
|
const babel = require('rollup-plugin-babel');
|
|
|
|
const resolve = require('@rollup/plugin-node-resolve');
|
2020-03-31 13:06:58 +02:00
|
|
|
|
2018-03-11 14:15:17 +01:00
|
|
|
const gulp = require('gulp')
|
2020-03-31 13:06:58 +02:00
|
|
|
const tap = require('gulp-tap')
|
2020-03-03 21:01:35 +01:00
|
|
|
const zip = require('gulp-zip')
|
|
|
|
const sass = require('gulp-sass')
|
|
|
|
const header = require('gulp-header')
|
2018-05-14 20:01:59 +02:00
|
|
|
const eslint = require('gulp-eslint')
|
2018-03-11 14:15:17 +01:00
|
|
|
const minify = require('gulp-clean-css')
|
|
|
|
const connect = require('gulp-connect')
|
2020-03-03 21:01:35 +01:00
|
|
|
const autoprefixer = require('gulp-autoprefixer')
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2020-03-05 11:35:20 +01:00
|
|
|
const root = yargs.argv.root || '.'
|
|
|
|
const port = yargs.argv.port || 8000
|
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
const banner = `/*!
|
|
|
|
* reveal.js ${pkg.version} (${new Date().toDateString()})
|
|
|
|
* ${pkg.homepage}
|
2020-03-03 21:01:35 +01:00
|
|
|
* MIT licensed
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Hakim El Hattab, https://hakim.se
|
|
|
|
*/\n`
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
const rollupConfig = {
|
|
|
|
plugins: [
|
|
|
|
babel({
|
|
|
|
exclude: 'node_modules/**',
|
|
|
|
compact: false,
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
corejs: 3,
|
|
|
|
useBuiltIns: 'entry',
|
|
|
|
modules: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
resolve(),
|
|
|
|
terser()
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('js', () => {
|
|
|
|
return rollup({
|
|
|
|
input: 'js/index.js',
|
|
|
|
...rollupConfig
|
|
|
|
}).then( bundle => {
|
|
|
|
bundle.write({
|
|
|
|
file: './dist/reveal.min.js',
|
|
|
|
format: 'umd',
|
|
|
|
banner: banner
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
gulp.task('plugins', () => {
|
|
|
|
return Promise.all([
|
|
|
|
{ input: './plugin/highlight/highlight.es5', output: './dist/plugin/highlight.js' },
|
|
|
|
{ input: './plugin/markdown/markdown.es5', output: './dist/plugin/markdown.js' },
|
|
|
|
{ input: './plugin/search/search.es5', output: './dist/plugin/search.js' },
|
|
|
|
{ input: './plugin/notes/notes.es5', output: './dist/plugin/notes.js' },
|
|
|
|
{ input: './plugin/zoom/zoom.es5', output: './dist/plugin/zoom.js' },
|
|
|
|
{ input: './plugin/math/math.es5', output: './dist/plugin/math.js' }
|
|
|
|
].map( plugin => {
|
|
|
|
return rollup({
|
|
|
|
input: plugin.input,
|
|
|
|
...rollupConfig
|
|
|
|
}).then( bundle => {
|
|
|
|
return bundle.write({
|
|
|
|
file: plugin.output,
|
|
|
|
format: 'umd'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
} ));
|
|
|
|
})
|
2020-04-15 10:23:51 +02:00
|
|
|
|
2020-03-03 21:01:35 +01:00
|
|
|
gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.{sass,scss}'])
|
|
|
|
.pipe(sass())
|
2020-03-06 19:58:40 +01:00
|
|
|
.pipe(gulp.dest('./dist/theme')))
|
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.task('css-core', () => gulp.src(['css/reveal.scss'])
|
|
|
|
.pipe(sass())
|
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(minify({compatibility: 'ie9'}))
|
|
|
|
.pipe(header(banner))
|
|
|
|
.pipe(gulp.dest('./dist')))
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2020-03-13 19:53:46 +01:00
|
|
|
gulp.task('css', gulp.parallel('css-themes', 'css-core'))
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.task('qunit', () => {
|
2020-03-31 13:06:58 +02:00
|
|
|
|
2020-04-15 11:07:20 +02:00
|
|
|
let serverConfig = {
|
|
|
|
root,
|
|
|
|
port: 8009,
|
|
|
|
host: '0.0.0.0',
|
|
|
|
name: 'test-server'
|
|
|
|
}
|
|
|
|
|
2020-04-15 11:14:45 +02:00
|
|
|
let server = connect.server( serverConfig )
|
2020-04-15 11:07:20 +02:00
|
|
|
|
2020-03-31 13:06:58 +02:00
|
|
|
let testFiles = glob.sync('test/*.html' )
|
|
|
|
|
2020-03-31 14:06:38 +02:00
|
|
|
let totalTests = 0;
|
|
|
|
let failingTests = 0;
|
|
|
|
|
|
|
|
let tests = Promise.all( testFiles.map( filename => {
|
2020-03-31 13:06:58 +02:00
|
|
|
return new Promise( ( resolve, reject ) => {
|
2020-04-16 14:51:34 +02:00
|
|
|
qunit.runQunitPuppeteer({
|
2020-04-15 11:07:20 +02:00
|
|
|
targetUrl: `http://${serverConfig.host}:${serverConfig.port}/${filename}`,
|
2020-04-07 09:57:28 +02:00
|
|
|
timeout: 20000,
|
2020-04-07 09:05:56 +02:00
|
|
|
redirectConsole: false,
|
2020-03-31 13:06:58 +02:00
|
|
|
puppeteerArgs: ['--allow-file-access-from-files']
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
if( result.stats.failed > 0 ) {
|
2020-03-31 14:06:38 +02:00
|
|
|
console.log(`${'!'} ${filename} [${result.stats.passed}/${result.stats.total}] in ${result.stats.runtime}ms`.red);
|
2020-04-16 14:51:34 +02:00
|
|
|
// qunit.printResultSummary(result, console);
|
|
|
|
qunit.printFailedTests(result, console);
|
2020-03-31 13:06:58 +02:00
|
|
|
}
|
2020-03-31 14:06:38 +02: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 13:06:58 +02:00
|
|
|
|
|
|
|
resolve();
|
|
|
|
})
|
2020-03-31 14:06:38 +02:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
2020-03-31 13:06:58 +02:00
|
|
|
reject();
|
|
|
|
});
|
|
|
|
} )
|
2020-03-31 14:06:38 +02: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-04-15 11:07:20 +02:00
|
|
|
} )
|
|
|
|
.finally( () => {
|
2020-04-15 11:14:45 +02:00
|
|
|
server.close();
|
2020-03-31 14:06:38 +02:00
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|
2020-03-31 13:06:58 +02:00
|
|
|
} )
|
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.task('eslint', () => gulp.src(['./js/**', 'gulpfile.js'])
|
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(eslint.format()))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.task('test', gulp.series( 'eslint', 'qunit' ))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.task('default', gulp.series(gulp.parallel('js', 'css', 'plugins'), 'test'))
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2020-04-07 10:05:16 +02:00
|
|
|
gulp.task('build', gulp.parallel('js', 'css'))
|
2020-04-07 10:00:28 +02:00
|
|
|
|
2018-05-14 20:01:59 +02:00
|
|
|
gulp.task('package', gulp.series('default', () =>
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2018-05-14 20:01:59 +02:00
|
|
|
gulp.src([
|
2018-03-11 14:15:17 +01:00
|
|
|
'./index.html',
|
2020-03-06 19:58:40 +01:00
|
|
|
'./dist/**',
|
2018-03-11 14:15:17 +01:00
|
|
|
'./lib/**',
|
|
|
|
'./images/**',
|
|
|
|
'./plugin/**',
|
|
|
|
'./**.md'
|
|
|
|
]).pipe(zip('reveal-js-presentation.zip')).pipe(gulp.dest('./'))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2018-05-14 20:01:59 +02:00
|
|
|
))
|
2018-03-11 14:15:17 +01:00
|
|
|
|
2018-05-14 20:01:59 +02:00
|
|
|
gulp.task('serve', () => {
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2018-03-11 14:15:17 +01:00
|
|
|
connect.server({
|
2020-03-05 11:35:20 +01:00
|
|
|
root: root,
|
|
|
|
port: port,
|
2020-03-11 08:13:53 +01:00
|
|
|
host: '0.0.0.0',
|
2020-03-05 11:35:20 +01:00
|
|
|
livereload: true
|
2018-03-11 14:15:17 +01:00
|
|
|
})
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2020-03-07 18:29:00 +01:00
|
|
|
gulp.watch(['js/**'], gulp.series('js', 'test'))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2020-04-16 14:51:34 +02:00
|
|
|
gulp.watch(['plugin/**/*.js'], gulp.series('plugins'))
|
|
|
|
|
2020-04-06 11:22:54 +02:00
|
|
|
gulp.watch(['test/*.html'], gulp.series('test'))
|
|
|
|
|
2020-03-03 21:01:35 +01:00
|
|
|
gulp.watch([
|
|
|
|
'css/theme/source/*.{sass,scss}',
|
2018-03-11 17:52:37 +01:00
|
|
|
'css/theme/template/*.{sass,scss}',
|
|
|
|
], gulp.series('css-themes'))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2020-03-13 19:53:46 +01:00
|
|
|
gulp.watch([
|
|
|
|
'css/reveal.scss',
|
|
|
|
'css/print/*.{sass,scss,css}'
|
|
|
|
], gulp.series('css-core'))
|
2020-03-03 21:01:35 +01:00
|
|
|
|
2018-03-11 14:15:17 +01:00
|
|
|
})
|