index.js
function compileJBB( config, parseCallback, resultCallback ) {

	// Continue compiling the JBB bundle
	var compile = function( bundleJSON, bundlePath, tempName ) {

		// Update path in config
		if (!config['path'])
			config['path'] = path.dirname(bundlePath);

		// Create the JBB bundle
		JBBCompiler.compile(
				bundleJSON,
				tempName,
				config,
				function() {

					// Check for sparse bundles
					if (config['sparse']) {
						resultCallback( null, {
							'basename': tempName,
							'suffix': [
								'.jbbp', '_b16.jbbp', 
							  	'_b32.jbbp', '_b64.jbbp' 
							]
						}); 
					} else {
						// Trigger callback
						resultCallback( null, {
							'basename': tempName,
							'suffix': [ '.jbb' ]
						});
					}

				}
			);

	};

	// Open a new temporary file (to be tracked by temp)
	temp.open({suffix: '_tmp'}, function(err, info) {

		// Handle errors
		if (err) {
			resultCallback(err, null);
			return;
		}
	    fs.close(info.fd, function(err) {
	      if (err) {
			resultCallback(err, null);
			return;
	      }

	      // We are ready, continue with compiling
	      parseCallback(function( bundleJSON, baseName ) {
		      compile( bundleJSON, baseName, info.path );
	      });
	    });

	});

}
function compileJBB( config, parseCallback, resultCallback ) {

	// Continue compiling the JBB bundle
	var compile = function( bundleJSON, bundlePath, tempName ) {

		// Update path in config
		if (!config['path'])
			config['path'] = path.dirname(bundlePath);

		// Create the JBB bundle
		JBBCompiler.compile(
				bundleJSON,
				tempName,
				config,
				function() {

					// Check for sparse bundles
					if (config['sparse']) {
						resultCallback( null, {
							'basename': tempName,
							'suffix': [
								'.jbbp', '_b16.jbbp', 
							  	'_b32.jbbp', '_b64.jbbp' 
							]
						}); 
					} else {
						// Trigger callback
						resultCallback( null, {
							'basename': tempName,
							'suffix': [ '.jbb' ]
						});
					}

				}
			);

	};

	// Open a new temporary file (to be tracked by temp)
	temp.open({suffix: '_tmp'}, function(err, info) {

		// Handle errors
		if (err) {
			resultCallback(err, null);
			return;
		}
	    fs.close(info.fd, function(err) {
	      if (err) {
			resultCallback(err, null);
			return;
	      }

	      // We are ready, continue with compiling
	      parseCallback(function( bundleJSON, baseName ) {
		      compile( bundleJSON, baseName, info.path );
	      });
	    });

	});

}
function compileJBB ( config , parseCallback , resultCallback ) { // Continue compiling the JBB bundle var compile = function ( bundleJSON , bundlePath , tempName ) { // Update path in config if ( ! config [ 'path' ] ) config [ 'path' ] = path . dirname ( bundlePath ) ; // Create the JBB bundle JBBCompiler . compile ( bundleJSON , tempName , config , function ( ) { // Check for sparse bundles if ( config [ 'sparse' ] ) { resultCallback ( null , { 'basename' : tempName , 'suffix' : [ '.jbbp' , '_b16.jbbp' , '_b32.jbbp' , '_b64.jbbp' ] } ) ; } else { // Trigger callback resultCallback ( null , { 'basename' : tempName , 'suffix' : [ '.jbb' ] } ) ; } } ) ; } ; // Open a new temporary file (to be tracked by temp) temp . open ( { suffix : '_tmp' } , function ( err , info ) { // Handle errors if ( err ) { resultCallback ( err , null ) ; return ; } fs . close ( info . fd , function ( err ) { if ( err ) { resultCallback ( err , null ) ; return ; } // We are ready, continue with compiling parseCallback ( function ( bundleJSON , baseName ) { compile ( bundleJSON , baseName , info . path ) ; } ) ; } ) ; } ) ; }
Helper function to compile the JBB bundle according to
the configuration options and return the temporary filename
were the bundle was created.
Helper function to compile the JBB bundle according to the configuration options and return the temporary filename were the bundle was created .