Created
June 16, 2019 04:07
-
-
Save neenjaw/69b4ffddee1eb012f49dd0f651d94923 to your computer and use it in GitHub Desktop.
Mixify Exercism Shell Scripts
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
#!/bin/bash | |
EXERCISES=$(cd exercises; ls -d *) | |
for EXERCISE in $EXERCISES | |
do | |
echo "* Attempting mixify: ${EXERCISE}" | |
./mixify_exercise.sh ${EXERCISE} | |
done |
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
#!/bin/bash | |
if [ ! $1 ] | |
then | |
echo "ERROR: Need to supply an exercise to mixify" | |
exit 1 | |
fi | |
EXERCISE=$1 | |
SKIP_FILE="skipped.out" | |
CUSTOMIZED_FILE="customized.out" | |
EX_DIR="./exercises/${EXERCISE}" | |
EX_BKP="./exercises/${EXERCISE}-bkp" | |
if [ -f "${EX_DIR}/mix.exs" ] | |
then | |
echo "SKIP: ${EXERCISE} is already mixified" | |
echo "$EXERCISE" >> $SKIP_FILE | |
exit 1 | |
fi | |
echo "* Mixifying exercise: ${1}" | |
EXAMPLE_FILE="example.exs" | |
EXAMPLE_PATH="${EX_BKP}/${EXAMPLE_FILE}" | |
if [ ! -f "${EX_DIR}/${EXAMPLE_FILE}" ] | |
then | |
echo "> Example file \"${EXAMPLE_FILE}\" doesn't exist, exiting." | |
exit 1; | |
fi | |
CODE_FILE="${EXERCISE//-/_}.exs" | |
if [ ! -f "${EX_DIR}/${CODE_FILE}" ] | |
then | |
echo "> Code file \"${CODE_FILE}\" doesn't exist, specify?" | |
read -p 'Code file name: ' CODE_FILE | |
if [ -z "$CODE_FILE" ] | |
then | |
exit 1 | |
fi | |
echo "$EXERCISE" >> $CUSTOMIZED_FILE | |
fi | |
TEST_FILE="${EXERCISE//-/_}_test.exs" | |
TEST_PATH="${EX_BKP}/${TEST_FILE}" | |
if [ ! -f "${EX_DIR}/${TEST_FILE}" ] | |
then | |
echo "> Test file \"${TEST_FILE}\" doesn't exist, exiting." | |
read -p 'Code file name: ' TEST_FILE | |
if [ -z "$TEST_FILE" ] | |
then | |
exit 1 | |
fi | |
fi | |
README_FILE="README.md" | |
README_PATH="${EX_BKP}/${README_FILE}" | |
if [ ! -f "${EX_DIR}/${README_FILE}" ] | |
then | |
echo "> Test file \"${README_FILE}\" doesn't exist, exiting." | |
exit 1; | |
fi | |
# Move the exercise to a backup directory | |
if [ -d $EXDIR ] | |
then | |
mv "${EX_DIR}" "${EX_BKP}" | |
fi | |
# create a blank mix project | |
mix new "${EX_DIR//-/_}" | |
if [ $EX_DIR != ${EX_DIR//-/_} ] | |
then | |
mv ${EX_DIR//-/_} $EX_DIR | |
fi | |
if [ "$CODE_FILE" != "${EXERCISE}.exs" ] | |
then | |
BASE_CODE_FILE=$(basename --suffix='.exs' "$CODE_FILE") | |
perl -pi -e "s/:${EXERCISE//-/_}/:${BASE_CODE_FILE}/" "${EX_DIR}/mix.exs" | |
fi | |
# copy the example and readme to the new dir | |
cp $EXAMPLE_PATH $EX_DIR | |
cp $README_PATH $EX_DIR | |
# add configure line to <exercise>/test/test_helper.exs | |
TEST_CONFIG="ExUnit.configure(exclude: :pending)" | |
echo $TEST_CONFIG >> "${EX_DIR}/test/test_helper.exs" | |
# trim leading lines from <exercise>_test.exs, | |
# put output into test dir | |
cat "${TEST_PATH}" | perl -ne 'print if /^defmodule/../^end/' > "${EX_DIR}/test/${TEST_FILE}" | |
# Copy the exercise from backup to the lib dir | |
rm "${EX_DIR}/lib/${EXERCISE//-/_}.ex" | |
cp "${EX_BKP}/${CODE_FILE}" "${EX_DIR}/lib/${CODE_FILE%?}" | |
# delete backup | |
# rm -rf $EX_BKP |
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
#!/bin/bash | |
if [ -d "./exercises/$1-bkp" ] && [ -d "./exercises/$1" ] | |
then | |
echo "RESETING \"$1\" TO BASE" | |
rm -rf "./exercises/$1" | |
mv "./exercises/$1-bkp" "./exercises/$1" | |
else | |
echo "NOTHING TO RESET" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment