2014-11-20 03:46:05 +03:00
|
|
|
/* global module */
|
|
|
|
|
2013-02-13 07:40:08 +04:00
|
|
|
module.exports = function(grunt) {
|
2018-01-02 03:17:13 +03:00
|
|
|
var dateFormat = require('dateformat');
|
2013-02-15 22:58:57 +04:00
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-15 22:58:57 +04:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-compress");
|
2013-02-21 22:54:11 +04:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-concat");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-uglify");
|
2017-12-02 03:21:08 +03:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-qunit");
|
2013-02-21 22:54:11 +04:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-connect");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
2013-02-27 21:59:51 +04:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-clean");
|
2017-01-08 17:52:57 +03:00
|
|
|
grunt.loadNpmTasks("grunt-eslint");
|
2013-03-21 21:26:03 +04:00
|
|
|
grunt.loadNpmTasks("grunt-git-describe");
|
2013-04-09 22:44:08 +04:00
|
|
|
grunt.loadNpmTasks('grunt-text-replace');
|
2018-01-02 03:17:13 +03:00
|
|
|
grunt.loadNpmTasks('grunt-istanbul');
|
2013-02-15 22:58:57 +04:00
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-04-23 04:20:07 +04:00
|
|
|
var packageJson = grunt.file.readJSON("package.json"),
|
|
|
|
distribution = "build/openseadragon/openseadragon.js",
|
2013-02-21 23:56:16 +04:00
|
|
|
minified = "build/openseadragon/openseadragon.min.js",
|
2013-04-23 04:20:07 +04:00
|
|
|
packageDirName = "openseadragon-bin-" + packageJson.version,
|
|
|
|
packageDir = "build/" + packageDirName + "/",
|
2013-03-25 21:02:41 +04:00
|
|
|
releaseRoot = "../site-build/built-openseadragon/",
|
2018-01-02 03:17:13 +03:00
|
|
|
coverageDir = 'coverage/' + dateFormat(new Date(), 'yyyymmdd-HHMMss'),
|
2013-02-13 07:40:08 +04:00
|
|
|
sources = [
|
|
|
|
"src/openseadragon.js",
|
2013-03-07 00:36:52 +04:00
|
|
|
"src/fullscreen.js",
|
2013-09-25 00:36:13 +04:00
|
|
|
"src/eventsource.js",
|
2013-02-13 07:40:08 +04:00
|
|
|
"src/mousetracker.js",
|
|
|
|
"src/control.js",
|
|
|
|
"src/controldock.js",
|
2016-03-21 23:11:50 +03:00
|
|
|
"src/placement.js",
|
2013-02-13 07:40:08 +04:00
|
|
|
"src/viewer.js",
|
|
|
|
"src/navigator.js",
|
|
|
|
"src/strings.js",
|
|
|
|
"src/point.js",
|
|
|
|
//"src/profiler.js",
|
|
|
|
"src/tilesource.js",
|
|
|
|
"src/dzitilesource.js",
|
|
|
|
"src/iiiftilesource.js",
|
|
|
|
"src/osmtilesource.js",
|
|
|
|
"src/tmstilesource.js",
|
2016-02-25 13:46:56 +03:00
|
|
|
"src/zoomifytilesource.js",
|
2013-02-13 07:40:08 +04:00
|
|
|
"src/legacytilesource.js",
|
2015-11-01 18:23:02 +03:00
|
|
|
"src/imagetilesource.js",
|
2013-02-13 07:40:08 +04:00
|
|
|
"src/tilesourcecollection.js",
|
|
|
|
"src/button.js",
|
|
|
|
"src/buttongroup.js",
|
|
|
|
"src/rectangle.js",
|
|
|
|
"src/referencestrip.js",
|
|
|
|
"src/displayrectangle.js",
|
|
|
|
"src/spring.js",
|
2014-12-19 18:06:21 +03:00
|
|
|
"src/imageloader.js",
|
2013-02-13 07:40:08 +04:00
|
|
|
"src/tile.js",
|
|
|
|
"src/overlay.js",
|
|
|
|
"src/drawer.js",
|
2014-08-07 00:48:18 +04:00
|
|
|
"src/viewport.js",
|
|
|
|
"src/tiledimage.js",
|
|
|
|
"src/tilecache.js",
|
|
|
|
"src/world.js"
|
2013-02-13 07:40:08 +04:00
|
|
|
];
|
|
|
|
|
2016-01-27 02:16:54 +03:00
|
|
|
var banner = "//! <%= pkg.name %> <%= pkg.version %>\n" +
|
|
|
|
"//! Built on <%= grunt.template.today('yyyy-mm-dd') %>\n" +
|
|
|
|
"//! Git commit: <%= gitInfo %>\n" +
|
|
|
|
"//! http://openseadragon.github.io\n" +
|
|
|
|
"//! License: http://openseadragon.github.io/license/\n\n";
|
|
|
|
|
2014-06-02 22:02:22 +04:00
|
|
|
// ----------
|
|
|
|
grunt.event.once('git-describe', function (rev) {
|
|
|
|
grunt.config.set('gitInfo', rev);
|
|
|
|
});
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-13 07:40:08 +04:00
|
|
|
// Project configuration.
|
|
|
|
grunt.initConfig({
|
2013-04-23 04:20:07 +04:00
|
|
|
pkg: packageJson,
|
2013-11-25 21:30:49 +04:00
|
|
|
osdVersion: {
|
2013-11-25 21:19:50 +04:00
|
|
|
versionStr: packageJson.version,
|
2013-11-25 22:44:34 +04:00
|
|
|
major: parseInt(packageJson.version.split('.')[0], 10),
|
|
|
|
minor: parseInt(packageJson.version.split('.')[1], 10),
|
|
|
|
revision: parseInt(packageJson.version.split('.')[2], 10)
|
2013-11-25 21:19:50 +04:00
|
|
|
},
|
2013-02-27 21:59:51 +04:00
|
|
|
clean: {
|
|
|
|
build: ["build"],
|
2013-04-24 05:16:33 +04:00
|
|
|
package: [packageDir],
|
2018-01-02 03:17:13 +03:00
|
|
|
coverage: ["instrumented"],
|
2013-02-27 21:59:51 +04:00
|
|
|
release: {
|
2013-07-23 05:11:14 +04:00
|
|
|
src: [releaseRoot],
|
2013-02-27 21:59:51 +04:00
|
|
|
options: {
|
|
|
|
force: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-02-13 07:40:08 +04:00
|
|
|
concat: {
|
2013-02-21 22:45:14 +04:00
|
|
|
options: {
|
2016-01-27 02:16:54 +03:00
|
|
|
banner: banner,
|
|
|
|
process: true,
|
|
|
|
sourceMap: true
|
2013-02-21 22:45:14 +04:00
|
|
|
},
|
2013-02-13 07:40:08 +04:00
|
|
|
dist: {
|
2013-02-15 00:02:17 +04:00
|
|
|
src: [ "<banner>" ].concat(sources),
|
2013-02-13 07:40:08 +04:00
|
|
|
dest: distribution
|
|
|
|
}
|
|
|
|
},
|
2013-04-09 22:44:08 +04:00
|
|
|
replace: {
|
|
|
|
cleanPaths: {
|
|
|
|
src: ['build/openseadragon/*.map'],
|
|
|
|
overwrite: true,
|
|
|
|
replacements: [
|
|
|
|
{
|
|
|
|
from: /build\/openseadragon\//g,
|
|
|
|
to: ''
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
2013-02-21 22:45:14 +04:00
|
|
|
uglify: {
|
2013-03-11 22:52:30 +04:00
|
|
|
options: {
|
2016-01-27 02:16:54 +03:00
|
|
|
preserveComments: false,
|
|
|
|
banner: banner,
|
2016-01-31 19:44:53 +03:00
|
|
|
compress: {
|
|
|
|
sequences: false,
|
|
|
|
join_vars: false
|
|
|
|
},
|
2014-06-02 22:02:22 +04:00
|
|
|
sourceMap: true,
|
2017-01-07 19:38:38 +03:00
|
|
|
sourceMapName: 'build/openseadragon/openseadragon.min.js.map',
|
|
|
|
sourceMapIn: 'build/openseadragon/openseadragon.js.map'
|
2013-03-11 22:52:30 +04:00
|
|
|
},
|
2013-02-14 22:21:35 +04:00
|
|
|
openseadragon: {
|
2017-01-07 19:38:38 +03:00
|
|
|
src: distribution,
|
2013-02-14 22:21:35 +04:00
|
|
|
dest: minified
|
|
|
|
}
|
|
|
|
},
|
2013-02-15 22:58:57 +04:00
|
|
|
compress: {
|
|
|
|
zip: {
|
2013-02-21 23:56:16 +04:00
|
|
|
options: {
|
2013-04-23 04:27:55 +04:00
|
|
|
archive: "build/releases/" + packageDirName + ".zip",
|
2013-04-19 09:01:15 +04:00
|
|
|
level: 9
|
2013-02-21 23:56:16 +04:00
|
|
|
},
|
|
|
|
files: [
|
2013-04-23 04:20:07 +04:00
|
|
|
{ expand: true, cwd: "build/", src: [ packageDirName + "/**" ] }
|
2013-02-21 23:56:16 +04:00
|
|
|
]
|
2013-02-15 22:58:57 +04:00
|
|
|
},
|
|
|
|
tar: {
|
2013-02-21 23:56:16 +04:00
|
|
|
options: {
|
2013-04-23 04:27:55 +04:00
|
|
|
archive: "build/releases/" + packageDirName + ".tar.gz",
|
2013-04-19 09:01:15 +04:00
|
|
|
level: 9
|
2013-02-21 23:56:16 +04:00
|
|
|
},
|
|
|
|
files: [
|
2013-04-23 04:20:07 +04:00
|
|
|
{ expand: true, cwd: "build/", src: [ packageDirName + "/**" ] }
|
2013-02-21 23:56:16 +04:00
|
|
|
]
|
2013-02-15 22:58:57 +04:00
|
|
|
}
|
|
|
|
},
|
2013-02-14 22:21:35 +04:00
|
|
|
qunit: {
|
2014-11-20 03:46:05 +03:00
|
|
|
normal: {
|
2013-02-21 23:17:05 +04:00
|
|
|
options: {
|
2018-01-02 03:17:13 +03:00
|
|
|
urls: [ "http://localhost:8000/test/test.html" ],
|
|
|
|
timeout: 500000
|
2013-02-21 23:17:05 +04:00
|
|
|
}
|
2014-11-20 03:46:05 +03:00
|
|
|
},
|
|
|
|
coverage: {
|
|
|
|
options: {
|
|
|
|
urls: [ "http://localhost:8000/test/coverage.html" ],
|
|
|
|
coverage: {
|
|
|
|
src: ['src/*.js'],
|
2018-01-02 03:17:13 +03:00
|
|
|
htmlReport: coverageDir + '/html/',
|
|
|
|
instrumentedFiles: 'instrumented/src/',
|
2014-11-20 03:46:05 +03:00
|
|
|
baseUrl: '.',
|
|
|
|
disposeCollector: true
|
2018-01-02 03:17:13 +03:00
|
|
|
},
|
|
|
|
inject: 'test/helpers/phantom-bridge.js',
|
|
|
|
timeout: 500000
|
2014-11-20 03:46:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
all: {
|
|
|
|
options: {
|
|
|
|
timeout: 10000
|
|
|
|
}
|
2013-02-21 23:17:05 +04:00
|
|
|
}
|
2013-02-14 22:21:35 +04:00
|
|
|
},
|
2013-02-21 22:45:14 +04:00
|
|
|
connect: {
|
2013-02-21 23:17:05 +04:00
|
|
|
server: {
|
|
|
|
options: {
|
|
|
|
port: 8000,
|
|
|
|
base: "."
|
|
|
|
}
|
2013-02-21 22:45:14 +04:00
|
|
|
}
|
2013-02-14 22:21:35 +04:00
|
|
|
},
|
|
|
|
watch: {
|
2013-03-12 21:43:27 +04:00
|
|
|
files: [ "Gruntfile.js", "src/*.js", "images/*" ],
|
2014-10-30 02:01:06 +03:00
|
|
|
tasks: "watchTask"
|
2013-02-14 22:21:35 +04:00
|
|
|
},
|
2017-01-08 17:52:57 +03:00
|
|
|
eslint: {
|
|
|
|
options: {
|
|
|
|
configFile: '.eslintrc.json'
|
|
|
|
},
|
|
|
|
target: sources
|
|
|
|
},
|
2013-03-21 21:26:03 +04:00
|
|
|
"git-describe": {
|
2017-07-18 02:38:18 +03:00
|
|
|
"options": {
|
|
|
|
failOnError: false
|
|
|
|
},
|
2014-06-02 22:02:22 +04:00
|
|
|
build: {}
|
2017-07-18 02:38:18 +03:00
|
|
|
},
|
2018-01-02 03:17:13 +03:00
|
|
|
gitInfo: "unknown",
|
|
|
|
instrument: {
|
|
|
|
files: sources,
|
|
|
|
options: {
|
|
|
|
lazy: false,
|
|
|
|
basePath: 'instrumented/'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reloadTasks: {
|
|
|
|
rootPath: "instrumented/src/"
|
|
|
|
},
|
|
|
|
storeCoverage: {
|
|
|
|
options: {
|
|
|
|
dir: coverageDir,
|
|
|
|
'include-all-sources': true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
makeReport: {
|
|
|
|
src: "coverage/**/*.json",
|
|
|
|
options: {
|
|
|
|
type: [ "lcov", "html" ],
|
|
|
|
dir: coverageDir,
|
|
|
|
print: "detail"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.event.on("qunit.coverage", function(coverage) {
|
|
|
|
var reportPath = coverageDir + "/coverage.json";
|
|
|
|
|
|
|
|
// Create the coverage file
|
|
|
|
grunt.file.write(reportPath, JSON.stringify(coverage));
|
2013-02-13 07:40:08 +04:00
|
|
|
});
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-27 21:59:51 +04:00
|
|
|
// Copy:build task.
|
|
|
|
// Copies the image files into the appropriate location in the build folder.
|
|
|
|
grunt.registerTask("copy:build", function() {
|
2013-02-15 01:24:50 +04:00
|
|
|
grunt.file.recurse("images", function(abspath, rootdir, subdir, filename) {
|
2013-06-19 21:33:25 +04:00
|
|
|
grunt.file.copy(abspath, "build/openseadragon/images/" + (subdir || "") + filename);
|
2013-02-15 01:24:50 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-04-23 04:20:07 +04:00
|
|
|
// ----------
|
|
|
|
// Copy:package task.
|
|
|
|
// Creates a directory tree to be compressed into a package.
|
|
|
|
grunt.registerTask("copy:package", function() {
|
|
|
|
grunt.file.recurse("build/openseadragon", function(abspath, rootdir, subdir, filename) {
|
2014-05-05 06:11:50 +04:00
|
|
|
var dest = packageDir +
|
|
|
|
(subdir ? subdir + "/" : '/') +
|
|
|
|
filename;
|
2013-04-23 04:20:07 +04:00
|
|
|
grunt.file.copy(abspath, dest);
|
|
|
|
});
|
2013-04-19 10:40:27 +04:00
|
|
|
grunt.file.copy("changelog.txt", packageDir + "changelog.txt");
|
2013-05-01 09:06:42 +04:00
|
|
|
grunt.file.copy("LICENSE.txt", packageDir + "LICENSE.txt");
|
2013-04-23 04:20:07 +04:00
|
|
|
});
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-27 21:59:51 +04:00
|
|
|
// Copy:release task.
|
2013-03-25 21:02:41 +04:00
|
|
|
// Copies the contents of the build folder into the release folder.
|
2013-02-27 21:59:51 +04:00
|
|
|
grunt.registerTask("copy:release", function() {
|
|
|
|
grunt.file.recurse("build", function(abspath, rootdir, subdir, filename) {
|
2013-07-22 11:52:24 +04:00
|
|
|
if (subdir === 'releases') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-05 06:11:50 +04:00
|
|
|
var dest = releaseRoot +
|
|
|
|
(subdir ? subdir + "/" : '/') +
|
|
|
|
filename;
|
2013-02-27 22:36:19 +04:00
|
|
|
|
|
|
|
grunt.file.copy(abspath, dest);
|
2013-02-27 21:59:51 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-30 22:05:19 +04:00
|
|
|
// ----------
|
2014-10-30 02:01:06 +03:00
|
|
|
// Bower task.
|
|
|
|
// Generates the Bower file for site-build.
|
2014-04-30 22:05:19 +04:00
|
|
|
grunt.registerTask("bower", function() {
|
|
|
|
var path = "../site-build/bower.json";
|
|
|
|
var data = grunt.file.readJSON(path);
|
|
|
|
data.version = packageJson.version;
|
|
|
|
grunt.file.write(path, JSON.stringify(data, null, 2) + "\n");
|
|
|
|
});
|
|
|
|
|
2014-10-30 02:01:06 +03:00
|
|
|
// ----------
|
|
|
|
// Watch task.
|
|
|
|
// Called from the watch feature; does a full build or a minbuild, depending on
|
|
|
|
// whether you used --min on the command line.
|
|
|
|
grunt.registerTask("watchTask", function() {
|
|
|
|
if (grunt.option('min')) {
|
|
|
|
grunt.task.run("minbuild");
|
|
|
|
} else {
|
|
|
|
grunt.task.run("build");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-27 21:59:51 +04:00
|
|
|
// Build task.
|
|
|
|
// Cleans out the build folder and builds the code and images into it, checking lint.
|
|
|
|
grunt.registerTask("build", [
|
2017-01-16 23:43:09 +03:00
|
|
|
"clean:build", "git-describe", "eslint", "concat", "uglify",
|
|
|
|
"replace:cleanPaths", "copy:build"
|
2013-02-27 21:59:51 +04:00
|
|
|
]);
|
2013-02-14 22:21:35 +04:00
|
|
|
|
2014-07-22 22:13:22 +04:00
|
|
|
// ----------
|
|
|
|
// Minimal build task.
|
2014-10-30 02:01:06 +03:00
|
|
|
// For use during development as desired. Creates only the unminified version.
|
2014-07-22 22:13:22 +04:00
|
|
|
grunt.registerTask("minbuild", [
|
|
|
|
"git-describe", "concat", "copy:build"
|
|
|
|
]);
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-14 22:21:35 +04:00
|
|
|
// Test task.
|
2013-02-27 21:59:51 +04:00
|
|
|
// Builds and runs unit tests.
|
2014-11-20 03:46:05 +03:00
|
|
|
grunt.registerTask("test", ["build", "connect", "qunit:normal"]);
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Coverage task.
|
|
|
|
// Outputs unit test code coverage report.
|
2018-01-02 03:17:13 +03:00
|
|
|
grunt.registerTask("coverage", ["clean:coverage", "instrument", "connect", "qunit:coverage", "makeReport"]);
|
2013-02-13 07:40:08 +04:00
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-15 22:58:57 +04:00
|
|
|
// Package task.
|
2013-04-23 04:13:42 +04:00
|
|
|
// Builds and creates the .zip and .tar.gz files.
|
2013-04-23 04:20:07 +04:00
|
|
|
grunt.registerTask("package", ["build", "copy:package", "compress", "clean:package"]);
|
2013-02-20 07:53:54 +04:00
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-27 21:59:51 +04:00
|
|
|
// Publish task.
|
2013-03-25 21:02:41 +04:00
|
|
|
// Cleans the built files out of the release folder and copies newly built ones over.
|
2014-04-30 22:05:19 +04:00
|
|
|
grunt.registerTask("publish", ["package", "clean:release", "copy:release", "bower"]);
|
2013-02-27 21:59:51 +04:00
|
|
|
|
2015-09-16 19:39:43 +03:00
|
|
|
// ----------
|
|
|
|
// Dev task.
|
|
|
|
// Builds, fires up a server and watches for changes.
|
|
|
|
grunt.registerTask("dev", ["build", "connect", "watch"]);
|
|
|
|
|
2013-03-12 21:49:48 +04:00
|
|
|
// ----------
|
2013-02-27 21:59:51 +04:00
|
|
|
// Default task.
|
|
|
|
// Does a normal build.
|
|
|
|
grunt.registerTask("default", ["build"]);
|
2013-02-14 22:21:35 +04:00
|
|
|
};
|