forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
256 lines (209 loc) · 6.6 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
module.exports = function(grunt) {
var _ = require('underscore');
// Load required NPM tasks.
// You must first run `npm install` in the project's root directory to get these dependencies.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('lumbar');
// Parse config files
var packageConfig = grunt.file.readJSON('package.json');
var pluginConfig = grunt.file.readJSON('fullcalendar.jquery.json');
// This will eventually get passed to grunt.initConfig()
// Initialize multitasks...
var config = {
concat: {},
uglify: {},
copy: {},
compress: {},
clean: {}
};
// Combine certain configs for the "meta" template variable (<%= meta.whatever %>)
config.meta = _.extend({}, packageConfig, pluginConfig);
// The "grunt" command with no arguments
grunt.registerTask('default', 'archive');
// Bare minimum for debugging
grunt.registerTask('dev', 'lumbar:build');
/* FullCalendar Modules
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('modules', 'Build the FullCalendar modules', [
'lumbar:build',
'concat:moduleVariables',
'uglify:modules'
]);
// assemble modules
config.lumbar = {
build: {
build: 'lumbar.json',
output: 'build/out' // a directory. lumbar doesn't like trailing slash
}
};
// replace template variables (<%= %>), IN PLACE
config.concat.moduleVariables = {
options: {
process: true // replace
},
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css' ],
dest: 'build/out/'
};
// create minified versions (*.min.js)
config.uglify.modules = {
options: {
preserveComments: 'some' // keep comments starting with /*!
},
expand: true,
src: 'build/out/fullcalendar.js', // only do it for fullcalendar.js
ext: '.min.js'
}
config.clean.modules = 'build/out/*';
/* Archive
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('archive', 'Create a distributable ZIP archive', [
'clean:modules',
'clean:archive',
'modules',
'copy:archiveModules',
'copy:archiveJQuery',
'concat:archiveJQueryUI',
'copy:archiveDemos',
'copy:archiveDemoTheme',
'copy:archiveMisc',
'compress:archive'
]);
// copy FullCalendar modules into ./fullcalendar/ directory
config.copy.archiveModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css' ],
dest: 'build/archive/fullcalendar/'
};
config.copy.archiveJQuery = {
src: 'lib/jquery/jquery.min.js',
dest: 'build/archive/lib/jquery.min.js'
};
config.concat.archiveJQueryUI = {
src: [
'lib/jquery-ui/ui/minified/jquery.ui.core.min.js',
'lib/jquery-ui/ui/minified/jquery.ui.widget.min.js',
'lib/jquery-ui/ui/minified/jquery.ui.mouse.min.js',
'lib/jquery-ui/ui/minified/jquery.ui.draggable.min.js',
'lib/jquery-ui/ui/minified/jquery.ui.resizable.min.js'
],
dest: 'build/archive/lib/jquery-ui.custom.min.js'
};
// copy demo files into ./demos/ directory
config.copy.archiveDemos = {
options: {
processContent: function(content) {
content = content.replace(/((?:src|href)=['"])([^'"]*)(['"])/g, function(m0, m1, m2, m3) {
return m1 + transformDemoPath(m2) + m3;
});
return content;
}
},
src: 'demos/*',
dest: 'build/archive/'
};
// copy the "cupertino" jquery-ui theme into the demo directory (for demos/theme.html)
config.copy.archiveDemoTheme = {
expand: true,
cwd: 'lib/jquery-ui/themes/cupertino/',
src: [ 'jquery-ui.min.css', 'images/*' ],
dest: 'build/archive/demos/cupertino/'
};
// in demo HTML, rewrites paths to work in the archive
function transformDemoPath(path) {
path = path.replace('../lib/jquery/jquery.js', '../lib/jquery.min.js');
path = path.replace('../lib/jquery-ui/ui/jquery-ui.js', '../lib/jquery-ui.custom.min.js');
path = path.replace('../lib/jquery-ui/themes/', '');
path = path.replace('../build/out/', '../fullcalendar/');
path = path.replace('/fullcalendar.js', '/fullcalendar.min.js');
return path;
}
// copy license and changelog
config.copy.archiveMisc = {
src: [ 'license.txt', 'changelog.txt' ],
dest: 'build/archive/'
};
// create the ZIP
config.compress.archive = {
options: {
archive: 'dist/<%= meta.name %>-<%= meta.version %>.zip'
},
expand: true,
cwd: 'build/archive/',
src: '**',
dest: '<%= meta.name %>-<%= meta.version %>/' // have a top-level directory in the ZIP file
};
config.clean.archive = 'build/archive/*';
config.clean.dist = 'dist/*';
/* Bower Component (http://bower.io/)
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('bower', 'Build the FullCalendar Bower component', [
'clean:modules',
'clean:bower',
'modules',
'copy:bowerModules',
'copy:bowerReadme',
'bowerConfig'
]);
// copy FullCalendar modules into bower component's root
config.copy.bowerModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css' ],
dest: 'build/bower/'
};
// copy the bower-specific README
config.copy.bowerReadme = {
src: 'build/bower-readme.md',
dest: 'build/bower/readme.md'
};
// assemble the bower config from existing configs
grunt.registerTask('bowerConfig', function() {
var bowerConfig = grunt.file.readJSON('build/bower.json');
grunt.file.write(
'build/bower/bower.json',
JSON.stringify(
_.extend({}, pluginConfig, bowerConfig), // combine 2 configs
null, // replacer
2 // indent
)
);
});
config.clean.bower = 'build/bower/*';
/* CDNJS (http://cdnjs.com/)
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('cdnjs', 'Build files for CDNJS\'s hosted version of FullCalendar', [
'clean:modules',
'clean:cdnjs',
'modules',
'copy:cdnjsModules',
'cdnjsConfig'
]);
config.copy.cdnjsModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css' ],
dest: 'build/cdnjs/<%= meta.version %>/'
};
grunt.registerTask('cdnjsConfig', function() {
var cdnjsConfig = grunt.file.readJSON('build/cdnjs.json');
grunt.file.write(
'build/cdnjs/package.json',
JSON.stringify(
_.extend({}, pluginConfig, cdnjsConfig), // combine 2 configs
null, // replace
2 // indent
)
);
});
config.clean.cdnjs = 'build/cdnjs/<%= meta.version %>/*';
// NOTE: not a complete clean. also need to manually worry about package.json and version folders
// finally, give grunt the config object...
grunt.initConfig(config);
};