-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(cjs): adapt script for converting js to cjs files to run in mul…
…tiple platform
- Loading branch information
Showing
5 changed files
with
41 additions
and
15 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
echo "" | ||
echo "Converting .js files to .cjs" | ||
echo "" | ||
|
||
build_folder="$1" | ||
|
||
if [ -z "${build_folder}" ]; then | ||
echo "\033[0;31mYou must provide a path to aim your build folder" | ||
exit 125 | ||
fi | ||
|
||
if [ ! -d "${build_folder}" ]; then | ||
echo "\033[0;31m${build_folder} folder does not exist" | ||
exit 125 | ||
fi | ||
|
||
files=$(find ${build_folder} -name "*.js") | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "\033[0;31m find command failed" | ||
exit 125 | ||
fi | ||
|
||
for path in $files; do | ||
echo "Converting $path" | ||
|
||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
sed -r -i'' "s/(require ?[^\"]+\"([^\"]+))\.js/\1.cjs/" "$path" | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
sed -r -i '' "s/(require ?[^\"]+\"([^\"]+))\.js/\1.cjs/" "$path" | ||
fi | ||
|
||
mv "$path" "${path/%.js/.cjs}" | ||
done | ||
|
||
echo "" | ||
echo "Done converting files to .cjs" | ||
echo "" |
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
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