-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
129 lines (110 loc) · 2.92 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
/**
* an example gulpfile to make ant-less existdb package builds a reality
*/
const { src, dest, watch, series, parallel } = require('gulp')
const { createClient } = require('@existdb/gulp-exist')
const replace = require('@existdb/gulp-replace-tmpl')
const zip = require("gulp-zip")
const rename = require('gulp-rename')
const del = require('delete')
// read metadata from package.json and .existdb.json
const { version, license } = require('./package.json')
const { package, servers } = require('./.existdb.json')
// .tmpl replacements to include
// first value wins
const replacements = [package, {version, license}]
const serverInfo = servers.localhost
const { port, hostname } = new URL(serverInfo.server)
const connectionOptions = {
basic_auth: {
user: serverInfo.user,
pass: serverInfo.password
},
host: hostname,
port
}
const existClient = createClient(connectionOptions);
/**
* Use the `delete` module directly, instead of using gulp-rimraf
*/
function clean (cb) {
del(['build'], cb);
}
exports.clean = clean
/**
* replace placeholders
* in src/repo.xml.tmpl and
* output to build/repo.xml
*/
function templates () {
return src('src/*.tmpl')
.pipe(replace(replacements, { prefix: "package" }))
.pipe(rename(path => { path.extname = "" }))
.pipe(dest('build/'))
}
exports.templates = templates
function watchTemplates () {
watch('src/*.tmpl', series(templates))
}
exports["watch:tmpl"] = watchTemplates
const static = [
"src/examples/*",
"src/content/*",
"src/test/*.*",
"src/icon.svg"
]
/**
* copy html templates, XSL stylesheet, XMLs and XQueries to 'build'
*/
function copyStatic () {
return src(static, {base: 'src'}).pipe(dest('build'))
}
exports.copy = copyStatic
function watchStatic () {
watch(static, series(copyStatic));
}
exports["watch:static"] = watchStatic
/**
* since this is a pure library package uploading
* the library itself will not update the compiled
* version in the cache.
* This is why the xar will be installed instead
*/
function watchBuild () {
watch('build/**/*', series(xar, installXar))
}
// construct the current xar name from available data
const packageName = () => `${package.target}-${version}.xar`
/**
* create XAR package in repo root
*/
function xar () {
return src('build/**/*', {base: 'build'})
.pipe(zip(packageName()))
.pipe(dest('.'))
}
/**
* upload and install the latest built XAR
*/
function installXar () {
return src(packageName())
.pipe(existClient.install({ packageUri: package.namespace }))
}
// composed tasks
const build = series(
clean,
templates,
copyStatic,
xar
)
const watchAll = parallel(
watchStatic,
watchTemplates,
watchBuild
)
exports.build = build
exports.watch = watchAll
exports.xar = build
exports.install = series(build, installXar)
// main task for day to day development
exports.default = series(build, installXar, watchAll)