Skip to content

Instantly share code, notes, and snippets.

@richardtape
Created May 7, 2015 23:39
Show Gist options
  • Save richardtape/1a6f9915482aa9c1d960 to your computer and use it in GitHub Desktop.
Save richardtape/1a6f9915482aa9c1d960 to your computer and use it in GitHub Desktop.
Create multiple composer.json files automatically with name of directory and push to repos
# Scenario: You have a lot (say, 200+) plugins/themes/whatevers that you need to add to a composer setup
# and none of them have composer.json files. Also, none of them are on a git repo anywhere
# Here's how I solved this problem which would have taken days to do manually
# To get git repo in each directory and then push existing code to appropriate repo
for d in ./*/ ; do (cd "$d" && git init); done
for d in ./*/ ; do (cd "$d" && git add .); done
# To allow an empty commit message, don't judge me
git config --global alias.nccommit 'commit -a --allow-empty-message -m ""'
for d in ./*/ ; do (cd "$d" && git nccommit); done
# ${PWD##*/} is *just* the current directory of the PWD path
for d in ./*/ ; do (cd "$d" && git remote add origin [email protected]:ctlt-plugins/"${PWD##*/}".git); done
for d in ./*/ ; do (cd "$d" && git push origin master); done
# Add an empty composer.json file to each of these dirs
for d in ./*/ ; do (cd "$d" && touch composer.json); done
# Create a default.json file which contains normal composer.json stuff but with a placeholder of {{NAME}} in the name attribute i.e.
# "name": "ubc/{{NAME}}",
# Copy this default content into each of the newly made composer.json files
for d in ./*/ ; do (cd "$d" && cat ~/sites/path/default.json >> composer.json); done
# Do a S&R for that placeholder with the PWD directory name - OS X bash requires the use of a backup file, so create with custom nam to easily delete
for d in ./*/ ; do (cd "$d" && sed -i .bakjson "s/{{NAME}}/${PWD##*\/}/g" composer.json); done
# Delete that backup file
for d in ./*/ ; do (cd "$d" && rm composer.json.bakjson); done
# Add and commit those composer.json files and push
for d in ./*/ ; do (cd "$d" && git add .); done
for d in ./*/ ; do (cd "$d" && git nccommit); done
for d in ./*/ ; do (cd "$d" && git push origin master); done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment