Saves new asset bundles configuration.
@param \yii\web\AssetBundle[] $targets list of asset bundles to be saved.
@param string $bundleFile output file name.
@throws Exception on failure.
17406
protected function saveTargets($targets, $bundleFile)
    {
        $array = [];
        foreach ($targets as $name => $target) {
            if (isset($this->targets[$name])) {
                $array[$name] = array_merge($this->targets[$name], [
                    '__class' => get_class($target),
                    'sourcePath' => null,
                    'basePath' => $this->targets[$name]['basePath'],
                    'baseUrl' => $this->targets[$name]['baseUrl'],
                    'js' => $target->js,
                    'css' => $target->css,
                    'depends' => [],
                ]);
            } else {
                if ($this->isBundleExternal($target)) {
                    $array[$name] = $this->composeBundleConfig($target);
                } else {
                    $array[$name] = [
                        'sourcePath' => null,
                        'js' => [],
                        'css' => [],
                        'depends' => $target->depends,
                    ];
                }
            }
        }
        $array = VarDumper::export($array);
        $version = date('Y-m-d H:i:s');
        $bundleFileContent = <<<EOD
<?php
/**
 * This file is generated by the "yii {$this->id}" command.
 * DO NOT MODIFY THIS FILE DIRECTLY.
 * @version {$version}
 */
return {$array};
EOD;
        if (!file_put_contents($bundleFile, $bundleFileContent, LOCK_EX)) {
            throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'.");
        }
        $this->stdout("Output bundle configuration created at '{$bundleFile}'.\n", Console::FG_GREEN);
    }
509228
public function removeBundle($bundle)
    {
        $bundles = $this->getBundles();
        if (($key = array_search($this->getBundleString($bundle), $bundles)) !== false) {
            unset($bundles[$key]);
            $this->setBundles($bundles);
        }
    }
1089723
public function generateBundleMigration(Bundle $bundle, $output = null)
    {
        $platforms = $this->getAvailablePlatforms();
        $version = date('YmdHis');
        $this->log("Generating migrations classes for '{$bundle->getName()}'...");
        if (!$output) {
            $output = $bundle;
        }

        foreach ($platforms as $driverName => $platform) {
            $queries = $this->generator->generateMigrationQueries($bundle, $platform);

            if (count($queries[Generator::QUERIES_UP]) > 0 || count($queries[Generator::QUERIES_DOWN]) > 0) {
                $this->log(" - Generating migration class for {$driverName} driver...");
                $this->writer->writeMigrationClass($output, $driverName, $version, $queries);
            } else {
                $this->log('Nothing to generate: database and mapping are synced');
                break;
            }
        }
    }
1321271
public function generateFixtures(
        BundleInterface $bundle,
        array $parameters,
        OutputInterface $output
    ) {
        $dirPath = $bundle->getPath() . '/DataFixtures/ORM/SearchPageGenerator/';
        $skeletonDir = $this->skeletonDir . '/DataFixtures/ORM/SearchPageGenerator/';

        try {
            $this->generateSkeletonBasedClass(
                $skeletonDir,
                $dirPath,
                'SearchFixtures',
                $parameters
            );
        } catch (\Exception $error) {
            throw new \RuntimeException($error->getMessage());
        }

        $output->writeln('Generating fixtures : <info>OK</info>');
    }
918265
public function getForAsset(AssetInterface $asset)
    {
        $sourceRoot = $asset->getSourceRoot();
        if (!isset($this->bundleMap[$sourceRoot])) {
            throw new \Exception('Could not map the asset to a bundle');
        }

        // get the relative path
        $templateName = $asset->getSourcePath();
        // by convention, all symfony views are in Resources/views/, therefore remove this segment
        $templateName = str_replace('Resources/views/', '', $templateName);
        // remove the .ng extension (our convention)
        $templateName = str_replace('.ng', '', $templateName);
        // prepend bundle name
        $bundleName = $this->bundleMap[$sourceRoot];
        $templateName = sprintf('%s/%s', $bundleName, $templateName);

        return $templateName;
    }
21749
public function setBundleInfo(array $bundleInfo) {
    $this->kernel->setDrupalBundles($this->getAutoloadedBundles($bundleInfo));
    $this->bundlesBooted = false;
  }
