11const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
23const { DATA_TRANSFORMATIONS_FOLDER_NAME } = require ( '../config/constants' ) ;
34
45const createFolderIfNotExist = ( folderPath ) => {
@@ -12,24 +13,20 @@ const createFolderIfNotExist = (folderPath) => {
1213} ;
1314
1415const initHandler = async ( { tableNames } ) => {
15- const baseTransformationsFolderPath = ` ${ process . cwd ( ) } / ${ DATA_TRANSFORMATIONS_FOLDER_NAME } ` ;
16+ const baseTransformationsFolderPath = path . join ( process . cwd ( ) , DATA_TRANSFORMATIONS_FOLDER_NAME ) ;
1617
1718 createFolderIfNotExist ( baseTransformationsFolderPath ) ;
1819
1920 tableNames ?. forEach ( ( tableName ) => {
2021 const isExist = createFolderIfNotExist ( `${ baseTransformationsFolderPath } /${ tableName } ` ) ;
2122 if ( ! isExist ) {
22- const origin = ` ${ __dirname } / ../config/transformation-template-file.js` ;
23- const destination = ` ${ baseTransformationsFolderPath } / ${ tableName } / v1_script-name.js` ;
23+ const origin = path . join ( __dirname , ' ../config/transformation-template-file.js' ) ;
24+ const destination = path . join ( baseTransformationsFolderPath , tableName , ' v1_script-name.js' ) ;
2425 const originFile = fs . readFileSync ( origin , 'utf8' ) ;
2526 const destinationFile = originFile . replace ( / { { YOUR_ T A B L E _ N A M E } } / g, tableName ) ;
26- fs . writeFile ( destination , destinationFile , 'utf8' , ( error ) => {
27- if ( error ) {
28- console . error ( `Could not write transformation template file for table ${ tableName } ` , error ) ;
29- throw error ;
30- }
31- console . info ( `Transformation template v1.js file has created for ${ tableName } ` ) ;
32- } ) ;
27+
28+ fs . writeFileSync ( destination , destinationFile ) ;
29+ console . info ( `Transformation template v1.js file has created for ${ tableName } ` ) ;
3330 }
3431 } ) ;
3532} ;
0 commit comments