Skip to content

Commit

Permalink
Makefile: improvements for bundle
Browse files Browse the repository at this point in the history
1. Internal 'bundler' target to check that Bundler is installed

2. 'bundle' target for building required gems into the `.vendor/bundle` directory:
    a. This is an alias for `.vendor/bundle` target which depends on Gemfile and Gemfile.lock
    b. It installs/updates bundled gems only if necessary

3. Gemfile target to check that Gemfile is present
   Gemfile.lock target
  • Loading branch information
maxim-belkin committed Jun 24, 2021
1 parent b33336b commit f3d50e8
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

# Settings
MAKEFILES=Makefile $(wildcard *.mk)
JEKYLL=bundle config set --local path .vendor/bundle && bundle install && bundle update && bundle exec jekyll
PARSER=bin/markdown_ast.rb
DST=_site

BUNDLE := $(shell which bundle 2>/dev/null)

# Check Python 3 is installed and determine if it's called via python3 or python
# (https://stackoverflow.com/a/4933395)
PYTHON3_EXE := $(shell which python3 2>/dev/null)
Expand Down Expand Up @@ -38,15 +39,19 @@ endif
## I. Commands for both workshop and lesson websites
## =================================================

.PHONY: site docker-serve repo-check clean clean-rmd
.PHONY: site site-offline docker-serve repo-check clean clean-rmd

## * serve : render website and run a local server
serve : lesson-md index.md
${JEKYLL} serve
serve : lesson-md index.md bundler .vendor/bundle
@bundle exec jekyll serve

## * site : build website but do not run a server
site : lesson-md index.md
${JEKYLL} build
site : update-bundle site-offline
@:

## * site-offline : same as 'site' but doesn't update Ruby gems
site-offline : lesson-md index.md bundler .vendor/bundle
@bundle exec jekyll build

## * docker-serve : use Docker to serve the site
docker-serve :
Expand Down Expand Up @@ -128,6 +133,7 @@ install-rmd-deps:

## * lesson-md : convert Rmarkdown files to markdown
lesson-md : ${RMD_DST}
@:

_episodes/%.md: _episodes_rmd/%.Rmd install-rmd-deps
@mkdir -p _episodes
Expand Down Expand Up @@ -160,9 +166,9 @@ lesson-fixme :
## IV. Auxililary (plumbing) commands
## =================================================

.PHONY : commands python
.PHONY : commands python bundler bundle update-bundle

## * commands : show all commands.
## * commands : show all commands
commands :
@sed -n -e '/^##/s|^##[[:space:]]*||p' $(MAKEFILE_LIST)

Expand All @@ -173,6 +179,40 @@ else
@:
endif

bundler :
ifeq (, $(BUNDLE))
$(error Please install Bundler using 'gem install bundler')
else
@:
endif

## * bundle : install Ruby gems (required for building lesson website locally)
bundle : .vendor/bundle
@:

.vendor/bundle: Gemfile.lock bundler
$(info Installing Ruby gems)
@bundle config set --local path '.vendor/bundle'
@bundle install
@touch .vendor/bundle

## * update-bundle : update Ruby gems (required for building lesson website locally)
update-bundle : Gemfile.lock bundler
$(info Updating Ruby gems)
@bundle config set --local path '.vendor/bundle'
@bundle update --quiet
@touch .vendor/bundle

Gemfile:
ifeq (, $(wildcard Gemfile))
$(error Gemfile not found!)
else
@:
endif

Gemfile.lock: Gemfile bundler
@bundle lock --update

index.md :
ifeq (, $(wildcard index.md))
$(error index.md not found)
Expand Down

0 comments on commit f3d50e8

Please sign in to comment.