File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -32,9 +32,15 @@ let testFileContent = getTestFileContent();
32
32
let codeFileName = path . join ( filePath , fileName ) + '.js' ;
33
33
let testFileName = path . join ( filePath , fileName ) + '.test.js' ;
34
34
35
+ checkForExistingFiles ( codeFileName , testFileName ) ; // or exit
36
+
35
37
writeFile ( codeFileName , codeFileContent ) ;
36
38
writeFile ( testFileName , testFileContent ) ;
37
39
40
+ /**
41
+ * Functions below
42
+ */
43
+
38
44
// Enforce proper command line usage with exactly 1 parameter
39
45
function enforceCommandLineUsage ( ) {
40
46
if ( process . argv . length !== 3 ) {
@@ -93,6 +99,19 @@ describe('${fileNameCamelCase}()', () => {
93
99
return content ;
94
100
}
95
101
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
+
96
115
function writeFile ( fileName , fileContent ) {
97
116
fs . writeFile ( fileName , fileContent , error => {
98
117
if ( error ) {
You can’t perform that action at this time.
0 commit comments