-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulp.js
80 lines (69 loc) · 2.28 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
70
71
72
73
74
75
76
77
78
79
80
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("../packages/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));
}
})
);
}
// Process
const sourcemaps = require("gulp-sourcemaps");
stream.add(sourcemaps.init({ loadMaps: true }));
// First convert TypeScript
const tsOptions = {
// Transpile to esnext so that Babel can apply all its magic
target: "ESNext",
// Preserve JSX so babel can optimize it, or add development/debug information
jsx: "Preserve"
};
const typescript = require("gulp-typescript");
const tsProject = typescript.createProject("tsconfig.json", tsOptions);
stream.add(tsProject());
// Then finalize with Babel
const babel = require("gulp-babel");
const babelConfigurator = require("@swissquote/babel-preset-swissquote/configurator-gulp");
const babelOptions = babelConfigurator(crafty, bundle);
babelOptions.ignore = ["**/*.d.ts"];
stream.add(babel(babelOptions));
if (bundle.concat) {
const concat = require("../packages/gulp-concat");
stream.add(concat(bundle.destination));
}
stream.add(sourcemaps.write("./"));
// Save
return stream.generate();
};
};