This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
79 lines (65 loc) · 1.97 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
import fs from "fs";
import gulp from "gulp";
import concat from "gulp-concat";
import insert from "gulp-inject-string";
import sourcemaps from "gulp-sourcemaps";
import envify from "gulp-envify";
import dotenv from "dotenv";
// Configuration
// ========================================================
const outputDir = "./dist";
const manifestFileName = "manifest.json";
const {parsed} = dotenv.config()
// Generate gulp tasks based on directories in ./cases
generateTasks("./cases");
// Helpers
// ========================================================
function generateTasks(basePath) {
let allTasks = [];
fs.readdirSync(basePath).forEach((name) => {
const stats = fs.statSync("cases/" + name);
if (stats.isDirectory()) {
try {
const manifest = JSON.parse(fs.readFileSync("cases/" + name + "/" + manifestFileName));
console.log("====> Defining test case '" + name + "' with manifest: ", manifest);
exports[name] = gulp.task(name, () => {
return buildPipeline(manifest, name + ".js");
});
allTasks.push(name);
}
catch (e) {
console.error(e)
console.error("====> Could not load manifest file for: " + name);
process.exit(1);
}
}
});
exports.watch = gulp.task("watch", () => {
const options = {
queue: true,
};
gulp.watch(["cases/**/*.js", "components/**/*.js"], options, gulp.parallel(allTasks));
});
exports.default = gulp.parallel(allTasks);
}
function buildPipeline(input, output) {
return gulp.src(input, { base: "." })
.pipe(envify(parsed))
.pipe(sourcemaps.init())
.pipe(concat(output))
.pipe(insert.wrap(getBanner(), getFooter()))
.pipe(sourcemaps.write())
.pipe(gulp.dest(outputDir));
}
function getBanner() {
return `//
// This file is automatically generated.
//
// (!!!) DO NOT MODIFY DIRECTLY! (!!!)
//\n\n`;
}
function getFooter() {
return `
// (!!!) DO NOT REMOVE OR CHANGE THE FOLLOWING LINES! (!!!)`;
}