Commit 3d55ee5a by Dmitry Kushnikov Committed by Carsten Brandt

Add possibility to customize path to binary using alias.

If you don't want to install command-line utils globally, you have to specify it's paths. public $commands = [ 'styl' => ['css', '@app/node_modules/bin/stylus < {from} > {to}'], ]; close #5130
parent 65edc03b
......@@ -25,6 +25,14 @@ class AssetConverter extends Component implements AssetConverterInterface
* @var array the commands that are used to perform the asset conversion.
* The keys are the asset file extension names, and the values are the corresponding
* target script types (either "css" or "js") and the commands used for the conversion.
*
* You may also use a path alias to specify the location of the command:
*
* ```php
* [
* 'styl' => ['css', '@app/node_modules/bin/stylus < {from} > {to}'],
* ]
* ```
*/
public $commands = [
'less' => ['css', 'lessc {from} {to} --no-color --source-map'],
......@@ -63,7 +71,7 @@ class AssetConverter extends Component implements AssetConverterInterface
/**
* Runs a command to convert asset files.
* @param string $command the command to run
* @param string $command the command to run. If prefixed with an `@` it will be treated as a path alias.
* @param string $basePath asset base path and command working directory
* @param string $asset the name of the asset file
* @param string $result the name of the file to be generated by the converter command
......@@ -73,6 +81,8 @@ class AssetConverter extends Component implements AssetConverterInterface
*/
protected function runCommand($command, $basePath, $asset, $result)
{
$command = Yii::getAlias($command);
$command = strtr($command, [
'{from}' => escapeshellarg("$basePath/$asset"),
'{to}' => escapeshellarg("$basePath/$result"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment