-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
158 lines (136 loc) · 3.61 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
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
157
158
/**
* an example gulpfile to make ant-less existdb package builds a reality
*/
const { src, dest, watch, series, parallel, lastRun } = require('gulp')
const { createClient, readOptionsFromEnv } = require('@existdb/gulp-exist')
const zip = require("gulp-zip")
const sass = require('gulp-sass')
const uglify = require('gulp-uglify-es').default
const replace = require('@existdb/gulp-replace-tmpl')
const rename = require('gulp-rename')
const del = require('delete')
const { app, version, license, author } = require('./package.json')
const replacements = [app, { version, license, author }]
const target = app.target
const defaultOptions = { basic_auth: { user: "admin", pass: "" } }
const connectionOptions = Object.assign(defaultOptions, readOptionsFromEnv())
const existClient = createClient(connectionOptions);
/**
* Use the `delete` module directly, instead of using gulp-rimraf
*/
function clean (cb) {
del(['build', 'dist'], cb);
}
exports.clean = clean
const tmplFiles = 'src/*.tmpl'
/**
* replace placeholders
* in src/repo.xml.tmpl and
* output to build/repo.xml
*/
function templates () {
return src(tmplFiles)
.pipe(replace(replacements, { debug: true }))
.pipe(rename(path => { path.extname = "" }))
.pipe(dest('build'))
}
exports.templates = templates
function watchTemplates () {
watch(tmplFiles, templates)
}
exports["watch:tmpl"] = watchTemplates
const scssFiles = 'src/scss/**/*.scss'
/**
* compile SCSS styles and put them into 'build/app/css'
*/
function styles () {
return src(scssFiles)
.pipe(sass().on('error', sass.logError))
.pipe(dest('build/css'));
}
exports.styles = styles
function watchStyles () {
watch(scssFiles, styles)
}
exports["watch:styles"] = watchStyles
const jsFiles = 'src/js/**/*.js'
/**
* minify EcmaSript files and put them into 'build/app/js'
*/
function minifyEs () {
return src(jsFiles)
.pipe(uglify())
.pipe(dest('build/js'))
}
exports.minify = minifyEs
function watchEs () {
watch(jsFiles, minifyEs)
}
exports["watch:es"] = watchEs
const static = 'src/**/*.{xml,html,xq,xquery,xql,xqm,xsl,xconf,svg,png}'
/**
* copy html templates, XSL stylesheet, XMLs and XQueries to 'build'
*/
function copyStatic () {
return src(static).pipe(dest('build'))
}
exports.copy = copyStatic
function watchStatic () {
watch(static, copyStatic);
}
exports["watch:static"] = watchStatic
const allFilesInBuild = 'build/**/*'
/**
* Upload all files in the build folder to existdb.
* This function will only upload what was changed
* since the last run (see gulp documentation for lastRun).
*/
function deploy () {
return src(allFilesInBuild, {
base: 'build',
since: lastRun(deploy)
})
.pipe(existClient.dest({target}))
}
function watchBuild () {
watch(allFilesInBuild, deploy)
}
// construct the current xar name from available data
const packageName = `${target}-${version}.xar`
/**
* create XAR package in repo root
*/
function xar () {
return src(allFilesInBuild, {base: 'build'})
.pipe(zip(packageName))
.pipe(dest('dist'))
}
/**
* upload and install the latest built XAR
*/
function installXar () {
return src(packageName, {cwd: 'dist'})
.pipe(existClient.install())
}
// composed tasks
const build = series(
clean,
styles,
minifyEs,
templates,
copyStatic
)
const watchAll = parallel(
watchStyles,
watchEs,
watchStatic,
watchTemplates,
watchBuild
)
exports.build = build
exports.watch = watchAll
exports.deploy = series(build, deploy)
exports.xar = series(build, xar)
exports.install = series(build, xar, installXar)
// main task for day to day development
exports.default = series(build, deploy, watchAll)