257741
protected function execute(InputInterface $input, OutputInterface $output)
    {
        /**
         * GENERATE THE BUNDLEBUNDLE
         */
        $bundleBundleDir = sprintf(self::BUNDLE_NAME_MASK, 'Bundle');

        // GravitonDynBundleBundle
        $bundleName = str_replace('/', '', $bundleBundleDir);

        // bundlebundle stuff..
        $this->bundleBundleNamespace = $bundleBundleDir;
        $this->bundleBundleDir = $input->getOption('srcDir') . $bundleBundleDir;
        $this->bundleBundleClassname = $bundleName;
        $this->bundleBundleClassfile = $this->bundleBundleDir . '/' . $this->bundleBundleClassname . '.php';

        $filesToWorkOn = $this->definitionLoader->load($input->getOption('json'));

        if (count($filesToWorkOn) < 1) {
            throw new \LogicException("Could not find any usable JSON files.");
        }

        $templateHash = $this->getTemplateHash();
        $existingBundles = $this->getExistingBundleHashes($input->getOption('srcDir'));

        /**
         * GENERATE THE BUNDLE(S)
         */
        foreach ($filesToWorkOn as $jsonDef) {
            $thisIdName = $jsonDef->getId();
            $namespace = sprintf(self::BUNDLE_NAME_MASK, $thisIdName);

            // make sure bundle is in bundlebundle
            $this->bundleBundleList[] = $namespace;

            $jsonDef->setNamespace($namespace);

            $bundleName = str_replace('/', '', $namespace);
            $bundleDir = $input->getOption('srcDir').$namespace;
            $bundleNamespace = str_replace('/', '\\', $namespace).'\\';

            try {
                $thisHash = sha1($templateHash.PATH_SEPARATOR.serialize($jsonDef));

                $needsGeneration = true;
                if (isset($existingBundles[$bundleDir])) {
                    if ($existingBundles[$bundleDir] == $thisHash) {
                        $needsGeneration = false;
                    }
                    unset($existingBundles[$bundleDir]);
                }

                if ($needsGeneration) {
                    $this->generateBundle($bundleNamespace, $bundleName, $input->getOption('srcDir'));
                    $this->generateGenerationHashFile($bundleDir, $thisHash);
                }

                if ($needsGeneration) {
                    $this->generateResources(
                        $jsonDef,
                        $bundleName,
                        $bundleDir,
                        $bundleNamespace
                    );

                    $output->write(
                        PHP_EOL.
                        sprintf('<info>Generated "%s" from definition %s</info>', $bundleName, $jsonDef->getId()).
                        PHP_EOL
                    );
                } else {
                    $output->write(
                        PHP_EOL.
                        sprintf('<info>Using pre-existing "%s"</info>', $bundleName).
                        PHP_EOL
                    );
                }
            } catch (\Exception $e) {
                $output->writeln(
                    sprintf('<error>%s</error>', $e->getMessage())
                );

                // remove failed bundle from list
                array_pop($this->bundleBundleList);
            }
        }

        // whatever is left in $existingBundles is not defined anymore and needs to be deleted..
        foreach ($existingBundles as $dirName => $hash) {
            $fileInfo = new \SplFileInfo($dirName);
            $bundleClassName = $this->getBundleClassnameFromFolder($fileInfo->getFilename());

            // remove from bundlebundle list
            unset($this->bundleBundleList[array_search($bundleClassName, $this->bundleBundleList)]);

            $this->fs->remove($dirName);

            $output->write(
                PHP_EOL.
                sprintf('<info>Deleted obsolete bundle "%s"</info>', $dirName).
                PHP_EOL
            );
        }

        // generate bundlebundle
        $this->generateBundleBundleClass();
    }
428518
public function pack($assetEncoders = array(), $nestedResourcesInclusion = true)
    {

        try {
            //call the factory to get the itemPacker implementation
            $itemPacker = $this->getItemPacker();

            $itemPacker->setAssetEncoders($assetEncoders);
            $itemPacker->setNestedResourcesInclusion($nestedResourcesInclusion);

            //then create the pack
            $itemPack = $itemPacker->packItem($this->item, $this->lang, $this->getStorageDirectory());

        } catch (Exception $e) {
            throw new common_Exception('The item ' . $this->item->getUri() . ' cannot be packed : ' . $e->getMessage());
        }

        return $itemPack;
    }
