Created
June 20, 2022 00:14
-
-
Save broskisworld/b9d8d05147dc1eb20203413bb488c59f to your computer and use it in GitHub Desktop.
A quick way to bulk import a bunch of files (Javascript, Typescript, Images, etc.) into a Node.js app
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
# USAGE | |
# get-js-imports [relativeDirectory = '.'] [js var suffix = ''] | |
# EXAMPLES | |
# get-js-imports | |
# get-js-imports ../components | |
# get-js-imports ../media Img | |
# DESCRIPTION | |
# A quick way to bulk import a bunch of files (Javascript, Typescript, Images, etc.) into a Node.js app | |
# Scans relativeDirectory and creates a list import statements like the following that you can copy-paste into your editor of choice | |
# | |
# Current folder contains files this-picture.png, that-vector.svg, and these-files.js | |
# > get-js-imports | |
# ~ import thisPicture from './thisPicture.png'; | |
# ~ import thatVector from './thatVector.svg'; | |
# ~ import theseFiles from './theseFiles.js'; | |
scanDir="$1" | |
# is scan dir blank? | |
if [ -z "$scanDir" ] | |
then | |
scanDir="." | |
fi | |
ls -1 $scanDir | while read -r line; do | |
filename=$(basename -- "$line") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
if [ "$filename" != "$extension" ] | |
then | |
importName=`echo "$filename" | perl -pe 's/-(.)/\u$1/g'` | |
# add suffix if exists | |
echo "import $importName$2 from '$scanDir/$filename';" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment