-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (50 loc) · 1.49 KB
/
Copy pathindex.js
File metadata and controls
53 lines (50 loc) · 1.49 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
var mapStream = require('map-stream');
var PluginError = require('gulp-util').PluginError;
var fs = require('fs');
module.exports = gulpJsonStructureValidator;
function jsondif(a,b,pre){
var dev = '';
for (var prop in a) {
if(b[prop]==undefined){
dev += pre+prop+'\n';
} else {
if (typeof b[prop] === 'object') {
dev += jsondif(a[prop],b[prop],pre+prop+'.');
}
}
}
return dev;
};
function gulpJsonStructureValidator(option) {
var template = "";
if (option) {
template = option.template;
}
return mapStream(function(file, cb) {
fs.readFile(template, 'utf8', function (err, data) {
if (err) {
error = new PluginError('gulp-json-structure-validator',{
name: 'JSON Structure Validate Error',
filename: file.path,
message: 'Read Template Error: ' + template
});
cb(error, file);
} else {
var templateObject = JSON.parse(data);
var content = file.contents;
var error;
if (content) {
var e = jsondif(templateObject, JSON.parse(content), '');
if (e != '') {
error = new PluginError('gulp-json-structure-validator',{
name: 'JSON Structure Validate Error',
filename: file.path,
message: '\nForgotten in "' + file.path + '"' + ':\n' +e
});
}
}
cb(error, file);
}
});
});
}