forked from gebrkn/copytables
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
97 lines (85 loc) · 2.38 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
"use strict";
const clip = require("gulp-clip-empty-files"),
cp = require("child_process"),
del = require("del"),
fs = require("fs"),
gulp = require("gulp"),
named = require("vinyl-named"),
pug = require("gulp-pug"),
path = require("path"),
sass = require("gulp-sass")(require("node-sass")),
sassTypes = require("node-sass").types,
webpack = require("webpack-stream"),
uglify = require("gulp-uglify"),
through = require("through2");
const DEST = "./app";
const TEST_URL = "http://localhost:9876/all";
const IS_DEV = process.env.NODE_ENV === "development";
// based on https://coderwall.com/p/fhgu_q/inlining-images-with-gulp-sass
function sassInlineImage(file) {
var filePath = path.resolve(process.cwd(), file.getValue()),
ext = filePath.split(".").pop(),
data = fs.readFileSync(filePath),
buffer = Buffer.from(data),
str = '"data:image/' + ext + ";base64," + buffer.toString("base64") + '"';
return sassTypes.String(str);
}
const webpackConfig = {
mode: IS_DEV ? "development" : "production",
devtool: false,
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: __dirname + "/convert-logs?" + (IS_DEV ? "dev" : ""),
},
],
},
],
},
};
gulp.task("pug", function () {
return gulp.src("./src/*.pug").pipe(pug()).pipe(gulp.dest(DEST));
});
gulp.task("sass", function () {
return gulp
.src("./src/*.sass")
.pipe(
sass({
functions: {
"inline-image($file)": sassInlineImage,
},
})
)
.pipe(clip())
.pipe(gulp.dest(DEST));
});
gulp.task("copy", function () {
return gulp.src("./src/*.{png,css,json,svg}").pipe(gulp.dest(DEST));
});
gulp.task("js", function () {
return gulp
.src("./src/*.js")
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(IS_DEV ? through.obj() : uglify())
.pipe(gulp.dest(DEST));
});
gulp.task("clean", function (done) {
del.sync(DEST);
done();
});
gulp.task("zip", function (done) {
const m = require("./src/manifest.json"),
fn = `copytables-${m.version}.zip`;
cp.execSync(`rm -f ./${fn} && zip -j ./${fn} ./app/*`);
done();
});
gulp.task("make", gulp.parallel("pug", "sass", "copy", "js"));
gulp.task("build", gulp.series("clean", "make"));
gulp.task("deploy", gulp.series("build", "zip"));
gulp.task("watch", function () {
gulp.watch("./src/**/*", gulp.series("make"));
});