-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
239 lines (196 loc) · 7.17 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
'use strict';
var fs = require('fs'),
gulp = require('gulp'),
exist = require('gulp-exist'),
newer = require('gulp-newer'),
del = require('del'),
less = require('gulp-less'),
path = require('path'),
sourcemaps = require('gulp-sourcemaps'),
LessAutoprefix = require('less-plugin-autoprefix'),
autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] }),
LessPluginCleanCSS = require('less-plugin-clean-css'),
cleanCSSPlugin = new LessPluginCleanCSS({advanced: true}),
input = {
'html': ['*.html', '*.xhtml'],
'templates': 'templates/**/*.html',
'css': 'resources/css/less/style.less',
'scripts': 'resources/js/**/*',
'vendor_scripts': [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/bootstrap/dist/js/bootstrap.min.js'
],
'xml': 'resources/xml/*.xml',
'images': 'resources/img/**/*',
'fonts': 'bower_components/bootstrap/fonts/**/*',
'articles': 'data/articles/*.html',
'i18n': 'data/i18n/*.xml'
},
output = {
'html': '.',
'templates': 'templates',
'css': 'resources/css',
'vendor_css': 'resources/css',
'scripts': 'resources/js',
'vendor_scripts': 'resources/js/vendor',
'xml': 'resources/xml',
'images': 'resources/img',
'fonts': 'resources/fonts',
'articles': 'data/articles',
'i18n': 'data/i18n'
}
;
// ************* existDB configuration *************** //
// var localConnectionOptions = {};
//
// if (fs.existsSync('./local.node-exist.json')) {
// localConnectionOptions = require('./local.node-exist.json');
// console.log('read from localConnectionOptions', localConnectionOptions)
// }
//
// var exClient = exist.createClient(localConnectionOptions);
//
// var targetConfiguration = {
// target: '/db/apps/lgpn-ling/'
// };
exist.defineMimeTypes({
'application/xml': ['odd']
});
var exClient = exist.createClient({
host: 'localhost',
port: '8080',
path: '/exist/xmlrpc',
basic_auth: { user: 'admin', pass: '' }
});
var targetConfiguration = {
target: '/db/apps/lgpn-ling/',
html5AsBinary: true
};
// **************** Styles ****************** //
gulp.task('build:styles', function(){
return gulp.src(input.css)
.pipe(sourcemaps.init())
.pipe(less({ plugins: [cleanCSSPlugin, autoprefix] }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(output.css))
});
gulp.task('deploy:styles', ['build:styles'], function () {
console.log('deploying less and css files');
return gulp.src('resources/css/**/*', {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
gulp.task('watch:styles', function () {
console.log('watching less files');
gulp.watch('resources/css/less/**/*.less', ['deploy:styles'])
});
// **************** Fonts ****************** //
gulp.task('fonts:copy', function () {
return gulp.src(input.fonts)
.pipe(gulp.dest(output.fonts))
});
gulp.task('fonts:deploy', ['fonts:copy'], function () {
return gulp.src(output.fonts, {base: '.'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// **************** Scripts ****************** //
gulp.task('vendor_scripts:copy', function () {
return gulp.src(input.vendor_scripts)
.pipe(gulp.dest(output.vendor_scripts));
});
gulp.task('deploy:scripts', ['vendor_scripts:copy'], function () {
return gulp.src(input.scripts, {base: '.'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch scripts
gulp.task('watch:scripts', function () {
gulp.watch(input.scripts, ['deploy:scripts'])
});
// ************* Templates *************** //
// Deploy templates
gulp.task('deploy:templates', function () {
return gulp.src(input.templates, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch templates
gulp.task('watch:templates', function () {
gulp.watch(input.templates, ['deploy:templates'])
});
// ************* HTML Pages *************** //
// Deploy HTML pages
gulp.task('deploy:html', function () {
return gulp.src(input.html, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch HTML pages
gulp.task('watch:html', function () {
gulp.watch(input.html, ['deploy:html'])
});
// ************* XML Pages *************** //
gulp.task('deploy:xml', function () {
return gulp.src(input.xml, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch xml files
gulp.task('watch:xml', function () {
gulp.watch(input.xml, ['deploy:xml'])
});
// ************* Articles, i18n keys *************** //
gulp.task('deploy:articles', function () {
return gulp.src(input.articles, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch articles
gulp.task('watch:articles', function () {
gulp.watch(input.articles, ['deploy:articles'])
});
gulp.task('deploy:i18n', function () {
return gulp.src(input.i18n, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch i18n
gulp.task('watch:i18n', function () {
gulp.watch(input.i18n, ['deploy:i18n'])
});
// ************* Images *************** //
gulp.task('deploy:images', function () {
return gulp.src(input.articles, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Watch articles
gulp.task('watch:images', function () {
gulp.watch(input.images, ['deploy:images'])
});
// ************* General Tasks *************** //
var pathsToWatchAndDeploy = [
'templates/**/*.html',
'resources/**/*',
'transform/*',
'*.html',
'*.xhtml',
'*{.xpr,.xqr,.xql,.xml,.xconf}',
'modules/**/*',
'!build.*',
'data/**/*',
'img/*'
];
// Watch and deploy all changed files
gulp.task('watch', ['watch:html', 'watch:styles', 'watch:scripts', 'watch:xml', 'watch:i18n', 'watch:articles', 'watch:images', 'watch:templates']);
gulp.task('build', ['build:styles', 'fonts:copy', 'vendor_scripts:copy']);
// Deploy files to existDB
gulp.task('deploy', ['build'], function () {
console.log('deploying files to local existdb');
return gulp.src(pathsToWatchAndDeploy, {base: './'})
.pipe(exClient.newer(targetConfiguration))
.pipe(exClient.dest(targetConfiguration))
});
// Default task (which is called by 'npm start' task)
gulp.task('default', ['build']);