-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfileOld.js
218 lines (177 loc) · 7.02 KB
/
gulpfileOld.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
var gulp = require('gulp');
var zip = require('gulp-zip');
var replace = require('gulp-replace');
var newer = require('gulp-newer');
var dateformat = require('dateformat');
var del = require('del');
var packageJson = require('./package.json');
var bump = require('gulp-bump');
var fs = require('fs');
var exist = require('@existdb/gulp-exist');
var existConfig = require('./existConfig.json');
var existClient = exist.createClient(existConfig);
var git = require('git-rev-sync');
var runSequence = require('run-sequence').use(gulp)
//handles xqueries
gulp.task('xql', function(){
return gulp.src('exist/xql/**/*')
.pipe(newer('build/resources/xql/'))
.pipe(gulp.dest('build/resources/xql/'));
});
//deploys xql to exist-db
gulp.task('deploy-xql', gulp.series('xql', function() {
return gulp.src(['**/*'], {cwd: 'build/resources/xql/'})
.pipe(existClient.newer({target: "/db/apps/bith-api/resources/xql/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/resources/xql/'}));
}))
//watches xql for changes
gulp.task('watch-xql',function() {
return gulp.watch(['exist/xql/**/*','exist/xqm/**/*'], gulp.series('deploy-xql'));
})
//handles controller changes
gulp.task('controller', function(){
return gulp.src('exist/eXist-db/controller.xql')
.pipe(newer('build/'))
.pipe(gulp.dest('build/'));
});
//deploys xql to exist-db
gulp.task('deploy-controller', gulp.series('controller', function() {
return gulp.src(['controller.xql'], {cwd: 'build/'})
.pipe(existClient.newer({target: "/db/apps/bith-api/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/'}));
}))
//watches controller changes
gulp.task('watch-controller',function() {
return gulp.watch('exist/eXist-db/controller.xql', gulp.series('deploy-controller'));
})
//handles xslt
gulp.task('xslt', function(){
return gulp.src('./exist/xslt/**/*')
.pipe(newer('./build/resources/xslt/'))
.pipe(gulp.dest('./build/resources/xslt/'));
});
//deploys xslt to exist-db
gulp.task('deploy-xslt', gulp.series('xslt', function() {
return gulp.src('**/*', {cwd: './build/resources/xslt/'})
.pipe(existClient.newer({target: "/db/apps/bith-api/resources/xslt/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/resources/xslt/'}));
}))
//watches xslt for changes
gulp.task('watch-xslt',function() {
return gulp.watch('exist/xslt/**/*', gulp.series('deploy-xslt'));
})
//handles html
gulp.task('html', function(){
return gulp.src('./exist/html/**/*')
.pipe(newer('./build/'))
.pipe(gulp.dest('./build/'));
});
//deploys html to exist-db
gulp.task('deploy-html', gulp.series('html', function() {
return gulp.src('**/*.html', {cwd: './build/'})
.pipe(existClient.newer({target: "/db/apps/bith-api/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/'}));
}))
//watches html for changes
gulp.task('watch-html',function() {
return gulp.watch('exist/html/**/*', gulp.series('deploy-html'));
})
//handles data
gulp.task('data', function(){
return gulp.src('./data/**/*')
.pipe(newer('./build/content/'))
.pipe(gulp.dest('./build/content/'));
});
//deploys data to exist-db
gulp.task('deploy-data', gulp.series('data', function() {
return gulp.src('**/*', {cwd: 'build/content/'})
.pipe(existClient.newer({target: "/db/apps/bith-api/content/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/content/'}));
}))
//watches xslt for changes
gulp.task('watch-data',function() {
return gulp.watch('data/**/*', gulp.series('deploy-data'));
})
//bump version on patch level
/*gulp.task('bump-patch', function () {
return gulp.src(['./package.json'])
.pipe(bump({type: 'patch'}))
.pipe(gulp.dest('./'));
});*/
//bump version on minor level
/*gulp.task('bump-minor', function () {
return gulp.src(['./package.json'])
.pipe(bump({type: 'minor'}))
.pipe(gulp.dest('./'));
});*/
//bump version on major level
/*gulp.task('bump-major', function () {
return gulp.src(['./package.json'])
.pipe(bump({type: 'major'}))
.pipe(gulp.dest('./'));
});*/
//set up basic xar structure
gulp.task('xar-structure', function() {
return gulp.src(['./exist/eXist-db/**/*'])
.pipe(replace('$$deployed$$', dateformat(Date.now(), 'isoUtcDateTime')))
.pipe(replace('$$version$$', getPackageJsonVersion()))
.pipe(replace('$$desc$$', packageJson.description))
.pipe(replace('$$license$$', packageJson.license))
.pipe(gulp.dest('./build/'));
});
//empty build folder
gulp.task('del', function() {
return del(['./build/**/*','./dist/' + packageJson.name + '-' + getPackageJsonVersion() + '.xar']);
});
//reading from fs as this prevents caching problems
function getPackageJsonVersion() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
gulp.task('git-info',function(done) {
console.log('Git Information:')
console.log(' short: ' + git.short())
console.log(' url: ' + git.remoteUrl())
console.log(' is dirty: ' + git.isDirty())
console.log(' long: ' + git.long())
console.log(' branch: ' + git.branch())
console.log(' tag: ' + git.tag())
console.log(' date: ' + git.date())
done()
});
function getGitInfo() {
return {short: git.short(),
url: 'https://github.com/BeethovensWerkstatt/module2/commit/' + git.short(),
dirty: git.isDirty()}
}
/**
* deploys the current build folder into a (local) exist database
*/
gulp.task('deploy', function() {
return gulp.src('**/*', {cwd: 'build'})
.pipe(existClient.newer({target: "/db/apps/bith-api/"}))
.pipe(existClient.dest({target: '/db/apps/bith-api/'}));
})
gulp.task('watch', gulp.parallel('watch-xql','watch-xslt','watch-data','watch-controller','watch-html'));
gulp.task('dist-finish', function() {
return gulp.src('./build/**/*')
.pipe(zip(packageJson.name + '-' + getPackageJsonVersion() + '.xar'))
.pipe(gulp.dest('./dist'));
})
//creates a dist version
gulp.task('dist', gulp.series('xar-structure', gulp.parallel('xql','xslt','data','html'), 'dist-finish'))
//creates a dist version with a version bump at patch level
/*gulp.task('dist-patch', gulp.series('bump-patch', 'dist'));*/
//creates a dist version with a version bump at minor level
/*gulp.task('dist-patch', gulp.series('bump-minor', 'dist'));*/
//creates a dist version with a version bump at major level
/*gulp.task('dist-patch', gulp.series('bump-major', 'dist']));*/
gulp.task('default', function() {
console.log('')
console.log('INFO: There is no default task, please run one of the following tasks:');
console.log('');
console.log(' "gulp dist" : creates a xar from the current sources');
console.log(' "gulp bump-patch" : bumps the semver version of this package at patch level');
console.log(' "gulp bump-minor" : bumps the semver version of this package at minor level');
console.log(' "gulp bump-major" : bumps the semver version of this package at major level');
console.log('');
});