forked from box/viewer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
197 lines (184 loc) · 6.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
/*global module*/
/*jshint node: true*/
var WRAPPER_HEADER = 'var Crocodoc = (function ($) {\n\n',
WRAPPER_FOOTER = '\n\nreturn Crocodoc;\n})(jQuery);';
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-connect-rewrite');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-image-embed');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-parallel');
var rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest;
// Middleware snippet for grunt-connect to make CORS testing a bit easier
var accessControlSnippet = function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.setHeader('Access-Control-Allow-Headers', '*');
return next();
};
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
options: {
hostname: '*',
port: 9000,
keepalive: true,
open: true
},
rules: [
{from: '^/examples/remember-page/(.*)$', to: '/examples/remember-page/index.html'}
],
development: {
options: {
middleware: function (connect, options) {
var middlewares = [];
// RewriteRules support
middlewares.push(rewriteRulesSnippet, accessControlSnippet);
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
var directory = options.directory || options.base[options.base.length - 1];
options.base.forEach(function (base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
return middlewares;
}
}
}
},
cssmin: {
minify: {
files: [{
'build/crocodoc.viewer.min.css': ['<%= concat.css.dest %>']
}]
}
},
uglify: {
options: {
mangle: true,
compress: true,
preserveComments: 'some'
},
dist: {
files: [{
'build/crocodoc.viewer.min.js': ['<%= concat.js.dest %>']
}]
}
},
concat: {
options: {
stripBanners: true,
banner: '/*! Crocodoc Viewer - v<%= pkg.version %> | (c) <%= grunt.template.today("yyyy") %> Box */\n\n',
},
js: {
// also use the jQuery wrapper for js files
options: {
banner: '<%= concat.options.banner %>' + WRAPPER_HEADER,
footer: WRAPPER_FOOTER
},
src: [
'src/js/core/crocodoc.js',
'src/js/core/scope.js',
'src/js/core/event-target.js',
'src/js/core/viewer.js',
'src/js/data-providers/*.js',
'src/js/utilities/*.js',
'src/js/components/*.js'
],
dest: 'build/crocodoc.viewer.js'
},
css: {
src: [
'src/css/viewer.css',
'src/css/theme.css',
'src/css/logo.css'
],
dest: 'build/crocodoc.viewer.css'
},
'css-no-logo': {
src: [
'src/css/viewer.css',
'src/css/theme.css'
],
dest: 'build/crocodoc.viewer.css'
}
},
jshint: {
options: {
jshintrc: true
},
files: ['Gruntfile.js', 'src/js/**/*.js', 'test/js/**/*.js', 'test/plugins/**/*.js']
},
qunit: {
viewer: ['test/index.html'],
plugins: ['test/plugins/index.html']
},
jsdoc : {
dist : {
src: ['src/js/**/*.js', 'test/js/**/*.js'],
options: {
destination: 'doc',
configure: 'jsdoc-conf.json'
}
}
},
imageEmbed: {
dist: {
src: ['build/crocodoc.viewer.css'],
dest: 'build/crocodoc.viewer.css',
options: {
deleteAfterEncoding: false,
baseDir: './'
}
}
},
copy: {
main: {
files: [{
expand: true,
cwd: 'build/',
src: ['*'],
dest: 'dist/',
filter: 'isFile'
}]
}
},
// this task allows us to run the connect and realtime servers in parallel
parallel: {
examples: {
options: { grunt: true },
tasks: [
'connect:development',
'realtime-example'
]
}
}
});
var useLogo = !grunt.option('no-logo');
var defaultTasks = ['test', 'concat:js'];
if (useLogo) {
defaultTasks.push('concat:css', 'imageEmbed');
} else {
defaultTasks.push('concat:css-no-logo');
}
// task to run the realtime example sse server
grunt.registerTask('realtime-example', function () {
this.async();
require('./examples/realtime/server')(9001);
});
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('doc', ['test', 'jsdoc']);
grunt.registerTask('default', defaultTasks);
grunt.registerTask('build', ['default', 'cssmin', 'uglify']);
grunt.registerTask('serve', ['default', 'configureRewriteRules', 'parallel:examples']);
grunt.registerTask('release', ['build', 'copy']);
};