diff --git a/bin/cli.js b/bin/cli.js index 5b16585..9c81b0b 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -30,28 +30,24 @@ const replaceTextOnFile = ({ textReplace, arrOfObjectsBeReplaced }) => { - fs.readFile(file, 'utf8', function (err,data) { - let result - if (err) { - return console.error(err); - } - if(arrOfObjectsBeReplaced){ - arrOfObjectsBeReplaced.forEach( obj => { - if(result){ - result = result.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' '); - }else{ - result = data.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' '); - } - }) - }else{ - result = data.replace(textToBeReplaced, textReplace).replace(/^\s*[\r\n]/gm, ' '); - } - - fs.writeFile(file, result, 'utf8', function (err) { - if (err){ - return console.error(err); + const data = fs.readFileSync(file, 'utf8'); + let result + if(arrOfObjectsBeReplaced){ + arrOfObjectsBeReplaced.forEach( obj => { + if(result){ + result = result.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' '); + }else{ + result = data.replace(obj.textToBeReplaced, obj.textReplace).replace(/^\s*[\r\n]/gm, ' '); } - }); + }) + }else{ + result = data.replace(textToBeReplaced, textReplace).replace(/^\s*[\r\n]/gm, ' '); + } + + fs.writeFileSync(file, result, 'utf8', function (err) { + if (err){ + return console.error(err); + } }); } diff --git a/package.json b/package.json index ea465db..1d9ebf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aleleba/create-react-ssr", - "version": "3.0.45", + "version": "3.0.46", "description": "Starter Kit of server side render of react", "bin": "./bin/cli.js", "main": "src/server/index",