Skip to content

Commit

Permalink
REFACTOR lib.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
nilswindisch committed Mar 7, 2018
1 parent b617540 commit afa22da
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 216 deletions.
220 changes: 4 additions & 216 deletions bin/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@
# shellcheck disable=SC2154
# shellcheck disable=SC2086


function browsersyncReload() {
log "🏁 BROWSERSYNC reload"
./node_modules/.bin/browser-sync \
reload \
--url http://${npm_package_config_url}:${npm_package_config_browsersync_port}
}

function browsersyncStart() {
log "🎬 BROWSERSYNC start"
./node_modules/.bin/browser-sync \
start \
-c ./browsersync.json \
--server ./serve \
--port "${npm_package_config_browsersync_port}" \
--ui-port "${npm_package_config_browsersync_uiport}"
}
source ./bin/lib/browsersync.sh
source ./bin/lib/postcss.sh
source ./bin/lib/image.sh
source ./bin/lib/jekyll.sh


function sassdoc() {
Expand All @@ -38,102 +25,6 @@ function cssCleanup() {
rm -r ./assets/css/*
}

function postcssO() {
if [ "$npm_package_config_postcss_o_active" = "true" ]; then
log "πŸ—οΈ PostCSS CSSO"
./node_modules/.bin/csso \
./assets/css/style.css \
./assets/css/style.css
else
log "πŸ—οΈ (PostCSS CSSO deactived)"
fi
}

function postcssPrefix() {
if [ "$npm_package_config_postcss_prefix_active" = "true" ]; then
log "πŸ—οΈ PostCSS Prefix"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u autoprefixer \
-b "${npm_package_config_css_prefix_versions}" \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Prefix deactived)"
fi
}

function postcssFontvalues() {
if [ "$npm_package_config_postcss_fontvalues_active" = "true" ]; then
log "πŸ—οΈ PostCSS Font Values"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u postcss-minify-font-values \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Font Values deactivated)"
fi
}

function postcssCalc() {
if [ "$npm_package_config_postcss_calc_active" = "true" ]; then
log "πŸ—οΈ PostCSS Calc"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u postcss-calc \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Calc deactivated)"
fi
}

function postcssCustomproperties() {
if [ "$npm_package_config_postcss_customproperties_active" = "true" ]; then
log "πŸ—οΈ PostCSS Custom Properties"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u postcss-custom-properties \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Custom Properties deactivated)"
fi
}

function postcssObjectfit() {
if [ "$npm_package_config_postcss_objectfit_active" = "true" ]; then
log "πŸ—οΈ PostCSS Objectfit"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u postcss-object-fit-images \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Objectfit deactivated)"
fi
}

function postcssSelectornot() {
if [ "$npm_package_config_postcss_selectornot_active" = "true" ]; then
log "πŸ—οΈ PostCSS Selector Not"
./node_modules/.bin/postcss \
./assets/css/style.css \
-m \
-u postcss-selector-not \
-o ./assets/css/style.css \
--verbose
else
log "πŸ—οΈ (PostCSS Selector Not deactivated)"
fi
}

function cssCopyToJekyll() {
log "πŸ—οΈ CSS copy to jekyll"
mkdir ./jekyll/assets/css
Expand All @@ -154,109 +45,6 @@ function distCleanup() {



function imgBuild() {
imgOptimize
imgMakeWebp
imgCopyToJekyll
}

function imgOptimize() {
mkdir ./assets/img/optimized/
log "πŸ—οΈ IMG optimize JPG"
# JPG
./node_modules/.bin/imagemin \
./assets/img/original/**.{jpg,jpeg} \
--out-dir=./assets/img/optimized/

# SVG
log "πŸ—οΈ IMG optimize SVG"
./node_modules/.bin/imagemin \
./assets/img/original/**.svg \
--plugin=svgo \
--out-dir=./assets/img/optimized/

# PNG
log "πŸ— IMG optimize PNG"
./node_modules/.bin/imagemin \
./assets/img/original/**.png \
--plugin=pngcrush \
--out-dir=./assets/img/optimized/
}

function imgMakeWebp() {
if [ "$npm_package_config_img_webp_active" = "true" ]; then
log "πŸ—οΈ IMG make WebP"
./node_modules/.bin/imagemin \
./assets/img/original/**.{jpg,jpeg} \
--plugin=webp \
--out-dir=./assets/img/optimized/
else
log "πŸ—οΈ (IMG make WebP deactivated)"
fi
}

function imgCopyToJekyll() {
log "πŸ—οΈ IMG copy to jekyll"
mkdir ./jekyll/assets/img
cp ./assets/img/optimized/**.* ./jekyll/assets/img
}

function imgWatch() {
log "😳 IMG watch"
./node_modules/.bin/nodemon \
-e jpeg,jpg,png,svg,gif \
--watch assets/img/original \
-x "./bin/img-build.sh"
}

function imgCleanup() {
log "πŸ—‘οΈ IMG Clean-Up"
rm -r ./assets/img/optimized/*
}





function jekyllBuildDist() {
log "πŸ—οΈ JEKYLL build [DIST]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml,jekyll_config_dist.yml
}

function jekyllBuildNetlify() {
log "πŸ—οΈ JEKYLL build [NETLIFY]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml,jekyll_config_netlify.yml
}

function jekyllBuildDev() {
log "πŸ—οΈ JEKYLL build [DEV]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml
}

function jekyllCleanup() {
log "πŸ—‘οΈ JEKYLL Clean-Up"
rm -r ./jekyll/assets/img/*
rm -r ./jekyll/assets/css/*
}

function jekyllWatchDev() {
log "😳 JEKYLL watch"
./node_modules/.bin/nodemon \
-e md,html,css,js,png,jpg,jpeg,svg \
--watch jekyll \
-x "./bin/jekyll-build--dev.sh; ./bin/browsersync-reload.sh;"
}





function log() {
echo "$1 | $(date '+%Y-%m-%d %H:%M:%S')" >> ./${npm_package_config_log_file}
}
Expand Down
21 changes: 21 additions & 0 deletions bin/lib/browsersync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# shellcheck disable=SC2154
# shellcheck disable=SC2086


function browsersyncReload() {
log "🏁 BROWSERSYNC reload"
./node_modules/.bin/browser-sync \
reload \
--url http://${npm_package_config_url}:${npm_package_config_browsersync_port}
}

function browsersyncStart() {
log "🎬 BROWSERSYNC start"
./node_modules/.bin/browser-sync \
start \
-c ./browsersync.json \
--server ./serve \
--port "${npm_package_config_browsersync_port}" \
--ui-port "${npm_package_config_browsersync_uiport}"
}
63 changes: 63 additions & 0 deletions bin/lib/image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# shellcheck disable=SC2154
# shellcheck disable=SC2086

function imgBuild() {
imgOptimize
imgMakeWebp
imgCopyToJekyll
}

function imgOptimize() {
mkdir ./assets/img/optimized/
log "πŸ—οΈ IMG optimize JPG"
# JPG
./node_modules/.bin/imagemin \
./assets/img/original/**.{jpg,jpeg} \
--out-dir=./assets/img/optimized/

# SVG
log "πŸ—οΈ IMG optimize SVG"
./node_modules/.bin/imagemin \
./assets/img/original/**.svg \
--plugin=svgo \
--out-dir=./assets/img/optimized/

# PNG
log "πŸ— IMG optimize PNG"
./node_modules/.bin/imagemin \
./assets/img/original/**.png \
--plugin=pngcrush \
--out-dir=./assets/img/optimized/
}

function imgMakeWebp() {
if [ "$npm_package_config_img_webp_active" = "true" ]; then
log "πŸ—οΈ IMG make WebP"
./node_modules/.bin/imagemin \
./assets/img/original/**.{jpg,jpeg} \
--plugin=webp \
--out-dir=./assets/img/optimized/
else
log "πŸ—οΈ (IMG make WebP deactivated)"
fi
}

function imgCopyToJekyll() {
log "πŸ—οΈ IMG copy to jekyll"
mkdir ./jekyll/assets/img
cp ./assets/img/optimized/**.* ./jekyll/assets/img
}

function imgWatch() {
log "😳 IMG watch"
./node_modules/.bin/nodemon \
-e jpeg,jpg,png,svg,gif \
--watch assets/img/original \
-x "./bin/img-build.sh"
}

function imgCleanup() {
log "πŸ—‘οΈ IMG Clean-Up"
rm -r ./assets/img/optimized/*
}
38 changes: 38 additions & 0 deletions bin/lib/jekyll.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# shellcheck disable=SC2154
# shellcheck disable=SC2086

function jekyllBuildDist() {
log "πŸ—οΈ JEKYLL build [DIST]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml,jekyll_config_dist.yml
}

function jekyllBuildNetlify() {
log "πŸ—οΈ JEKYLL build [NETLIFY]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml,jekyll_config_netlify.yml
}

function jekyllBuildDev() {
log "πŸ—οΈ JEKYLL build [DEV]"
bundle exec \
jekyll build \
--config jekyll_config_base.yml
}

function jekyllCleanup() {
log "πŸ—‘οΈ JEKYLL Clean-Up"
rm -r ./jekyll/assets/img/*
rm -r ./jekyll/assets/css/*
}

function jekyllWatchDev() {
log "😳 JEKYLL watch"
./node_modules/.bin/nodemon \
-e md,html,css,js,png,jpg,jpeg,svg \
--watch jekyll \
-x "./bin/jekyll-build--dev.sh; ./bin/browsersync-reload.sh;"
}
Loading

0 comments on commit afa22da

Please sign in to comment.