public function requireJson(array $packages)
{
$json = array();
// Construct the packages configuration.
foreach ($packages as $package) {
// Retrieve information from the extra options.
$extra = isset($package['extra']) ? $package['extra'] : array();
$options = isset($extra['component']) ? $extra['component'] : array();
// Construct the base details.
$name = $this->getComponentName($package['name'], $extra);
$component = array('name' => $name);
// Build the "main" directive.
$scripts = isset($options['scripts']) ? $options['scripts'] : array();
if (!empty($scripts)) {
// Put all scripts into a build.js file.
$result = $this->aggregateScripts($package, $scripts, $name . DIRECTORY_SEPARATOR . $name . '-built.js');
if ($result) {
// If the aggregation was successful, add the script to the
// packages array.
$component['main'] = $name . '-built.js';
// Add the component to the packages array.
$json['packages'][] = $component;
}
}
// Add the shim definition for the package.
$shim = isset($options['shim']) ? $options['shim'] : array();
if (!empty($shim)) {
$json['shim'][$name] = $shim;
}
// Add the config definition for the package.
$packageConfig = isset($options['config']) ? $options['config'] : array();
if (!empty($packageConfig)) {
$json['config'][$name] = $packageConfig;
}
}
// Provide the baseUrl.
$json['baseUrl'] = $this->baseUrl;
// Merge in configuration options from the root.
if ($this->config->has('component')) {
$config = $this->config->get('component');
if (isset($config) && is_array($config)) {
// Use a recursive, distict array merge.
$json = $this->arrayMergeRecursiveDistinct($json, $config);
}
}
return $json;
}