1
1
const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
2
3
const { DATA_TRANSFORMATIONS_FOLDER_NAME } = require ( '../config/constants' ) ;
3
4
4
5
const createFolderIfNotExist = ( folderPath ) => {
@@ -12,24 +13,20 @@ const createFolderIfNotExist = (folderPath) => {
12
13
} ;
13
14
14
15
const initHandler = async ( { tableNames } ) => {
15
- const baseTransformationsFolderPath = ` ${ process . cwd ( ) } / ${ DATA_TRANSFORMATIONS_FOLDER_NAME } ` ;
16
+ const baseTransformationsFolderPath = path . join ( process . cwd ( ) , DATA_TRANSFORMATIONS_FOLDER_NAME ) ;
16
17
17
18
createFolderIfNotExist ( baseTransformationsFolderPath ) ;
18
19
19
20
tableNames ?. forEach ( ( tableName ) => {
20
21
const isExist = createFolderIfNotExist ( `${ baseTransformationsFolderPath } /${ tableName } ` ) ;
21
22
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' ) ;
24
25
const originFile = fs . readFileSync ( origin , 'utf8' ) ;
25
26
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 } ` ) ;
33
30
}
34
31
} ) ;
35
32
} ;
0 commit comments