@ -8,51 +8,29 @@ let eslint = require("gulp-eslint");
let gulp = require ( "gulp" ) ;
let header = require ( "gulp-header" ) ;
let mocha = require ( "gulp-mocha" ) ;
let package _ = require ( "./package" ) ;
let peg = require ( "./lib/peg" ) ;
let rename = require ( "gulp-rename" ) ;
let runSequence = require ( "run-sequence" ) ;
let source = require ( "vinyl-source-stream" ) ;
let spawn = require ( "child_process" ) . spawn ;
let transform = require ( "gulp-transform" ) ;
let uglify = require ( "gulp-uglify" ) ;
const HEADER = [
"// PEG.js " + package _ . version ,
"//" ,
"// https://pegjs.org/" ,
"//" ,
"// Copyright (c) 2010-2016 David Majda" ,
"// Licensed under the MIT License." ,
""
] . map ( line => ` ${ line } \n ` ) . join ( "" ) ;
const JS _FILES = [
"lib/**/*.js" ,
"!lib/parser.js" ,
"test/benchmark/**/*.js" ,
"test/benchmark/run" ,
"test/impact" ,
"test/spec/**/*.js" ,
"test/server/run" ,
"bin/*.js" ,
"gulpfile.js"
] ;
const TEST _FILES = [
"test/spec/**/*.js"
] ;
function generate ( contents ) {
return peg . generate ( contents . toString ( ) , {
output : "source" ,
format : "commonjs"
} ) ;
function execFile ( args ) {
return spawn ( "node" , args . split ( " " ) , { stdio : "inherit" } ) ;
}
// Run ESLint on all JavaScript files.
gulp . task ( "lint" , ( ) =>
gulp . src ( JS _FILES )
gulp . src ( [
"lib/**/*.js" ,
"!lib/parser.js" ,
"test/benchmark/**/*.js" ,
"test/benchmark/run" ,
"test/impact" ,
"test/spec/**/*.js" ,
"test/server/run" ,
"bin/*.js" ,
"gulpfile.js"
] )
. pipe ( eslint ( ) )
. pipe ( eslint . format ( ) )
. pipe ( eslint . failAfterError ( ) )
@ -60,18 +38,31 @@ gulp.task("lint", () =>
// Run tests.
gulp . task ( "test" , ( ) =>
gulp . src ( TEST _FILES , { read : false } )
gulp . src ( "test/spec/**/*.spec.js" , { read : false } )
. pipe ( mocha ( ) )
) ;
// Run benchmarks.
gulp . task ( "benchmark" , ( ) =>
spawn ( "node" , [ "test/benchmark/run" ] , { stdio : "inherit" } )
) ;
gulp . task ( "benchmark" , ( ) => execFile ( "test/benchmark/run" ) ) ;
// Create the browser build.
gulp . task ( "browser:build" , ( ) =>
browserify ( "lib/peg.js" , { standalone : "peg" } )
gulp . task ( "browser:build" , ( ) => {
const HEADER = [
"//" ,
"// PEG.js v" + require ( "./package" ) . version ,
"// https://pegjs.org/" ,
"//" ,
"// Copyright (c) 2010-2016 David Majda" ,
"// Copyright (c) 2017+ Futago-za Ryuu" ,
"//" ,
"// Licensed under the MIT License." ,
"//" ,
""
]
. map ( line => ` ${ line } \n ` )
. join ( "" ) ;
return browserify ( "lib/peg.js" , { standalone : "peg" } )
. transform ( babelify , { presets : "es2015" , compact : false } )
. bundle ( )
. pipe ( source ( "peg.js" ) )
@ -81,20 +72,15 @@ gulp.task("browser:build", () =>
. pipe ( buffer ( ) )
. pipe ( uglify ( ) )
. pipe ( header ( HEADER ) )
. pipe ( gulp . dest ( "browser" ) )
) ;
. pipe ( gulp . dest ( "browser" ) ) ;
} ) ;
// Delete the browser build.
gulp . task ( "browser:clean" , ( ) =>
del ( "browser" )
) ;
gulp . task ( "browser:clean" , ( ) => del ( "browser" ) ) ;
// Generate the grammar parser.
gulp . task ( "parser" , ( ) =>
gulp . src ( "src/parser.pegjs" )
. pipe ( transform ( generate ) )
. pipe ( rename ( { extname : ".js" } ) )
. pipe ( gulp . dest ( "lib" ) )
execFile ( "bin/peg src/parser.pegjs -o lib/parser.js" )
) ;
// Default task.