Permalink
Browse files

Write the destination css file prior to inline imports / minify

This closes #39

Wrong assumption on destination file being the same than one of the source
file, was broken whenever the destination file does not exists yet.

Bumped version number to 0.2.2
  • Loading branch information...
mklabs committed May 24, 2012
1 parent 17b3bb3 commit a3a94ed1a0dbcd7a0cd32d4c5462da984eba71c9
Showing with 38 additions and 15 deletions.
  1. +1 −1 package.json
  2. +7 −5 tasks/css.js
  3. +19 −0 test/fixtures/css/grunt.js
  4. +1 −1 test/tasks/minify.js
  5. +10 −5 test/tasks/test-css.js
  6. +0 −3 test/tasks/test-usemin.js
View
@@ -2,7 +2,7 @@
"author": "Paul Irish, Divya Manian",
"name": "node-build-script",
"description": "HTML5 Boilerplate node build script - Professional front-end template. So much goodness baked in by default",
- "version": "0.2.1",
+ "version": "0.2.2",
"homepage": "http://h5bp.com",
"bin": {
"html5-boilerplate": "./bin/h5bp",
View
@@ -6,16 +6,12 @@ var fs = require('fs'),
module.exports = function(grunt) {
-
-
// **css* task works pretty much the same as grunt's min task. The task
// target is the destination, data is an array of glob patterns. These
// files are concataned and run through requirejs optimizer to handle
// @import inlines in CSS files.
grunt.task.registerMultiTask('css', 'Concats, replaces @imports and minifies the CSS files', function() {
- this.requiresConfig('staging');
-
- // if defined, files get prepended by the output config value
+ // css files for this subtarget destination
var files = this.data;
// subtarget name is the output destination
@@ -24,6 +20,12 @@ module.exports = function(grunt) {
// async task
var cb = this.async();
+ // write the destination css, a simple concat of the original files
+ // without compression
+ grunt.file.write(target, grunt.helper('mincss', files, {
+ nocompress: true
+ }));
+
// replace @import statements
//
// XXX no error handling in this helper so far..
View
@@ -0,0 +1,19 @@
+
+var path = require('path');
+
+module.exports = function(grunt) {
+
+ //
+ // Grunt configuration
+ //
+ grunt.config.init({
+
+ css: {
+ 'css/compressed.css': ['css/style.css']
+ }
+
+ });
+
+ grunt.loadNpmTasks(path.join(__dirname, '..'));
+
+};
View
@@ -17,7 +17,7 @@ describe("build:minify task", function() {
describe("When the build script ends", function() {
it("Then the outcome should be 'test/fixtures/default/build.minify.html'", function() {
- helpers.copyFile('.test/publish/index.html', 'test/fixtures/default/build.minify.html');
+ helpers.assertFile('.test/publish/index.html', 'test/fixtures/default/build.minify.html');
});
});
});
View
@@ -15,16 +15,21 @@ describe("CSS task", function() {
// copy in some files, with @imports to test out the inline imports
var files = fs.readdirSync(path.join(__dirname, '../fixtures/css'))
.filter(function(f) {
- return !(/expected/).test(f) && path.extname(f);
+ return !(/expected/).test(f) && path.extname(f) === '.css';
})
.map(function(f) {
return path.join('css', f);
});
- helpers.copy(files, '.test/css', done);
+ // gruntfile with our css config for test
+ helpers.copyFile('test/fixtures/css/grunt.js', '.test/grunt.js', function(err) {
+ if(err) return done(err);
+ helpers.copy(files, '.test/css', done);
+ });
+
});
- describe("As a build script user I want to be able to run the css task So that I can see the css task in action", function() {
+ describe("As a build script user I want to be able to run the css task So that I can see the css task in action", function() {
describe("css task", function() {
@@ -39,8 +44,8 @@ describe("CSS task", function() {
done();
});
- it("Then './test/css/style.css' should be the same as 'test/fixtures/css/expected.css'", function(done) {
- helpers.assertFile('.test/css/style.css', 'test/fixtures/css/expected.css');
+ it("Then './test/css/compressed.css' should be the same as 'test/fixtures/css/expected.css'", function(done) {
+ helpers.assertFile('.test/css/compressed.css', 'test/fixtures/css/expected.css');
done();
});
@@ -72,9 +72,6 @@ describe("USEMIN task", function() {
});
it("Then '.test/usemin.html' should be the same as 'test/fixtures/usemin/index.html'", function(done) {
- // todo: task log output doesn"t return things that were changed between
- // <!-- build:<target> path/to/foo.js --> directives
- helpers.copyFile(".test/usemin.html", "test/fixtures/usemin/reved.html");
helpers.assertFile(".test/usemin.html", "test/fixtures/usemin/reved.html");
done();
});

0 comments on commit a3a94ed

Please sign in to comment.