-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gruntfile.js
208 lines (194 loc) · 5.53 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
/* eslint-env node, es6 */
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-git-describe');
grunt.loadNpmTasks('grunt-jsdoc');
// //TODO Use config object in package.json (see https://docs.npmjs.com/files/package.json)
// var devConfig;
// try {
// devConfig = require('./devconfig.js');
// } catch (e) {
// devConfig = null;
// }
var packageJson = grunt.file.readJSON('package.json');
var docsGlobals = '../OpenSeadragonImaging/shared/docs/docs-globals.js';
var distributionName = 'openseadragon-viewerinputhook.js';
var minifiedName = 'openseadragon-viewerinputhook.min.js';
var srcDir = 'src/';
var buildDir = 'build/';
var builtDir = buildDir + 'openseadragon-viewerinputhook/';
var distribution = builtDir + distributionName;
var minified = builtDir + minifiedName;
var docsDir = buildDir + 'docs/';
var publishRepoBuildDir = '../OpenSeadragonImaging/builds/';
var publishRepoDocsDir = '../OpenSeadragonImaging/docs/openseadragon-viewerinputhook/';
var publishRepoDemoDir = '../OpenSeadragonImaging/demo/';
var publishRepoDemoLibDir = publishRepoDemoDir + 'lib/';
// var publishDemoDirDev = devConfig ? devConfig.sitePhysPath : '';
// var publishBuildDirDev = devConfig ? devConfig.buildPhysPath : '';
var sources = [srcDir + 'viewerinputhook.js'];
var builtSources = [distributionName, minifiedName];
//var demoSiteSources = ['content/**', 'lib/**', 'scripts/**', 'index.html', 'Web.config'];
var banner =
'//! <%= pkg.name %> <%= pkg.version %>\n' +
'//! Build date: <%= grunt.template.today("yyyy-mm-dd") %>\n' +
'//! Git commit: <%= grunt.option("gitRevision") %>\n' +
'//! https://github.com/msalsbery/OpenSeadragonViewerInputHook\n';
//+ '//! License: http://msalsbery.github.io/openseadragonannohost/index.html\n\n';
grunt.event.once('git-describe', rev => {
grunt.option('gitRevision', rev);
// grunt.log.writeln('Git rev tag: ' + rev.tag);
// grunt.log.writeln('Git rev since: ' + rev.since);
// grunt.log.writeln('Git rev object: ' + rev.object);
// grunt.log.writeln('Git rev dirty: ' + rev.dirty);
});
grunt.initConfig({
pkg: packageJson,
viewerinputhookVersion: {
versionStr: packageJson.version
},
'git-describe': {
options: {
failOnError: true
},
build: {}
},
clean: {
build: {
src: [builtDir]
},
doc: {
src: [docsDir]
}
},
eslint: {
options: {
//fix: true,
configFile: '.eslintrc.json'
},
target: sources
},
copy: {
dev: {
files: [
// Copy built source(s) to demo site lib server folder
{
expand: true,
cwd: builtDir,
src: builtSources,
dest: publishRepoDemoLibDir //,
//filter: 'isFile'
}
]
},
prod: {
files: [
// Copy built source(s) to builds folder in OpenSeadragonImaging repository
{
expand: true,
cwd: builtDir,
src: builtSources,
dest: publishRepoBuildDir
},
// Copy built source(s) to demo/lib folder in OpenSeadragonImaging repository
{
expand: true,
cwd: builtDir,
src: builtSources,
dest: publishRepoDemoLibDir
},
// Copy documentation files to docs folder in OpenSeadragonImaging repository
{
expand: true,
cwd: docsDir,
src: ['**'],
dest: publishRepoDocsDir
}
]
}
},
concat: {
options: {
banner: banner,
process: true,
sourceMap: false
},
build: {
src: sources,
dest: distribution
}
},
uglify: {
options: {
compress: {
sequences: false,
join_vars: false
},
banner: banner,
sourceMap: false,
output: {
comments: false
}
},
build: {
files: [
{
src: distribution,
dest: minified
}
]
}
},
watch: {
files: ['Gruntfile.js', srcDir + '*.js'],
tasks: ['build']
//options: {
// event: ['added', 'deleted'], //'all', 'changed', 'added', 'deleted'
//}
},
jsdoc: {
dist: {
src: [docsGlobals, distribution], //, 'README.md'
options: {
destination: docsDir,
//template: "node_modules/docstrap/template",
configure: 'doc-conf.json',
private: false
}
}
}
});
// grunt.registerTask('gitdescribe', () => {
// grunt.event.once('git-describe', (rev) => {
// grunt.option('gitRevision', rev);
// // grunt.log.writeln('Git rev tag: ' + rev.tag);
// // grunt.log.writeln('Git rev since: ' + rev.since);
// // grunt.log.writeln('Git rev object: ' + rev.object);
// // grunt.log.writeln('Git rev dirty: ' + rev.dirty);
// });
// grunt.task.run('git-describe');
// });
// // Copies built source to a local server publish folder (see /devconfig.js)
// grunt.registerTask('publish-dev', function () {
// if (publishDemoDirDev && publishBuildDirDev) {
// grunt.task.run(['copy:dev']);
// } else {
// throw new Error('devconfig.js error or not implemented!');
// }
// });
// Builds and copies sources and docs to OpenSeadragonImaging repository
grunt.registerTask('publish', ['build', 'doc', 'copy:prod']);
// Build task(s).
grunt.registerTask('build', ['clean:build', 'git-describe', 'eslint', 'concat', 'uglify']);
// Dev task(s).
grunt.registerTask('dev', ['build', 'copy:dev']);
// Documentation task(s).
grunt.registerTask('doc', ['clean:doc', 'jsdoc']);
// Default task(s).
grunt.registerTask('default', ['build']);
};