Skip to content

Commit

Permalink
Simplify get-block task by modularizing create-predefined-block as task
Browse files Browse the repository at this point in the history
  • Loading branch information
ronilaukkarinen committed Sep 13, 2022
1 parent 06c92b4 commit 599044e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
36 changes: 36 additions & 0 deletions bin/tasks/create-predefined-block.sh
Original file line number Diff line number Diff line change
@@ -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
37 changes: 1 addition & 36 deletions bin/tasks/get-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 599044e

Please sign in to comment.