Updated gulpfile.js

- Updated glob for test files
- Updated HEADER var for generated browser build
- Inlined list of JS_FILES to lint
- Added helper 'execFile'
- Simplyfied 'gulp benchmark'
- Parser generator now use's 'bin/peg.js'
- Moved HEADER var into 'browser:build' function
- Simplyfied 'gulp browser:clean'
- removed dependency 'gulp-transform'
master
Futago-za Ryuu 7 years ago
parent 9802bae15f
commit 35832f474f

@ -8,51 +8,29 @@ let eslint = require("gulp-eslint");
let gulp = require("gulp"); let gulp = require("gulp");
let header = require("gulp-header"); let header = require("gulp-header");
let mocha = require("gulp-mocha"); let mocha = require("gulp-mocha");
let package_ = require("./package");
let peg = require("./lib/peg");
let rename = require("gulp-rename"); let rename = require("gulp-rename");
let runSequence = require("run-sequence"); let runSequence = require("run-sequence");
let source = require("vinyl-source-stream"); let source = require("vinyl-source-stream");
let spawn = require("child_process").spawn; let spawn = require("child_process").spawn;
let transform = require("gulp-transform");
let uglify = require("gulp-uglify"); let uglify = require("gulp-uglify");
const HEADER = [ function execFile(args) {
"// PEG.js " + package_.version, return spawn("node", args.split(" "), { stdio: "inherit" });
"//",
"// 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"
});
} }
// Run ESLint on all JavaScript files. // Run ESLint on all JavaScript files.
gulp.task("lint", () => 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())
.pipe(eslint.format()) .pipe(eslint.format())
.pipe(eslint.failAfterError()) .pipe(eslint.failAfterError())
@ -60,18 +38,31 @@ gulp.task("lint", () =>
// Run tests. // Run tests.
gulp.task("test", () => gulp.task("test", () =>
gulp.src(TEST_FILES, { read: false }) gulp.src("test/spec/**/*.spec.js", { read: false })
.pipe(mocha()) .pipe(mocha())
); );
// Run benchmarks. // Run benchmarks.
gulp.task("benchmark", () => gulp.task("benchmark", () => execFile("test/benchmark/run"));
spawn("node", ["test/benchmark/run"], { stdio: "inherit" })
);
// Create the browser build. // Create the browser build.
gulp.task("browser:build", () => gulp.task("browser:build", () => {
browserify("lib/peg.js", { standalone: "peg" }) 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 }) .transform(babelify, { presets: "es2015", compact: false })
.bundle() .bundle()
.pipe(source("peg.js")) .pipe(source("peg.js"))
@ -81,20 +72,15 @@ gulp.task("browser:build", () =>
.pipe(buffer()) .pipe(buffer())
.pipe(uglify()) .pipe(uglify())
.pipe(header(HEADER)) .pipe(header(HEADER))
.pipe(gulp.dest("browser")) .pipe(gulp.dest("browser"));
); });
// Delete the browser build. // Delete the browser build.
gulp.task("browser:clean", () => gulp.task("browser:clean", () => del("browser"));
del("browser")
);
// Generate the grammar parser. // Generate the grammar parser.
gulp.task("parser", () => gulp.task("parser", () =>
gulp.src("src/parser.pegjs") execFile("bin/peg src/parser.pegjs -o lib/parser.js")
.pipe(transform(generate))
.pipe(rename({ extname: ".js" }))
.pipe(gulp.dest("lib"))
); );
// Default task. // Default task.

@ -70,7 +70,6 @@
"gulp-header": "1.8.8", "gulp-header": "1.8.8",
"gulp-mocha": "3.0.1", "gulp-mocha": "3.0.1",
"gulp-rename": "1.2.2", "gulp-rename": "1.2.2",
"gulp-transform": "1.0.8",
"gulp-uglify": "2.0.0", "gulp-uglify": "2.0.0",
"morgan": "1.7.0", "morgan": "1.7.0",
"run-sequence": "1.2.2", "run-sequence": "1.2.2",

Loading…
Cancel
Save