-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
167 lines (140 loc) · 5.26 KB
/
gulpfile.js
File metadata and controls
167 lines (140 loc) · 5.26 KB
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
import gulp from 'gulp';
import zip from 'gulp-zip';
import replace from 'gulp-replace';
import newer from 'gulp-newer';
import exist from '@existdb/gulp-exist';
import dateformat from 'dateformat';
import fs from 'fs';
import { readFileSync } from 'fs';
import git from 'git-rev-sync';
import { deleteAsync } from 'del';
import { exec } from 'child_process';
const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
const existConfig = JSON.parse(readFileSync('./existConfig.json', 'utf8'));
const existClient = exist.createClient(existConfig);
//handles xqueries
gulp.task('xql', function(){
return gulp.src('source/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 (done) {
gulp.src(['**/*'], {cwd: 'build/resources/xql/'})
.pipe(existClient.newer({target: '/db/apps/odd-api/resources/xql/'}))
.pipe(existClient.dest({target: '/db/apps/odd-api/resources/xql/'}));
done();
}));
//handles html
gulp.task('html', function(){
//var git = getGitInfo();
return gulp.src('./source/html/**/*')
//.pipe(newer('./build/'))
//.pipe(replace('$$git-url$$', git.url))
//.pipe(replace('$$git-short$$', git.short))
//.pipe(replace('$$git-dirty$$', git.dirty))
.pipe(gulp.dest('./build/'));
});
//deploys html to exist-db
gulp.task('deploy-html', gulp.series('html', function(done) {
gulp.src('**/*.html', {cwd: './build/'})
.pipe(existClient.newer({target: "/db/apps/odd-api/"}))
.pipe(existClient.dest({target: '/db/apps/odd-api/'}));
done();
}));
//handles data
gulp.task('data', function(){
return gulp.src('./data/**/*')
.pipe(newer('./build/data/'))
.pipe(gulp.dest('./build/data/'));
});
//deploys data to exist-db
gulp.task('deploy-data', gulp.series('data', function(done) {
gulp.src('**/*', {cwd: 'build/data/'})
.pipe(existClient.newer({target: "/db/apps/odd-api/data/"}))
.pipe(existClient.dest({target: '/db/apps/odd-api/data/'}));
done();
}));
//set up basic xar structure
gulp.task('xar-structure', function() {
return gulp.src(['./source/eXist-db/**/*'])
.pipe(replace('$$deployed$$', dateformat(Date.now(), 'isoUtcDateTime')))
.pipe(replace('$$version$$', getPackageJsonVersion()))
.pipe(replace('$$desc$$', packageJson.description))
.pipe(replace('$$license$$', packageJson.license))
.pipe(replace('$$name$$', packageJson.name))
.pipe(gulp.dest('./build/'));
});
// simply copies the openapi v1 file to the build folder
gulp.task('openapi_v1', function(){
return gulp.src('./source/openapi/v1/openapi_v1.yaml')
.pipe(gulp.dest('./build/'));
});
// bundles the v2 openapi file using redocly and saves it to the build folder
gulp.task('openapi_v2', function (done) {
// create the target folder
const outputDir = './build';
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// run redocly to bundle the OpenAPI description
exec('npx @redocly/cli bundle source/openapi/v2/openapi_v2.yaml -o build/openapi_v2.yaml', (err, stdout, stderr) => {
if (err) {
console.error('Failed to bundle the OpenAPI description: ', stderr);
done(err);
return;
}
done();
});
});
//empty build folder
gulp.task('del', function() {
return deleteAsync(['./build/**/*','./dist/' + packageJson.name + '-' + getPackageJsonVersion() + '.xar']);
});
/**
* deploys the current build folder into a (local) exist database
*/
/*gulp.task('deploy', gulp.series('deploy-data', 'deploy-html', 'deploy-xql', function (done) {
done();
}));*/
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', 'html', 'xql', 'data', 'openapi_v1', 'openapi_v2', 'dist-finish', function (done) {
done();
}));
//copies XQSuite test files to the build folder
gulp.task('xqsuite', function(){
return gulp.src('./tests/xqsuite/**/*')
.pipe(gulp.dest('./build/xqsuite'));
});
//creates a dist version including the XQSuite tests
gulp.task('dist-with-tests', gulp.series('xqsuite', 'dist', function (done) {
done();
}));
//reading from fs as this prevents caching problems
function getPackageJsonVersion() {
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function getGitInfo() {
return {short: git.short(),
url: 'https://github.com/Edirom/odd-api/commit/' + git.short(),
dirty: git.isDirty()}
}
gulp.task('git-info', function() {
console.log('Git Information: ')
console.log(git.short());
console.log(git.remoteUrl());
console.log(git.isDirty());
console.log('link is https://github.com/Edirom/odd-api/commit/' + git.short());
});
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();
});