Skip to content

Commit

Permalink
Added git support for templates directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-kuendig committed Jul 5, 2018
1 parent 95ada35 commit 10282ff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ Usually it is located under `~/.config/composer`.

Place the files you want to use as defaults in `~/.config/composer/october`. All files from the `templates` directory can be overwritten.

#### File templates from a git repository

If your templates folder is a git repository `oc-bootstrapper` will pull the latest changes for the repo every time
you run `october init`.

This is a great feature if you want to share the template files with your team via a central
git repository. Just make sure you are able to fetch the latest changes via `git pull` and you're all set!

```bash
cd ~/.config/composer/october
git clone your-central-templates-repo.git .
git branch --set-upstream-to=origin/master master
git pull # Make sure this works without any user interaction
```

## ToDo

- [ ] Update command to update private plugins
Expand Down
2 changes: 1 addition & 1 deletion october
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
require __DIR__.'/vendor/autoload.php';
}

$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.3.2');
$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.4.0');
$app->add(new \OFFLINE\Bootstrapper\October\Console\InitCommand);
$app->add(new \OFFLINE\Bootstrapper\October\Console\InstallCommand);
$app->run();
3 changes: 3 additions & 0 deletions src/Console/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->createWorkingDirectory($dir);

$output->writeln('<info>Updating template files...</info>');
$this->updateTemplateFiles();

$template = $this->getTemplate('october.yaml');
$target = $dir . DS . 'october.yaml';

Expand Down
35 changes: 34 additions & 1 deletion src/Util/UsesTemplate.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

namespace OFFLINE\Bootstrapper\October\Util;

use GitElephant\Repository;
use RuntimeException;

trait UsesTemplate
{
/**
Expand All @@ -14,8 +18,37 @@ trait UsesTemplate
public function getTemplate($file)
{
$dist = __DIR__ . DS . implode(DS, ['..', '..', 'templates', $file]);
$overwrite = __DIR__ . DS . implode(DS, ['..', '..', '..', '..', '..', 'october', $file]);
$overwrite = $this->getTemplateOverridePath($file);

return file_exists($overwrite) ? realpath($overwrite) : realpath($dist);
}

/**
* If the template path contains a git repo update its contents.
*/
public function updateTemplateFiles()
{
$overridePath = $this->getTemplateOverridePath();
if ( ! is_dir($overridePath . DS . '.git')) {
return;
}

$repo = Repository::open($overridePath);
try {
$repo->pull();
} catch (\Throwable $e) {
throw new RuntimeException('Error while updating template files: ' . $e->getMessage());
}
}

/**
* Return the path to the local composer .config path where
* the template files are stored.
*
* @return string
*/
protected function getTemplateOverridePath($file = null)
{
return __DIR__ . DS . implode(DS, ['..', '..', '..', '..', '..', 'october', $file]);
}
}

0 comments on commit 10282ff

Please sign in to comment.