Skip to content

Commit aef7b55

Browse files
Updated readme
1 parent 387ea6c commit aef7b55

1 file changed

Lines changed: 119 additions & 1 deletion

File tree

README.md

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# platform.di
1+
# Installer
22

33
![Packagist Version](https://img.shields.io/packagist/v/codenamephp/installer)
44
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/codenamephp/installer)
@@ -15,3 +15,121 @@ Installer that uses template folders to setup projects, e.g. from a github templ
1515
Easiest way is via composer. Just run `composer require codenamephp/installer` in your cli which should install the latest version for you.
1616

1717
## Usage
18+
19+
The idea is to have a start script in a subfolder. The script itself just sets up the installer and the dependencies and by that also what the installer is
20+
actually doing. The reason to put it in its own folder is so the files are clearly separated from the rest of the files so the installer can easily remove
21+
itself.
22+
23+
First require the installer package using composer so we can start using its classes.
24+
25+
Best practice is to create a `.installer` folder and an `install.php`. The following example will render the files in the
26+
`.installer/templates` folder into the parent folder replacing all eisting files and replacing all variables in the templates with the variables form the array.
27+
Once this is done the `.installer` folder is deleted.
28+
29+
There's also variable replacement in paths. In this example, a framed replacer is used so common folder names that also might appear as variable are not
30+
replaced by accident (like "vendor" in this example). The default for the prefix and suffix is '__' so if a file
31+
`.installer/templates/files/__vendor__/__componentName__.json` would exist it would end up in `files/codenamephp/some.component.json`
32+
so you can change the final structure on the fly (e.g. have a folder structure that matches your namespace).
33+
34+
`.installer/install.php`:
35+
36+
```php
37+
use de\codenamephp\installer\StepExecutor;/** @noinspection PhpIncludeInspection */
38+
use de\codenamephp\installer\steps\CopyTemplateFolder;
39+
use de\codenamephp\installer\steps\DeleteFilesAndFolders;
40+
use de\codenamephp\installer\steps\SequentialCollection;
41+
use de\codenamephp\installer\templateCopy\directoryHandler\CreateDirectoryWithSymfonyFilesystem;
42+
use de\codenamephp\installer\templateCopy\fileHandler\RenderWithTwigAndDumpWithSymfonyFilesystem;
43+
use de\codenamephp\installer\templateCopy\variableReplacer\FramedStringReplace;
44+
use Symfony\Component\Filesystem\Filesystem;
45+
use Twig\Environment;
46+
use Twig\Loader\FilesystemLoader;
47+
48+
return call_user_func(static function() {
49+
require_once __DIR__ . '/../vendor/autoload.php';
50+
51+
$filesystem = new Filesystem();
52+
$variableReplacer = new FramedStringReplace();
53+
54+
(new StepExecutor(
55+
new SequentialCollection(
56+
new CopyTemplateFolder(
57+
new \de\codenamephp\installer\templateCopy\RecursiveIterator(
58+
new CreateDirectoryWithSymfonyFilesystem($filesystem,$variableReplacer),
59+
new RenderWithTwigAndDumpWithSymfonyFilesystem($filesystem, $variableReplacer, new Environment(new FilesystemLoader('/', '/')))
60+
),
61+
__DIR__ . '/templates',
62+
__DIR__ . '/..',
63+
[
64+
'vendor' => 'codenamephp',
65+
'componentName' => basename(__DIR__ . '/..'),
66+
'namespace' => implode('\\', array_merge(['de', 'codenamephp'], explode('.', basename(__DIR__ . '/..'))))
67+
]
68+
),
69+
new DeleteFilesAndFolders($filesystem, [
70+
__DIR__
71+
]),
72+
)
73+
))->run();
74+
});
75+
```
76+
77+
`.installer/templates/composer.json`:
78+
79+
```json
80+
{
81+
"name": "{{vendor}}/{{componentName}}",
82+
"description": "",
83+
"type": "library",
84+
"license": "Apache-2.0",
85+
"require": {
86+
"php": "^8.0"
87+
},
88+
"require-dev": {
89+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
90+
"phpcompatibility/php-compatibility": "^9.0",
91+
"squizlabs/php_codesniffer": "^3.5",
92+
"mikey179/vfsstream": "^1.6.8"
93+
},
94+
"autoload": {
95+
"psr-4": {
96+
"{{namespace|replace({'\\':'\\\\'})}}\\": [
97+
"src"
98+
]
99+
}
100+
},
101+
"autoload-dev": {
102+
"psr-4": {
103+
"{{namespace|replace({'\\':'\\\\'})}}\\test\\": [
104+
"test"
105+
]
106+
}
107+
}
108+
}
109+
```
110+
111+
`.installer/templates/README.md`:
112+
113+
```markdown
114+
# {{componentName}}
115+
116+
![Packagist Version](https://img.shields.io/packagist/v/{{vendor}}/{{componentName}})
117+
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/{{vendor}}/{{componentName}})
118+
![Lines of code](https://img.shields.io/tokei/lines/github/{{vendor}}/{{componentName}})
119+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/{{vendor}}/{{componentName}})
120+
![CI](https://github.com/{{vendor}}/{{componentName}}/workflows/CI/badge.svg)
121+
![Packagist Downloads](https://img.shields.io/packagist/dt/{{vendor}}/{{componentName}})
122+
![GitHub](https://img.shields.io/github/license/{{vendor}}/{{componentName}})
123+
124+
## Installation
125+
126+
Easiest way is via composer. Just run `composer require {{vendor}}/{{componentName}}` in your cli which should install the latest version for you.
127+
128+
## Usage
129+
```
130+
131+
This example could be part of a GitHub template repository. After the repository was created on GitHub the repo can be cloned to local and after
132+
running `composer install && php .installer/install.php && composer update` the repo would be ready for development.
133+
134+
This example can be adapted to the repository needs. Since the installer itself only executes steps custom steps can be added in the repository by implementing
135+
the `\de\codenamephp\installer\steps\iStep` interface and adding it to the installer.

0 commit comments

Comments
 (0)