Created
January 4, 2023 09:59
-
-
Save icodeyou/0a747857b15c617086bffc3ab86f7a3a to your computer and use it in GitHub Desktop.
Script to import assets from folder generated by Figma Export
This file contains hidden or 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
#!/bin/bash | |
# Copyright Rémi Deronzier | |
source ./import_one_figma_asset.sh | |
# variables | |
downloadsFolderName=$DOWNLOADS_FOLDER_NAME | |
downloadsFolderPath="$HOME/$downloadsFolderName" | |
figmaFolderNamePattern="CDA - Production Maquette" | |
allAssetNames=() | |
badDefaultAssetName="ProductionMaquette" | |
shouldStopProgram=false | |
ifsBackup=$IFS | |
# functions | |
getArchiveName() { | |
# Set space as delimiter | |
revBaseFileName=$(echo $1 | sed 's/ //g' | rev) | |
revBaseFileNameWithoutExtension=${revBaseFileName:4} | |
archiveName=$(echo $revBaseFileNameWithoutExtension | rev) | |
} | |
getAssetName() { | |
# Set hyphen as delimiter | |
IFS='-' | |
# Read the split words into an array based on hyphen delimiter | |
read -a strarr <<<"$1" | |
# Print the splitted words | |
assetName=${strarr[${#strarr[@]} - 1]} | |
echo "Extract asset Name : $assetName" | |
# Go back to original delimiter | |
IFS=$ifsBackup | |
} | |
deleteOneAsset() { | |
rm "$assetsFolderPath/$1" | |
rm "$assetsFolderPath/$scaleFactor2/$1" | |
rm "$assetsFolderPath/$scaleFactor3/$1" | |
} | |
deleteAllAssets() { | |
echo "Delete all assets previously imported" | |
for asset in ${allAssetNames[@]}; do | |
deleteOneAsset $asset | |
done | |
} | |
deleteAllArchives() { | |
echo "Delete all archives" | |
rm *"$figmaFolderNamePattern"*.zip | |
} | |
revertAllAssetsImportations() { | |
deleteAllAssets | |
shouldStopProgram=true | |
} | |
# logic | |
main() { | |
cd $downloadsFolderPath | |
for baseArchiveName in *"$figmaFolderNamePattern"*; do | |
echo "Begin processing archive $baseArchiveName" | |
getArchiveName "$baseArchiveName" | |
getAssetName $archiveName | |
if [ "$assetName" == "$badDefaultAssetName" ]; then | |
revertAllAssetsImportations | |
echo "Stop Figma importation assets because asset name is empty" | |
exit | |
fi | |
mainSingleArchive | |
if [ $shouldStopProgram == true ]; then | |
echo "Stop Figma importation assets because one asset already exists in the project" | |
exit | |
fi | |
done | |
deleteAllArchives | |
echo End | |
} | |
# execution | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment