Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/node-plop/src/actions/addMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ function dropFileRootFolder(file) {
function stripExtensions(shouldStrip, fileName) {
const maybeFile = path.parse(fileName);

if (
Array.isArray(shouldStrip) &&
!shouldStrip.map((item) => `.${item}`).includes(maybeFile.ext)
)
return fileName;
if (Array.isArray(shouldStrip)) {
return shouldStrip.map((item) => `.${item}`).includes(maybeFile.ext)
? path.join(maybeFile.dir, maybeFile.name)
: fileName;
}

return path.parse(maybeFile.name).ext !== "" || maybeFile.name.startsWith(".")
? path.join(maybeFile.dir, maybeFile.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ describe("addMany-strip-extensions", function () {
});

test("Check that dot files generated without hbs extension", () => {
const dotPath = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.gitignore"
);
const dotPath = path.resolve(testSrcPath, "remove-dotfile-hbs/.gitignore");
const dotPathWithExtension = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.eslintrc.cjs"
Expand All @@ -50,4 +47,18 @@ describe("addMany-strip-extensions", function () {
expect(fs.existsSync(dotPath)).toBe(true);
expect(fs.existsSync(dotPathWithExtension)).toBe(true);
});

test("Check that hbs is removed even when there are no other extensions", () => {
const noExtensionPath = path.resolve(
testSrcPath,
"remove-noextension-hbs/Dockerfile"
);
const extensionPath = path.resolve(
testSrcPath,
"remove-noextension-hbs/Dockerfile.test"
);

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