Skip to content

Commit

Permalink
Merge pull request #366 from alarner/main
Browse files Browse the repository at this point in the history
Ensure addMany actions strip extensions correctly on dot files
  • Loading branch information
crutchcorn authored Feb 7, 2023
2 parents 67c0661 + af69444 commit 4140c53
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/node-plop/src/actions/addMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function stripExtensions(shouldStrip, fileName) {
)
return fileName;

return path.parse(maybeFile.name).ext !== ""
return path.parse(maybeFile.name).ext !== "" || maybeFile.name.startsWith(".")
? path.join(maybeFile.dir, maybeFile.name)
: fileName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ describe("addMany-strip-extensions", function () {
expect(fs.existsSync(nonSpecPath)).toBe(true);
expect(fs.existsSync(specPath)).toBe(true);
});

test("Check that dot files generated without hbs extension", () => {
const dotPath = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.gitignore"
);
const dotPathWithExtension = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.eslintrc.cjs"
);

expect(fs.existsSync(dotPath)).toBe(true);
expect(fs.existsSync(dotPathWithExtension)).toBe(true);
});
});
8 changes: 8 additions & 0 deletions packages/node-plop/tests/addMany-strip-extensions/plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export default function (plop) {
templateFiles: "plop-templates/remove-all/*",
abortOnFail: true,
},
{
type: "addMany",
destination: "src/",
stripExtensions: ["hbs"],
templateFiles: "plop-templates/remove-dotfile-hbs/*",
abortOnFail: true,
globOptions: { dot: true },
},
],
});
}

0 comments on commit 4140c53

Please sign in to comment.