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')
|
2021-05-19 19:48:42 +00:00
|
|
|
const through = require('through2');
|
2020-04-16 12:51:34 +00:00
|
|
|
const qunit = require('node-qunit-puppeteer')
|
|
|
|
|
2020-04-17 08:59:55 +00:00
|
|
|
const {rollup} = require('rollup')
|
|
|
|
const {terser} = require('rollup-plugin-terser')
|
2020-05-26 07:46:50 +00:00
|
|
|
const babel = require('@rollup/plugin-babel').default
|
2020-05-04 08:39:37 +00:00
|
|
|
const commonjs = require('@rollup/plugin-commonjs')
|
2020-05-26 07:46:50 +00:00
|
|
|
const resolve = require('@rollup/plugin-node-resolve').default
|
2021-05-19 19:48:42 +00:00
|
|
|
const sass = require('sass')
|
2020-03-31 11:06:58 +00:00
|
|
|
|
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 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 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
|
2021-11-21 04:23:28 +00:00
|
|
|
const host = yargs.argv.host || 'localhost'
|
2020-03-05 10:35:20 +00:00
|
|
|
|
2020-04-16 12:51:34 +00:00
|
|
|
const banner = `/*!
|
2020-05-25 14:21:27 +00:00
|
|
|
* reveal.js ${pkg.version}
|
2020-04-16 12:51:34 +00:00
|
|
|
* ${pkg.homepage}
|
2020-03-03 20:01:35 +00:00
|
|
|
* MIT licensed
|
|
|
|
*
|
2022-01-03 11:38:51 +00:00
|
|
|
* Copyright (C) 2011-2022 Hakim El Hattab, https://hakim.se
|
2020-03-03 20:01:35 +00:00
|
|
|
*/\n`
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-04-22 14:07:51 +00:00
|
|
|
// Prevents warnings from opening too many test pages
|
|
|
|
process.setMaxListeners(20);
|
|
|
|
|
2020-05-04 09:13:11 +00:00
|
|
|
const babelConfig = {
|
2020-05-26 07:46:50 +00:00
|
|
|
babelHelpers: 'bundled',
|
|
|
|
ignore: ['node_modules'],
|
2020-05-04 09:13:11 +00:00
|
|
|
compact: false,
|
2020-05-18 13:59:18 +00:00
|
|
|
extensions: ['.js', '.html'],
|
2020-05-26 07:46:50 +00:00
|
|
|
plugins: [
|
|
|
|
'transform-html-import-to-string'
|
|
|
|
],
|
2020-05-04 09:13:11 +00:00
|
|
|
presets: [[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
corejs: 3,
|
2020-05-26 07:46:50 +00:00
|
|
|
useBuiltIns: 'usage',
|
2020-05-04 09:13:11 +00:00
|
|
|
modules: false
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
};
|
|
|
|
|
2020-05-26 07:46:50 +00:00
|
|
|
// Our ES module bundle only targets newer browsers with
|
|
|
|
// module support. Browsers are targeted explicitly instead
|
|
|
|
// of using the "esmodule: true" target since that leads to
|
|
|
|
// polyfilling older browsers and a larger bundle.
|
2020-05-04 09:13:11 +00:00
|
|
|
const babelConfigESM = JSON.parse( JSON.stringify( babelConfig ) );
|
2020-05-26 07:46:50 +00:00
|
|
|
babelConfigESM.presets[0][1].targets = { browsers: [
|
2021-10-28 12:23:19 +00:00
|
|
|
'last 2 Chrome versions',
|
|
|
|
'last 2 Safari versions',
|
|
|
|
'last 2 iOS versions',
|
|
|
|
'last 2 Firefox versions',
|
|
|
|
'last 2 Edge versions',
|
2020-05-26 07:46:50 +00:00
|
|
|
] };
|
2020-05-04 09:13:11 +00:00
|
|
|
|
2020-05-27 07:06:31 +00:00
|
|
|
let cache = {};
|
2020-05-19 17:04:46 +00:00
|
|
|
|
2020-05-04 09:13:11 +00:00
|
|
|
// Creates a bundle with broad browser support, exposed
|
|
|
|
// as UMD
|
|
|
|
gulp.task('js-es5', () => {
|
2020-04-16 12:51:34 +00:00
|
|
|
return rollup({
|
2020-05-27 07:06:31 +00:00
|
|
|
cache: cache.umd,
|
2020-04-16 12:51:34 +00:00
|
|
|
input: 'js/index.js',
|
2020-05-26 07:46:50 +00:00
|
|
|
plugins: [
|
|
|
|
resolve(),
|
|
|
|
commonjs(),
|
|
|
|
babel( babelConfig ),
|
|
|
|
terser()
|
|
|
|
]
|
2020-04-16 12:51:34 +00:00
|
|
|
}).then( bundle => {
|
2020-05-27 07:06:31 +00:00
|
|
|
cache.umd = bundle.cache;
|
2020-05-04 09:13:11 +00:00
|
|
|
return bundle.write({
|
|
|
|
name: 'Reveal',
|
|
|
|
file: './dist/reveal.js',
|
|
|
|
format: 'umd',
|
2020-04-17 08:59:55 +00:00
|
|
|
banner: banner,
|
|
|
|
sourcemap: true
|
|
|
|
});
|
2020-05-04 09:13:11 +00:00
|
|
|
});
|
|
|
|
})
|
2020-04-17 08:59:55 +00:00
|
|
|
|
2020-05-04 09:13:11 +00:00
|
|
|
// Creates an ES module bundle
|
|
|
|
gulp.task('js-es6', () => {
|
|
|
|
return rollup({
|
2020-05-27 07:06:31 +00:00
|
|
|
cache: cache.esm,
|
2020-05-04 09:13:11 +00:00
|
|
|
input: 'js/index.js',
|
2020-05-26 07:46:50 +00:00
|
|
|
plugins: [
|
|
|
|
resolve(),
|
|
|
|
commonjs(),
|
|
|
|
babel( babelConfigESM ),
|
|
|
|
terser()
|
|
|
|
]
|
2020-05-04 09:13:11 +00:00
|
|
|
}).then( bundle => {
|
2020-05-27 07:06:31 +00:00
|
|
|
cache.esm = bundle.cache;
|
2020-05-04 09:13:11 +00:00
|
|
|
return bundle.write({
|
|
|
|
file: './dist/reveal.esm.js',
|
|
|
|
format: 'es',
|
2020-04-17 08:59:55 +00:00
|
|
|
banner: banner,
|
|
|
|
sourcemap: true
|
2020-04-16 12:51:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
2020-05-04 09:13:11 +00:00
|
|
|
gulp.task('js', gulp.parallel('js-es5', 'js-es6'));
|
2020-04-16 12:51:34 +00:00
|
|
|
|
2020-05-04 09:13:11 +00:00
|
|
|
// Creates a UMD and ES module bundle for each of our
|
|
|
|
// built-in plugins
|
2020-04-16 12:51:34 +00:00
|
|
|
gulp.task('plugins', () => {
|
|
|
|
return Promise.all([
|
2020-05-18 12:41:56 +00:00
|
|
|
{ name: 'RevealHighlight', input: './plugin/highlight/plugin.js', output: './plugin/highlight/highlight' },
|
|
|
|
{ name: 'RevealMarkdown', input: './plugin/markdown/plugin.js', output: './plugin/markdown/markdown' },
|
|
|
|
{ name: 'RevealSearch', input: './plugin/search/plugin.js', output: './plugin/search/search' },
|
|
|
|
{ name: 'RevealNotes', input: './plugin/notes/plugin.js', output: './plugin/notes/notes' },
|
|
|
|
{ name: 'RevealZoom', input: './plugin/zoom/plugin.js', output: './plugin/zoom/zoom' },
|
|
|
|
{ name: 'RevealMath', input: './plugin/math/plugin.js', output: './plugin/math/math' },
|
2020-04-16 12:51:34 +00:00
|
|
|
].map( plugin => {
|
|
|
|
return rollup({
|
2020-05-27 07:06:31 +00:00
|
|
|
cache: cache[plugin.input],
|
2020-04-16 12:51:34 +00:00
|
|
|
input: plugin.input,
|
2020-05-26 07:46:50 +00:00
|
|
|
plugins: [
|
|
|
|
resolve(),
|
|
|
|
commonjs(),
|
|
|
|
babel({
|
|
|
|
...babelConfig,
|
|
|
|
ignore: [/node_modules\/(?!(highlight\.js|marked)\/).*/],
|
|
|
|
}),
|
|
|
|
terser()
|
|
|
|
]
|
2020-04-16 12:51:34 +00:00
|
|
|
}).then( bundle => {
|
2020-05-27 07:06:31 +00:00
|
|
|
cache[plugin.input] = bundle.cache;
|
2020-05-04 08:39:37 +00:00
|
|
|
bundle.write({
|
|
|
|
file: plugin.output + '.esm.js',
|
|
|
|
name: plugin.name,
|
|
|
|
format: 'es'
|
|
|
|
})
|
|
|
|
|
|
|
|
bundle.write({
|
|
|
|
file: plugin.output + '.js',
|
2020-04-17 07:47:03 +00:00
|
|
|
name: plugin.name,
|
2020-04-16 12:51:34 +00:00
|
|
|
format: 'umd'
|
|
|
|
})
|
|
|
|
});
|
|
|
|
} ));
|
|
|
|
})
|
2020-04-15 08:23:51 +00:00
|
|
|
|
2021-05-19 19:48:42 +00:00
|
|
|
// a custom pipeable step to transform Sass to CSS
|
|
|
|
function compileSass() {
|
|
|
|
return through.obj( ( vinylFile, encoding, callback ) => {
|
|
|
|
const transformedFile = vinylFile.clone();
|
|
|
|
|
|
|
|
sass.render({
|
|
|
|
data: transformedFile.contents.toString(),
|
|
|
|
includePaths: ['css/', 'css/theme/template']
|
|
|
|
}, ( err, result ) => {
|
|
|
|
if( err ) {
|
|
|
|
console.log( vinylFile.path );
|
|
|
|
console.log( err.formatted );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
transformedFile.extname = '.css';
|
|
|
|
transformedFile.contents = result.css;
|
|
|
|
callback( null, transformedFile );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-03 20:01:35 +00:00
|
|
|
gulp.task('css-themes', () => gulp.src(['./css/theme/source/*.{sass,scss}'])
|
2021-05-19 19:48:42 +00:00
|
|
|
.pipe(compileSass())
|
2020-03-06 18:58:40 +00:00
|
|
|
.pipe(gulp.dest('./dist/theme')))
|
|
|
|
|
2020-04-16 12:51:34 +00:00
|
|
|
gulp.task('css-core', () => gulp.src(['css/reveal.scss'])
|
2021-05-19 19:48:42 +00:00
|
|
|
.pipe(compileSass())
|
2020-04-16 12:51:34 +00:00
|
|
|
.pipe(autoprefixer())
|
|
|
|
.pipe(minify({compatibility: 'ie9'}))
|
|
|
|
.pipe(header(banner))
|
|
|
|
.pipe(gulp.dest('./dist')))
|
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-04-16 12:51:34 +00:00
|
|
|
gulp.task('qunit', () => {
|
2020-03-31 11:06:58 +00:00
|
|
|
|
2020-04-15 09:07:20 +00:00
|
|
|
let serverConfig = {
|
|
|
|
root,
|
|
|
|
port: 8009,
|
2021-10-05 20:48:46 +00:00
|
|
|
host: 'localhost',
|
2020-04-15 09:07:20 +00:00
|
|
|
name: 'test-server'
|
|
|
|
}
|
|
|
|
|
2020-04-15 09:14:45 +00:00
|
|
|
let server = connect.server( serverConfig )
|
2020-04-15 09:07:20 +00:00
|
|
|
|
2020-03-31 11:06:58 +00:00
|
|
|
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 ) => {
|
2020-04-16 12:51:34 +00:00
|
|
|
qunit.runQunitPuppeteer({
|
2020-04-15 09:07:20 +00:00
|
|
|
targetUrl: `http://${serverConfig.host}:${serverConfig.port}/${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);
|
2020-04-16 12:51:34 +00:00
|
|
|
// qunit.printResultSummary(result, console);
|
|
|
|
qunit.printFailedTests(result, console);
|
2020-03-31 11:06:58 +00:00
|
|
|
}
|
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-04-15 09:07:20 +00:00
|
|
|
} )
|
|
|
|
.finally( () => {
|
2020-04-15 09:14:45 +00:00
|
|
|
server.close();
|
2020-03-31 12:06:38 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
} );
|
2020-03-31 11:06:58 +00:00
|
|
|
} )
|
|
|
|
|
2020-04-16 12:51:34 +00:00
|
|
|
gulp.task('eslint', () => gulp.src(['./js/**', 'gulpfile.js'])
|
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(eslint.format()))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-04-16 12:51:34 +00:00
|
|
|
gulp.task('test', gulp.series( 'eslint', 'qunit' ))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-04-16 12:51:34 +00:00
|
|
|
gulp.task('default', gulp.series(gulp.parallel('js', 'css', 'plugins'), 'test'))
|
2018-03-11 13:15:17 +00:00
|
|
|
|
2020-04-17 08:59:55 +00:00
|
|
|
gulp.task('build', gulp.parallel('js', 'css', 'plugins'))
|
2020-04-07 08:00:28 +00:00
|
|
|
|
2022-03-21 08:35:30 +00:00
|
|
|
gulp.task('package', gulp.series(() =>
|
|
|
|
|
|
|
|
gulp.src(
|
|
|
|
[
|
|
|
|
'./index.html',
|
|
|
|
'./dist/**',
|
|
|
|
'./lib/**',
|
|
|
|
'./images/**',
|
|
|
|
'./plugin/**',
|
2022-10-24 11:06:31 +00:00
|
|
|
'./**/*.md'
|
2022-03-21 08:35:30 +00:00
|
|
|
],
|
|
|
|
{ base: './' }
|
|
|
|
)
|
|
|
|
.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
|
|
|
|
2022-10-24 11:06:31 +00:00
|
|
|
gulp.task('reload', () => gulp.src(['**/*.html', '**/*.md'])
|
2020-05-20 10:08:57 +00:00
|
|
|
.pipe(connect.reload()));
|
|
|
|
|
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,
|
2021-11-21 04:23:28 +00:00
|
|
|
host: host,
|
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
|
|
|
|
2022-10-24 11:06:31 +00:00
|
|
|
gulp.watch(['**/*.html', '**/*.md'], gulp.series('reload'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2021-11-10 20:14:05 +00:00
|
|
|
gulp.watch(['js/**'], gulp.series('js', 'reload', 'eslint'))
|
2020-04-16 12:51:34 +00:00
|
|
|
|
2022-02-28 08:19:58 +00:00
|
|
|
gulp.watch(['plugin/**/plugin.js', 'plugin/**/*.html'], gulp.series('plugins', 'reload'))
|
2020-04-06 09:22:54 +00:00
|
|
|
|
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}',
|
2020-05-20 10:08:57 +00:00
|
|
|
], gulp.series('css-themes', 'reload'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2020-03-13 18:53:46 +00:00
|
|
|
gulp.watch([
|
2020-05-19 08:22:19 +00:00
|
|
|
'css/*.scss',
|
2020-03-13 18:53:46 +00:00
|
|
|
'css/print/*.{sass,scss,css}'
|
2020-05-20 10:08:57 +00:00
|
|
|
], gulp.series('css-core', 'reload'))
|
|
|
|
|
|
|
|
gulp.watch(['test/*.html'], gulp.series('test'))
|
2020-03-03 20:01:35 +00:00
|
|
|
|
2022-10-24 11:06:31 +00:00
|
|
|
})
|