/
gulp.js
69 lines (59 loc) · 1.9 KB
/
gulp.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
module.exports = function createTask(crafty, bundle, StreamHandler) {
return cb => {
// Init
const stream = new StreamHandler(
bundle.source,
crafty.config.destination_js +
(bundle.directory ? `/${bundle.directory}` : ""),
cb
);
// Avoid compressing if it's already at the latest version
if (crafty.isWatching()) {
const newer = require("gulp-newer");
stream.add(newer(crafty.config.destination_js + bundle.destination));
}
// Linting
const {
toTempFile
} = require("@swissquote/crafty-preset-eslint/src/eslintConfigurator");
const eslint = require("gulp-eslint-new");
stream.add(eslint(
{
overrideConfigFile: toTempFile(crafty.config.eslint)
}
)).add(eslint.format());
// Fail the build if we have linting
// errors and we build directly
if (!crafty.isWatching()) {
stream.add(
eslint.results(results => {
const count = results.errorCount;
if (count) {
const message = `ESLint failed with ${count}${
count === 1 ? " error" : " errors"
}`;
cb(new crafty.Information(message));
}
})
);
}
const swc = require("gulp-swc");
const { getConfigurationGulp } = require("./configuration.js");
const swcOptions = getConfigurationGulp(crafty, bundle);
stream.add(swc(swcOptions, bundle));
// Process
const sourcemaps = require("gulp-sourcemaps");
stream.add(sourcemaps.init({ loadMaps: true }));
if (bundle.concat) {
const concat = require("gulp-concat");
stream.add(concat(bundle.destination));
}
if (crafty.getEnvironment() === "production") {
const terser = require("gulp-terser");
stream.add(terser({ ...crafty.config.terser, sourceMap: {} }));
}
stream.add(sourcemaps.write("./"));
// Save
return stream.generate();
};
};