-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
137 lines (117 loc) · 3.06 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
/**
* an example gulpfile to make ant-less existdb package builds a reality
*/
import { src, dest, watch, series, parallel, lastRun } from 'gulp'
import { createClient } from '@existdb/gulp-exist'
import replace from '@existdb/gulp-replace-tmpl'
import zip from 'gulp-zip'
import rename from 'gulp-rename'
import del from 'delete'
import pkg from './package.json' with { type: 'json' }
const { app, version, license } = pkg
const replacements = [app, { version, license }]
const packageUri = app.namespace
// read metadata from .existdb.json
import existJSON from './.existdb.json' with { type: 'json' }
const serverInfo = existJSON.servers.localhost
const url = new URL(serverInfo.server)
const connectionOptions = {
host: url.hostname,
port: url.port,
secure: url.protocol === 'https:',
basic_auth: {
user: serverInfo.user,
pass: serverInfo.password
}
}
const existClient = createClient(connectionOptions);
/**
* Use the `delete` module directly, instead of using gulp-rimraf
*/
function clean (cb) {
del(['build', 'dist'], cb);
}
/**
* replace placeholders
* in src/repo.xml.tmpl and
* output to build/repo.xml
*/
function templates () {
return src('src/*.tmpl')
.pipe(replace(replacements, {unprefixed:true}))
.pipe(rename(path => { path.extname = "" }))
.pipe(dest('build/'))
}
function watchTemplates () {
watch('src/*.tmpl', series(templates))
}
const staticFiles = 'src/**/*.{xml,html,xq,xqm,xsl,xconf,json,svg,js,css,png,jpg,map}'
/**
* copy html templates, XSL stylesheet, XMLs and XQueries to 'build'
*/
function copyStatic () {
return src(staticFiles).pipe(dest('build'))
}
function watchStatic () {
watch(staticFiles, series(copyStatic));
}
/**
* 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 deployApp () {
return src('build/**/*', {
base: 'build/',
since: lastRun(deploy)
})
.pipe(existClient.dest({target}))
}
function watchBuild () {
watch('build/**/*', series(deploy))
}
// construct the current xar name from available data
const xarFilename = `${app.abbrev}-${version}.xar`
/**
* create XAR package in repo root
*/
function createXar () {
return src('build/**/*', {base: 'build/'})
.pipe(zip(xarFilename))
.pipe(dest('dist'))
}
/**
* upload and install the latest built XAR
*/
function installXar () {
return src(xarFilename, { cwd:'dist/', encoding: false })
.pipe(existClient.install({ packageUri }))
}
// composed tasks
const build = series(
clean,
templates,
copyStatic
)
const deploy = series(build, deployApp)
const watchAll = parallel(
watchStatic,
watchTemplates,
watchBuild
)
const xar = series(build, createXar)
const install = series(build, xar, installXar)
export {
clean,
templates,
watchTemplates,
copyStatic,
watchStatic,
build,
deploy,
xar,
install,
watchAll as watch,
}
// main task for day to day development
export default series(build, deploy, watchAll)