import * as path from "path" ; import { argv } from "yargs" ; import chalk from "chalk" ; import { outputFilePromise } from "../common/utility" ; import { getGenerator } from "../common/base" ; export const generateTask = async ( { env = argv . env || "DEV" , func = argv . func , file = argv . file , object = argv . object , output = argv . output as string , user = argv . user as string , } ) => { try { if ( ! func ) { throw Error ( "Func cannot be empty." ) ; } const resp = await getGenerator ( { func , file , env , object , user } ) ; const outputPath = output ? path . resolve ( output ) : path . resolve ( `./scripts/${ resp . obj . owner }/file_${ object }_${ new Date ( ) . getTime ( ) }.sql` ) ; await outputFilePromise ( outputPath , resp . result ) ; console . log ( `${ outputPath } ${ chalk . green ( "created." ) }` ) ; } catch ( err ) { console . error ( err . message ) ; } } ;