You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| **type** | string | Type of file.<br/><br/>**Choices:**<ul><li>`text`</li><li>`php_array`</li><li>`json`</li><li>`yaml`</li><li>`docker_compose`</li></ul>**Default:** `text`<br/>**Optional** |
90
-
| **destination** | string | Path of the destination file in the project that will be created or merged.<br/><br/>**Required** |
91
-
| **source** | string | Path of the source file in the package which content will be used to create or merge in the destination file.<br/><br/>**Required** if **content** isn't defined |
92
-
| **content** | string | Text to merge in the destination file.<br/><br/>**Required** if **source** isn't defined |
93
-
| **entries** | array<string, mixed> | Key-value pairs used to fill a PHP or JSON array.<br/><br/>**Required** if **type** is of type `php_array` or `json` |
94
-
| **filters** | {keys: array\<string>, values: array\<string>} | Filters for **entries** when **type** is `php_array`.<br/><br/>**Choices:**<ul><li>`keys`<ul><li>`class_constant` Convert the given string to a class constant. As an example, `'Williarin\Cook'` becomes `Williarin\Cook::class`</li></ul></li><li>`values`<ul><li>`class_constant` See above</li><li>`single_line_array` If the value is an array, it will be exported on a single line</li></ul></li></ul>**Optional** |
95
-
| **valid_sections** | array\<string> | Used if **type** is `yaml` or `json` in order to restrict which top-level parameters need to be merged.<br/><br/>Example: `[parameters, services]`<br/><br/>**Optional** |
96
-
| **blank_line_after** | array\<string> | Used if **type** is `yaml` in order to add a blank line under the merged section.<br/><br/>Example: `[services]`<br/><br/>**Optional** |
97
-
| **uninstall_empty_sections** | boolean | Used if **type** is `yaml` in order to remove an empty recipe section when uninstalling the recipe.<br/><br/>**Default:** `false`<br/>**Optional** |
| **type** | string | Type of file.<br/><br/>**Choices:**<ul><li>`text`</li><li>`php_array`</li><li>`json`</li><li>`yaml`</li><li>`env`</li><li>`docker_compose`</li></ul>**Default:** `text`<br/>**Optional** |
90
+
| **destination** | string | Path of the destination file in the project that will be created or merged.<br/><br/>**Required** |
91
+
| **source** | string | Path of the source file in the package which content will be used to create or merge in the destination file.<br/><br/>**Required** if **content** isn't defined |
92
+
| **content** | string | Text to merge in the destination file.<br/><br/>**Required** if **source** isn't defined |
93
+
| **entries** | array<string, mixed> | Key-value pairs used to fill a PHP or JSON array.<br/><br/>**Required** if **type** is of type `php_array` or `json` |
94
+
| **filters** | {keys: array\<string>, values: array\<string>} | Filters for **entries** when **type** is `php_array`.<br/><br/>**Choices:**<ul><li>`keys`<ul><li>`class_constant` Convert the given string to a class constant. As an example, `'Williarin\Cook'` becomes `Williarin\Cook::class`</li></ul></li><li>`values`<ul><li>`class_constant` See above</li><li>`single_line_array` If the value is an array, it will be exported on a single line</li></ul></li></ul>**Optional** |
95
+
| **valid_sections** | array\<string> | Used if **type** is `yaml` or `json` in order to restrict which top-level parameters need to be merged.<br/><br/>Example: `[parameters, services]`<br/><br/>**Optional** |
96
+
| **blank_line_after** | array\<string> | Used if **type** is `yaml` in order to add a blank line under the merged section.<br/><br/>Example: `[services]`<br/><br/>**Optional** |
97
+
| **uninstall_empty_sections** | boolean | Used if **type** is `yaml` in order to remove an empty recipe section when uninstalling the recipe.<br/><br/>**Default:** `false`<br/>**Optional** |
98
+
| **if_exists** | string | Used if **type** is `text` or `env`. <br/><br/>**Choices:**<ul><li>For type `type`<ul><li>`append` Adds content to the end of an existing file, or creates a new one.</li><li>`overwrite` Overwrites existing content, or creates a new file.</li><li>`ignore` Doesn't alter an existing file, or creates a new file.</li></ul></li><li>For type `env`<ul><li>`comment` Comments same name env vars</li><li>`delete` Delete same name env vars</li></ul></li></ul>**Default:** `append` for `text` type. `comment` for `env` type.<br/>**Optional** |
98
99
99
100
#### Directories
100
101
@@ -114,33 +115,92 @@ You can use colors using [Symfony Console](https://symfony.com/doc/current/conso
114
115
115
116
The text merger can be used to extend any text-based file such as:
116
117
* .gitignore
117
-
* .env
118
118
* Makefile
119
119
120
120
As it's the default merger, you can simply use the `destination: source` format in the recipe.
121
121
122
+
**Example 1:** append to an existing file
123
+
124
+
Given `yourrepo/recipe/.gitignore` with this content:
125
+
```
126
+
# Ignore the .env file
127
+
.env
128
+
```
129
+
With this recipe:
130
+
```yaml
131
+
files:
132
+
.gitignore: recipe/.gitignore
133
+
```
134
+
The created `.gitignore` file will look like this:
135
+
```
136
+
###> yourname/yourrepo ###
137
+
# Ignore the .env file
138
+
.env
139
+
###< yourname/yourrepo ###
140
+
```
141
+
142
+
The `###> yourname/yourrepo ###` opening comment and `###< yourname/yourrepo ###` closing comment are used by Cook to identify the recipe in the file.
143
+
If you're familiar with Symfony Flex, the syntax is the same.
144
+
145
+
**Example 2:** overwrite an existing file
146
+
147
+
If you want to overwrite the existing file, you can use the `if_exists` parameter.
148
+
149
+
```yaml
150
+
files:
151
+
.gitignore:
152
+
source: recipe/.gitignore
153
+
if_exists: overwrite
154
+
```
155
+
This will replace the entire content of the `.gitignore` file with the content of `recipe/.gitignore`.
156
+
157
+
**Example 3:** ignore an existing file
158
+
159
+
If you want to ignore the existing file, you can use the `if_exists` parameter.
160
+
161
+
```yaml
162
+
files:
163
+
.gitignore:
164
+
source: recipe/.gitignore
165
+
if_exists: ignore
166
+
```
167
+
This will not alter the existing `.gitignore` file, and will not create a new one if it doesn't exist.
168
+
169
+
#### Env
170
+
171
+
The env merger is used to add new environment variables to an existing `.env` file or create a new one if it doesn't exist.
172
+
122
173
**Example 1:** merge or create a `.env` file with a given source file
123
174
124
175
Given `yourrepo/recipe/.env` with this content:
125
176
```dotenv
126
177
SOME_ENV_VARIABLE='hello'
127
178
ANOTHER_ENV_VARIABLE='world'
128
179
```
180
+
And an existing `.env` file in the project with this content:
181
+
```dotenv
182
+
# Existing environment variables
183
+
SOME_ENV_VARIABLE='foo'
184
+
```
129
185
With this recipe:
130
186
```yaml
131
187
files:
132
-
.env: recipe/.env
188
+
.env:
189
+
type: env
190
+
source: recipe/.env
133
191
```
134
192
The created `.env` file will look like this:
135
193
```dotenv
194
+
# Existing environment variables
195
+
#SOME_ENV_VARIABLE='foo'
196
+
136
197
###> yourname/yourrepo ###
137
198
SOME_ENV_VARIABLE='hello'
138
199
ANOTHER_ENV_VARIABLE='world'
139
200
###< yourname/yourrepo ###
140
201
```
141
202
142
-
The `###> yourname/yourrepo ###` opening comment and `###< yourname/yourrepo ###` closing comment are used by Cook to identify the recipe in the file.
143
-
If you're familiar with Symfony Flex, the syntax is the same.
203
+
The existing `SOME_ENV_VARIABLE` is commented out to avoid conflicts with the new value, this is the default behavior of the env merger.
144
204
145
205
**Example 2:** merge or create a `.env` file with a string input
0 commit comments