-
Notifications
You must be signed in to change notification settings - Fork 20
/
gulpfile.js
189 lines (167 loc) · 4.23 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
const gulp = require("gulp");
const gutil = require("gulp-util");
const gfile = require("gulp-file");
const plumber = require("gulp-plumber");
const sourcemaps = require("gulp-sourcemaps");
const less = require("gulp-less");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const webpack = require("webpack");
const webpackStream = require("webpack-stream");
const filter = require("gulp-filter");
const livereload = require("gulp-livereload");
const gitDescribe = require("git-describe").gitDescribe;
const download = require("gulp-download");
gulp.task("env:set-release", function(done) {
gitDescribe(__dirname, { match: null }).then(function(gitInfo) {
var release = gitInfo.semverString;
if (!release) {
throw Error("Unable to determine release");
}
gutil.log("Setting JOUST_RELEASE to", gutil.colors.green(release));
process.env.JOUST_RELEASE = release;
done();
});
});
gulp.task(
"version:write",
gulp.series("env:set-release", function() {
const version = process.env.JOUST_RELEASE;
return gfile("VERSION", version, { src: true }).pipe(
gulp.dest("dist/"),
);
}),
);
gulp.task(
"compile:scripts:web",
gulp.series("env:set-release", function() {
const config = require("./webpack.config.js");
config.entry = { joust: config.entry.joust }; // remove all bundles but joust
config.target = "web";
config.plugins = config.plugins.concat([
new webpack.optimize.UglifyJsPlugin({
comments: false,
compress: {
warnings: false,
},
sourceMap: true,
}),
new webpack.BannerPlugin({
banner:
"Joust " +
process.env.JOUST_RELEASE +
"\n" +
"https://github.com/HearthSim/Joust",
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
]);
config.devtool = "#source-map";
return gulp
.src("ts/run.ts")
.pipe(webpackStream(config, webpack))
.pipe(gulp.dest("dist/"));
}),
);
gulp.task("compile:scripts", gulp.series("compile:scripts:web"));
gulp.task("compile:scripts:dev", function() {
return gulp
.src("ts/run.ts")
.pipe(webpackStream(require("./webpack.config.js"), webpack))
.pipe(gulp.dest("dist/"));
});
gulp.task("compile:styles", function() {
return gulp
.src("less/joust.less")
.pipe(
plumber(function(err) {
gutil.log(gutil.colors.red(err));
this.emit("end", new gutil.PluginError(err));
}),
)
.pipe(sourcemaps.init())
.pipe(less({ strictMath: true }))
.pipe(
postcss([
autoprefixer({
browsers: ["last 2 versions"],
remove: false,
}),
cssnano(),
]),
)
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist/"))
.pipe(filter(["**/*.css"]))
.pipe(livereload());
});
gulp.task("html:dev", function() {
return gulp.src("html/**/*.html").pipe(gulp.dest("dist/"));
});
gulp.task("html:web", function() {
return gulp.src("html/index.html").pipe(gulp.dest("dist/"));
});
gulp.task("html", gulp.series("html:dev"));
gulp.task("assets", function() {
return gulp.src("assets/**/*.*").pipe(gulp.dest("dist/assets/"));
});
gulp.task("enums:download", function() {
return download("https://api.hearthstonejson.com/v1/enums.d.ts").pipe(
gulp.dest("ts/"),
);
});
gulp.task(
"compile:web",
gulp.parallel(
"compile:scripts:web",
"compile:styles",
"html:web",
"assets",
"version:write",
),
);
gulp.task("compile", gulp.series("compile:web"));
gulp.task(
"compile:dev",
gulp.parallel(
"compile:scripts:dev",
"compile:styles",
"html:dev",
"assets",
),
);
gulp.task(
"watch:styles",
gulp.series("compile:styles", function() {
return gulp.watch(["less/**/*.less"], gulp.series("compile:styles"));
}),
);
gulp.task(
"watch:html",
gulp.series("html", function() {
return gulp.watch(["html/**/*.html"], gulp.series("html"));
}),
);
gulp.task(
"watch:assets",
gulp.series("assets", function() {
return gulp.watch(["assets/**/*.*"], gulp.series("assets"));
}),
);
gulp.task(
"watch",
gulp.parallel("watch:styles", "watch:html", "watch:assets", function() {
livereload.listen();
gutil.log(
gutil.colors.yellow(
"Warning: not compiling or watching TypeScript files",
),
);
gutil.log(
gutil.colors.yellow('Use "webpack --watch -d" for development'),
);
}),
);
gulp.task("default", gulp.series("watch"));