Skip to content

Commit

Permalink
chore: upgrade gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Mar 26, 2024
1 parent f1264b1 commit a166ad4
Show file tree
Hide file tree
Showing 4 changed files with 920 additions and 612 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 500 # Needed for env:set-release
fetch-tags: true

- uses: actions/setup-node@v3
with:
Expand All @@ -25,14 +28,14 @@ jobs:
- name: Prettier
run: yarn run lint:prettier

- name: TSLint
continue-on-error: true
run: yarn run lint:tslint

- name: Build
run: yarn run build

deploy:
name: Deploy
needs: [test]
Expand Down
265 changes: 116 additions & 149 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");

const _ = require("lodash");
const through = require("through2");

const webpack = require("webpack");
const webpackStream = require("webpack-stream");

Expand All @@ -22,57 +19,62 @@ const gitDescribe = require("git-describe").gitDescribe;

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

const fs = require("fs");
const path = require("path");

gulp.task("default", ["watch"]);
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("compile", ["compile:web"]);
gulp.task("compile:web", [
"compile:scripts:web",
"compile:styles",
"html:web",
"assets",
gulp.task(
"version:write",
]);
gulp.task("compile:dev", [
"compile:scripts:dev",
"compile:styles",
"html:dev",
"assets",
]);

gulp.task("compile:scripts", ["compile:scripts:web"]);

gulp.task("compile:scripts:web", ["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.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
Expand Down Expand Up @@ -107,116 +109,81 @@ gulp.task("compile:styles", function() {
.pipe(livereload());
});

gulp.task("env:set-release", function(cb) {
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;
cb();
});
});

gulp.task("version:write", ["env:set-release"], function() {
const version = process.env.JOUST_RELEASE;
return gfile("VERSION", version, { src: true }).pipe(gulp.dest("dist/"));
});

gulp.task("html", ["html:dev"]);

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("watch", ["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("watch:styles", ["compile:styles"], function() {
return gulp.watch(["less/**/*.less"], ["compile:styles"]);
});

gulp.task("watch:html", ["html"], function() {
return gulp.watch(["html/**/*.html"], ["html"]);
});

gulp.task("watch:assets", ["assets"], function() {
return gulp.watch(["assets/**/*.*"], ["assets"]);
});

gulp.task("enums", function() {
gutil.log(
gutil.colors.red(
'"enums" has been split up in "enums:download" (preferred) and "enums:generate" (legacy)',
),
);
});

gulp.task("enums:download", function() {
download("https://api.hearthstonejson.com/v1/enums.d.ts").pipe(
return download("https://api.hearthstonejson.com/v1/enums.d.ts").pipe(
gulp.dest("ts/"),
);
});

gulp.task("enums:download:json", function() {
download("https://api.hearthstonejson.com/v1/enums.json").pipe(
gulp.dest("./"),
);
});

gulp.task("enums:generate:download", ["enums:download:json", "enums:generate"]);

gulp.task("enums:generate", function() {
return gulp
.src(process.env.ENUMS_JSON || "enums.json")
.pipe(
through.obj(function(file, encoding, callback) {
gutil.log(
"Reading enums from",
gutil.colors.magenta(file.path),
);
var json = String(file.contents);
var out =
"// this file was automatically generated by `gulp enums`\n";
out +=
"// enums.json can be obtained from https://api.hearthstonejson.com/v1/enums.json\n";
var enums = JSON.parse(json);
_.each(enums, function(keys, name) {
out += "\nexport const enum " + name + " {\n";
foo = [];
_.each(keys, function(value, key) {
foo.push("\t" + key + " = " + value);
});
out += foo.join(",\n") + "\n";
out += "}\n";
gutil.log(
"Found enum",
'"' + gutil.colors.cyan(name) + '"',
"with",
gutil.colors.magenta(foo.length, "members"),
);
});
file.path = "enums.d.ts";
file.contents = new Buffer(out);
gutil.log("Writing to", gutil.colors.magenta(file.path));
callback(null, file);
}),
)
.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"));
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"electron": "^14",
"filereader-stream": "^1.0.0",
"git-describe": "^4.0.1",
"gulp": "^3.9.1",
"gulp": "^4.0.2",
"gulp-download": "0.0.1",
"gulp-file": "^0.3.0",
"gulp-file": "^0.4.0",
"gulp-filter": "^5.0.0",
"gulp-less": "^3.3.0",
"gulp-livereload": "^3.8.1",
Expand Down Expand Up @@ -86,8 +86,5 @@
"arrowParens": "always",
"trailingComma": "all"
},
"resolutions": {
"graceful-fs": "4.2.3"
},
"private": true
}
Loading

0 comments on commit a166ad4

Please sign in to comment.