Browse Source

Output of "yii\console\controllers\AssetController::actionCompress()" has been made verbose.

tags/2.0.0-beta
Klimov Paul 12 years ago
parent
commit
1c786edbc6
  1. 38
      yii/console/controllers/AssetController.php

38
yii/console/controllers/AssetController.php

@ -89,13 +89,15 @@ class AssetController extends Controller
$targets = $this->loadTargets($this->targets, $bundles); $targets = $this->loadTargets($this->targets, $bundles);
$this->publishBundles($bundles, $this->assetManager); $this->publishBundles($bundles, $this->assetManager);
$timestamp = time(); $timestamp = time();
foreach ($targets as $target) { foreach ($targets as $name => $target) {
echo "Creating output bundle '{$name}':\n";
if (!empty($target->js)) { if (!empty($target->js)) {
$this->buildTarget($target, 'js', $bundles, $timestamp); $this->buildTarget($target, 'js', $bundles, $timestamp);
} }
if (!empty($target->css)) { if (!empty($target->css)) {
$this->buildTarget($target, 'css', $bundles, $timestamp); $this->buildTarget($target, 'css', $bundles, $timestamp);
} }
echo "\n";
} }
$targets = $this->adjustDependency($targets, $bundles); $targets = $this->adjustDependency($targets, $bundles);
@ -109,6 +111,8 @@ class AssetController extends Controller
*/ */
protected function loadConfiguration($configFile) protected function loadConfiguration($configFile)
{ {
echo "Loading configuration from '{$configFile}'...\n";
foreach (require($configFile) as $name => $value) { foreach (require($configFile) as $name => $value) {
if (property_exists($this, $name)) { if (property_exists($this, $name)) {
$this->$name = $value; $this->$name = $value;
@ -133,6 +137,7 @@ class AssetController extends Controller
*/ */
protected function loadBundles($bundles, $extensions) protected function loadBundles($bundles, $extensions)
{ {
echo "Collecting source bundles information...\n";
$result = array(); $result = array();
foreach ($bundles as $name => $bundle) { foreach ($bundles as $name => $bundle) {
$bundle['class'] = 'yii\\web\\AssetBundle'; $bundle['class'] = 'yii\\web\\AssetBundle';
@ -221,13 +226,16 @@ class AssetController extends Controller
*/ */
protected function publishBundles($bundles, $options) protected function publishBundles($bundles, $options)
{ {
echo "\nPublishing bundles:\n";
if (!isset($options['class'])) { if (!isset($options['class'])) {
$options['class'] = 'yii\\web\\AssetManager'; $options['class'] = 'yii\\web\\AssetManager';
} }
$am = Yii::createObject($options); $am = Yii::createObject($options);
foreach ($bundles as $bundle) { foreach ($bundles as $name => $bundle) {
$bundle->publish($am); $bundle->publish($am);
echo " '".$name."' published.\n";
} }
echo "\n";
} }
/** /**
@ -270,6 +278,8 @@ class AssetController extends Controller
*/ */
protected function adjustDependency($targets, $bundles) protected function adjustDependency($targets, $bundles)
{ {
echo "Creating new bundle configuration...\n";
$map = array(); $map = array();
foreach ($targets as $name => $target) { foreach ($targets as $name => $target) {
foreach ($target->depends as $bundle) { foreach ($target->depends as $bundle) {
@ -342,7 +352,7 @@ class AssetController extends Controller
} }
$array = var_export($array, true); $array = var_export($array, true);
$version = date('Y-m-d H:i:s', time()); $version = date('Y-m-d H:i:s', time());
file_put_contents($bundleFile, <<<EOD $bytesWritten = file_put_contents($bundleFile, <<<EOD
<?php <?php
/** /**
* This file is generated by the "yiic script" command. * This file is generated by the "yiic script" command.
@ -352,15 +362,24 @@ class AssetController extends Controller
return $array; return $array;
EOD EOD
); );
if ($bytesWritten <= 0) {
throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'.");
}
echo "Output bundle configuration created at '{$bundleFile}'.\n";
} }
/** /**
* Compresses given Java Script files and combines them into the single one. * Compresses given Java Script files and combines them into the single one.
* @param array $inputFiles list of source file names. * @param array $inputFiles list of source file names.
* @param string $outputFile output file name. * @param string $outputFile output file name.
* @throws \yii\console\Exception on failure
*/ */
protected function compressJsFiles($inputFiles, $outputFile) protected function compressJsFiles($inputFiles, $outputFile)
{ {
if (empty($inputFiles)) {
return;
}
echo " Compressing JavaScript files...\n";
if (is_string($this->jsCompressor)) { if (is_string($this->jsCompressor)) {
$tmpFile = $outputFile . '.tmp'; $tmpFile = $outputFile . '.tmp';
$this->combineJsFiles($inputFiles, $tmpFile); $this->combineJsFiles($inputFiles, $tmpFile);
@ -372,15 +391,24 @@ EOD
} else { } else {
$log = call_user_func($this->jsCompressor, $this, $inputFiles, $outputFile); $log = call_user_func($this->jsCompressor, $this, $inputFiles, $outputFile);
} }
if (!file_exists($outputFile)) {
throw new Exception("Unable to compress JavaScript files into '{$outputFile}'.");
}
echo " JavaScript files compressed into '{$outputFile}'.\n";
} }
/** /**
* Compresses given CSS files and combines them into the single one. * Compresses given CSS files and combines them into the single one.
* @param array $inputFiles list of source file names. * @param array $inputFiles list of source file names.
* @param string $outputFile output file name. * @param string $outputFile output file name.
* @throws \yii\console\Exception on failure
*/ */
protected function compressCssFiles($inputFiles, $outputFile) protected function compressCssFiles($inputFiles, $outputFile)
{ {
if (empty($inputFiles)) {
return;
}
echo " Compressing CSS files...\n";
if (is_string($this->cssCompressor)) { if (is_string($this->cssCompressor)) {
$tmpFile = $outputFile . '.tmp'; $tmpFile = $outputFile . '.tmp';
$this->combineCssFiles($inputFiles, $tmpFile); $this->combineCssFiles($inputFiles, $tmpFile);
@ -392,6 +420,10 @@ EOD
} else { } else {
$log = call_user_func($this->cssCompressor, $this, $inputFiles, $outputFile); $log = call_user_func($this->cssCompressor, $this, $inputFiles, $outputFile);
} }
if (!file_exists($outputFile)) {
throw new Exception("Unable to compress CSS files into '{$outputFile}'.");
}
echo " CSS files compressed into '{$outputFile}'.\n";
} }
/** /**

Loading…
Cancel
Save