-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathesm.sh
More file actions
executable file
·19 lines (15 loc) · 822 Bytes
/
esm.sh
File metadata and controls
executable file
·19 lines (15 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
# Define the directory to start the search
root_directory="dist/esm"
echo "Adding .js extension to relative imports in files:"
# Find all JavaScript files and iterate through them and add the .js extension to relative imports
find "$root_directory" -type f -name "*.js" | while read -r file; do
sed -i.bak -E "s/(import .* from '[.]{0,2}\/[^']*)'/\1.js'/g" "$file"
sed -i.bak -E "s/(import \* as .* from '[.]{0,2}\/[^']*)'/\1.js'/g" "$file"
sed -i.bak -E "s/(export \* as .* from '[.]{0,2}\/[^']*)'/\1.js'/g" "$file"
done
# Remove all backup files
find "$root_directory" -type f -name "*.bak" -exec rm {} +
echo -e "\nCreating package.json file in $root_directory"
# Create a package.json file to indicate that this is an ESM package
echo '{ "type": "module" }' > "$root_directory/package.json"