diff --git a/gulpfile.js b/gulpfile.js index 806c284..277ff9f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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. diff --git a/package.json b/package.json index d90ab4f..bedc0e3 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ "gulp-header": "1.8.8", "gulp-mocha": "3.0.1", "gulp-rename": "1.2.2", - "gulp-transform": "1.0.8", "gulp-uglify": "2.0.0", "morgan": "1.7.0", "run-sequence": "1.2.2",