Skip to content

Commit 0fe7348

Browse files
committed
Close GH-535: Adding version numbers in build. Minifying CSS..
1 parent 36c9240 commit 0fe7348

4 files changed

Lines changed: 57 additions & 31 deletions

File tree

Gruntfile.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,39 @@ module.exports = function(grunt) {
7777
},
7878
s3: {
7979
options: s3,
80-
prod: {
81-
// Files to be uploaded.
80+
minor: {
8281
upload: [
8382
{
8483
src: 'dist/cdn/*',
85-
dest: 'vjs/'+version.full+'/',
84+
dest: 'vjs/'+version.majorMinor+'/',
8685
rel: 'dist/cdn/',
8786
headers: {
88-
'Cache-Control': 'public, max-age=31536000'
87+
'Cache-Control': 'public, max-age=2628000'
8988
}
90-
},
89+
}
90+
]
91+
},
92+
patch: {
93+
upload: [
9194
{
9295
src: 'dist/cdn/*',
93-
dest: 'vjs/'+version.majorMinor+'/',
96+
dest: 'vjs/'+version.full+'/',
9497
rel: 'dist/cdn/',
9598
headers: {
96-
'Cache-Control': 'public, max-age=2628000'
99+
'Cache-Control': 'public, max-age=31536000'
97100
}
98101
}
99102
]
100103
}
104+
},
105+
cssmin: {
106+
minify: {
107+
expand: true,
108+
cwd: 'build/files/',
109+
src: ['video-js.css'],
110+
dest: 'build/files/',
111+
ext: '.min.css'
112+
}
101113
}
102114
});
103115

@@ -106,6 +118,7 @@ module.exports = function(grunt) {
106118
grunt.loadNpmTasks('grunt-contrib-watch');
107119
grunt.loadNpmTasks('grunt-contrib-clean');
108120
grunt.loadNpmTasks('grunt-contrib-copy');
121+
grunt.loadNpmTasks('grunt-contrib-cssmin');
109122
grunt.loadNpmTasks('grunt-s3');
110123
grunt.loadNpmTasks('contribflow');
111124

@@ -133,28 +146,35 @@ module.exports = function(grunt) {
133146
sourceFiles[i] = sourceFiles[i].replace(/\\/g, '/');
134147
}
135148

136-
// grunt.file.write('build/files/sourcelist.txt', sourceList.join(','));
137-
// Allow time for people to update their index.html before they remove these
138-
// grunt.file.write('build/files/sourcelist.js', 'var sourcelist = ["' + sourceFiles.join('","') + '"]');
139-
140149
// Create a combined sources file. https://github.com/zencoder/video-js/issues/287
141150
var combined = '';
142151
sourceFiles.forEach(function(result){
143152
combined += grunt.file.read(result);
144153
});
154+
// Replace CDN version ref in js. Use major/minor version.
155+
combined = combined.replace(/GENERATED_CDN_VSN/g, version.majorMinor);
145156
grunt.file.write('build/files/combined.video.js', combined);
146157

158+
// Copy over other files
147159
grunt.file.copy('src/css/video-js.css', 'build/files/video-js.css');
148160
grunt.file.copy('src/css/video-js.png', 'build/files/video-js.png');
149161
grunt.file.copy('src/swf/video-js.swf', 'build/files/video-js.swf');
150-
// grunt.file.copy('src/css/font/', 'build/files/font/');
151162

163+
// Inject version number into css file
164+
var css = grunt.file.read('build/files/video-js.css');
165+
css = css.replace(/GENERATED_AT_BUILD/g, version.full);
166+
grunt.file.write('build/files/video-js.css', css);
167+
168+
// Copy over font files
152169
grunt.file.recurse('src/css/font', function(absdir, rootdir, subdir, filename) {
153170
// Block .DS_Store files
154171
if ('filename'.substring(0,1) !== '.') {
155172
grunt.file.copy(absdir, 'build/files/font/' + filename);
156173
}
157174
});
175+
176+
// Minify CSS
177+
grunt.task.run(['cssmin']);
158178
});
159179

