symfony2 assetics yui compressor on windows (path syntax)
Asked Answered
P

3

3

I'm trying to get assetics running with the yui compressor and, if this is running, sass. Right now, both don't work. When removing all filters from config.yml and the twig template, it works and php app/console assetic:dump does copy the css and js files.

Now I want to add the yui compressor and my config.yml looks like this:

assetic:
  debug: %kernel.debug%
  use_controller: false
  filters:
    yui_js:
      jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar

Adding the filter to the template and running assetic:dump again ends in the following error (translation of message by me):

[RuntimeException]
The syntax for filename, directory name or drive name is wrong

I found an article telling me to specify the path to java.exe, so I add this to config.yml:

assetic:
  ..
  java: C:/Program Files (x86)/Java/jre6/bin/java.exe
  ..

Now assetic:dump tells me:

[RuntimeException]
The COMMAND "C:/Program" is either written wrong or

I tried playing around with both variables (using \ or \ instead of /, adding single or double quotes, working with short alias Progra~1 or Progra~2) in the config, but I didn't get anywhere. The both errors comming up all the time. Maybe someone can point me in the right direction.

Patriapatriarch answered 19/11, 2011 at 15:45 Comment(5)
Have you tried using double quotes, single quotes, replacing spaces with \ ?Athamas
Sorry, didn't mean brakets, meant quotes, so yes, tried combinations of them. Also tried writing Program\ Files\ (x86) and some other stuff. If anybody could guide me where to find the integration of assetic into symfony2, I may be able to figure it out myself, but I simply don't find it (where the command is defined, where the configuration is read etc.).Patriapatriarch
If Program\ Files\ output the very same message, then please try Program\\ Files\\Athamas
Doesn't change anything. The only thing that seems to change it a bit is using C:\Progra~2\Java\jre6\bin\java.exe but then I get the first message again.Patriapatriarch
Wow, I think I finally got something: I found link and then changed line 95 to if (defined('PHP_WINDOWS_VERSION_MAJOR')) { and now I get Error creating output file. I'll see how far I can get with this.Patriapatriarch
P
6

Ok, I figured it out. Man, this one was brutal.

Let's start with the easy stuff. A working version of the config.yml can look like this:

assetic:
  debug: false
  use_controller: false
  java: C:\Program Files (x86)\Java\jre6\bin\java.exe
  sass: C:\Program Files (x86)\Ruby192\bin\sass.bat
  filters:
    scss: ~
    yui_js:
      jar: %kernel.root_dir%\Resources\java\yuicompressor-2.4.6.jar

For some reason, assetic is always importing a whole directory for scss, so I had to make a combine.scss which imports the other scss files in the correct order.

And now it gets ugly, as one have to change the assetics core in order to get this working. The developers of assetic know this bug and I think it is fixed in some development trunk/branch but not the stable one.

The Assetic\Util\ProcessBuilder has to be changed on line 95

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {

,line 103

$script .= ' '.implode(' ', array_map('escapeshellarg', $args));

and line 110

return new Process($script, $this->cwd, null, $this->stdin, $this->timeout, $options);

I hope this bug get fixed soon and till then anybody trying to get it working finds this thread... Took me like 8 hours of debuging, reading and trying different approaches.

Patriapatriarch answered 19/11, 2011 at 22:53 Comment(3)
The current version of Symfony2 (version 2.0.5) has version 1.0.2 of Assetic which is broken on Windows. Current master fix the issue your are mentionning. Check this commit for the version with the fix. Note also that compass is broken right now in current master of Assetic, if you try to make it run on Windows. This issue and this one talk about the issue with compass.Argus
this bug is still present in symfony 2.0.9 which is bundled with assetic 1.0.2Trilateration
Has this been fixed? I'm having the same issue but only with SASS?Azotobacter
M
0

Answer by Boo Nov 19 at 22:53 did work for me by changing everything he mentioned in Assetic\Util\ProcessBuilder (I ignored line 95 as it looks the same as in my file)

Now it works on windows. Thanks!

Just to confirm. Im using Symfony 2.0.7 and yuicompressor-2.4.7

Mcewen answered 21/12, 2011 at 18:46 Comment(0)
D
0

For other users who use window server 2008 r2 :

  1. Maybe you should change the C:\windows\Temp folder property to 777 (read/write) for the IIS user / or the machine's normal user

  2. please unpack the ruby.7z from rubyinstaller.org , and go to C:\_ruby193\bin , in this unpack position you should exec the CMD prompt , type :

    ruby -S gem install sass
    

    so that you will get the sass.bat in that position

  3. It's time to use Boo's best answer , and please notice that in symfony2 dev env maybe it's not necessary to change the use_controller to false (in the config.yml) , because there's another use_controller in the config_dev.yml (set to true) , and in routing_dev.yml there's also a _assetic router , they're perhaps associated.

Doorframe answered 1/2, 2012 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.