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

Fix: file encoding of binary files in template #155

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ function processTemplateFactory(
log.verbose("Copying to output location");
// for other files, simply copy them to the output folder
createNestedDirectories(schema, file, outputFolder);
fs.writeFileSync(`${outputFolder}/${file}`, source);
fs.copyFileSync(
gkocak-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
`${generatorTemplatesPath}/${file}`,
`${outputFolder}/${file}`
);
}
};
}
Expand Down
16 changes: 8 additions & 8 deletions test/generate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe("generate", () => {
skipValidation: true,
output: outDir,
});
console.error(fs.writeFileSync.mock.calls);
expect(fs.writeFileSync).toHaveBeenCalledWith(
`${outDir}/${fileName}.${fileExtension}`,
fakeSchema
console.error(fs.copyFileSync.mock.calls);
expect(fs.copyFileSync).toHaveBeenCalledWith(
`${generatorPath}/template/${fileName}.${fileExtension}`,
`${outDir}/${fileName}.${fileExtension}`
);
});

Expand All @@ -75,7 +75,7 @@ describe("generate", () => {
);
});

it("should copy files in directories", async () => {
it("should copy non-handlebars files in directories", async () => {
const fileShortName = "ExampleFile";
const extension = "java";
const basePath = `somewhere/else`;
Expand All @@ -89,9 +89,9 @@ describe("generate", () => {
skipValidation: true,
output: outDir,
});
expect(fs.writeFileSync).toHaveBeenCalledWith(
`${outDir}/${basePath}/${fileShortName}.${extension}`,
fakeSchema
expect(fs.copyFileSync).toHaveBeenCalledWith(
`${generatorPath}/template/${basePath}/${fileShortName}.${extension}`,
`${outDir}/${basePath}/${fileShortName}.${extension}`
);
});
it("should change the filename of Handlebars files in directories", async () => {
Expand Down