builder-amd-css
Advanced tools
Comparing version 0.0.2 to 0.0.3
33
index.js
@@ -1,2 +0,2 @@ | ||
var mutex, requireCssFiles, | ||
var mutex, queue, requireCssFiles, | ||
fs = require( "fs" ), | ||
@@ -8,3 +8,5 @@ glob = require( "glob" ), | ||
queue = []; | ||
requireCssFiles = {}; | ||
glob.sync( __dirname + "/bower_components/require-css/**", { nodir: true } ).forEach(function( filepath ) { | ||
@@ -14,2 +16,23 @@ requireCssFiles[ filepath.replace( __dirname, "" ).replace( /^\//, "" ) ] = fs.readFileSync( filepath ); | ||
function enqueueBuildCss() { | ||
queue.push( arguments ); | ||
if ( queue.length === 1 ) { | ||
dequeueBuildCss(); | ||
} | ||
} | ||
function dequeueBuildCss() { | ||
var callback; | ||
var args = queue[ 0 ]; | ||
if ( args !== undefined ) { | ||
callback = args[ 2 ]; | ||
args[ 2 ] = function() { | ||
queue.shift(); | ||
callback.apply( {}, arguments ); | ||
dequeueBuildCss(); | ||
}; | ||
buildCss.apply( {}, args ); | ||
} | ||
} | ||
function buildCss( files, config, callback ) { | ||
@@ -19,9 +42,9 @@ var localCallback, include; | ||
if ( mutex ) { | ||
throw new Error( "Concurrent calls not supported" ); | ||
return callback( new Error( "Concurrent calls not supported" ) ); | ||
} | ||
if ( typeof config !== "object" ) { | ||
throw new Error( "missing or invalid config (object expected)" ); | ||
return callback( new Error( "missing or invalid config (object expected)" ) ); | ||
} | ||
if ( !Array.isArray( config.include ) ) { | ||
throw new Error( "missing or invalid config.include (array expected)" ); | ||
return callback( new Error( "missing or invalid config.include (array expected)" ) ); | ||
} | ||
@@ -96,3 +119,3 @@ mutex = true; | ||
buildCss( clonedFiles, config, callback ); | ||
enqueueBuildCss( clonedFiles, config, callback ); | ||
}; |
{ | ||
"name": "builder-amd-css", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
@@ -32,2 +32,3 @@ "repository": { | ||
"devDependencies": { | ||
"async": "0.9.0", | ||
"chai": "1.10.x", | ||
@@ -34,0 +35,0 @@ "jshint": "2.6.x", |
var files, | ||
async = require( "async" ), | ||
expect = require( "chai" ).expect, | ||
@@ -90,1 +91,30 @@ fs = require( "fs" ), | ||
}); | ||
describe( "Concurrent runs", function() { | ||
var barCss, fooCss; | ||
before(function( done ) { | ||
async.parallel([ | ||
function( callback ) { | ||
AmdCssBuilder( files, { include: [ "bar" ] }, callback ); | ||
}, | ||
function( callback ) { | ||
AmdCssBuilder( files, { include: [ "foo" ] }, callback ); | ||
} | ||
], function( error, result ) { | ||
if ( error ) { | ||
return done( error ); | ||
} | ||
barCss = result[ 0 ][ 0 ]; | ||
fooCss = result[ 1 ][ 0 ]; | ||
done(); | ||
}); | ||
}); | ||
it( "must be enqueued", function() { | ||
expect( barCss ).to.equal( ".bar {}\n" ); | ||
expect( fooCss ).to.equal( ".foo {}\n.bar {}\n" ); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39677
705
4