diff --git a/CHANGELOG.md b/CHANGELOG.md index 300fa54..e05ea7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### 1.2.3: 2022-09-13 * Modularize check-updates as task +* Simplify get-block task by modularizing create-predefined-block as task ### 1.2.2: 2022-09-12 diff --git a/bin/tasks/create-predefined-block.sh b/bin/tasks/create-predefined-block.sh new file mode 100644 index 0000000..d8e61dc --- /dev/null +++ b/bin/tasks/create-predefined-block.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# All the typical tasks that we do in every single block +# Checking if block already exists +if [[ -f "${PROJECT_THEME_PATH}/template-parts/blocks/${BLOCK_NAME}.php" && -f "${PROJECT_THEME_PATH}/template-parts/blocks/${BLOCK_NAME_TO_RENAME_TO}.php" ]] ; then + echo " +${RED}Block already exists. The newtheme script will now quit...${TXTRESET} + " + exit +else + echo "${YELLOW}Copying ${BLOCK_NAME} block assets...${TXTRESET}" + + # The block file + cp -nv ${AIRBLOCKS_THEME_PATH}/template-parts/blocks/${BLOCK_NAME}.php ${PROJECT_THEME_PATH}/template-parts/blocks/ + + # Styles for block + cp -nv ${AIRBLOCKS_THEME_PATH}/sass/gutenberg/blocks/_${BLOCK_NAME}.scss ${PROJECT_THEME_PATH}/sass/gutenberg/blocks/ + + # Import block styles to _blocks.scss + sed -e "/\/\/ ACF blocks/a\\ + @import 'gutenberg/blocks/${BLOCK_NAME}';" < ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss > ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks_with_changes.scss + rm ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss + mv ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks_with_changes.scss ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss + + # Block icon + mkdir -p ${PROJECT_THEME_PATH}/svg/block-icons + cp -nv ${AIRBLOCKS_THEME_PATH}/svg/block-icons/${BLOCK_NAME}.svg ${PROJECT_THEME_PATH}/svg/block-icons/ +fi + +# Start block import script +if [ -f "${SCRIPTS_LOCATION}/blocks/${BLOCK_NAME}.sh" ]; then + source ${SCRIPTS_LOCATION}/blocks/${BLOCK_NAME}.sh +else + echo " +${RED}Block called $BLOCK_NAME does not exist (yet) in the importer script. Or perhaps you mistyped it?" + exit +fi diff --git a/bin/tasks/get-block.sh b/bin/tasks/get-block.sh index 6cb2d01..541ed19 100644 --- a/bin/tasks/get-block.sh +++ b/bin/tasks/get-block.sh @@ -18,42 +18,7 @@ source ${SCRIPTS_LOCATION}/tasks/acf.sh if [[ $IS_NEW_BLOCK =~ "yes" ]] ; then source ${SCRIPTS_LOCATION}/tasks/create-empty-block.sh else - - # All the typical tasks that we do in every single block - # Checking if block already exists - if [[ -f "${PROJECT_THEME_PATH}/template-parts/blocks/${BLOCK_NAME}.php" && -f "${PROJECT_THEME_PATH}/template-parts/blocks/${BLOCK_NAME_TO_RENAME_TO}.php" ]] ; then - echo " -${RED}Block already exists. The newtheme script will now quit...${TXTRESET} - " - exit - else - echo "${YELLOW}Copying ${BLOCK_NAME} block assets...${TXTRESET}" - - # The block file - cp -nv ${AIRBLOCKS_THEME_PATH}/template-parts/blocks/${BLOCK_NAME}.php ${PROJECT_THEME_PATH}/template-parts/blocks/ - - # Styles for block - cp -nv ${AIRBLOCKS_THEME_PATH}/sass/gutenberg/blocks/_${BLOCK_NAME}.scss ${PROJECT_THEME_PATH}/sass/gutenberg/blocks/ - - # Import block styles to _blocks.scss - sed -e "/\/\/ ACF blocks/a\\ - @import 'gutenberg/blocks/${BLOCK_NAME}';" < ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss > ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks_with_changes.scss - rm ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss - mv ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks_with_changes.scss ${PROJECT_THEME_PATH}/sass/gutenberg/_blocks.scss - - # Block icon - mkdir -p ${PROJECT_THEME_PATH}/svg/block-icons - cp -nv ${AIRBLOCKS_THEME_PATH}/svg/block-icons/${BLOCK_NAME}.svg ${PROJECT_THEME_PATH}/svg/block-icons/ - fi - - # Start block import script - if [ -f "${SCRIPTS_LOCATION}/blocks/${BLOCK_NAME}.sh" ]; then - source ${SCRIPTS_LOCATION}/blocks/${BLOCK_NAME}.sh - else - echo " -${RED}Block called $BLOCK_NAME does not exist (yet) in the importer script. Or perhaps you mistyped it?" - exit - fi + source ${SCRIPTS_LOCATION}/tasks/create-predefined-block.sh fi # Tasks that should be run after block-specific tasks