-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,041 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ coverage/* | |
documentation/* | ||
node_modules/* | ||
docs/* | ||
esm/* |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ coverage | |
npm-debug.log | ||
yarn-error.log | ||
/docs | ||
/esm |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash -e | ||
|
||
############################## | ||
# CONFIG | ||
############################## | ||
|
||
# The path where the ESM build will be generated. | ||
OUTPUT_PATH="./esm" | ||
# The directory that needs to be copied and transpiled. | ||
SOURCE="./src" | ||
# The path to the transformations jscodeshift will use; this variable exists just to | ||
# avoid writing the long path on each transformation. | ||
CODEMODS_PATH="node_modules/5to6-codemod/transforms" | ||
# The list of transformations needed in order to make the code ESM compatible. | ||
# | ||
# - cjs: changes all 'require' statements to 'import'. | ||
# - exports: changes all `module.exports` statements to `export` . | ||
TRANSFORMATIONS=("cjs" "exports") | ||
|
||
############################## | ||
# EXECUTION | ||
############################## | ||
|
||
# Delete the output path if it already exists and create it again. | ||
rm -rf $OUTPUT_PATH && mkdir $OUTPUT_PATH; | ||
|
||
# Copy all the files that need transpilation. jscodeshift is a tool for codemods, | ||
# so it doesn't transpile from one place to another, so we first need to move the files | ||
# and then transform them. | ||
cp -R "$SOURCE/" "$OUTPUT_PATH"; | ||
# for SOURCE in "${SOURCES[@]}"; | ||
# do cp -R "./$SOURCE" "$OUTPUT_PATH/$SOURCE"; | ||
# done | ||
|
||
# Delete any hidden/configuration file that was copied during the previous step. | ||
find $OUTPUT_PATH -maxdepth 2 -type f -name ".*" -depth -delete; | ||
|
||
# jscodeshift doesn't allow for multiple transformations at once, that's why it needs | ||
# too iterate the list and apply one by one. | ||
for TRANSFORMATION in "${TRANSFORMATIONS[@]}"; | ||
do jscodeshift -t "$CODEMODS_PATH/$TRANSFORMATION.js" $OUTPUT_PATH; | ||
done | ||
|
||
# Add a `package.json` with the `type: 'module'` on the output directory so imports | ||
# from Node native ESM modules won't cause errors. | ||
echo "{ \"type\": \"module\" }" > "$OUTPUT_PATH/package.json"; |
Oops, something went wrong.