@@ -4,7 +4,7 @@ import nodePath from 'path'
44import { prompt } from 'prompts'
55import recursiveReadDir from 'recursive-readdir'
66import { CONSTANTS } from '../../constants'
7- import { enumPrefixName , enumSnippetName , enumSnippetVariable , enumSuffixName } from '../../enums'
7+ import { enumPrefixName , enumSnippetName , enumSnippetVariable , enumSuffixName , enumSymbol } from '../../enums'
88import type { TypeCase , TypeStringConversionMethod } from '../../types'
99import { ModuleConfig } from '../config'
1010import { ModulePath } from '../path'
@@ -177,17 +177,25 @@ export class ModuleSnippet {
177177 paths . forEach ( ( pathToSnippet ) => {
178178 const data = this . formatSnippet ( pathToSnippet )
179179 const myPath = this . modulePath . generate ( { config, name, path, pathToSnippet } )
180- if ( this . isSnippet ( myPath . pathWriteSnippetFile ) ) throw new Error ( 'isSnippet' )
181- if ( this . isSnippet ( myPath . pathFlatWriteSnippetFile ) ) throw new Error ( 'isSnippet' )
182- fs . mkdirSync ( this . options . isFlat ? myPath . pathFlatSnippetFile : myPath . pathSnippetFile , {
183- recursive : true ,
184- } )
185- fs . writeFileSync (
186- this . options . isFlat ? myPath . pathFlatWriteSnippetFile : myPath . pathWriteSnippetFile ,
187- data
188- )
189- // eslint-disable-next-line no-console
190- console . log ( `${ chalk . green ( `√` ) } ${ chalk . gray ( myPath . snippetFileName ) } ` )
180+ const pathSnippetFile = this . options . isFlat ? myPath . pathFlatSnippetFile : myPath . pathSnippetFile
181+ const pathWriteSnippetFile = this . options . isFlat
182+ ? myPath . pathFlatWriteSnippetFile
183+ : myPath . pathWriteSnippetFile
184+ if ( this . isSnippet ( pathWriteSnippetFile ) ) {
185+ // eslint-disable-next-line no-console
186+ console . log (
187+ `${ chalk . red ( enumSymbol . cross ) } ${ chalk . gray (
188+ `The files ${ myPath . snippetFileName } on the path ${ pathWriteSnippetFile } already exist`
189+ ) } `
190+ )
191+ } else {
192+ fs . mkdirSync ( pathSnippetFile , {
193+ recursive : true ,
194+ } )
195+ fs . writeFileSync ( pathWriteSnippetFile , data )
196+ // eslint-disable-next-line no-console
197+ console . log ( `${ chalk . green ( enumSymbol . check ) } ${ chalk . gray ( myPath . snippetFileName ) } ` )
198+ }
191199 } )
192200 } )
193201 }
0 commit comments