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
parent
ef3abf33b9
commit
9956b42392
@ -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
|
@ -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"]);
|
Loading…
Reference in New Issue