more regarding CompileAssets
This commit is contained in:
parent
afa393ba25
commit
114ce70d3a
@ -1,13 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ApplicationInstaller;
|
namespace ApplicationInstaller;
|
||||||
|
|
||||||
|
use Composer\Script\Event;
|
||||||
|
use Rails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post-install script ran when installing the system
|
* Post-install script ran when installing the system
|
||||||
* using composer. It compiles assets.
|
* using Composer to compile assets.
|
||||||
*/
|
*/
|
||||||
class CompileAssets
|
class CompileAssets
|
||||||
{
|
{
|
||||||
static public function compile()
|
static public function compile(Event $event)
|
||||||
{
|
{
|
||||||
$railsRoot = __DIR__ . '/../..';
|
$railsRoot = __DIR__ . '/../..';
|
||||||
|
|
||||||
@ -16,8 +19,25 @@ class CompileAssets
|
|||||||
$target = $railsRoot . '/config/config.php';
|
$target = $railsRoot . '/config/config.php';
|
||||||
copy($file, $target);
|
copy($file, $target);
|
||||||
|
|
||||||
|
# Load rails
|
||||||
require $railsRoot . '/config/boot.php';
|
require $railsRoot . '/config/boot.php';
|
||||||
\Rails::assets()->compileAll();
|
|
||||||
|
# Reset configuration to production, because Rails will load
|
||||||
|
# development by default when ran from CGI, and Assets won't
|
||||||
|
# set environment to production itself. Fix this later.
|
||||||
|
Rails::resetConfig('production');
|
||||||
|
|
||||||
|
# Load console
|
||||||
|
$console = new Console($event->getIO());
|
||||||
|
|
||||||
|
# Warn about compiling
|
||||||
|
$console->write("[Compiling assets]");
|
||||||
|
|
||||||
|
# Set console to assets
|
||||||
|
Rails::assets()->setConsole($console);
|
||||||
|
|
||||||
|
# Compile files
|
||||||
|
Rails::assets()->compileAll();
|
||||||
|
|
||||||
# Delete temporary config file.
|
# Delete temporary config file.
|
||||||
unlink($target);
|
unlink($target);
|
||||||
|
20
install/ApplicationInstaller/Console.php
Executable file
20
install/ApplicationInstaller/Console.php
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace ApplicationInstaller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Console used by CompileAssets.
|
||||||
|
*/
|
||||||
|
class Console extends \Rails\Console\Console
|
||||||
|
{
|
||||||
|
private $io;
|
||||||
|
|
||||||
|
public function __construct($io)
|
||||||
|
{
|
||||||
|
$this->io = $io;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function write($message, $n = 1)
|
||||||
|
{
|
||||||
|
$this->io->write($message . str_repeat("\n", $n));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user