-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
99 lines (82 loc) · 2.8 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
const gulp = require('gulp')
const zip = require('gulp-zip')
const replace = require('gulp-replace')
const dateformat = require('dateformat')
const bump = require('gulp-bump')
const newer = require('gulp-newer')
const fs = require('fs')
const exist = require('gulp-exist')
const git = require('git-rev-sync')
const packageJson = require('./package.json')
const existConfig = require('./existConfig.json')
const existClient = exist.createClient(existConfig)
// 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-app-template/**/*'])
.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/'))
})
// reading from fs as this prevents caching problems
function getPackageJsonVersion () {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
}
// gets git info used in other tasks
function getGitInfo () {
return { short: git.short(),
url: 'https://github.com/BeethovensWerkstatt/module2/commit/' + git.short(),
dirty: git.isDirty() }
}
// handles data
gulp.task('data', function () {
return gulp.src('./data/**/*')
.pipe(newer('./build/content/'))
.pipe(gulp.dest('./build/content/'))
})
// handles verovio
gulp.task('verovio', function () {
return gulp.src('./data/**/*')
.pipe(newer('./build/content/'))
.pipe(gulp.dest('./build/content/'))
})
/**
* deploys the current build folder into a (local) exist database
*/
gulp.task('deploy', function () {
const git = getGitInfo()
return gulp.src('**/*', { cwd: 'build' })
.pipe(replace('$$git-url$$', git.url))
.pipe(replace('$$git-short$$', git.short))
.pipe(replace('$$git-dirty$$', git.dirty))
.pipe(existClient.newer({ target: '/db/apps/modul2/' }))
.pipe(existClient.dest({ target: '/db/apps/modul2/' }))
})
gulp.task('dist', function () {
const git = getGitInfo()
return gulp.src('./build/**/*')
.pipe(replace('$$git-url$$', git.url))
.pipe(replace('$$git-short$$', git.short))
.pipe(replace('$$git-dirty$$', git.dirty))
.pipe(zip(packageJson.name + '-' + getPackageJsonVersion() + '.xar'))
.pipe(gulp.dest('./dist'))
})