-
Notifications
You must be signed in to change notification settings - Fork 205
/
gulpfile.js
95 lines (82 loc) · 2.57 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
'use script';
var gulp = require('gulp');
var webserver = require('gulp-webserver');
var fs = require('fs');
var minimist = require('minimist');
var xmllint = require('xmllint');
var chalk = require('chalk');
var $ = require('gulp-load-plugins')({ lazy: true });
gulp.task('help', $.taskListing.withFilters(function (task) {
var mainTasks = ['default', 'help', 'serve-static', 'validate-xml'];
var isSubTask = mainTasks.indexOf(task) < 0;
return isSubTask;
}));
gulp.task('default', ['help']);
/** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ **/
/**
* Startup static webserver.
*/
gulp.task('serve-static', function () {
gulp.src('.')
.pipe(webserver({
https: true,
port: '8443',
host: 'localhost',
directoryListing: true,
fallback: 'index.html'
}));
});
/**
* Validates the Office add-in manifest for submission to the store.
*/
gulp.task('validate-xml', function () {
var options = minimist(process.argv.slice(2));
var xsd = fs.readFileSync('./manifest.xsd');
var xmlFilePath = options.xmlfile;
var resultsAsJson = options.json || false;
var xml = fs.readFileSync(xmlFilePath);
if (!resultsAsJson) {
console.log('\nValidating ' + chalk.blue(xmlFilePath.substring(xmlFilePath.lastIndexOf('/') + 1)) + ':');
}
// verify valid XML against the XSD schema
var result = xmllint.validateXML({
xml: xml,
schema: xsd
});
// check the <HighResolutionIconUrl> property
_validateHighResolutionIconUrl(xml, result);
if (resultsAsJson) {
console.log(JSON.stringify(result));
}
else {
if (result.errors === null) {
console.log(chalk.green('Valid'));
}
else {
console.log(chalk.red('Invalid'));
result.errors.forEach(function (e) {
console.log(chalk.red(e));
});
}
}
});
/** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ **/
/**
* Ensures the <HighResolutionIconUrl> element is present and valid.
*
* @param {object} xml - XML document to process.
* @param {object} result - Result object from validating the XML.
*/
function _validateHighResolutionIconUrl(xml, result) {
if (xml && result) {
var xmlString = xml.toString();
if (xmlString.indexOf('<HighResolutionIconUrl ') > -1 &&
xmlString.indexOf('<HighResolutionIconUrl DefaultValue="https://') < 0) {
if (result.errors === null) {
result.errors = [];
}
result.errors.push('The value of the HighResolutionIconUrl attribute contains an unsupported URL.'
+ ' You can only use https:// URLs.');
}
}
}