Created
March 2, 2017 06:06
-
-
Save tscanlin/df012c6277a66246ea54318176f2c260 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exec = require('child_process').exec | |
exec("npm --save uninstall react react-dom", (err, o) => { | |
console.log(err, o); | |
}) | |
exec("npm --save install preact preact-compat", (err, o) => { | |
console.log(err, o); | |
}) | |
function stringExists(options, callback) { | |
console.log('grep -rl "' + options.searchString + '" ' + options.filePattern) | |
exec('grep -rl "' + options.searchString + '" ' + options.filePattern, (err, o) => { | |
// console.log(err, o) | |
callback(o !== '') | |
}) | |
} | |
function findReplaceInFiles(options, callback) { | |
// find ./node_modules/react-scripts/config/*.config.* -type f -exec sed -i 's/alias: {/alias: {\n \'react\': \'preact-compat\',\n \'react-dom\': \'preact-compat\',/gi' {} ; | |
console.log("find " + options.filePattern + " -type f -exec sed -i \"s/" + options.searchString + "/" + options.replaceString + "/gi\" {} \\;"); | |
return exec("find " + options.filePattern + " -type f -exec sed -i \"s/" + options.searchString + "/" + options.replaceString + "/gi\" {} \\;", callback) | |
} | |
stringExists({ | |
filePattern: './node_modules/react-scripts/config/', | |
searchString: 'preact-compat', | |
}, | |
(bool) => { | |
console.log(bool); | |
// if (!bool) { | |
findReplaceInFiles({ | |
filePattern: './node_modules/react-scripts/config/*.config.*', | |
searchString: 'alias: {', | |
replaceString: "alias: {\\n\\t\\t\\t\\'react\\': \\'preact-compat\\',\\n\\t\\t\\t\\'react-dom\\': \\'preact-compat\\'," | |
}, (err, o) => { | |
console.log(err, o) | |
}) | |
// } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment