Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp #83

Merged
merged 2 commits into from
Apr 25, 2018
Merged

Gulp #83

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/bootstrap-osx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ nvm install 9.4
nvm alias default 9.4

# install/update global packages
npm install -g tslint typescript-formatter
npm install -g [email protected]
gem install copyright-header

# install CircleCI CLI
Expand Down
34 changes: 0 additions & 34 deletions bin/build

This file was deleted.

160 changes: 160 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
const _spawn = require("child_process").spawn
const { join } = require("path")

const gulp = require("gulp")
const cached = require("gulp-cached")
// const debug = require("gulp-debug")
// const exec = require("gulp-exec")
const pegjs = require("gulp-pegjs")
const sourcemaps = require("gulp-sourcemaps")
const gulpTslint = require("gulp-tslint")
const tslint = require("tslint")
const ts = require("gulp-typescript")

const tsProject = ts.createProject("tsconfig.json", {
declaration: true,
})
const reporter = ts.reporter.longReporter()

const tsSources = "src/**/*.ts"
const testTsSources = "test/**/*.ts"
const pegjsSources = "src/*.pegjs"

const staticFiles = ["package.json", "package-lock.json", "static/**", ".snyk"]

let destDir = "build"

class TaskError extends Error {
toString() {
return this.messsage
}
}

function setDestDir(path) {
destDir = path
}

const children = []

process.env.FORCE_COLOR = true

function spawn(cmd, args, cb) {
const child = _spawn(cmd, args, { stdio: "pipe", shell: true, env: process.env })
children.push(child)

const output = []
child.stdout.on("data", (data) => output.push(data))
child.stderr.on("data", (data) => output.push(data))

child.on("exit", (code) => {
if (code !== 0) {
console.log(output.join(""))
die()
}
cb()
})

return child
}

function die() {
for (const child of children) {
!child.killed && child.kill()
}
process.exit(1)
}

gulp.task("check-licenses", (cb) =>
spawn("./bin/check-licenses", [], cb)
)

gulp.task("mocha", (cb) =>
spawn("node_modules/.bin/nyc", ["node_modules/.bin/mocha"], cb)
)

gulp.task("pegjs", () =>
gulp.src(pegjsSources)
.pipe(pegjs({ format: "commonjs" }))
.pipe(gulp.dest(join(destDir, "src")))
)

gulp.task("pegjs-watch", () =>
gulp.watch(pegjsSources, gulp.parallel("pegjs"))
)

gulp.task("static", () => {
return gulp.src(staticFiles, { base: "./" })
.pipe(cached("static"))
.pipe(gulp.dest(destDir))
})

gulp.task("static-watch", () => {
return gulp.watch(staticFiles, gulp.parallel("static"))
})

gulp.task("tsc", () =>
tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject(reporter))
.on("error", die)
.pipe(sourcemaps.write())
.pipe(gulp.dest(join(destDir, "src")))
)

gulp.task("tsc-watch", () =>
_spawn("tsc", [
"-w",
"--pretty",
"--declaration",
"-p", __dirname,
"--outDir", join(destDir, "src"),
],
{ stdio: "inherit" },
)
)

gulp.task("tsfmt", (cb) => {
spawn("node_modules/.bin/tsfmt", ["--verify"], cb)
})

gulp.task("tsfmt-watch", () => {
const verify = (path) => {
try {
_spawn("node_modules/.bin/tsfmt", ["--verify", path], { stdio: "inherit" })
} catch (_) { }
}

return gulp.watch([tsSources, testTsSources])
.on("add", verify)
.on("change", verify)
})

gulp.task("tslint", () =>
gulp.src(tsSources)
.pipe(cached("tslint"))
.pipe(gulpTslint({
program: tslint.Linter.createProgram("./tsconfig.json"),
formatter: "verbose"
}))
.pipe(gulpTslint.report())
)

gulp.task("tslint-tests", () =>
gulp.src(testTsSources)
.pipe(cached("tslint-tests"))
.pipe(gulpTslint({
formatter: "verbose"
}))
.pipe(gulpTslint.report())
)

gulp.task("tslint-watch", () =>
gulp.watch([tsSources, testTsSources], gulp.parallel("tslint", "tslint-tests"))
)

gulp.task("lint", gulp.parallel("check-licenses", "tslint", "tslint-tests", "tsfmt"))
gulp.task("build", gulp.parallel("pegjs", "static", "tsc"))
gulp.task("dist", gulp.series((done) => { setDestDir("dist"); done() }, "lint", "build"))
gulp.task("test", gulp.parallel("build", "lint", "mocha"))
gulp.task("watch", gulp.parallel("pegjs-watch", "static-watch", "tsc-watch", "tsfmt-watch", "tslint-watch"))
gulp.task("default", gulp.series("watch"))
Loading