-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (55 loc) · 1.75 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
const { task, src, dest, series, watch } = require("gulp")
const { join, dirname, relative, sep } = require("path")
const uglify = require("gulp-uglify")
const ts = require("gulp-typescript")
const merge = require("merge2")
const glob = require("glob")
const sass = require("gulp-sass")(require("sass"))
const cwd = join(__dirname, "src")
const build = join(__dirname, "build")
function pages(){
return src("pages/**", { cwd }).pipe(dest(build))
}
function public(){
return src("public/**", { cwd }).pipe(dest("public", { cwd: build }))
}
function scripts(){
const configs = glob
.sync("**/tsconfig.json", { cwd })
.sort(path => path.lastIndexOf("/") * -1)
/** @type {ReadWriteStream[]} */
const streams = []
for(const config of configs){
const _configs = new Set(configs.filter(path => !relative(config, path).startsWith(`..${sep}..`)))
const absolute = join(cwd, config)
const directory = dirname(config)
const output = join(build, directory)
_configs.delete(config)
const tsResult = src("**/*.ts", {
cwd: dirname(absolute),
ignore: Array.from(_configs).map(path => dirname(path) + "/**")
}).pipe(ts.createProject(absolute, { declaration: true })())
streams.push(merge([
tsResult.js.pipe(uglify()).pipe(dest(output)),
tsResult.dts.pipe(dest(output))
]))
}
return merge(streams)
}
function styles(){
return src("styles/*.scss", { cwd })
.pipe(sass.sync({ outputStyle: "compressed" }).on("error", sass.logError))
.pipe(dest("styles", { cwd: build }))
}
task("build", () => merge([
pages(),
public(),
scripts(),
styles()
]))
task("watch", series("build", function watching(){
watch("pages/**", { cwd }, pages)
watch("public/**", { cwd }, public)
watch("scripts/**", { cwd }, scripts)
watch("styles/**", { cwd }, styles)
}))