-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
98 lines (90 loc) · 2.41 KB
/
gulpfile.js
File metadata and controls
98 lines (90 loc) · 2.41 KB
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
const gulp = require("gulp")
const { series } = gulp
const minify = require("gulp-minify")
const inject = require("gulp-inject-string")
const rename = require("gulp-rename")
const fs = require("fs")
const del = require("del")
const exec = require("child_process").exec
const FILENAME = "cljs.jar"
const ENV = process.env.ENV
const VERSION = process.env.VERSION || "1.10.758"
const download = () => {
return new Promise((resolve, reject) => {
fs.access(FILENAME, fs.constants.R_OK, err => {
if (err) {
// file doesn't exist
console.log(
`Downloading ${FILENAME} r${VERSION} this may take a few moments...`
)
exec(
`curl -L https://github.com/clojure/clojurescript/releases/download/r${VERSION}/${FILENAME} > ${FILENAME}`,
(err, stdout, stderr) => {
if (err != null) {
console.error(stderr)
reject(err)
} else {
console.log("...done")
resolve()
}
}
)
} else {
console.log(`${FILENAME} already downloaded`)
resolve()
}
})
})
}
const env = () => {
// ensure prod or dev
return ENV === "prod" ? ENV : "dev"
}
const build = tier => {
return new Promise((resolve, reject) => {
exec(
`java -cp ${FILENAME}:./src clojure.main build/${tier}.${env()}.clj`,
(err, stdout, stderr) => {
if (err != null) {
console.error(stderr)
reject(err)
} else {
resolve()
}
}
)
})
}
const clean = () => {
return del(["out", "server.js", "public/js/**/*", "public/css/style.min.css", "views/index.pug"])
}
const buildClient = async () => {
await build("client")
await gulp
.src("views/index-template.pug")
.pipe(inject.replace("#CLIENT_JS#", "client.js"))
.pipe(rename("index.pug"))
.pipe(gulp.dest("views"))
if (env() === "prod") {
await gulp
.src(["public/js/client.js"])
.pipe(
minify({
ext: {
min: ".min.js"
}
})
)
.pipe(gulp.dest("public/js"))
return gulp
.src("views/index-template.pug")
.pipe(inject.replace("#CLIENT_JS#", "client.min.js"))
.pipe(rename("index.pug"))
.pipe(gulp.dest("views"))
}
return Promise.resolve()
}
const buildServer = () => {
return build("server")
}
exports.default = series(clean, download, buildClient, buildServer)