Browse files

async_config task

  • Loading branch information...
1 parent 2a871fc commit 7f5d1897694daebab4fcb8320926f20897f46462 @johnbender johnbender committed Jun 4, 2012
Showing with 74 additions and 61 deletions.
  1. +13 −0 build/config.js
  2. +60 −61 build/tasks/css.js
  3. +1 −0 build/tasks/custom_init.js
View
13 build/config.js
@@ -87,9 +87,13 @@ 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 );
@@ -100,6 +104,15 @@ module.exports = function( grunt ) {
}
};
+ grunt.registerTask( 'async_config', 'git hashes for output headers', function() {
+ var done = this.async();
+
+ grunt.config.get( 'global' ).helpers.asyncConfig(function(config) {
+ grunt.config.set( 'global', config );
+ done();
+ });
+ });
+
grunt.registerTask( 'test_config', 'glob all the test files', function() {
var done = this.async(), test_paths, server_paths = [], env = process.env;
View
121 build/tasks/css.js
@@ -32,85 +32,84 @@ module.exports = function( grunt ) {
grunt.registerTask( 'css_without_deps', 'compile and minify the css', function() {
var done = this.async(),
theme = grunt.config.get( 'css' ).theme,
- require = grunt.config.get( 'css' ).require;
+ require = grunt.config.get( 'css' ).require,
+ global_config = grunt.config.get( 'global' );
- helpers.asyncConfig(function( config ) {
- // pull the includes together using require js
- requirejs.optimize( require.all );
+ // pull the includes together using require js
+ requirejs.optimize( require.all );
- // dump the versioned header into the normal css file
- grunt.file.write( regularFile + '.css', config.ver.header );
+ // dump the versioned header into the normal css file
+ grunt.file.write( regularFile + '.css', global_config.ver.header );
- // add the compiled css to the normal css file
- helpers.appendFrom( regularFile + '.css', require.all.out );
+ // add the compiled css to the normal css file
+ helpers.appendFrom( regularFile + '.css', require.all.out );
- helpers.minify({
- output: regularFile + '.min.css',
- input: regularFile + '.css',
- header: config.ver.min,
- minCallback: function( unminified ) {
- return sqwish.minify( unminified, false );
- }
- });
+ helpers.minify({
+ output: regularFile + '.min.css',
+ input: regularFile + '.css',
+ header: global_config.ver.min,
+ minCallback: function( unminified ) {
+ return sqwish.minify( unminified, false );
+ }
+ });
- // pull the includes together using require js
- requirejs.optimize( require.structure );
+ // pull the includes together using require js
+ requirejs.optimize( require.structure );
- // dump the versioned header into the structure css file
- grunt.file.write( structureFile + '.css', config.ver.header );
+ // dump the versioned header into the structure css file
+ grunt.file.write( structureFile + '.css', global_config.ver.header );
- // add the compiled structure css to the normal css file
- helpers.appendFrom( structureFile + '.css', require.structure.out );
+ // add the compiled structure css to the normal css file
+ helpers.appendFrom( structureFile + '.css', require.structure.out );
- // add the min header into the minified file
- grunt.file.write( structureFile + '.min.css', config.ver.min );
+ // add the min header into the minified file
+ grunt.file.write( structureFile + '.min.css', global_config.ver.min );
- // minify the structure css
- helpers.minify({
- output: structureFile + '.min.css',
- input: structureFile + '.css',
- header: config.ver.min,
- minCallback: function( unminified ) {
- return sqwish.minify( unminified, false );
- }
- });
+ // minify the structure css
+ helpers.minify({
+ output: structureFile + '.min.css',
+ input: structureFile + '.css',
+ header: global_config.ver.min,
+ minCallback: function( unminified ) {
+ return sqwish.minify( unminified, false );
+ }
+ });
- // dump the versioned header into the theme css file
- grunt.file.write( themeFile + '.css', config.ver.header );
+ // dump the versioned header into the theme css file
+ grunt.file.write( themeFile + '.css', global_config.ver.header );
- // dump the theme css into the theme css file
- helpers.appendFrom( themeFile + '.css', 'css/themes/default/jquery.mobile.theme.css' );
+ // dump the theme css into the theme css file
+ helpers.appendFrom( themeFile + '.css', 'css/themes/default/jquery.mobile.theme.css' );
- // minify the theme css
- helpers.minify({
- output: themeFile + '.min.css',
- input: themeFile + '.css',
- header: config.ver.min,
- minCallback: function( unminified ) {
- return sqwish.minify( unminified, false );
- }
- });
+ // minify the theme css
+ helpers.minify({
+ output: themeFile + '.min.css',
+ input: themeFile + '.css',
+ header: global_config.ver.min,
+ minCallback: function( unminified ) {
+ return sqwish.minify( unminified, false );
+ }
+ });
- // remove the requirejs compile output
- fs.unlink( require.all.out );
- fs.unlink( require.structure.out );
+ // remove the requirejs compile output
+ fs.unlink( require.all.out );
+ fs.unlink( require.structure.out );
- // copy images directory
- var imagesPath = path.join( config.dirs.output, 'images' ), fileCount = 0;
+ // copy images directory
+ var imagesPath = path.join( global_config.dirs.output, 'images' ), fileCount = 0;
- grunt.file.mkdir( imagesPath );
- grunt.file.recurse( path.join('css', 'themes', theme, 'images'), function( full, root, sub, filename ) {
+ grunt.file.mkdir( imagesPath );
+ grunt.file.recurse( path.join('css', 'themes', theme, 'images'), function( full, root, sub, filename ) {
- fileCount++;
- var is = fs.createReadStream( full );
- var os = fs.createWriteStream( path.join(imagesPath, filename) );
- util.pump(is, os, function() {
- fileCount--;
- if( fileCount == 0 ) { done(); }
- });
+ fileCount++;
+ var is = fs.createReadStream( full );
+ var os = fs.createWriteStream( path.join(imagesPath, filename) );
+ util.pump(is, os, function() {
+ fileCount--;
+ if( fileCount == 0 ) { done(); }
});
});
});
- grunt.registerTask( 'css', 'custom_init css_without_deps' );
+ grunt.registerTask( 'css', 'async_config custom_init css_without_deps' );
};
View
1 build/tasks/custom_init.js
@@ -2,6 +2,7 @@ var fs = require( 'fs' ), path = require( 'path' );
module.exports = function( grunt ) {
var config = grunt.config.get( 'global' );
+
// TODO having issues overriding default init task
grunt.registerTask( 'custom_init', 'ensure the output directory is present', function() {
if( !path.existsSync(config.dirs.output) ) {

0 comments on commit 7f5d189

Please sign in to comment.