function uploadArtifactsToS3() {
    const walkSync = (currentDirPath, callback) => {
        fs.readdirSync(currentDirPath).forEach((name) => {
            const filePath = path.join(currentDirPath, name);
            const stat = fs.statSync(filePath);
            if (stat.isFile()) {
                callback(filePath, stat);
            } else if (stat.isDirectory()) {
                walkSync(filePath, callback);
            }
        });
    };

    walkSync(uploadFolder, async (filePath) => {
        let bucketPath = filePath.substring(uploadFolder.length - 1);
        let params = {
            Bucket: process.env.SOURCE_BUCKET || 'bucket',
            Key: `${bucketPath}`,
            Body: fs.readFileSync(filePath)
        };
        try {
            await s3.putObject(params).promise();
            console.log(`Successfully uploaded ${bucketPath} to s3 bucket`);
            await fs.promises.unlink(filePath);
        } catch (error) {
            console.error(`error in uploading ${bucketPath} to s3 bucket`);
            throw new Error(`error in uploading ${bucketPath} to s3 bucket`);
        }
    });
}
// pretty ugly - no await but works
pretty ugly - no await but works
pretty ugly - no await but works
function uploadArtifactsToS3() {
    const walkSync = (currentDirPath, callback) => {
        fs.readdirSync(currentDirPath).forEach((name) => {
            const filePath = path.join(currentDirPath, name);
            const stat = fs.statSync(filePath);
            if (stat.isFile()) {
                callback(filePath, stat);
            } else if (stat.isDirectory()) {
                walkSync(filePath, callback);
            }
        });
    };
    walkSync(uploadFolder, async (filePath) => {
        let bucketPath = filePath.substring(uploadFolder.length - 1);
        let params = {
            Bucket: process.env.SOURCE_BUCKET || 'bucket',
            Key: `${bucketPath}`,
            Body: fs.readFileSync(filePath)
        };
        try {
            await s3.putObject(params).promise();
            console.log(`Successfully uploaded ${bucketPath} to s3 bucket`);
            await fs.promises.unlink(filePath);
        } catch (error) {
            console.error(`error in uploading ${bucketPath} to s3 bucket`);
            throw new Error(`error in uploading ${bucketPath} to s3 bucket`);
        }
    });
}
function uploadArtifactsToS3 ( ) { const walkSync = ( currentDirPath , callback ) => { fs . readdirSync ( currentDirPath ) . forEach ( ( name ) => { const filePath = path . join ( currentDirPath , name ) ; const stat = fs . statSync ( filePath ) ; if ( stat . isFile ( ) ) { callback ( filePath , stat ) ; } else if ( stat . isDirectory ( ) ) { walkSync ( filePath , callback ) ; } } ) ; } ; walkSync ( uploadFolder , async ( filePath ) => { let bucketPath = filePath . substring ( uploadFolder . length - 1 ) ; let params = { Bucket : process . env . SOURCE_BUCKET || 'bucket' , Key : ` ${ bucketPath } ` , Body : fs . readFileSync ( filePath ) } ; try { await s3 . putObject ( params ) . promise ( ) ; console . log ( ` ${ bucketPath } ` ) ; await fs . promises . unlink ( filePath ) ; } catch ( error ) { console . error ( ` ${ bucketPath } ` ) ; throw new Error ( ` ${ bucketPath } ` ) ; } } ) ; }
pretty ugly - no await but works
pretty ugly - no await but works