1062740
function compileFile( sourceBundle, bundleFile, config, callback ) {
	var fname = sourceBundle + "/bundle.json";
	fs.readFile(fname, 'utf8', function (err,data) {
		if (err) {
			console.error("Unable to load file",fname);
			if (callback) callback( err, null );
			return;
		}

		// Update path if missing
		if (!config['path'])
			config['path'] = path.dirname( sourceBundle );

		// Compile
		compile( JSON.parse(data), bundleFile, config, callback );

	});
}
230636
public function addAsset($type, $assetName, $fileName, $dependencies = array())
    {
        if (!isset($this->assets[$type]) || !is_array($this->assets[$type])) {
            $this->assets[$type] = array();
        }
        
        $asset = new Asset(
            $type,
            $assetName,
            $this->buildSourceFilePath($fileName),
            $dependencies
        );
        
        $this->assets[$type][$assetName] = $asset;
        $this->saveAssets();
    }
340046
@Override
	public void writeBundleTo(String bundlePath, Writer writer) throws ResourceNotFoundException {
		
		String text = (String) cacheMgr.get(TEXT_CACHE_PREFIX + bundlePath);
		try {
			// If it's not cached yet
			if (null == text) {
				String charsetName = rsHandler.getConfig().getResourceCharset().name();
				ByteArrayOutputStream baOs = new ByteArrayOutputStream();
				WritableByteChannel wrChannel = Channels.newChannel(baOs);
				Writer tempWriter = Channels.newWriter(wrChannel, charsetName);
				rsHandler.writeBundleTo(bundlePath, tempWriter);
				text = baOs.toString(charsetName);
				cacheMgr.put(TEXT_CACHE_PREFIX + bundlePath, text);
			}

			// Write the text to the outputstream
			writer.write(text);
			writer.flush();

		} catch (IOException e) {
			throw new BundlingProcessException("Unexpected IOException writing bundle[" + bundlePath + "]", e);
		}finally {
			IOUtils.close(writer);
		}
	}
444802
public function append(AssetTarget $target)
    {
        $name = $target->name();
        $this->indexed[$name] = $target;
        $this->items[] = $name;
    }
756172
function compile( bundleData, bundleFile, config, callback ) {
	var baseDir = config['path'] || path.dirname(bundleFile);
	var encoder, profileEncoder = [], profileLoader = [], bundleLoader;

	// Compile stages
	var openBundle = function( cb ) {
		return function() {

			// Create encoder
			encoder = new BinaryEncoder(
					bundleFile,
					{
						'name' 			: bundleData['name'],
						'base_dir' 		: baseDir,
						'log'			: config['log'] || 0x00,
						'sparse'		: config['sparse'],
					}
				);

			// Add profiles
			for (var i=0; i<profileEncoder.length; i++) {
				encoder.addProfile( profileEncoder[i] );
			}

			// We are ready
			cb();
		}
	}

	var loadBundles = function( cb ) {
		return function() {
			// Load a bundle by specs
			bundleLoader.addBySpecs( bundleData );
			// Solve dependencies and load resources
			bundleLoader.load( cb );
		}
	}

	var compileExports = function( cb ) {
		return function() {
			// Get the bundle to encode
			var bundle = bundleLoader.bundles[ bundleData['name'] ];

			// Encode resources
			for (var k in bundle.resources) {
				encoder.encode( bundle.resources[k], k );
			}

			// Embed blobs
			for (var k in bundle.blobs) {
				encoder.embedBlob( bundle.blobs[k][0], k, bundle.blobs[k][1] );
			}

			// We are done
			cb();
		}
	}

	var closeBundle = function( cb ) {
		return function() {
			// Close & Complete
			encoder.close();
			cb();
		}
	}

	// Check for profileTable/profileLoader
	if (config['profileEncoder'] || config['profileLoader']) {

		// Check for missing arguments
		if (!config['profileEncoder']) {
			callback( "Got 'profileLoader' but missing 'profileEncoder' in the arguments" );
			return;
		}
		if (!config['profileLoader']) {
			callback( "Got 'profileEncoder' but missing 'profileLoader' in the arguments" );
			return;
		}

		// Fetch
		profileEncoder = config['profileEncoder'];
		profileLoader = config['profileLoader'];

		// Make sure it's array
		if (!(profileEncoder instanceof Array))
			profileEncoder = [ profileEncoder ];
		if (!(profileLoader instanceof Array))
			profileLoader = [ profileLoader ];

	} else {

		// Identify some important information
		var profile = config['profile'] || bundleData['profile'];
		if (!profile) {
			callback( "No jbb profile was specified!");
			return;
		}

		// Make sure it's array
		if (typeof profile === 'string')
			profile = [ profile ];

		// Require
		for (var i=0; i<profile.length; i++) {
			var pname = profile[i];
			if (pname[0] == ".") {
				profileEncoder.push( require( path.join(process.cwd(), pname, '/profile-encode') ) );
				profileLoader.push( require( path.join(process.cwd(), pname, "/profile-loader") ) );
			} else {
				profileEncoder.push( require('jbb-profile-'+pname+'/profile-encode') );
				profileLoader.push( require('jbb-profile-'+pname+"/profile-loader") );
			}
		}

	}

	// Load profile table and compiler helper
	bundleLoader = new BundlesLoader( baseDir );
	for (var i=0; i<profileLoader.length; i++) {
		bundleLoader.addProfileLoader( profileLoader[i] );
	}

	// Chained initialization of profile loaders
	var context = { 'remaining': profileLoader.length }
	var init_callback = (function() {
		if (--this.remaining == 0) {
			openBundle(
				loadBundles(
					compileExports(
						closeBundle( callback || function(){} )
						) 
					) 
			)();
		}
	}).bind(context);

	// Initialize profile compiler with the specs file
	for (var i=0; i<profileLoader.length; i++) {
		if (!profileLoader[i].initialize) {
			init_callback();
		} else {
			profileLoader[i].initialize( init_callback, bundleData );
		}
	}

}
772071
public function setPropertyFile($propertyFile)
    {
        if (!file_exists($this->getDirectory() . DIRECTORY_SEPARATOR . $propertyFile)) {
            throw new \Exception(Lang::get('property_file_missing'));
        }

        $this->propertyFile = $propertyFile;
    }
