Skip to content
Browse files

Merge pull request #86 from caridy/cssassets

version 0.4.1: adding support for assets on css modules
  • Loading branch information...
2 parents dd6424a + 9cb1c2d commit b8643a376d60422e16474614e4fbe377e26d2257 @caridy caridy committed Jun 10, 2013
View
2 conf/docs/project.json
@@ -1,5 +1,5 @@
{
"projectName": "shifter - blazingly fast yui builder",
- "version": "0.4.0",
+ "version": "0.4.1",
"yuiSeedUrl": "http://yui.yahooapis.com/3.6.0/build/yui/yui.js"
}
View
14 lib/module.js
@@ -712,7 +712,19 @@ var build = function (mod, name, options, callback) {
}));
}
if (mod.cssfiles && mod.cssfiles.length) {
- exports.css(mod, name, stack.add(noop));
+ // if assets are allow for css modules, cssproc should be honored as well
+ if (options.cssproc) {
+ mod.cssproc = options.cssproc;
+ }
+ exports.css(mod, name, stack.add(function (err) {
+ if (err) {
+ log.warn('skipping assets copy due to previous build error');
+ } else {
+ if (options.assets && mod.assets) {
+ copyAssets(mod, name, stack.add(noop));
+ }
+ }
+ }));
}
if (mod.copy && mod.copy.length) {
View
6 output/index.html
@@ -23,7 +23,7 @@
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
- <div class="content"><h2 id="welcome-to-shifter-040">welcome to shifter 0.4.0!</h2>
+ <div class="content"><h2 id="welcome-to-shifter-041">welcome to shifter 0.4.1!</h2>
<div class="intro">
<center>
@@ -51,7 +51,7 @@ <h2 id="help">command line arguments</h2>
<pre class="code terminal"><span class="noselect">$ </span>shifter -h
-blazingly fast builds with shifter@0.4.0
+blazingly fast builds with shifter@0.4.1
pass no arguments and shifter will build the module from the current directory
@@ -530,7 +530,7 @@ <h2 class="no-toc">Table of Contents</h2>
<div class="bd">
<ul class="toc">
<li>
-<a href="#welcome-to-shifter-040">welcome to shifter 0.4.0!</a>
+<a href="#welcome-to-shifter-041">welcome to shifter 0.4.1!</a>
</li>
<li>
<a href="#what">what is shifter?</a>
View
4 package.json
@@ -2,7 +2,7 @@
"name": "shifter",
"description": "New YUI build tool based on Gearjs, so let's shift some gears",
"author": "Dav Glass <davglass@gmail.com>",
- "version": "0.4.0",
+ "version": "0.4.1",
"dependencies": {
"progress": "~0.1.0",
"ansi-color": "*",
@@ -26,7 +26,7 @@
},
"devDependencies": {
"selleck": "*",
- "vows": "*"
+ "vows": "*"
},
"keywords": [
"builder", "gearjs", "yui", "yuilibrary", "cli"
View
172 tests/12-builder-css-with-assets.js
@@ -0,0 +1,172 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ path = require('path'),
+ fs = require('fs'),
+ Stack = require('../lib/stack').Stack,
+ spawn = require('child_process').spawn,
+ shifter = require('../lib'),
+ base = path.join(__dirname, 'assets/yql/'),
+ crypto = require('crypto'),
+ buildBase = path.join(base, 'build'),
+ buildXBase = path.join(base, 'build-csswithassets'),
+ srcBase = path.join(base, 'src/csswithassets'),
+ rimraf = require('rimraf');
+
+
+var tests = {
+ 'clean build': {
+ topic: function() {
+ rimraf(path.join(buildBase, 'csswithassets'), this.callback);
+ },
+ 'should not have build dir and': {
+ topic: function() {
+ var self = this;
+ fs.stat(path.join(buildBase, 'csswithassets'), function(err) {
+ self.callback(null, err);
+ });
+ },
+ 'should not have build/csswithassets': function(foo, err) {
+ assert.isNotNull(err);
+ assert.equal(err.code, 'ENOENT');
+ },
+ 'should build csswithassets and': {
+ topic: function() {
+ shifter.init({
+ silent: true,
+ cwd: srcBase,
+ 'global-config': false,
+ cache: false,
+ cssproc: 'http://domain.name/path/'
+ }, this.callback);
+ },
+ 'should create build dir and': {
+ topic: function() {
+ fs.stat(path.join(buildBase, 'csswithassets'), this.callback);
+ },
+ 'should create build/csswithassets': function(err, stat) {
+ assert.isNull(err);
+ assert.isTrue(stat.isDirectory());
+ }
+ },
+ 'should honor cssproc and': {
+ topic: function() {
+ var file = path.join(buildBase, 'csswithassets', 'csswithassets.css');
+ return fs.readFileSync(file, 'utf8');
+ },
+ 'should have added the proper token': function(topic) {
+ assert.isTrue(/http\:\/\/domain\.name\/path\//.test(topic));
+ }
+ },
+ 'should produce same files and': {
+ topic: function() {
+ var stack = new Stack();
+ var results = {
+ pre: {},
+ post: {}
+ },
+ self = this;
+
+ fs.readdir(path.join(buildBase, 'csswithassets'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ if (path.extname(file) === '.css') {
+ fs.readFile(path.join(buildBase, 'csswithassets', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ console.error(file, data);
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.post[file] = d;
+ }));
+ }
+ }(file));
+ });
+ }));
+
+ fs.readdir(path.join(buildXBase, 'csswithassets'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ if (path.extname(file) === '.css') {
+ fs.readFile(path.join(buildXBase, 'csswithassets', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.pre[file] = d;
+ }));
+ }
+ }(file));
+ });
+ }));
+
+ stack.done(function() {
+ self.callback(null, results);
+ });
+
+ },
+ 'min should be same with cssmin': function(err, results) {
+ assert.ok(results.pre['csswithassets-min.css']);
+ assert.ok(results.post['csswithassets-min.css']);
+ assert.equal(results.pre['csswithassets-min.css'], results.post['csswithassets-min.css']);
+ },
+ 'raw should be same without cssmin': function(err, results) {
+ assert.ok(results.pre['csswithassets.css']);
+ assert.ok(results.post['csswithassets.css']);
+ assert.equal(results.pre['csswithassets.css'], results.post['csswithassets.css']);
+ }
+ },
+ 'should have copied the assets folder and': {
+ topic: function() {
+ var stack = new Stack();
+ var results = {
+ pre: {},
+ post: {}
+ },
+ self = this;
+
+ fs.readdir(path.join(buildBase, 'csswithassets/assets'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ if (path.extname(file) === '.png') {
+ fs.readFile(path.join(buildBase, 'csswithassets/assets', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ console.error(file, data);
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.post[file] = d;
+ }));
+ }
+ }(file));
+ });
+ }));
+
+ fs.readdir(path.join(buildXBase, 'csswithassets/assets'), stack.add(function(err, files) {
+ files.forEach(function(file) {
+ (function(file) {
+ if (path.extname(file) === '.png') {
+ fs.readFile(path.join(buildXBase, 'csswithassets/assets', file), stack.add(function(err, data) {
+ var shasum = crypto.createHash('sha1');
+ shasum.update(data);
+ var d = shasum.digest('hex');
+ results.pre[file] = d;
+ }));
+ }
+ }(file));
+ });
+ }));
+
+ stack.done(function() {
+ self.callback(null, results);
+ });
+
+ },
+ 'png image should be copied': function(err, results) {
+ assert.ok(results.pre['img.png']);
+ assert.ok(results.post['img.png']);
+ assert.equal(results.pre['img.png'], results.post['img.png']);
+ }
+ }
+ }
+ }
+ }
+};
+
+vows.describe('building csswithassets with UglifyJS').addBatch(tests).export(module);
View
1 tests/assets/yql/build-csswithassets/csswithassets/assets/img.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1 tests/assets/yql/build-csswithassets/csswithassets/csswithassets-min.css
@@ -0,0 +1 @@
+.foo{background-image:url("http://domain.name/path/csswithassets/assets/img.png")}#yui3-css-stamp.csswithassets{display:none}
View
6 tests/assets/yql/build-csswithassets/csswithassets/csswithassets.css
@@ -0,0 +1,6 @@
+.foo {
+ background-image: url("http://domain.name/path/csswithassets/assets/img.png");
+}
+
+/* YUI CSS Detection Stamp */
+#yui3-css-stamp.csswithassets { display: none; }
View
1 tests/assets/yql/src/csswithassets/assets/img.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
11 tests/assets/yql/src/csswithassets/build.json
@@ -0,0 +1,11 @@
+{
+ "name": "csswithassets",
+ "builds": {
+ "csswithassets": {
+ "cssfiles": [
+ "csswithassets.css"
+ ],
+ "assets": true
+ }
+ }
+}
View
3 tests/assets/yql/src/csswithassets/css/csswithassets.css
@@ -0,0 +1,3 @@
+.foo {
+ background-image: url("assets/img.png");
+}

0 comments on commit b8643a3

Please sign in to comment.
Something went wrong with that request. Please try again.