Skip to content

Commit 7a76116

Browse files
committed
chore: upgrade gulp
1 parent f1264b1 commit 7a76116

File tree

3 files changed

+854
-579
lines changed

3 files changed

+854
-579
lines changed

gulpfile.js

+55-118
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const postcss = require("gulp-postcss");
99
const autoprefixer = require("autoprefixer");
1010
const cssnano = require("cssnano");
1111

12-
const _ = require("lodash");
13-
const through = require("through2");
14-
1512
const webpack = require("webpack");
1613
const webpackStream = require("webpack-stream");
1714

@@ -22,29 +19,24 @@ const gitDescribe = require("git-describe").gitDescribe;
2219

2320
const download = require("gulp-download");
2421

25-
const fs = require("fs");
26-
const path = require("path");
27-
28-
gulp.task("default", ["watch"]);
29-
30-
gulp.task("compile", ["compile:web"]);
31-
gulp.task("compile:web", [
32-
"compile:scripts:web",
33-
"compile:styles",
34-
"html:web",
35-
"assets",
36-
"version:write",
37-
]);
38-
gulp.task("compile:dev", [
39-
"compile:scripts:dev",
40-
"compile:styles",
41-
"html:dev",
42-
"assets",
43-
]);
22+
gulp.task("env:set-release", function(cb) {
23+
gitDescribe(__dirname, { match: null }).then(function(gitInfo) {
24+
var release = gitInfo.semverString;
25+
if (!release) {
26+
throw Error("Unable to determine release");
27+
}
28+
gutil.log("Setting JOUST_RELEASE to", gutil.colors.green(release));
29+
process.env.JOUST_RELEASE = release;
30+
cb();
31+
});
32+
});
4433

45-
gulp.task("compile:scripts", ["compile:scripts:web"]);
34+
gulp.task("version:write", gulp.series("env:set-release", function() {
35+
const version = process.env.JOUST_RELEASE;
36+
return gfile("VERSION", version, { src: true }).pipe(gulp.dest("dist/"));
37+
}));
4638

