From 7e759c6e2b06652884b2176581e829fd83264194 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 2 Aug 2020 19:06:50 +0200 Subject: [PATCH] Improve the `typestest` target in the Gulpfile This commit: - moves the preparation work to a new `typestest-pre` target similar to how the other targets work; - moves the `TYPESTEST_DIR` definition to the top of the file like we did for all other directory variables; - renames the `TYPES_BUILD_DIR` variable to `TYPES_DIR` since it's shorter and the naming scheme then corresponds to the other directory variables; - switches to `const`/template strings in the types targets where needed; - converts the `if (err !== null)` check to `if (err)` similar to other targets. --- gulpfile.js | 71 ++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b15db4ee8..39a39bd90 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -63,7 +63,8 @@ var GH_PAGES_DIR = BUILD_DIR + "gh-pages/"; var SRC_DIR = "src/"; var LIB_DIR = BUILD_DIR + "lib/"; var DIST_DIR = BUILD_DIR + "dist/"; -var TYPES_BUILD_DIR = BUILD_DIR + "types/"; +var TYPES_DIR = BUILD_DIR + "types/"; +var TYPESTEST_DIR = BUILD_DIR + "typestest/"; var COMMON_WEB_FILES = ["web/images/*.{png,svg,gif,cur}", "web/debugger.js"]; var MOZCENTRAL_DIFF_FILE = "mozcentral.diff"; @@ -1143,12 +1144,12 @@ gulp.task("jsdoc", function (done) { }); gulp.task("types", function (done) { - console.log("### Generating typescript definitions using tsc"); - var args = [ + console.log("### Generating TypeScript definitions using `tsc`"); + const args = [ "target ES2020", "allowJS", "declaration", - `outDir ${TYPES_BUILD_DIR}`, + `outDir ${TYPES_DIR}`, "strict", "esModuleInterop", "forceConsistentCasingInFileNames", @@ -1352,40 +1353,34 @@ gulp.task( }) ); +gulp.task( + "typestest-pre", + gulp.series("testing-pre", "generic", "types", function () { + const [packageJsonSrc] = packageBowerJson(); + return merge([ + packageJsonSrc.pipe(gulp.dest(TYPESTEST_DIR)), + gulp + .src([ + GENERIC_DIR + "build/pdf.js", + GENERIC_DIR + "build/pdf.worker.js", + SRC_DIR + "pdf.worker.entry.js", + ]) + .pipe(gulp.dest(TYPESTEST_DIR + "build/")), + gulp.src(TYPES_DIR + "**/**").pipe(gulp.dest(TYPESTEST_DIR + "build/")), + ]); + }) +); + gulp.task( "typestest", - gulp.series( - "testing-pre", - "generic", - "types", - - function () { - var packageJsonSrc = packageBowerJson()[0]; - var TYPESTEST_DIR = BUILD_DIR + "typestest/"; - - return merge([ - packageJsonSrc.pipe(gulp.dest(TYPESTEST_DIR)), - gulp - .src([ - GENERIC_DIR + "build/pdf.js", - GENERIC_DIR + "build/pdf.worker.js", - SRC_DIR + "pdf.worker.entry.js", - ]) - .pipe(gulp.dest(TYPESTEST_DIR + "build/")), - gulp - .src(TYPES_BUILD_DIR + "**/**") - .pipe(gulp.dest(TYPESTEST_DIR + "build/")), - ]); - }, - function (done) { - exec(`node_modules/.bin/tsc -p test/types`, function (err, stdout) { - if (err !== null) { - console.log("couldn't compile typescript test: " + stdout); - } - done(err); - }); - } - ) + gulp.series("typestest-pre", function (done) { + exec("node_modules/.bin/tsc -p test/types", function (err, stdout) { + if (err) { + console.log(`Couldn't compile TypeScript test: ${stdout}`); + } + done(err); + }); + }) ); gulp.task("baseline", function (done) { @@ -1752,9 +1747,7 @@ gulp.task( gulp .src(LIB_DIR + "**/*", { base: LIB_DIR }) .pipe(gulp.dest(DIST_DIR + "lib/")), - gulp - .src(TYPES_BUILD_DIR + "**/**") - .pipe(gulp.dest(DIST_DIR + "build/")), + gulp.src(TYPES_DIR + "**/**").pipe(gulp.dest(DIST_DIR + "build/")), ]); } )