forked from mlenser/roll20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
80 lines (69 loc) · 2.46 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
var gulp = require('gulp');
var inject = require('gulp-inject');
var uglify = require('gulp-uglify');
var fs = require('fs');
var jsoncombine = require('gulp-jsoncombine');
var eol = require('gulp-eol');
function entitySorter(a, b) {
if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
}
return 0;
}
function compileSources(sources, arrayProp, patch) {
var entities = {};
entities[arrayProp] = [];
Object.keys(sources).forEach(function (sourceName) {
var source = sources[sourceName];
if (!source.version) {
throw new Error('JSON file: ' + source + ' has no version number');
}
if (!entities.version) {
entities.version = source.version;
}
else if (entities.version !== source.version) {
throw new Error('JSON file: ' + source + ' has version number ' + source.version + ' that is incompatible with other files');
}
entities[arrayProp] = entities[arrayProp].concat(source[arrayProp]);
entities.patch = patch;
});
entities[arrayProp].sort(entitySorter);
return entities;
}
function makeJSOutput(entityLists) {
var output = "on('ready', function() {\n";
entityLists.forEach(function (entityList) {
output += ' ShapedScripts.addEntities(' + JSON.stringify(entityList) + ');\n';
});
output += '});\n';
return output;
}
gulp.task('compileSpells', function () {
gulp.src('./data/spellSourceFiles/spellData.json')
.pipe(jsoncombine('5e-spells.js', function (sources) {
return new Buffer(makeJSOutput([compileSources(sources, 'spells')]));
}))
.pipe(eol())
.pipe(gulp.dest('./data'));
});
gulp.task('compileHouseruledSpells', function () {
gulp.src('./data/spellSourceFiles/*.json')
.pipe(jsoncombine('5e-spells-houserules.js', function (sources) {
var output = makeJSOutput([compileSources({ spellData: sources.spellData }, 'spells'), compileSources({ spellDataHouseruleAlterations: sources.spellDataHouseruleAlterations }, 'spells', true)]);
return new Buffer(output);
}))
.pipe(eol())
.pipe(gulp.dest('./data'));
});
gulp.task('compileMonsters', function () {
gulp.src('./data/monsterSourceFiles/*.json')
.pipe(jsoncombine('5e-monsters.js', function (sources) {
return new Buffer(makeJSOutput([compileSources(sources, 'monsters')]));
}))
.pipe(eol())
.pipe(gulp.dest('./data'));
});
gulp.task('compileAll', ['compileSpells', 'compileHouseruledSpells', 'compileMonsters']);
gulp.task('default', ['compileAll']);