I need to convert lots of Javascript files replacing import with require. Obviously doing edits by hand would be daunting so I want to automate it with a script. How can I accomplish this using a Unix shell script? Below are the patterns that I would like to replace. All other contents of the file should remain unchanged. Spacing could be inconsistent between tokens..
I was thinking about awk etc but not really familiar with the syntax.
import Foo from 'bar'; -> const Foo = require('bar');
import Foo from "bar"; -> const Foo = require("bar");
import {Foo} from "bar"; -> const {Foo} = require("bar");
import {Foo, Bar, baz as Baz} from 'bar' -> const {Foo, Bar, baz as Baz} = require('bar');