示例#1
0
 /**
  * @param \Aquarium\Resources\Package|string $packageName
  * @return string
  */
 public static function getClassPath($packageName)
 {
     if ($packageName instanceof Package) {
         return self::getClassPath($packageName->Name);
     }
     return Config::instance()->directories()->PhpTargetDir . DIRECTORY_SEPARATOR . self::getClassName($packageName) . '.php';
 }
示例#2
0
 /**
  * @param IShell $shell
  * @throws GulpException When gulp exit with none zero code.
  */
 public function execute(IShell $shell)
 {
     $commandParts = array_merge(['export HOME="' . $this->getHomeDirectory() . '" &&'], ["cd {$this->path} &&"], ['gulp'], [$this->action], $this->arguments, ['2>&1']);
     $command = implode(' ', $commandParts);
     $result = $shell->execute($command, $this->output);
     if ($result !== 0) {
         Config::log()->logBuildException($this->output);
         throw new GulpException($result, $this->output);
     }
 }
示例#3
0
 /**
  * @throws \Exception
  */
 public function compile()
 {
     $packageDefinitionManager = Config::instance()->packageDefinitionManager();
     foreach ($packageDefinitionManager->getNames() as $name) {
         $originalPackage = $packageDefinitionManager->get($name);
         Config::log()->logPackageBuildStart($originalPackage);
         $compiledPackage = $this->compilePackage($originalPackage);
         /** @var IPhpBuilder $builder */
         $builder = Config::skeleton(IPhpBuilder::class);
         $builder->buildPhpFile($compiledPackage);
         Config::log()->logPackageBuildComplete($compiledPackage);
     }
 }
示例#4
0
 /**
  * Remove any files from the package directory.
  * @param Package $p
  */
 public function cleanDirectory(Package $p)
 {
     $targetDir = Config::instance()->directories()->CompiledResourcesDir;
     $packageDir = $targetDir . DIRECTORY_SEPARATOR . $p->getName('_');
     $allFiles = array_merge($p->Scripts->get(), $p->Styles->get(), $p->Views->get());
     foreach (glob($packageDir . '/*') as $path) {
         if (!is_file($path)) {
             continue;
         }
         if (in_array($path, $allFiles)) {
             continue;
         }
         unlink($path);
     }
 }
示例#5
0
 /**
  * @param string $resource
  * @return bool|int|string
  */
 private function getFullPath($resource)
 {
     if (self::$isTestMode || $resource[0] == DIRECTORY_SEPARATOR) {
         return $resource;
     }
     if (preg_match('/(\\*)/', $resource)) {
         $this->loadDirectory = true;
         $fullPath = $this->addAllFilesInDirectory($resource);
     } else {
         $this->loadDirectory = false;
         $fullPath = Config::instance()->directories()->getPathToSource($resource);
     }
     if (!$fullPath) {
         throw new \Exception("Can't find path to source file '{$resource}'");
     }
     return $fullPath;
 }
示例#6
0
 /**
  * @return bool
  */
 public static function compile()
 {
     $compiler = Config::instance()->compiler();
     try {
         self::prepare();
         Config::instance()->log()->logMessage('Starting compilation');
         $startTime = round(microtime(true), 4);
         $compiler->compile();
         $runTime = round(abs(round(microtime(true), 4) - $startTime), 4);
         Config::instance()->log()->logMessage("Complete in {$runTime} seconds");
     } catch (GulpException $e) {
         return false;
     } catch (\Exception $e) {
         Config::instance()->log()->logException($e, 'Unexpected error encounter during compilation');
         return false;
     }
     return true;
 }
示例#7
0
 private function preLoad()
 {
     if (!is_null($this->data)) {
         return;
     }
     if (!$this->filePath) {
         $this->filePath = Config::instance()->directories()->StateFile;
     }
     $data = file_get_contents($this->filePath);
     if (!$data) {
         $data = '[]';
     }
     /** @var PackageResourceSet[] $objects */
     $objects = Mappers::simple()->getObjects($data, PackageResourceSet::class);
     $this->data = [];
     foreach ($objects as $object) {
         $this->data[$object->PackageName] = $object;
     }
 }
