New env merger and if_exists conditions#12
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
textorenv.Choices:
- For type
- For type
Default:typeappendAdds content to the end of an existing file, or creates a new one.overwriteOverwrites existing content, or creates a new file.ignoreDoesn't alter an existing file, or creates a new file.envcommentComments same name env varsdeleteDelete same name env varsappendfortexttype.commentforenvtype.Optional
Text
The text merger can be used to extend any text-based file such as:
As it's the default merger, you can simply use the
destination: sourceformat in the recipe.Example 1: append to an existing file
Given
yourrepo/recipe/.gitignorewith this content:With this recipe:
The created
.gitignorefile will look like this:The
###> yourname/yourrepo ###opening comment and###< yourname/yourrepo ###closing comment are used by Cook to identify the recipe in the file.If you're familiar with Symfony Flex, the syntax is the same.
Example 2: overwrite an existing file
If you want to overwrite the existing file, you can use the
if_existsparameter.This will replace the entire content of the
.gitignorefile with the content ofrecipe/.gitignore.Example 3: ignore an existing file
If you want to ignore the existing file, you can use the
if_existsparameter.This will not alter the existing
.gitignorefile, and will not create a new one if it doesn't exist.Env
The env merger is used to add new environment variables to an existing
.envfile or create a new one if it doesn't exist.Example 1: merge or create a
.envfile with a given source fileGiven
yourrepo/recipe/.envwith this content:And an existing
.envfile in the project with this content:With this recipe:
The created
.envfile will look like this:The existing
SOME_ENV_VARIABLEis commented out to avoid conflicts with the new value, this is the default behavior of the env merger.Example 2: merge or create a
.envfile with a string inputAlternatively, you can use
contentinstead ofsource, to avoid creating a file in your repository.