Skip to content

Commit c319edc

Browse files
committed
Disabled overwriting existing files
1 parent 25f99ca commit c319edc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

generate.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ let testFileContent = getTestFileContent();
3232
let codeFileName = path.join(filePath, fileName) + '.js';
3333
let testFileName = path.join(filePath, fileName) + '.test.js';
3434

35+
checkForExistingFiles(codeFileName, testFileName); // or exit
36+
3537
writeFile(codeFileName, codeFileContent);
3638
writeFile(testFileName, testFileContent);
3739

40+
/**
41+
* Functions below
42+
*/
43+
3844
// Enforce proper command line usage with exactly 1 parameter
3945
function enforceCommandLineUsage() {
4046
if (process.argv.length !== 3) {
@@ -93,6 +99,19 @@ describe('${fileNameCamelCase}()', () => {
9399
return content;
94100
}
95101

102+
function checkForExistingFiles(...files) {
103+
const existingFiles = files.filter(file => fs.existsSync(file));
104+
105+
if (existingFiles.length > 0) {
106+
const fileString = existingFiles.map(str => ' ' + str).join('\n');
107+
console.error(
108+
'Files already exist:\n%s\n\nAborting... nothing modified.',
109+
fileString
110+
);
111+
process.exit(9);
112+
}
113+
}
114+
96115
function writeFile(fileName, fileContent) {
97116
fs.writeFile(fileName, fileContent, error => {
98117
if (error) {

0 commit comments

Comments
 (0)