47-
gulp.task("compile:scripts:web", ["env:set-release"], function() {
39+
gulp.task("compile:scripts:web", gulp.series("env:set-release", function() {
4840
const config = require("./webpack.config.js");
4941
config.entry = { joust: config.entry.joust }; // remove all bundles but joust
5042
config.target = "web";
@@ -72,7 +64,9 @@ gulp.task("compile:scripts:web", ["env:set-release"], function() {
7264
.src("ts/run.ts")
7365
.pipe(webpackStream(config, webpack))
7466
.pipe(gulp.dest("dist/"));
75-
});
67+
}));
68+
69+
gulp.task("compile:scripts", gulp.series("compile:scripts:web"));
7670

7771
gulp.task("compile:scripts:dev", function() {
7872
return gulp
@@ -107,116 +101,59 @@ gulp.task("compile:styles", function() {
107101
.pipe(livereload());
108102
});
109103

110-
gulp.task("env:set-release", function(cb) {
111-
gitDescribe(__dirname, { match: null }).then(function(gitInfo) {
112-
var release = gitInfo.semverString;
113-
if (!release) {
114-
throw Error("Unable to determine release");
115-
}
116-
gutil.log("Setting JOUST_RELEASE to", gutil.colors.green(release));
117-
process.env.JOUST_RELEASE = release;
118-
cb();
119-
});
120-
});
121-
122-
gulp.task("version:write", ["env:set-release"], function() {
123-
const version = process.env.JOUST_RELEASE;
124-
return gfile("VERSION", version, { src: true }).pipe(gulp.dest("dist/"));
125-
});
126-
127-
gulp.task("html", ["html:dev"]);
128-
129104
gulp.task("html:dev", function() {
130105
return gulp.src("html/**/*.html").pipe(gulp.dest("dist/"));
131106
});
132-
133107
gulp.task("html:web", function() {
134108
return gulp.src("html/index.html").pipe(gulp.dest("dist/"));
135109
});
110+
gulp.task("html", gulp.series("html:dev"));
136111

137112
gulp.task("assets", function() {
138113
return gulp.src("assets/**/*.*").pipe(gulp.dest("dist/assets/"));
139114
});
140115

141-
gulp.task("watch", ["watch:styles", "watch:html", "watch:assets"], function() {
142-
livereload.listen();
143-
gutil.log(
144-
gutil.colors.yellow(
145-
"Warning: not compiling or watching TypeScript files",
146-
),
147-
);
148-
gutil.log(gutil.colors.yellow('Use "webpack --watch -d" for development'));
116+
gulp.task("enums:download", function() {
117+
return download("https://api.hearthstonejson.com/v1/enums.d.ts").pipe(gulp.dest("ts/"));
149118
});
150119

151-
gulp.task("watch:styles", ["compile:styles"], function() {
152-
return gulp.watch(["less/**/*.less"], ["compile:styles"]);
153-
});
120+
gulp.task("compile:web", gulp.parallel(
121+
"compile:scripts:web",
122+
"compile:styles",
123+
"html:web",
124+
"assets",
125+
"version:write",
126+
));
154127

155-
gulp.task("watch:html", ["html"], function() {
156-
return gulp.watch(["html/**/*.html"], ["html"]);
157-
});
128+
gulp.task("compile", gulp.series("compile:web"));
158129

159-
gulp.task("watch:assets", ["assets"], function() {
160-
return gulp.watch(["assets/**/*.*"], ["assets"]);
161-
});
130+
gulp.task("compile:dev", gulp.parallel(
131+
"compile:scripts:dev",
132+
"compile:styles",
133+
"html:dev",
134+
"assets",
135+
));
162136

163-
gulp.task("enums", function() {
164-
gutil.log(
165-
gutil.colors.red(
166-
'"enums" has been split up in "enums:download" (preferred) and "enums:generate" (legacy)',
167-
),
168-
);
169-
});
137+
gulp.task("watch:styles", gulp.series("compile:styles", function() {
138+
return gulp.watch(["less/**/*.less"], gulp.series("compile:styles"));
139+
}));
170140

171-
gulp.task("enums:download", function() {
172-
download("https://api.hearthstonejson.com/v1/enums.d.ts").pipe(
173-
gulp.dest("ts/"),
174-
);
175-
});
141+
gulp.task("watch:html", gulp.series("html", function() {
142+
return gulp.watch(["html/**/*.html"], gulp.series("html"));
143+
}));
176144

177-
gulp.task("enums:download:json", function() {
178-
download("https://api.hearthstonejson.com/v1/enums.json").pipe(
179-
gulp.dest("./"),
180-
);
181-
});
145+
gulp.task("watch:assets", gulp.series("assets", function() {
146+
return gulp.watch(["assets/**/*.*"], gulp.series("assets"));
147+
}));
182148

183-
gulp.task("enums:generate:download", ["enums:download:json", "enums:generate"]);
149+
gulp.task("watch", gulp.parallel("watch:styles", "watch:html", "watch:assets", function() {
150+
livereload.listen();
151+
gutil.log(
152+
gutil.colors.yellow(
153+
"Warning: not compiling or watching TypeScript files",
154+
),
155+
);
156+
gutil.log(gutil.colors.yellow('Use "webpack --watch -d" for development'));
157+
}));
184158

185-
gulp.task("enums:generate", function() {
186-
return gulp
187-
.src(process.env.ENUMS_JSON || "enums.json")
188-
.pipe(
189-
through.obj(function(file, encoding, callback) {
190-
gutil.log(
191-
"Reading enums from",
192-
gutil.colors.magenta(file.path),
193-
);
194-
var json = String(file.contents);
195-
var out =
196-
"// this file was automatically generated by `gulp enums`\n";
197-
out +=
198-
"// enums.json can be obtained from https://api.hearthstonejson.com/v1/enums.json\n";
199-
var enums = JSON.parse(json);
200-
_.each(enums, function(keys, name) {
201-
out += "\nexport const enum " + name + " {\n";
202-
foo = [];
203-
_.each(keys, function(value, key) {
204-
foo.push("\t" + key + " = " + value);
205-
});
206-
out += foo.join(",\n") + "\n";
207-
out += "}\n";
208-
gutil.log(
209-
"Found enum",
210-
'"' + gutil.colors.cyan(name) + '"',
211-
"with",
212-
gutil.colors.magenta(foo.length, "members"),
213-
);
214-
});
215-
file.path = "enums.d.ts";
216-
file.contents = new Buffer(out);
217-
gutil.log("Writing to", gutil.colors.magenta(file.path));
218-
callback(null, file);
219-
}),
220-
)
221-
.pipe(gulp.dest("ts/"));
222-
});
159+
gulp.task("default", gulp.series("watch"));

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"electron": "^14",
4848
"filereader-stream": "^1.0.0",
4949
"git-describe": "^4.0.1",
50-
"gulp": "^3.9.1",
50+
"gulp": "^4.0.2",
5151
"gulp-download": "0.0.1",
52-
"gulp-file": "^0.3.0",
52+
"gulp-file": "^0.4.0",
5353
"gulp-filter": "^5.0.0",
5454
"gulp-less": "^3.3.0",
5555
"gulp-livereload": "^3.8.1",
@@ -86,8 +86,5 @@
8686
"arrowParens": "always",
8787
"trailingComma": "all"
8888
},
89-
"resolutions": {
90-
"graceful-fs": "4.2.3"
91-
},
9289
"private": true
9390
}

0 commit comments

Comments
 (0)