Switch from Make to Gulp

The core of the transition is getting rid of Makefile and replacing it
with gulpfile.js. The rest is details (fixing dependencies, changing all
references to "make", etc.).

Target/task names mostly stay the same, so in most cases "gulp foo" does
what "make foo" did before. The only exceptions are "make browser" and
"make browserclean", which are now "gulp browser:build" and "gulp
browser:clean" (it feels more systematic).

Functionality is mostly unchanged (modulo Gulp clutter in the console),
but there are two small exceptions:

  gulp spec

    The reporter now displays just dots while previously it displayed
    spec descriptions. There is also a deprecation warning (most likely
    because I used an old version of gulp-jasmine in order to support
    Jasmine 1.x). I kept these issues unfixed because I plan to switch
    to Mocha soon (#409).

  gulp browser:build

    The copyright header is now added manually both to the development
    and minified build. Before, it was added only to the development
    build and the minified build relied on preserving it using "uglify
    --comments". This was broken since switching to //-style comments.

    There is now also an empty line between the header and the source
    code.

Fixes #444.
redux
David Majda 8 years ago
parent ef3abf33b9
commit 9956b42392

@ -4,6 +4,8 @@ node_js:
- "4.0"
- "5.0"
- "6.0"
before_script:
- npm install -g gulp
cache:
directories:
- node_modules

@ -46,8 +46,8 @@ see good examples.
When appropriate, add documentation and tests.
Before submitting, make sure your change passes the specs (`make spec`) and
ESLint checks (`make lint`).
Before submitting, make sure your change passes the specs (`gulp spec`) and
ESLint checks (`gulp lint`).
[issues]: https://github.com/pegjs/pegjs/issues
[issues-search-bugs]: https://github.com/pegjs/pegjs/issues?q=is%3Aopen+is%3Aissue+label%3ABug

@ -1,99 +0,0 @@
# ===== Variables =====
PEGJS_VERSION = `cat $(VERSION_FILE)`
# ===== Directories =====
SRC_DIR = src
LIB_DIR = lib
BIN_DIR = bin
BROWSER_DIR = browser
SPEC_DIR = spec
BENCHMARK_DIR = benchmark
NODE_MODULES_DIR = node_modules
NODE_MODULES_BIN_DIR = $(NODE_MODULES_DIR)/.bin
# ===== Files =====
MAIN_FILE = $(LIB_DIR)/peg.js
PARSER_SRC_FILE = $(SRC_DIR)/parser.pegjs
PARSER_OUT_FILE = $(LIB_DIR)/parser.js
BROWSER_FILE_DEV = $(BROWSER_DIR)/peg.js
BROWSER_FILE_MIN = $(BROWSER_DIR)/peg.min.js
SPEC_SERVER_FILE = $(SPEC_DIR)/server
BENCHMARK_SERVER_FILE = $(BENCHMARK_DIR)/server
VERSION_FILE = VERSION
# ===== Executables =====
ESLINT = $(NODE_MODULES_BIN_DIR)/eslint
BROWSERIFY = $(NODE_MODULES_BIN_DIR)/browserify
UGLIFYJS = $(NODE_MODULES_BIN_DIR)/uglifyjs
JASMINE_NODE = $(NODE_MODULES_BIN_DIR)/jasmine-node
PEGJS = $(BIN_DIR)/pegjs
BENCHMARK_RUN = $(BENCHMARK_DIR)/run
# ===== Targets =====
# Default target
all: browser
# Generate the grammar parser
parser:
$(PEGJS) -o $(PARSER_OUT_FILE) $(PARSER_SRC_FILE)
# Build the browser version of the library
browser:
mkdir -p $(BROWSER_DIR)
rm -f $(BROWSER_FILE_DEV)
rm -f $(BROWSER_FILE_MIN)
echo "// PEG.js $(PEGJS_VERSION)" >> $(BROWSER_FILE_DEV)
echo '//' >> $(BROWSER_FILE_DEV)
echo '// http://pegjs.org/' >> $(BROWSER_FILE_DEV)
echo '//' >> $(BROWSER_FILE_DEV)
echo '// Copyright (c) 2010-2016 David Majda' >> $(BROWSER_FILE_DEV)
echo '// Licensed under the MIT license.' >> $(BROWSER_FILE_DEV)
$(BROWSERIFY) \
--standalone peg \
--transform [ babelify --presets [ es2015 ] --compact false ] \
$(MAIN_FILE) >> $(BROWSER_FILE_DEV)
$(UGLIFYJS) \
--mangle \
--compress warnings=false \
--comments /Copyright/ \
-o $(BROWSER_FILE_MIN) \
$(BROWSER_FILE_DEV)
# Remove browser version of the library (created by "browser")
browserclean:
rm -rf $(BROWSER_DIR)
# Run the spec suite
spec:
$(JASMINE_NODE) --verbose $(SPEC_DIR)
# Run the benchmark suite
benchmark:
$(BENCHMARK_RUN)
# Run ESLint on the source
lint:
$(ESLINT) \
`find $(LIB_DIR) -name '*.js' -and -not -path '$(PARSER_OUT_FILE)'` \
`find $(SPEC_DIR) -name '*.js' -and -not -path '$(SPEC_DIR)/vendor/*'` \
$(SPEC_SERVER_FILE) \
$(BENCHMARK_DIR)/*.js \
$(BENCHMARK_RUN) \
$(BENCHMARK_SERVER_FILE) \
$(PEGJS)
.PHONY: all parser browser browserclean spec benchmark lint
.SILENT: all parser browser browserclean spec benchmark lint

@ -20,7 +20,7 @@ All commands in the following steps need to be executed in PEG.js root directory
2. Execute the benchmark suite:
```console
$ make benchmark
$ gulp benchmark
```
3. Wait for results.

@ -0,0 +1,105 @@
"use strict";
/* eslint-env node */
let babelify = require("babelify");
let browserify = require("browserify");
let buffer = require("vinyl-buffer");
let del = require("del");
let eslint = require("gulp-eslint");
let gulp = require("gulp");
let header = require("gulp-header");
let jasmine = require("gulp-jasmine");
let package_ = require("./package");
let peg = require("./lib/peg");
let rename = require("gulp-rename");
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,
"//",
"// http://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",
"spec/**/*.js",
"spec/server",
"!spec/vendor/**/*",
"benchmark/**/*.js",
"benchmark/run",
"benchmark/server",
"!benchmark/vendor/**/*",
"bin/pegjs",
"gulpfile.js"
];
const SPEC_FILES = [
"spec/**/*.js",
"!spec/vendor/**/*"
];
function generate(contents) {
return peg.generate(contents.toString(), {
output: "source",
format: "commonjs"
});
}
// Run ESLint on all JavaScript files.
gulp.task("lint", () =>
gulp.src(JS_FILES)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
// Run specs.
gulp.task("spec", () =>
gulp.src(SPEC_FILES)
.pipe(jasmine())
);
// Run benchmarks.
gulp.task("benchmark", () =>
spawn("benchmark/run", { stdio: "inherit" })
);
// Create the browser build.
gulp.task("browser:build", () =>
browserify("lib/peg.js", { standalone: "peg" })
.transform(babelify, { presets: "es2015", compact: false })
.bundle()
.pipe(source("peg.js"))
.pipe(header(HEADER))
.pipe(gulp.dest("browser"))
.pipe(rename({ suffix: ".min" }))
.pipe(buffer())
.pipe(uglify())
.pipe(header(HEADER))
.pipe(gulp.dest("browser"))
);
// Delete the browser build.
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"))
);
// Default task.
gulp.task("default", ["lint", "spec"]);