160180
grunt.registerMultiTask('minify', 'Minify JS files using Closure Compiler.', function() {
@@ -175,24 +195,26 @@ module.exports = function(grunt) {
175195
filePatterns = filePatterns.concat(this.data.src);
176196
}
177197

198+
// Build closure compiler shell command
178199
var command = 'java -jar build/compiler/compiler.jar'
179200
+ ' --compilation_level ADVANCED_OPTIMIZATIONS'
180201
// + ' --formatting=pretty_print'
181202
+ ' --js_output_file=' + dest
182203
+ ' --create_source_map ' + dest + '.map --source_map_format=V3'
183204
+ ' --jscomp_warning=checkTypes --warning_level=VERBOSE'
184-
+ ' --output_wrapper "/*! ' + pkg.copyright + ' */\n (function() {%output%})();//@ sourceMappingURL=video.js.map"';
205+
+ ' --output_wrapper "/*! Video.js v' + version.full + ' ' + pkg.copyright + ' */\n (function() {%output%})();//@ sourceMappingURL=video.js.map"';
185206

207+
// Add each js file
186208
grunt.file.expand(filePatterns).forEach(function(file){
187209
command += ' --js='+file;
188210
});
189211

212+
// Add externs
190213
externs.forEach(function(extern){
191214
command += ' --externs='+extern;
192215
});
193216

194-
// grunt.log.writeln(command)
195-
217+
// Run command
196218
exec(command, { maxBuffer: 500*1024 }, function(err, stdout, stderr){
197219

198220
if (err) {
@@ -211,14 +233,18 @@ module.exports = function(grunt) {
211233
grunt.registerTask('dist', 'Creating distribution', function(){
212234
var exec = require('child_process').exec;
213235
var done = this.async();
236+
var css, jsmin, jsdev;
214237

238+
// Manually copy each source file
215239
grunt.file.copy('build/files/minified.video.js', 'dist/video-js/video.js');
216240
grunt.file.copy('build/files/combined.video.js', 'dist/video-js/video.dev.js');
217241
grunt.file.copy('build/files/video-js.css', 'dist/video-js/video-js.css');
242+
grunt.file.copy('build/files/video-js.min.css', 'dist/video-js/video-js.min.css');
218243
grunt.file.copy('build/files/video-js.swf', 'dist/video-js/video-js.swf');
219244
grunt.file.copy('build/demo-files/demo.html', 'dist/video-js/demo.html');
220245
grunt.file.copy('build/demo-files/demo.captions.vtt', 'dist/video-js/demo.captions.vtt');
221246

247+
// Copy over font files
222248
grunt.file.recurse('build/files/font', function(absdir, rootdir, subdir, filename) {
223249
// Block .DS_Store files
224250
if ('filename'.substring(0,1) !== '.') {
@@ -227,18 +253,17 @@ module.exports = function(grunt) {
227253
});
228254

229255
// CDN version uses already hosted font files
230-
// Minified version only
231-
// doesn't need demo files
256+
// Minified version only, doesn't need demo files
232257
grunt.file.copy('build/files/minified.video.js', 'dist/cdn/video.js');
233-
grunt.file.copy('build/files/video-js.css', 'dist/cdn/video-js.css');
258+
grunt.file.copy('build/files/video-js.min.css', 'dist/cdn/video-js.css');
234259
grunt.file.copy('build/files/video-js.swf', 'dist/cdn/video-js.swf');
235260

236-
237-
238-
var css = grunt.file.read('dist/cdn/video-js.css');
261+
// Replace font urls with CDN versions
262+
css = grunt.file.read('dist/cdn/video-js.css');
239263
css = css.replace(/font\//g, '../f/1/');
240264
grunt.file.write('dist/cdn/video-js.css', css);
241265

266+
// Zip up into video-js-VERSION.zip
242267
exec('cd dist && zip -r video-js-'+version.full+'.zip video-js && cd ..', { maxBuffer: 500*1024 }, function(err, stdout, stderr){
243268

244269
if (err) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"mocha": "~1.8.1",
3131
"contribflow": "~0.2.0",
3232
"grunt-s3": "~0.2.0-alpha",
33-
"semver": "~1.1.4"
33+
"semver": "~1.1.4",
34+
"grunt-contrib-cssmin": "~0.6.0"
3435
},
3536
"testling": {
3637
"browsers": [

src/css/video-js.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*
2-
VideoJS Default Styles (http://videojs.com)
1+
/*!
2+
Video.js Default Styles (http://videojs.com)
33
Version GENERATED_AT_BUILD
44
*/
55

src/js/core.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ vjs.options = {
7171
// techOrder: ['flash','html5'],
7272

7373
'html5': {},
74-
'flash': { 'swf': vjs.ACCESS_PROTOCOL + 'vjs.zencdn.net/4.0/video-js.swf' },
74+
'flash': {},
7575

7676
// Default of web browser is 300x150. Should rely on source width/height.
7777
'width': 300,
@@ -90,14 +90,14 @@ vjs.options = {
9090
}
9191
};
9292

93+
// Set CDN Version of swf
94+
// The added (+) blocks the replace from changing this GENERATED_CDN_VSN string
95+
if (vjs.CDN_VERSION !== 'GENERATED'+'_CDN_VSN') {
96+
videojs.options['flash']['swf'] = vjs.ACCESS_PROTOCOL + 'vjs.zencdn.net/'+vjs.CDN_VERSION+'/video-js.swf';
97+
}
98+
9399
/**
94100
* Global player list
95101
* @type {Object}
96102
*/
97103
vjs.players = {};
98-
99-
100-
// Set CDN Version of swf
101-
if (vjs.CDN_VERSION != 'GENERATED_CDN_VSN') {
102-
videojs.options['flash']['swf'] = vjs.ACCESS_PROTOCOL + 'vjs.zencdn.net/'+vjs.CDN_VERSION+'/video-js.swf';
103-
}

0 commit comments

Comments
 (0)