Browse files

move js to min/concat

  • Loading branch information...
1 parent 51b4176 commit 667c17ed94f83ac02f3e07a247405d42e8e377ea @johnbender johnbender committed Jun 4, 2012
Showing with 41 additions and 27 deletions.
  1. +19 −4 build/config.js
  2. +1 −1 build/tasks/css.js
  3. +21 −21 build/tasks/js.js
  4. +0 −1 package.json
View
23 build/config.js
@@ -47,6 +47,25 @@ module.exports = function( grunt ) {
fs.closeSync( id );
},
+ // in place
+ sed: function( file, filter ) {
+ var id, inputString = fs.readFileSync(file).toString();
+
+ inputString = filter ? filter(inputString) : inputString;
+
+ grunt.file.write( file, inputString );
+ },
+
+ configExtend: function( prop, extension ) {
+ var config = grunt.config.get( prop ) || {};
+
+ for( p in extension ){
+ config[p] = extension[p];
+ }
+
+ grunt.config.set( prop, config );
+ },
+
minify: function( opts ) {
var max = grunt.file.read( opts.input ),
min = opts.minCallback(max);
@@ -87,13 +106,9 @@ module.exports = function( grunt ) {
global.shas.build_sha = stdout;
global.ver.min = grunt.template.process( global.ver.min, global.shas );
- console.log( "first finished" );
-
child_process.exec( 'git log -1 --format=format:"%H"', function( err, stdout, stderr ) {
global.shas.head_sha = stdout;
- console.log( "second finished" );
-
// NOTE not using a template here because the Makefile depends on the v@VERSION
global.ver.header = grunt.file.read( global.files.license )
.replace(/v@VERSION/, global.shas.build_sha );
View
2 build/tasks/css.js
@@ -29,7 +29,7 @@ module.exports = function( grunt ) {
}
});
- grunt.config.set( 'concat', {
+ helpers.configExtend( 'concat', {
structure: {
src: [ '<banner:global.ver.header>', structureFile + '.compiled.css' ],
dest: structureFile + '.css'
View
42 build/tasks/js.js
@@ -3,15 +3,15 @@ var requirejs = require( 'requirejs' ),
fs = require( 'fs' );
module.exports = function( grunt ) {
- var config = grunt.config.get( 'global' ),
+ var min = {}, config = grunt.config.get( 'global' ),
outputFile = path.join( config.dirs.output, config.names.root ),
helpers = config.helpers;
grunt.config.set( 'js', {
require: {
baseUrl: 'js',
name: 'jquery.mobile',
- exclude:[
+ exclude: [
'jquery',
'../external/requirejs/order',
'../external/requirejs/depend',
@@ -27,37 +27,37 @@ module.exports = function( grunt ) {
}
});
- grunt.registerTask( 'js_without_deps', 'compile and minify the js', function() {
- var done = this.async(),
- require = grunt.config.get( 'js' ).require,
+ helpers.configExtend( 'concat', {
+ js: {
+ src: [ '<banner:global.ver.header>', outputFile + '.compiled.js' ],
+ dest: outputFile + '.js'
+ }
+ });
+
+ // setup minification
+ min[ outputFile + '.min.js' ] = [ "<banner:global.ver.min>", outputFile + '.js' ];
+ grunt.config.set( 'min', min );
+
+ grunt.registerTask( 'js:compile', function() {
+ var require = grunt.config.get( 'js' ).require,
global_config = grunt.config.get( 'global' );
// pull the includes together using require js
requirejs.optimize( require );
- // dump the versioned header into the normal js file
- grunt.file.write( outputFile + '.js', global_config.ver.header );
-
- // add the compiled js to the normal js file, replace the version tag
- // with the contents from version.txt
- helpers.appendFrom( outputFile + '.js', require.out, function( fileContents ) {
+ // replace the version with the value in version.text
+ helpers.sed( require.out, function( fileContents ) {
return fileContents.replace( /__version__/, '"' + global_config.ver.official + '"' );
});
+ });
- helpers.minify({
- output: outputFile + '.min.js',
- input: outputFile + '.js',
- header: global_config.ver.min,
- minCallback: function( unminified ) {
- return grunt.helper( 'uglify', unminified, {});
- }
- });
+ grunt.registerTask( 'js:cleanup', 'compile and minify the js', function() {
+ var require = grunt.config.get( 'js' ).require;
// remove the requirejs compile output
fs.unlink( require.out );
- done();
});
// NOTE custom dasks don't accept dependencies so we alias
- grunt.registerTask( 'js', 'custom_init config:async js_without_deps' );
+ grunt.registerTask( 'js', 'custom_init config:async js:compile concat:js min js:cleanup' );
};
View
1 package.json
@@ -14,7 +14,6 @@
"grunt": "0.3.x",
"grunt-css": "0.2.0",
"requirejs": "1.0.8",
- "sqwish": "0.2.0",
"glob-whatev": "~0.1.4"
},
"engine": {

0 comments on commit 667c17e

Please sign in to comment.