-
Notifications
You must be signed in to change notification settings - Fork 67
/
Gruntfile.js
217 lines (193 loc) · 7.25 KB
/
Gruntfile.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
module.exports = function(grunt) {
// ----------
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks('grunt-jsdoc');
// ----------
var buildRoot = "build/";
var releaseRoot = "../openseadragon.github.com/";
var builtSourceUnMinified = "built-openseadragon/openseadragon/openseadragon.js";
var foldersToCopy = {
css: "css",
images: "images",
releases: "releases",
"built-openseadragon": ""
};
var examples = {
"tilesource-custom": "Custom Tile Source",
"tilesource-dzi": "DZI Tile Source",
"tilesource-osm": "OpenStreetMap Tile Source",
"tilesource-tms": "Tiled Map Service Tile Source",
"tilesource-iiif": "IIIF Tile Source",
"tilesource-legacy": "Legacy Tile Source",
"tilesource-zoomify": "Zoomify Tile Source",
"tilesource-zoomit": "Zoom.it Tile Source",
"tilesource-image": "Image Tile Source",
"tilesource-sequence": "Sequence Mode",
"tilesource-collection": "Collection Mode",
"ui-binding-custom-buttons": "Binding Custom Buttons",
"ui-reference-strip": "Image Reference Strip",
"ui-toolbar": "Toolbar",
"ui-viewport-navigator": "Viewport Navigator",
"ui-zoom-and-pan": "Viewport Zoom and Pan",
"ui-overlays": "Overlays",
"ui-rotation": "Rotation",
"ui-keyboard-navigation": "Keyboard Navigation",
"ui-customize-tooltips": "Customize Tooltips",
"ui-tiledimage-polygon-cropping" : "Crop TiledImage with Polygons",
"developer-debug-mode": "Developer Tools - Debug Mode",
"creating-zooming-images": "Creating Zooming Images",
"viewport-coordinates": "Viewport Coordinates",
"in-the-wild": "OpenSeadragon in the Wild",
"multi-image": "Multi-Image",
"advanced-data-model": "Advanced data model with TileSource"
};
// ----------
function getVersion() {
var data = grunt.file.read(builtSourceUnMinified);
var matches = data.match(/@version\s*openseadragon\s*(.*)\s*/);
if (matches && matches.length == 2) {
return matches[1];
}
grunt.fail.fatal("Unable to locate version number in " + builtSourceUnMinified);
return "";
}
// ----------
// Project configuration.
grunt.initConfig({
clean: {
www: {
src: [
buildRoot + "*",
"!" + buildRoot + "example-images",
"!" + buildRoot + "openseadragonizer",
"!" + buildRoot + "docs"
]
},
doc: {
src: [
buildRoot + "docs/"
]
},
release: {
src: [
releaseRoot + "*",
"!" + releaseRoot + "README.md",
"!" + releaseRoot + "CONTRIBUTING.md",
"!" + releaseRoot + "node_modules",
"!" + releaseRoot + "Gruntfile.js",
"!" + releaseRoot + "package.json",
"!" + releaseRoot + "example-images",
"!" + releaseRoot + "openseadragonizer"
],
options: {
force: true
}
}
},
connect: {
server: {
options: {
port: 9000,
base: buildRoot
}
}
},
watch: {
files: [ "Gruntfile.js", "www/*", "css/*", "built-openseadragon/**"],
tasks: ["build"]
},
jsdoc : {
src: [builtSourceUnMinified, 'doc-home.md'],
options: {
destination: buildRoot + 'docs',
configure: 'doc-conf.json',
private: false
}
}
});
// ----------
// Make:www task.
// Builds all of the HTML pages.
grunt.registerTask("make:www", function() {
var base = grunt.file.read("www/base.html");
var version = getVersion();
var shortVersion = version.split('.');
shortVersion.pop();
shortVersion = shortVersion.join('.');
var make = function(src, dest, title) {
var content = grunt.file.read(src);
var built = grunt.template.process(base, {
data: {
title: title,
version: version,
shortVersion: shortVersion,
content: content
}
});
grunt.file.write(dest, built);
};
for (var key in examples) {
make("www/" + key + ".html",
buildRoot + "examples/" + key + "/index.html",
examples[key] + " | ");
}
make("www/index.html", buildRoot + "index.html", "");
make("www/license.html", buildRoot + "license/index.html", "License | ");
// meta-refresh redirect; doesn't use base template
grunt.file.copy("www/releases.html", buildRoot + "releases/index.html");
});
// ----------
// Copy:build task.
// Copies needed files to the build folder.
grunt.registerTask("copy:build", function() {
var copyOne = function(from, to) {
grunt.file.recurse(from, function(abspath, rootdir, subdir, filename) {
var dest = buildRoot
+ to
+ "/"
+ (subdir ? subdir + "/" : "")
+ filename;
grunt.file.copy(abspath, dest);
});
};
for (var key in foldersToCopy) {
copyOne(key, foldersToCopy[key]);
}
});
// ----------
// Copy:release task.
// Copies needed files to the release folder.
grunt.registerTask("copy:release", function() {
grunt.file.recurse(buildRoot, function(abspath, rootdir, subdir, filename) {
if (subdir && /^(example-images|openseadragonizer)/.test(subdir)) {
return;
}
var dest = releaseRoot
+ (subdir ? subdir + "/" : '/')
+ filename;
grunt.file.copy(abspath, dest);
});
});
// ----------
// Build task.
// Cleans the built files out of the build folder and builds new ones, except the docs, which take some time.
grunt.registerTask("build", ["clean:www", "make:www", "copy:build"]);
// ----------
// Doc task.
// Cleans the doc files out of the build folder and builds new ones.
grunt.registerTask("doc", ["clean:doc", "jsdoc"]);
// ----------
// Publish task.
// Cleans the built files out of ../openseadragon.github.com, builds, and copies newly built ones over.
grunt.registerTask("publish", ["build", "doc", "clean:release", "copy:release"]);
// ----------
// Dev task.
// Builds, fires up a server and watches for changes.
grunt.registerTask("dev", ["build", "connect", "watch"]);
// ----------
// Default task.
// Cleans the built files out of ../openseadragon.github.com, builds, and copies newly built ones over.
grunt.registerTask("default", ["build"]);
};