Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
additional minor fix for append
Browse files Browse the repository at this point in the history
  • Loading branch information
amwmedia committed Oct 18, 2019
1 parent 8b8bb3c commit 3b5aeef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-plop",
"version": "0.21.0",
"version": "0.22.0",
"description": "programmatic plopping for fun and profit",
"main": "lib/index.js",
"types": "index.d.ts",
Expand Down
5 changes: 2 additions & 3 deletions src/actions/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ const doAppend = function*(data, cfg, plop, fileData) {
// if the appended string should be unique (default),
// remove any occurence of it (but only if pattern would match)

const { separator = '\n' } = cfg;
if (cfg.unique !== false) {
// only remove after "pattern", so that we remove not too much accidentally
const parts = fileData.split(cfg.pattern);
const lastPart = parts[parts.length - 1];
const lastPartWithoutDuplicates = lastPart.replace(
new RegExp(stringToAppend, 'g'),
new RegExp(separator + stringToAppend, 'g'),
''
);
fileData = fileData.replace(lastPart, lastPartWithoutDuplicates);
}

const { separator = '\n' } = cfg;

// add the appended string to the end of the "fileData" if "pattern"
// was not provided, i.e. null or false
if (!cfg.pattern) {
Expand Down

0 comments on commit 3b5aeef

Please sign in to comment.