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

fs.append causes a conflict #1049

Closed
evil-shrike opened this issue Nov 29, 2017 · 3 comments
Closed

fs.append causes a conflict #1049

evil-shrike opened this issue Nov 29, 2017 · 3 comments
Labels

Comments

@evil-shrike
Copy link

If a generator copies a file and then tries to add more content into it there will be a conflict

this.fs.copyTpl(this.templatePath('_appsettings.json.properties'), 'appsettings.json.properties', this);

// later 
this.fs.append('appsettings.json.properties', 'DATA_SOURCE=db');

User will be prompted:

 conflict appsettings.json.properties
? Overwrite appsettings.json.properties? overwrite
    force appsettings.json.properties

It's completely misleading as actually there's no any conflict. The file didn't exist before the run. It's just adding more content in the same session.

@Cyborg572
Copy link

I'm running into this same problem. I'm trying to clone a repository, and then append some values from the generator options.

My workaround, for now, is to use spawnCommand to run the git clone, read the contents of the file I want to append to, use spawnCommand to delete it, and then then this.fs.write to write the file with added values. Oddly enough if I use this.fs.delete, it still throws the conflict.

@ghost
Copy link

ghost commented Mar 13, 2018

@evil-shrike
Here is my solution. I try to read again and concat the content, and finally write all over again.

      const originalContent = fs.readFileSync(this.destinationPath('', 'src/content.js'), 'utf8');
      const toAppendContent = this.fs.read(this.templatePath('add_content'), 'utf8')
      fs.writeFile(this.destinationPath('', 'src/content.js'), originalContent.concat(toAppendContent), function (err) {
        if (err) return console.log(err);
      });

@github-actions
Copy link
Contributor

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

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

No branches or pull requests

2 participants