This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
61 lines (50 loc) · 1.81 KB
/
index.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
"use strict";
var through = require('through');
var gutil = require('gulp-util');
var File = gutil.File;
function emitwebXML(stream, opts) {
// TODO - replace w/ real template
var mm = (opts.mimeMapping || []).map(function (mm) {
return '<mime-mapping>' +
'<extension>' + mm.extension + '</extension>' +
'<mime-type>' + mm.type + '</mime-type>' +
'</mime-mapping>';
});
var xml = '<web-app version="' + (opts.version || '3.0') + '"' +
' xmlns="http://java.sun.com/xml/ns/javaee"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xsi:schemaLocation="' + (opts.schemaLocation || 'http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd') + '"' +
'>\n' +
'<display-name>' + opts.displayName + '</display-name>\n' +
'<welcome-file-list>' +
'<welcome-file>' + opts.welcome + '</welcome-file>' +
'</welcome-file-list>\n' +
mm.join('\n');
(opts.webappExtras || []).forEach(function (each) {
if (typeof each === 'function') {
xml += each(opts);
} else if (typeof each === 'string') {
xml += each;
} else {
var err = new gutil.PluginError('war', 'invalid extras' + each);
stream.emit('error', err);
}
});
xml += '</web-app>\n';
var f = new File({
contents: new Buffer(xml),
path: 'WEB-INF/web.xml'
});
stream.emit('data', f);
}
module.exports = function (options) {
var passThrough = function (file) {
return this.queue(file);
};
var onEnd = function () {
emitwebXML(this, options);
this.emit('data', new File({path: 'META-INF/', contents: null, stat: {isDirectory: function() {return true;}}}));
this.emit('end');
};
return through(passThrough, onEnd);
};