forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
244 lines (199 loc) · 6.36 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
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 lumbarConfig = grunt.file.readJSON('lumbar.json');
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', '!jquery*' ],
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:archiveDependencies',
'copy:archiveDemos',
'copy:archiveMisc',
'compress:archive'
]);
// copy FullCalendar modules into ./fullcalendar/ directory
config.copy.archiveModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css', '!jquery*' ],
dest: 'build/archive/fullcalendar/'
};
// copy jQuery and jQuery UI into the ./jquery/ directory
config.copy.archiveDependencies = {
expand: true,
flatten: true,
src: [
// we want to retain the original filenames
lumbarConfig.modules['jquery'].scripts[0],
lumbarConfig.modules['jquery-ui'].scripts[0]
],
dest: 'build/archive/jquery/'
};
// copy demo files into ./demos/ directory
config.copy.archiveDemos = {
options: {
processContentExclude: 'demos/*/**', // don't process anything more than 1 level deep (like assets)
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/'
};
// in demo HTML, rewrites paths to work in the archive
function transformDemoPath(path) {
path = path.replace('/build/out/jquery.js', '/' + lumbarConfig.modules['jquery'].scripts[0]);
path = path.replace('/build/out/jquery-ui.js', '/' + lumbarConfig.modules['jquery-ui'].scripts[0]);
path = path.replace('/lib/', '/jquery/');
path = path.replace('/build/out/', '/fullcalendar/');
path = path.replace('/fullcalendar.js', '/fullcalendar.min.js');
return path;
}
// copy license and changelog
config.copy.archiveMisc = {
src: "*.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://twitter.github.com/bower/)
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('component', 'Build the FullCalendar component for the Bower package manager', [
'clean:modules',
'clean:component',
'modules',
'copy:componentModules',
'copy:componentReadme',
'componentConfig'
]);
// copy FullCalendar modules into component root
config.copy.componentModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css', '!jquery*' ],
dest: 'build/component/'
};
// copy the component-specific README
config.copy.componentReadme = {
src: 'build/component-readme.md',
dest: 'build/component/readme.md'
};
// assemble the component's config from existing configs
grunt.registerTask('componentConfig', function() {
var config = grunt.file.readJSON('build/component.json');
grunt.file.write(
'build/component/component.json',
JSON.stringify(
_.extend({}, pluginConfig, config), // combine 2 configs
null, // replacer
2 // indent
)
);
});
config.clean.component = 'build/component/*';
/* CDN (http://cdnjs.com/)
----------------------------------------------------------------------------------------------------*/
grunt.registerTask('cdn', 'Build files for CDNJS\'s hosted version of FullCalendar', [
'clean:modules',
'clean:cdn',
'modules',
'copy:cdnModules',
'cdnConfig'
]);
config.copy.cdnModules = {
expand: true,
cwd: 'build/out/',
src: [ '*.js', '*.css', '!jquery*' ],
dest: 'build/cdn/<%= meta.version %>/'
};
grunt.registerTask('cdnConfig', function() {
var config = grunt.file.readJSON('build/cdn.json');
grunt.file.write(
'build/cdn/package.json',
JSON.stringify(
_.extend({}, pluginConfig, config), // combine 2 configs
null, // replace
2 // indent
)
);
});
config.clean.cdn = 'build/cdn/<%= 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);
};