public function run() { if ($this->templateType === self::TEMPLATE_TYPE_DIR) { $cakeJson = $this->join(realpath($this->template), 'cheesecake.json'); } elseif ($this->templateType === self::TEMPLATE_TYPE_REMOTE_GIT) { $repo = Repository::createFromRemote($this->template); $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json'); } elseif ($this->templateType === self::TEMPLATE_TYPE_LOCAL_GIT) { $repo = Repository::open($this->template); $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json'); } else { throw new CheesecakeUnknownTemplateException(); } if (!file_exists($cakeJson)) { throw new CheesecakeNotFoundExeption(); } $replace = []; $args = json_decode(file_get_contents($cakeJson), true); // Detect if we need the cli promt $diff = array_diff(array_keys($args), array_keys($this->params)); if (count($diff) > 0 && false === $this->noInteraction) { foreach ($args as $key => $value) { // :S $args[$key] = cli\prompt($key, $value, $marker = ' : '); } } else { // Merge constructor params with cheesecake.json $args = array_merge($args, $this->params); } $replace = ['cheesecake' => $args]; $tmpDir = $this->join(sys_get_temp_dir(), sha1(uniqid())); if (!$this->fs->copyDirectory($this->template, $tmpDir)) { throw new CheesecakeFilesystemExeption(); } $this->processHook('pre_gen.php', $tmpDir); $this->processDirs($tmpDir, $replace); $this->processFiles($tmpDir, $replace); if (!$this->fs->delete($this->join($tmpDir, 'cheesecake.json'))) { throw new CheesecakeFilesystemExeption(); } if (!$this->fs->copyDirectory($tmpDir, $this->output)) { throw new CheesecakeFilesystemExeption(); } if (!$this->fs->deleteDirectory($tmpDir)) { throw new CheesecakeFilesystemExeption(); } $this->processHook('post_gen.php', $this->output); $hookDir = $this->join($this->output, 'hooks'); if (is_dir($hookDir)) { if (!$this->fs->deleteDirectory($hookDir)) { throw new CheesecakeFilesystemExeption(); } } return true; }
/** * @Given I have initialised a git repository */ public function iHaveInitialisedAGitRepository() { $path = $this->getFileSystemPath(); $this->repository = Repository::open($path); $this->repository->init(); }
/** * @return GitRepository */ public static function fromCurrentWorkingDirectory() { return new self(Repository::open(realpath('.'))); }
<?php use GitElephant\Repository; use Sami\Version\GitVersionCollection; $dir = __DIR__ . '/src'; $versions = GitVersionCollection::create($dir); $versions->add('master', 'master branch'); foreach (Repository::open('.')->getTags() as $tag) { $versions->addFromTags($tag->getName()); } return new Sami\Sami($dir, array('build_dir' => 'build/%version%', 'cache_dir' => 'cache/%version%', 'title' => 'GitElephant API', 'default_opened_level' => 2, 'versions' => $versions));
/** * @param null|string $name the folder name * @param int $index the repository index (for getting them back) * * @return void */ protected function initRepository($name = null, $index = null) { $tempDir = realpath(sys_get_temp_dir()); $tempName = null === $name ? tempnam($tempDir, 'gitelephant') : $tempDir . DIRECTORY_SEPARATOR . $name; $this->path = $tempName; @unlink($this->path); $fs = new Filesystem(); $fs->mkdir($this->path); $this->caller = new Caller(new GitBinary(), $this->path); if (is_null($index)) { $this->repository = Repository::open($this->path); $this->assertInstanceOf('GitElephant\\Repository', $this->repository); } else { if (!is_array($this->repository)) { $this->repository = array(); } $this->repository[$index] = Repository::open($this->path); $this->assertInstanceOf('GitElephant\\Repository', $this->repository[$index]); } }