-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsnjekyll
executable file
·180 lines (142 loc) · 6 KB
/
snjekyll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/make -f
# ^ Shbang is hardcoded as env doesn't allow passing of flags to program
# Review better ways to do this, though /usr/bin/make *should* be fairly
# portable
#------------------------------------------------------------------------------
# - User documentation
#
define USAGE
usage: ./snjekyll <task>
Setup, build and serve a Jekyll based website on a local computer.
Requires an installation of Ruby, including the Ruby development library
and headers.
Available tasks:
setup Install RubyGem requirements into current working directory
build Build the site using `jekyll build`
test Test the built site using `htmlproofer`
Note that this can only be run after a direct build
and will not work in `serve` mode yet.
serve Start a non-detached local jekyll server instance
The site can be viewed at 'http://127.0.0.1:4000' in
your favoured browser. The server will watch for changes
to the site files and rebuild automatically. Simply
refresh your browser to pick up the changes.
update-gems Update installed gems and Gemfile.lock.
If the Gemfile.lock file changes, it must be submitted as a PR.
clean-gems Remove local bundle of gems
clean-site Remove local site generated output and metadata
clean Remove both gems and site
help Print this message
endef
# Export the usage def so it's usable in recipes
export USAGE
#------------------------------------------------------------------------------
# - Global Make configuration
#
# Source directory
SNJEKYLL_SOURCE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# "Binary" directory (where the script is run from)
SNJEKYLL_BINARY_DIR:= $(realpath $(CURDIR))
# Current Jekyll config requires source=binary dirs, so assert this
# - Use SNJEKYLL_BINARY_DIR in later commands to allow future use
# of separate source/build dirs
ifneq ($(SNJEKYLL_BINARY_DIR),$(SNJEKYLL_SOURCE_DIR))
$(error "snjekyll must be run from $(SNJEKYLL_SOURCE_DIR)!")
endif
# Checks for Requirements
UNAME:=$(shell uname)
# 1. ruby command in the PATH
RUBY_VERSION:=$(shell ruby --version 2>/dev/null)
ifndef RUBY_VERSION
$(error "No working ruby executable in the PATH")
endif
# 2. On linuces that requisite ruby-dev package is available for gems
# Can probably use pkg-config to check this, but package name not
# always obvious (ruby, ruby-2.0)
# On macOS we *should* always have it whether using system or Homebrew
ifeq ($(UNAME),Linux)
$(warning "[snjekyll]: NotImplementedYet: check for existence of Ruby development package")
endif
# 3. On macOS with Homebrew, we *may* have a clash with the brewed "xz"
# formula. Should check for this.
ifeq ($(UNAME),Darwin)
HAVE_BREWED_XZ:=$(shell brew ls xz 2>/dev/null)
ifdef HAVE_BREWED_XZ
$(warning "[snjekyll]: Homebrew install of `xz` detected: \
You may see errors in the install of the `nokogiri` gem.\
If so, do `brew unlink xz` and try again. You can relink \
the `xz` formulae after Jekyll installation is complete.")
endif
endif
# Gem/Bundle setup.
# - PATH is auto-exported to recipe commands
# - GEM_HOME needs explicit export
SNJEKYLL_GEM_HOME:=$(SNJEKYLL_BINARY_DIR)/.gem
GEM_HOME:=$(SNJEKYLL_GEM_HOME)
export GEM_HOME
BUNDLE_BINSTUBS:=$(GEM_HOME)/bin
PATH:=$(BUNDLE_BINSTUBS):$(PATH)
# Bundler and Jekyll executables
# - We need these as suitable shorthands, *and* so that we can use full paths
# in recipes. Whilst PATH should help, there appear to be issues with the use
# of this in recipes on macOS.
BUNDLE_EXEC:=$(BUNDLE_BINSTUBS)/bundle
JEKYLL_EXEC:=$(BUNDLE_BINSTUBS)/jekyll
# Site Contents
# `serve` target will start jekyll in watching mode which will
# regenerate automatically (except for changes to _config.yml).
# However, in detach mode we need to rebuild the site
#------------------------------------------------------------------------------
# Targets and Rules
.PHONY: all help usage build serve setup
all: usage
# Usage/help
help: usage
usage:
@echo "$$USAGE"
# Build the site
# TODO: Don't have a big site, so just build without content deps
build: $(JEKYLL_EXEC)
@echo "[snjekyll]: Building site"
@$(BUNDLE_EXEC) exec jekyll build
@echo "[snjekyll]: Site built"
test: $(JEKYLL_EXEC)
@echo "[snjekyll]: htmlproofer test"
@$(BUNDLE_EXEC) exec htmlproofer --log-level debug --url-ignore "Falaise" $(SNJEKYLL_BINARY_DIR)/_site
# Start the local jekyll server in place
# TODO: Review detaching the server, but then need mechanism for shutdown
# using pgrep/pkill (not simple in makefiles due to subshell running
# where pgrep will find itself!
serve: setup
@$(BUNDLE_EXEC) exec jekyll serve
# Install the bundler gem if required
$(BUNDLE_EXEC):
@echo "[snjekyll]: Installing bundler gem locally, this may take some time"
@gem install -V bundler
@echo "[snjekyll]: Done installing bundler"
# Install the jekyll bundle if required
$(JEKYLL_EXEC): $(BUNDLE_EXEC) Gemfile Gemfile.lock
@echo "[snjekyll]: (Re)installing bundle for Jekyll"
@$(BUNDLE_EXEC) install --path $(GEM_HOME) --binstubs=$(GEM_HOME)/bin
@echo "[snjekyll]: Jekyll installed o.k."
# Setup local tools
setup: $(JEKYLL_EXEC)
# Update Gemfile
# See http://bundler.io/v1.16/man/bundle-update.1.html
# Warn user that Gemfile.lock must be commited
update-gems: setup
@echo "[snjekyll]: Updating Gems..."
@$(BUNDLE_EXEC) update
@echo "[snjekyll]: Updated gems, Gemfile.lock status:"
@echo `git status -s Gemfile.lock`
@echo "[snjekyll]: If the above status shows 'M', please commit Gemfile.lock and submit a Pull Request"
# Explicit site clean
clean-site:
@echo "[snjekyll]: Removing generated site and metadata"
@test -e $(BUNDLE_EXEC) && $(BUNDLE_EXEC) exec jekyll clean || echo "[snjekyll]: No bundle command available (this is o.k.)"
# Clean up the local gems
clean-gems:
@echo "[snjekyll]: Removing installed bundles/gems"
@rm -Rf $(SNJEKYLL_GEM_HOME)
# Clean everything (order is important as we require gems to do clean!)
clean: clean-site clean-gems