2016-10-11 11:33:20 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-09-10 05:57:12 +02:00
|
|
|
const { spawn } = require( "child_process" );
|
|
|
|
const { series, src, task } = require( "gulp" );
|
2017-10-25 20:19:42 +02:00
|
|
|
const eslint = require( "gulp-eslint" );
|
|
|
|
const mocha = require( "gulp-mocha" );
|
|
|
|
const del = require( "del" );
|
2018-03-23 03:00:03 +01:00
|
|
|
const pump = require( "pump" );
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2018-01-07 17:32:33 +01:00
|
|
|
function node( args, cb ) {
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2018-01-07 17:32:33 +01:00
|
|
|
spawn( "node", args.split( " " ), { stdio: "inherit" } )
|
|
|
|
|
|
|
|
.on( "error", cb )
|
|
|
|
.on( "close", code => {
|
|
|
|
|
|
|
|
if ( ! code ) cb();
|
|
|
|
|
|
|
|
} );
|
2017-10-25 20:19:42 +02:00
|
|
|
|
2016-10-11 11:33:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run ESLint on all JavaScript files.
|
2018-03-23 03:00:03 +01:00
|
|
|
task( "lint", () => pump(
|
|
|
|
|
|
|
|
src( [
|
2017-10-25 20:19:42 +02:00
|
|
|
"**/.*rc.js",
|
2018-09-08 03:39:12 +02:00
|
|
|
"packages/**/*.js",
|
2017-10-25 20:19:42 +02:00
|
|
|
"test/benchmark/**/*.js",
|
|
|
|
"test/benchmark/run",
|
|
|
|
"test/impact",
|
|
|
|
"test/spec/**/*.js",
|
2018-01-19 09:55:04 +01:00
|
|
|
"src/*.js",
|
2018-09-10 05:57:12 +02:00
|
|
|
"rollup.config.js",
|
2018-09-06 06:52:02 +02:00
|
|
|
"gulpfile.js",
|
|
|
|
"server.js",
|
2018-03-23 03:00:03 +01:00
|
|
|
] ),
|
|
|
|
eslint( { dotfiles: true } ),
|
|
|
|
eslint.format(),
|
|
|
|
eslint.failAfterError()
|
|
|
|
|
|
|
|
) );
|
2016-10-11 11:33:20 +02:00
|
|
|
|
2016-12-08 10:05:17 +01:00
|
|
|
// Run tests.
|
2018-03-23 03:00:03 +01:00
|
|
|
task( "test", () => pump(
|
|
|
|
|
|
|
|
src( "test/spec/**/*.spec.js", { read: false } ),
|
|
|
|
mocha()
|
|
|
|
|
|
|
|
) );
|
2016-10-11 11:33:20 +02:00
|
|
|
|
|
|
|
// Run benchmarks.
|
2018-01-07 17:32:33 +01:00
|
|
|
task( "benchmark", cb => {
|
|
|
|
|
|
|
|
node( "test/benchmark/run", cb );
|
|
|
|
|
|
|
|
} );
|
2016-10-11 11:33:20 +02:00
|
|
|
|
2017-11-28 18:49:51 +01:00
|
|
|
// Generate the grammar parser.
|
2018-01-07 17:32:33 +01:00
|
|
|
task( "build:parser", cb => {
|
|
|
|
|
2018-09-08 03:39:12 +02:00
|
|
|
node( "packages/pegjs/bin/peg src/parser.pegjs -o packages/pegjs/lib/parser.js -c src/pegjs.config.js", cb );
|
2018-01-07 17:32:33 +01:00
|
|
|
|
|
|
|
} );
|
2017-11-28 18:49:51 +01:00
|
|
|
|
|
|
|
// Delete the generated files.
|
|
|
|
task( "clean", () =>
|
2018-09-10 05:57:12 +02:00
|
|
|
del( [ "packages/pegjs/dist", "website/js/*-bundle.js", "examples/*.js" ] )
|
2016-10-11 11:33:20 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Default task.
|
2018-03-23 03:00:03 +01:00
|
|
|
task( "default", series( "lint", "test" ) );
|