@@ -29,7 +29,7 @@ export function generateError(conversion: Conversion, message: string, sql: stri
2929 return new Promise < void > ( resolve => {
3030 message += `\n\n\tSQL: ${ sql } \n\n` ;
3131 const buffer : Buffer = Buffer . from ( message , conversion . _encoding ) ;
32- log ( conversion , message , undefined , true ) ;
32+ log ( conversion , message , undefined ) ;
3333
3434 fs . open ( conversion . _errorLogsPath , 'a' , conversion . _0777 , ( error : Error , fd : number ) => {
3535 if ( error ) {
@@ -48,13 +48,10 @@ export function generateError(conversion: Conversion, message: string, sql: stri
4848 * Writes given log to the "/all.log" file.
4949 * If necessary, writes given log to the "/{tableName}.log" file.
5050 */
51- export function log ( conversion : Conversion , log : string | NodeJS . ErrnoException , tableLogPath ?: string , isErrorLog ?: boolean ) : void {
51+ export function log ( conversion : Conversion , log : string | NodeJS . ErrnoException , tableLogPath ?: string ) : void {
52+ console . log ( log ) ;
5253 const buffer : Buffer = Buffer . from ( `${ log } \n\n` , conversion . _encoding ) ;
5354
54- if ( ! isErrorLog ) {
55- console . log ( log ) ;
56- }
57-
5855 fs . open ( conversion . _allLogsPath , 'a' , conversion . _0777 , ( error : Error , fd : number ) => {
5956 if ( ! error ) {
6057 fs . write ( fd , buffer , 0 , buffer . length , null , ( ) => {
@@ -124,28 +121,37 @@ export function readExtraConfig(config: any, baseDir: string): Promise<any> {
124121/**
125122 * Creates logs directory.
126123 */
127- export function createLogsDirectory ( conversion : Conversion ) : Promise < Conversion > {
128- return new Promise < Conversion > ( resolve => {
129- const logTitle : string = 'FsOps::createLogsDirectory' ;
130- console . log ( `\t--[${ logTitle } ] Creating logs directory...` ) ;
124+ export async function createLogsDirectory ( conversion : Conversion ) : Promise < Conversion > {
125+ const logTitle : string = 'FsOps::createLogsDirectory' ;
126+ await createDirectory ( conversion , conversion . _logsDirPath , logTitle ) ;
127+ await createDirectory ( conversion , conversion . _notCreatedViewsPath , logTitle ) ;
128+ return conversion ;
129+ }
130+
131+ /**
132+ * Creates a directory at the specified path.
133+ */
134+ function createDirectory ( conversion : Conversion , directoryPath : string , logTitle : string ) : Promise < void > {
135+ return new Promise < void > ( resolve => {
136+ console . log ( `\t--[${ logTitle } ] Creating directory ${ directoryPath } ...` ) ;
131137
132- fs . stat ( conversion . _logsDirPath , ( directoryDoesNotExist : Error , stat : fs . Stats ) => {
138+ fs . stat ( directoryPath , ( directoryDoesNotExist : Error , stat : fs . Stats ) => {
133139 if ( directoryDoesNotExist ) {
134- fs . mkdir ( conversion . _logsDirPath , conversion . _0777 , e => {
140+ fs . mkdir ( directoryPath , conversion . _0777 , e => {
135141 if ( e ) {
136- console . log ( `\t--[${ logTitle } ] Cannot perform a migration due to impossibility to create "logs_directory" : ${ conversion . _logsDirPath } ` ) ;
142+ console . log ( `\t--[${ logTitle } ] Cannot perform a migration due to impossibility to create directory : ${ directoryPath } ` ) ;
137143 process . exit ( ) ;
138144 } else {
139- log ( conversion , ' \t--[logTitle] Logs directory is created...' ) ;
140- resolve ( conversion ) ;
145+ log ( conversion , ` \t--[${ logTitle } ] Directory ${ directoryPath } is created...` ) ;
146+ resolve ( ) ;
141147 }
142148 } ) ;
143149 } else if ( ! stat . isDirectory ( ) ) {
144150 console . log ( `\t--[${ logTitle } ] Cannot perform a migration due to unexpected error` ) ;
145151 process . exit ( ) ;
146152 } else {
147- log ( conversion , `\t--[${ logTitle } ] Logs directory already exists...` ) ;
148- resolve ( conversion ) ;
153+ log ( conversion , `\t--[${ logTitle } ] Directory ${ directoryPath } already exists...` ) ;
154+ resolve ( ) ;
149155 }
150156 } ) ;
151157 } ) ;
0 commit comments