示例#8
0
 public function test_cleanDirectory()
 {
     touch($this->packagePath . '/inp_a');
     touch($this->packagePath . '/inp_b');
     touch($this->packagePath . '/notin_a');
     // Sanity check
     $this->assertFileExists($this->packagePath . '/inp_a');
     $this->assertFileExists($this->packagePath . '/inp_b');
     $this->assertFileExists($this->packagePath . '/notin_a');
     $package = new Package('package/name');
     $package->Scripts->add($this->packagePath . '/inp_a');
     $package->Styles->add($this->packagePath . '/inp_b');
     Config::instance()->directories()->CompiledResourcesDir = $this->targetPath;
     (new CompileHelper())->cleanDirectory($package);
     $this->assertFileExists($this->packagePath . '/inp_a');
     $this->assertFileExists($this->packagePath . '/inp_b');
     $this->assertFileExists($this->packagePath . '/Dir/.keep');
     $this->assertFileNotExists($this->packagePath . '/notin_a');
 }
 public function test_sanity()
 {
     $p = new Package('a/b');
     $p->Requires->add('req-a');
     $p->Requires->add('req-1');
     $p->Inscribed->add('ins-a');
     $p->Inscribed->add('ins-1');
     $p->Styles->add('style1');
     $p->Styles->add('style2');
     $p->Scripts->add('script-a');
     $p->Scripts->add('script-b');
     Config::instance()->directories()->CompiledResourcesDir = 'a';
     Config::instance()->directories()->PhpTargetDir = self::PATH;
     // TEST:
     (new DefaultPhpBuilder())->buildPhpFile($p);
     $this->assertFileExists(self::PATH . '/' . Utils::PACKAGE_CLASS_NAME_PREFIX . $p->getName(Utils::PACKAGE_PATH_SEPARATOR) . '.php', 'PHP class file was not created or created in wrong directory!');
     $pLoaded = (new CompiledPackages())->get($p->Name);
     $this->assertEquals(['req-a', 'req-1'], $pLoaded->Requires->get());
     $this->assertEquals(['script-a', 'script-b'], $pLoaded->Scripts->get());
     $this->assertEquals(['style1', 'style2'], $pLoaded->Styles->get());
     $this->assertEquals(['ins-a', 'ins-1'], $pLoaded->Inscribed->get());
 }
示例#10
0
 /**
  * @param Package $p
  * @return CompilerSetup
  */
 public function preCompileView(Package $p)
 {
     $unroll = new PackageUnroll(Config::instance()->packageDefinitionManager());
     $unroll->setOriginPackage($p);
     $views = $unroll->getViews();
     return $this->preCompileActions($p, [new HandleBarAction()], $views);
 }
示例#11
0
 /**
  * @param \Aquarium\Resources\Package $package
  */
 public function buildPhpFile(Package $package)
 {
     $className = Utils::getClassName($package->Name);
     $resource = $this->createFile($className);
     Config::instance()->directories()->truncateResourcesToPublicDir($package);
     try {
         $this->writePhpFile($resource, $package);
     } finally {
         fclose($resource);
     }
 }
示例#12
0
 public function test_fullStuck_NoPhpBuild()
 {
     $gulpCompiler = new GulpPackageCompiler();
     $gulpCompiler->setup()->style()->sass()->cssmin();
     $this->setupWithPackageLoader($gulpCompiler, SanityTestHelper_Scss_And_Css::class);
     $this->setupDirectories();
     Config::instance()->provider()->package('scss/a');
     $this->assertFileExists(self::SANITY_DIR . '/target/scss_a/a.css');
     $this->assertFileExists(self::SANITY_DIR . '/target/scss_a/b.css');
 }
示例#13
0
 public function __construct()
 {
     $this->factory = Config::skeleton(IGulpActionFactory::class);
 }
示例#14
0
 public function test_getClassPath_PackagePassed()
 {
     $sep = DIRECTORY_SEPARATOR;
     Config::instance()->directories()->PhpTargetDir = "{$sep}a{$sep}b";
     $this->assertEquals("{$sep}a{$sep}b{$sep}" . Utils::PACKAGE_CLASS_NAME_PREFIX . 'a_b.php', Utils::getClassPath(new Package('a/b')));
 }
示例#15
0
 protected function setUp()
 {
     Config::instance()->logConfig()->setLogStream(new VoidStream());
 }
示例#16
0
 /**
  * @runInSeparateProcess
  */
 public function test_get_DifferentPackageRequested()
 {
     Config::instance()->directories()->PhpTargetDir = self::PATH;
     $cp = new CompiledPackages();
     $this->assertNotSame($cp->get('a/b'), $cp->get('c/d'));
 }
示例#17
0
<?php

namespace Aquarium\Resources\Compilation;

use Skeleton\Type;
use Aquarium\Resources\Config;
/** @var \Skeleton\Skeleton $skeleton */
$skeleton = Config::skeleton();
$skeleton->set(IPhpBuilder::class, DefaultPhpBuilder::class, Type::Singleton);
示例#18
0
 public function __construct()
 {
     $this->timeHelper = Config::skeleton(ITimestampHelper::class);
 }