Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#345 Conditionals for file creation #432

Merged
merged 1 commit into from
Aug 21, 2019

Conversation

ihostage
Copy link
Contributor

@ihostage ihostage commented Aug 18, 2019

Fixes #345
Inspired by lagom/lagom-java.g8#60

@eed3si9n
Copy link
Member

@ihostage Thanks. I am actually not familiar with this area of the code, but our latest docs updated in #374 says:

These could also be used include/exclude files or directories:

src/main/g8
├── \$name__normalize\$
│   ├── \$if(jvm.truthy)\$jvm\$endif\$
│   │   └── src
│   │       └── main
│   │           └── scala
│   │               └── \$organization__packaged\$
│   │                   └── \$name;format="Camel"\$.scala

Is there a problem with that?
Also does this code change need and update of the doc?

@ihostage
Copy link
Contributor Author

Hi, @eed3si9n 👋

Is there a problem with that?

Yep 😞We have a 2 problem now:

  1. If I ignore a directory, how written in docs, G8 just skips this directory from the path to file. Nothing to more. All nested directory and files will be created. If I want to ignore a directory, I need to add conditions for all nested directories and pray, that I will see Skipping existing file: on the log because we have a second problem. 😄
  2. Following from the first problem. G8 will crash If I try to ignore file (not a directory) and this file will be templating a first. For example, I have the next easy template:
src/main/g8
└── simple_folder
    ├── $if(condition.truthy)$ignored_file$endif$
    └── simple_file.txt

Expected result:

src/main/g8
└── simple_folder
    └── simple_file.txt

Actual result:

src/main/g8
└── simple_folder ← it's a file with the content of $if(condition.truthy)$ignored_file$endif$ 😱 

How it works:

  1. Set condition=no
  2. Process src/main/g8/simple_folder/$if(condition.truthy)$ignored_file$endif$
  3. Evaluated path → src/main/g8/simple_folder
  4. Create file src/main/g8/simple_folder with content of $if(condition.truthy)$ignored_file$endif$
  5. Process src/main/g8/simple_folder/simple_file.txt
  6. Evaluated path → src/main/g8/simple_folder/simple_file.txt
  7. Create parent directory src/main/g8/simple_folder
  8. Crash, because src/main/g8/simple_folder is a file, created on point 4.

Test, implemented on this PR, reproduce a two our problem. You can revert my changes of code and run test for seeing current behavior. 😉

Also does this code change need and update of the doc?

Nope 😄 On this PR the behavior of G8 that I expected after reading the docs. But you right, I updated PR and added some information about the case of skipping directory from the path.

@eed3si9n eed3si9n merged commit de5c4dd into foundweekends:master Aug 21, 2019
@ihostage ihostage deleted the issues-345 branch August 21, 2019 16:05
@vpavkin
Copy link

vpavkin commented Mar 19, 2020

For some reason I still see issues described by @ihostage, although I use 0.12.0 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Conditionals for file creation
3 participants