@ -42,19 +42,26 @@
"bin": "bin/pegjs",
"repository": "pegjs/pegjs",
"scripts": {
"test": "make lint && make spec"
"test": "gulp"
},
"devDependencies": {
"babel-preset-es2015": "6.14.0",
"babelify": "7.3.0",
"browserify": "13.1.0",
"eslint": "3.7.1",
"del": "2.2.2",
"eslint-config-dmajda": "1.0.0",
"express": "4.14.0",
"glob": "7.0.6",
"jasmine-node": "1.14.5",
"gulp": "3.9.1",
"gulp-eslint": "3.0.1",
"gulp-header": "1.8.8",
"gulp-jasmine": "0.2.0",
"gulp-rename": "1.2.2",
"gulp-transform": "1.0.8",
"gulp-uglify": "2.0.0",
"morgan": "1.7.0",
"uglify-js": "2.7.0"
"vinyl-buffer": "1.0.0",
"vinyl-source-stream": "1.1.0"
},
"engines": {
"node": ">=4"

@ -19,7 +19,7 @@ All commands in the following steps need to be executed in PEG.js root directory
2. Execute the spec suite:
```console
$ make spec
$ gulp spec
```
3. Watch the specs pass (or fail).

@ -13,7 +13,7 @@ prepare() {
}
run_benchmark() {
echo $(make benchmark | awk 'BEGIN { FS = " *│ *" } /Total/ { split($5, a, " "); print a[1] }')
echo $(gulp benchmark | awk 'BEGIN { FS = " *│ *" } /Total/ { split($5, a, " "); print a[1] }')
}
measure_speed() {

Loading…
Cancel
Save