jondot / hygen

The simple, fast, and scalable code generator that lives in your project.

Home Page:http://www.hygen.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inject "after" skips extra line

gerektoolhy opened this issue · comments

Hi,

My template seems to be injecting content at a wrong place. I suspect there is something wrong with my template, its just I do not see what. This is the template file:

---
to: <%= project_path %>/docker-compose.yml
after: >
  services:
inject: true
skip_if: >
  first_line
---
first_line
last_line

This template should modify this docker-compose file, and add two new lines just below services: tag. However, injection happens after my-app: # auto-generated line, not after services:.

Below are steps to reproduce, and all files are in a branch, which you can see in this PR: https://github.com/jondot/hygen/pull/429/files


Steps to reproduce

hygen app docker_compose:add_app_db_migration --project_path ./target_file

Actual output:

diff --git a/target_file/docker-compose.yml b/target_file/docker-compose.yml
index 17173ea..f6fb3c1 100644
--- a/target_file/docker-compose.yml
+++ b/target_file/docker-compose.yml
@@ -2,6 +2,9 @@ version: "3.5"

 services:
   my-app: # auto-generated
+first_line
+last_line
+
     image: "my-image"
     container_name: container-name
     environment:

Expected output:

diff --git a/target_file/docker-compose.yml b/target_file/docker-compose.yml
index 17173ea..2ddcbc2 100644
--- a/target_file/docker-compose.yml
+++ b/target_file/docker-compose.yml
@@ -1,6 +1,9 @@
 version: "3.5"

 services:
+first_line
+last_line
+
   my-app: # auto-generated
     image: "my-image"
     container_name: container-name