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.
This commit is contained in:
Tim van der Meij 2020-08-02 19:06:50 +02:00
parent 9989879458
commit 7e759c6e2b
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -63,7 +63,8 @@ var GH_PAGES_DIR = BUILD_DIR + "gh-pages/";
var SRC_DIR = "src/"; var SRC_DIR = "src/";
var LIB_DIR = BUILD_DIR + "lib/"; var LIB_DIR = BUILD_DIR + "lib/";
var DIST_DIR = BUILD_DIR + "dist/"; 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 COMMON_WEB_FILES = ["web/images/*.{png,svg,gif,cur}", "web/debugger.js"];
var MOZCENTRAL_DIFF_FILE = "mozcentral.diff"; var MOZCENTRAL_DIFF_FILE = "mozcentral.diff";
@ -1143,12 +1144,12 @@ gulp.task("jsdoc", function (done) {
}); });
gulp.task("types", function (done) { gulp.task("types", function (done) {
console.log("### Generating typescript definitions using tsc"); console.log("### Generating TypeScript definitions using `tsc`");
var args = [ const args = [
"target ES2020", "target ES2020",
"allowJS", "allowJS",
"declaration", "declaration",
`outDir ${TYPES_BUILD_DIR}`, `outDir ${TYPES_DIR}`,
"strict", "strict",
"esModuleInterop", "esModuleInterop",
"forceConsistentCasingInFileNames", "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( gulp.task(
"typestest", "typestest",
gulp.series( gulp.series("typestest-pre", function (done) {
"testing-pre", exec("node_modules/.bin/tsc -p test/types", function (err, stdout) {
"generic", if (err) {
"types", console.log(`Couldn't compile TypeScript test: ${stdout}`);
}
function () { done(err);
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.task("baseline", function (done) { gulp.task("baseline", function (done) {
@ -1752,9 +1747,7 @@ gulp.task(
gulp gulp
.src(LIB_DIR + "**/*", { base: LIB_DIR }) .src(LIB_DIR + "**/*", { base: LIB_DIR })
.pipe(gulp.dest(DIST_DIR + "lib/")), .pipe(gulp.dest(DIST_DIR + "lib/")),
gulp gulp.src(TYPES_DIR + "**/**").pipe(gulp.dest(DIST_DIR + "build/")),
.src(TYPES_BUILD_DIR + "**/**")
.pipe(gulp.dest(DIST_DIR + "build/")),
]); ]);
} }
) )