Skip to content

Commit

Permalink
chore: convert gulpfile to Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed May 11, 2018
1 parent 89307e8 commit 66c8ff1
Show file tree
Hide file tree
Showing 4 changed files with 2,319 additions and 2,224 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ build/
coverage/
dist/
examples/**/app.yaml
*.js
*.map
src/**/*.js
src/**/*.map
src/**/*.d.ts
Expand Down
42 changes: 22 additions & 20 deletions gulpfile.js → gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const _spawn = require("child_process").spawn
const { join } = require("path")
import { spawn as _spawn, ChildProcess } from "child_process"
import { join } from "path"

const gulp = require("gulp")
const cached = require("gulp-cached")
Expand All @@ -26,27 +26,28 @@ let destDir = "build"

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

function setDestDir(path) {
destDir = path
}

const children = []
const children: ChildProcess[] = []

process.env.FORCE_COLOR = true
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))
const output: string[] = []
child.stdout.on("data", (data) => output.push(data.toString()))
child.stderr.on("data", (data) => output.push(data.toString()))

child.on("exit", (code) => {
console.log(code)
if (code !== 0) {
console.log(output.join(""))
die()
Expand All @@ -65,21 +66,21 @@ function die() {
}

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

gulp.task("mocha", (cb) =>
spawn("node_modules/.bin/nyc", ["node_modules/.bin/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")))
.pipe(gulp.dest(join(destDir, "src"))),
)

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

gulp.task("static", () => {
Expand All @@ -98,7 +99,7 @@ gulp.task("tsc", () =>
.pipe(tsProject(reporter))
.on("error", die)
.pipe(sourcemaps.write())
.pipe(gulp.dest(join(destDir, "src")))
.pipe(gulp.dest(join(destDir, "src"))),
)

gulp.task("tsc-watch", () =>
Expand All @@ -110,7 +111,7 @@ gulp.task("tsc-watch", () =>
"--outDir", join(destDir, "src"),
],
{ stdio: "inherit" },
)
),
)

gulp.task("tsfmt", (cb) => {
Expand All @@ -134,27 +135,28 @@ gulp.task("tslint", () =>
.pipe(cached("tslint"))
.pipe(gulpTslint({
program: tslint.Linter.createProgram("./tsconfig.json"),
formatter: "verbose"
formatter: "verbose",
}))
.pipe(gulpTslint.report())
.pipe(gulpTslint.report()),
)

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

gulp.task("tslint-watch", () =>
gulp.watch([tsSources, testTsSources], gulp.parallel("tslint", "tslint-tests"))
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("watch",
gulp.parallel("pegjs-watch", "static-watch", "tsc-watch", "tsfmt-watch", "tslint-watch"))
gulp.task("default", gulp.series("watch"))
Loading

0 comments on commit 66c8ff1

Please sign in to comment.