-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
111 lines (92 loc) · 3.49 KB
/
gulpfile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const gulp = require("gulp");
const sequence = require("gulp-sequence");
const notify = require("gulp-notify");
const plumber = require("gulp-plumber");
const server = require("gulp-live-server");
const eslint = require("gulp-eslint");
const beautify = require("gulp-beautify");
const babel = require("gulp-babel");
const babelPresetEnv = require("babel-preset-env");
const babelTransformerAmd = require("babel-plugin-transform-es2015-modules-amd");
const eslintRc = require("./.eslintrc.json");
const ALL_JS_FILES = "*.js";
const JS_DEV_SOURCE = "./dev";
const JS_SOURCE = "./src";
const JS_DESTINATION = "./dist";
gulp.task("localAutosave", function() {
return gulp.src(`${JS_SOURCE}/${ALL_JS_FILES}`)
.pipe(gulp.dest("./local_autosave"));
});
gulp.task("lint", function() {
return gulp.src(`${JS_SOURCE}/${ALL_JS_FILES}`)
.pipe(eslint(eslintRc))
.pipe(eslint.format())
.pipe(notify(function(file) {
const SINGULAR = 1;
let result = false;
if (file.eslint.warningCount + file.eslint.errorCount) {
result = {
title: "",
message: file.eslint.messages.map(message => {
let severityMessage = "";
const SEVERITY = {
Error: 0,
Warning: 1
};
switch (message.severity) {
case SEVERITY.Error:
severityMessage = "Error";
break;
case SEVERITY.Warning:
severityMessage = "Warning";
break;
default:
severityMessage = "Info";
break;
}
return `${severityMessage}: ${message.message}`;
}).join("\n")
};
if (file.eslint.errorCount) {
let multipleErrors = file.eslint.errorCount > SINGULAR;
result.title = `ESLint found ${!multipleErrors?"an":""} error${multipleErrors?"s":""}"`;
} else {
result.title = "ESLint something to warn you about in your code.";
}
}
return result;
}))
.pipe(eslint.failAfterError());
});
gulp.task("beautify", function() {
return gulp.src(`${JS_DEV_SOURCE}/${ALL_JS_FILES}`)
.pipe(plumber())
.pipe(beautify())
.pipe(eslint({
fix: true
}))
.pipe(gulp.dest(JS_SOURCE));
});
gulp.task("build", function() {
return gulp.src(`${JS_SOURCE}/${ALL_JS_FILES}`)
.pipe(plumber())
.pipe(babel({
presets: [babelPresetEnv],
plugins: [babelTransformerAmd]
}))
.pipe(gulp.dest(JS_DESTINATION))
.pipe(notify("Build done."));
});
gulp.task("develop", function(callback) {
return sequence("beautify", ["lint", "build"], "localAutosave", callback);
});
gulp.task("watch-develop", function() {
return gulp.watch(`${JS_DEV_SOURCE}/${ALL_JS_FILES}`, ["develop"]);
});
gulp.task("serve-develop", function() {
let serverInst = server.static("./"); //equals to gls.static('public', 3000);
serverInst.start();
return gulp.watch(`${JS_DEV_SOURCE}/${ALL_JS_FILES}`, ["develop"], function(file) {
serverInst.notify(file);
});
});