Created
February 1, 2018 14:38
-
-
Save davidgtonge/cc3c86f0e7d5ed8bbe7081a58dd548d9 to your computer and use it in GitHub Desktop.
replace
This file contains 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 replace = require("replace-in-file") | |
const files = "./test/**/*.js" | |
const opts1 = { | |
files, | |
from: /import\s([a-zA-Z]*)\sfrom\s("[a-z\.\/\_\-\@]*")/g, | |
to: (match, p1, p2) => `const ${p1} = require(${p2})`, | |
} | |
const opts2 = { | |
files, | |
from: /import\s"([a-z\.\/\_\-\@]*)"\s*\n/g, | |
to: (match, p1) => `require(${p1})`, | |
} | |
const opts3 = { | |
files, | |
from: /import\s(\{[a-zA-Z\,\s]*})\sfrom\s("[a-z\.\/\_\-\@]*")/g, | |
to: (match, p1, p2) => `const ${p1} = require(${p2})`, | |
} | |
Promise.all([replace(opts1), replace(opts2), replace(opts3)]) | |
.then(changes => { | |
console.log(changes) | |
}) | |
.catch(error => { | |
console.error("Error occurred:", error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment