forked from vicalejuri/iching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
156 lines (128 loc) · 3.21 KB
/
gulpfile.babel.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
/* eslint-disable no-alert, no-console */
import gulp from "gulp";
import gulpLoadPlugins from "gulp-load-plugins";
import gutil from "gulp-util";
import webpack from "webpack";
import WebpackDevServer from "webpack-dev-server";
import BrowserSync from "browser-sync";
import eslint from "gulp-eslint";
import del from "del";
import run from "gulp-run";
import RunSequence from "run-sequence";
import scraper from "scraperjs";
import scrapeIchingTable from "./extra/scrape/scrape";
const $ = gulpLoadPlugins();
let path = require("path");
const browserSync = BrowserSync.create();
let options = {};
gulp.task("clean", cb => del(["dist/"]));
// Scrape ichingfortune and save to #{./src/assets/iching.json}
gulp.task("scrape", cb => {
scrapeIchingTable();
});
gulp.task("lint", () =>
gulp
.src(["src/**/*.js"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
// run webpack bundler
gulp.task("bundle", cb => {
const config = require(`./webpack.${options.dist ? "dist." : ""}config`);
const bundler = webpack(config);
function bundlerCallback(err, stats) {
console.log(stats.toString());
gutil.log(
"[webpack]",
stats.toString({
colors: true,
progress: true
})
);
browserSync.reload();
cb();
}
if (options.watch) {
bundler.watch(200, bundlerCallback);
} else {
bundler.run(bundlerCallback);
}
});
gulp.task("bundle:dist", cb => {
options.dist = true;
RunSequence("bundle", cb);
});
// Bundle everything for phonegap
gulp.task(
"bundle:phonegap",
gulp.series("clean", cb => {
options.dist = true;
RunSequence(["assets", "copy", "bundle", "phonegap:copy"]);
})
);
gulp.task("assets", cb =>
gulp.src("src/assets/**/*").pipe(gulp.dest("dist/assets/"))
);
gulp.task("sprites", () => {
// Create sprite from tarot images
let tarot = gulp.src("extra/tarot/*.jpg").pipe(
$.spritesmith({
cssName: "tarot_sprites.css",
imgName: "tarot-sprite.png"
})
);
tarot.img.pipe(gulp.dest("src/assets/img/tarot/"));
tarot.css.pipe(gulp.dest("src/styles/components/"));
});
/*
gulp.task("fonts", cb => {
gulp.src(["./src/styles/fonts/*"]).pipe(gulp.dest("dist/assets/fonts"));
});
*/
gulp.task("copy", cb => {
gulp
.src(["./src/*.html", "./src/*.ico", "./src/*.webmanifest"])
.pipe(gulp.dest("dist/"));
cb();
});
gulp.task("phonegap:copy", cb => {
gulp.src(["dist/**/*"]).pipe(gulp.dest("phonegap/www/"));
});
gulp.task(
"build",
gulp.series("clean", cb => {
RunSequence(["assets", "copy", "bundle"], cb);
})
);
gulp.task(
"build:dist",
gulp.series("clean", cb => {
options.dist = true;
RunSequence(["assets", "copy", "bundle"], cb);
})
);
gulp.task(
"build:watch",
gulp.series("clean", cb => {
options.watch = true;
RunSequence(["build"], () => {
gulp.watch("src/styles/**", ["assets"]);
});
})
);
gulp.task(
"dev-server",
gulp.series("copy", cb => {
browserSync.init({
server: {
baseDir: "./dist/"
}
});
gulp.watch("./src/**/*.js", gulp.series("bundle"));
return run("webpack-dev-server", { verbosity: 3 }).exec();
})
);
gulp.task("gh-publish", cb => {
gulp.src(["./dist/**"]).pipe(gulp.dest("docs/"));
});