const fs = require('fs');

async function readAndReplaceFileContent(path, writeFn) {
    const content = fs.readFileSync(path, 'utf-8');
    return Promise.resolve().then(() => {    
        return writeFn && writeFn(content);
    }).then((modifiedContent) => {
        if (modifiedContent !== undefined && modifiedContent !== null) {
            fs.writeFileSync(path, modifiedContent);
            return modifiedContent;
        }
        return content;
    });
}

// Temporary patch to be removed; fix coming in future
async function patchCssToReactnative(){
    let packagePath = `${__dirname}/../node_modules/css-to-react-native/index.js`;
      if (fs.existsSync(packagePath)) {
          await readAndReplaceFileContent(packagePath, (c) => {
              if(c.includes('boxShadow: boxShadow,')){
                  return c.replace('boxShadow: boxShadow,', '')
              }
              });
          console.log('Patched css-to-react-native.')
      }
}

function patch() {
    patchCssToReactnative();
}

patch();