-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.ts
138 lines (114 loc) · 3.47 KB
/
gulpfile.ts
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
if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
import { Assets, GulpHelper, Pug, Rollup, RollupPlugins as RP, Sass, setSeriesFunction, task } from "@keupoz/buildtools";
import { create as bs_create } from "browser-sync";
import { emptyDirSync } from "fs-extra";
import { parallel, series } from "gulp";
const PRODUCTION = process.env.NODE_ENV === "production",
NAME = "ColorWheel2",
DEMOSRC = "demo",
DEMOOUT = "docs",
LIBSRC = "src",
LIBOUT = "dist";
const DEMO = {
assets: new Assets({ inputDir: `${DEMOSRC}/assets`, outputDir: `${DEMOOUT}/assets` }, !PRODUCTION),
rollup: new Rollup({
input: `${DEMOSRC}/scripts/main.ts`,
output: {
compact: PRODUCTION,
format: "iife",
file: `${DEMOOUT}/app.js`
},
plugins: [
RP.get("commonjs")(),
RP.get("typescript2")(),
RP.get("uglify", PRODUCTION)()
],
treeshake: PRODUCTION
}, !PRODUCTION),
sass: new Sass({
file: `${DEMOSRC}/styles/index.sass`,
outFile: `${DEMOOUT}/index.css`,
outputStyle: PRODUCTION ? "compressed" : "expanded",
}, !PRODUCTION),
pug: new Pug({
filename: `${DEMOSRC}/index.pug`,
output: `${DEMOOUT}/index.html`
}, !PRODUCTION)
};
const LIB = {
js: new Rollup({
input: `${LIBSRC}/${NAME}.ts`,
output: PRODUCTION ? [
{
name: NAME,
file: `${LIBOUT}/${NAME}.js`,
format: "umd"
}, {
name: NAME,
file: `${LIBOUT}/${NAME}.min.js`,
compact: true,
format: "umd"
}, {
file: `${LIBOUT}/${NAME}.es.js`,
format: "es"
}
] : {
name: NAME,
file: `${LIBOUT}/${NAME}.js`,
format: "umd"
},
plugins: [
RP.get("json")(),
RP.get("typescript2")(),
RP.get("uglify", PRODUCTION)()
],
treeshake: PRODUCTION
}, !PRODUCTION),
dts: new Rollup({
input: `${LIBSRC}/${NAME}.ts`,
output: {
file: `${LIBOUT}/${NAME}.d.ts`,
format: "es"
},
plugins: [
RP.get("dts").default()
]
}, false)
};
setSeriesFunction(series);
const HELPER = new GulpHelper();
const demo_assets = task("demo:assets", () => DEMO.assets.bundle()),
demo_html = task("demo:html", () => DEMO.pug.bundle()),
demo_css = task("demo:css", () => DEMO.sass.bundle()),
demo_js = task("demo:js", () => DEMO.rollup.bundle());
const lib_js = task("lib:js", async () => {
await LIB.js.bundle();
await LIB.dts.bundle();
});
function clear(done: () => void): void {
emptyDirSync(DEMOOUT);
emptyDirSync(LIBOUT);
done();
}
function watch(done: () => void) {
HELPER
.setCloseCallback(done)
.add(DEMO.assets, demo_assets)
.add(DEMO.pug, demo_html)
.add(DEMO.sass, demo_css)
.add(DEMO.rollup, demo_js)
.add(LIB.js, lib_js);
process.on("SIGINT", () => {
console.log("Stopping watchers...");
HELPER.close();
process.exit();
});
bs_create().init({
server: DEMOOUT,
files: `${DEMOOUT}/**/*`
});
}
const build = series(clear, lib_js, parallel(demo_assets, demo_html, demo_css, demo_js)),
dev = series(build, watch);
export { build, dev };
export default build;