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
Merged

Conversation

@ihostage
Copy link
Contributor

ihostage commented Aug 18, 2019

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

@ihostage ihostage mentioned this pull request Aug 18, 2019
0 of 1 task complete
@eed3si9n

This comment has been minimized.

Copy link
Member

eed3si9n commented Aug 19, 2019

@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 ihostage force-pushed the ihostage:issues-345 branch from efd8ac9 to 7cd8ad7 Aug 19, 2019
@ihostage

This comment has been minimized.

Copy link
Contributor Author

ihostage commented Aug 19, 2019

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
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@ihostage ihostage deleted the ihostage:issues-345 branch Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.