1126282
function setBundleConfig(bundleName,_bundleMap){
	    	var targetName = bundleName.split("/").join("_");
	    	grunt.config("uglify."+targetName+".files",_bundleMap);
	    	grunt.config("uglify."+targetName+".options.footer",
	    	';\n(function(foo,bundles){foo.__bundled__ = foo.__bundled__ ? foo.__bundled__.concat(bundles) : bundles;})(this,["'+
	    		bundleName
	    	+'"]);'
	    	);
	    }
943525
@Override
	public void writeBundleTo(String bundlePath, Writer writer) throws ResourceNotFoundException {

		Reader rd = null;

		try {

			// If debug mode is on, resources are retrieved one by one.
			if (config.isDebugModeOn()) {

				rd = resourceHandler.getResource(null, bundlePath);
			} else {

				for (String prefix : bundlePrefixes) {
					if (bundlePath.startsWith(prefix)) {
						bundlePath = bundlePath.substring(prefix.length());
						break;
					}
				}

				// Prefixes are used only in production mode
				String path = PathNormalizer.removeVariantPrefixFromPath(bundlePath);
				rd = resourceBundleHandler.getResourceBundleReader(path);
				if (liveProcessBundles.contains(path)) {
					rd = processInLive(rd);
				}
			}

			IOUtils.copy(rd, writer);
			writer.flush();
		} catch (IOException e) {
			throw new BundlingProcessException("Unexpected IOException writing bundle[" + bundlePath + "]", e);
		} finally {
			IOUtils.close(rd);
			IOUtils.close(writer);
		}
	}
873598
public static function loadBundle(&$bundle)
    {
        if (sizeof($bundle->content) == 0) {
            return;
        }
        
        // check for cached, preloaded bundle
        $bundleCache = Cache::getInstance('MEMCACHE', 'APC', 'FILE_ENCODED');
        $bundleCachePath = "xqbundle/{$bundle->bundleId}";
        
        if (!DEBUG && ($bundleCache->available() && $bundleCache->hasCached($bundleCachePath))) {
            $bundle = $bundleCache->getCached($bundleCachePath);
            return;
        }
        
        // preload
        $bundle->lastModified = null;
        $bundle->files = array();
        
        $fileNames = array();
        foreach ($bundle->content as $file) {
            $preloaded = self::getBundleFileDetails($bundle, $file);
            
            $bundle->files[] = $preloaded;
            $fileNames[] = $preloaded->path;
        }
        
        $bundle->contentType = self::getBundleContentType($bundle);
        $bundle->tag = md5($bundle->lastModified . $bundle->bundleId . implode('-', $fileNames));
        
        $bundle->output = self::getBundleContent($bundle);
        
        if (!DEBUG && $bundleCache->available()) {
            $bundleCache->cache($bundleCachePath, $bundle);
        }
    }