Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 10282ff

Browse files
Added git support for templates directory
1 parent 95ada35 commit 10282ff

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ Usually it is located under `~/.config/composer`.
207207

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

210+
#### File templates from a git repository
211+
212+
If your templates folder is a git repository `oc-bootstrapper` will pull the latest changes for the repo every time
213+
you run `october init`.
214+
215+
This is a great feature if you want to share the template files with your team via a central
216+
git repository. Just make sure you are able to fetch the latest changes via `git pull` and you're all set!
217+
218+
```bash
219+
cd ~/.config/composer/october
220+
git clone your-central-templates-repo.git .
221+
git branch --set-upstream-to=origin/master master
222+
git pull # Make sure this works without any user interaction
223+
```
224+
210225
## ToDo
211226

212227
- [ ] Update command to update private plugins

october

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (file_exists(__DIR__.'/../../autoload.php')) {
88
require __DIR__.'/vendor/autoload.php';
99
}
1010

11-
$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.3.2');
11+
$app = new Symfony\Component\Console\Application('October CMS Bootstrapper', '0.4.0');
1212
$app->add(new \OFFLINE\Bootstrapper\October\Console\InitCommand);
1313
$app->add(new \OFFLINE\Bootstrapper\October\Console\InstallCommand);
1414
$app->run();

src/Console/InitCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
4949

5050
$this->createWorkingDirectory($dir);
5151

52+
$output->writeln('<info>Updating template files...</info>');
53+
$this->updateTemplateFiles();
54+
5255
$template = $this->getTemplate('october.yaml');
5356
$target = $dir . DS . 'october.yaml';
5457

src/Util/UsesTemplate.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
2+
23
namespace OFFLINE\Bootstrapper\October\Util;
34

5+
use GitElephant\Repository;
6+
use RuntimeException;
7+
48
trait UsesTemplate
59
{
610
/**
@@ -14,8 +18,37 @@ trait UsesTemplate
1418
public function getTemplate($file)
1519
{
1620
$dist = __DIR__ . DS . implode(DS, ['..', '..', 'templates', $file]);
17-
$overwrite = __DIR__ . DS . implode(DS, ['..', '..', '..', '..', '..', 'october', $file]);
21+
$overwrite = $this->getTemplateOverridePath($file);
1822

1923
return file_exists($overwrite) ? realpath($overwrite) : realpath($dist);
2024
}
25+
26+
/**
27+
* If the template path contains a git repo update its contents.
28+
*/
29+
public function updateTemplateFiles()
30+
{
31+
$overridePath = $this->getTemplateOverridePath();
32+
if ( ! is_dir($overridePath . DS . '.git')) {
33+
return;
34+
}
35+
36+
$repo = Repository::open($overridePath);
37+
try {
38+
$repo->pull();
39+
} catch (\Throwable $e) {
40+
throw new RuntimeException('Error while updating template files: ' . $e->getMessage());
41+
}
42+
}
43+
44+
/**
45+
* Return the path to the local composer .config path where
46+
* the template files are stored.
47+
*
48+
* @return string
49+
*/
50+
protected function getTemplateOverridePath($file = null)
51+
{
52+
return __DIR__ . DS . implode(DS, ['..', '..', '..', '..', '..', 'october', $file]);
53+
}
2154
}

0 commit comments

Comments
 (0)