Skip to content

Commit

Permalink
Makefile: create a target netlify-build. Do not git clean before …
Browse files Browse the repository at this point in the history
…a `yarn start`.
  • Loading branch information
JulioJu committed Sep 20, 2020
1 parent 12157c2 commit 8e9a409
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
71 changes: 54 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := start

.PHONY: start start_netlify build build_preview clean _common _build_common
.PHONY: start start-netlify netlify-build netlify-build-preview clean _common _netlify-build-common

# ==============================================================================
# Run Netlify in watch mode
Expand All @@ -12,7 +12,8 @@ start:
# -v, --verbose verbose output
yarn hugo server -s site -v

start_netlify:
# Target to test netlify-cms locally
start-netlify:
make _common
netlify-cms-proxy-server &
sleep 3
Expand All @@ -23,16 +24,16 @@ start_netlify:
# ==============================================================================

# Target used by Netlify to build the prod version.
build:
make _build_common
netlify-build:
make _netlify-build-common
# -s, --source string filesystem path to read files relative from
# -d, --destination string filesystem path to write files to
# -v, --verbose verbose output
yarn hugo -s site -d ../dist -v

# Target used by Netlify to build his preview
build_preview:
make _build_common
netlify-build-preview:
make _netlify-build-common
# -s, --source string filesystem path to read files relative from
# -d, --destination string filesystem path to write files to
# -D, --buildDrafts include content marked as draft
Expand All @@ -41,28 +42,64 @@ build_preview:
yarn hugo -s site -d ../dist -D -F -v

clean:
# We should clean the repo, because Netlify does not clean the repo
# Options `-f -f` is not an error. See https://github.com/sogilis/Blog/pull/160#discussion_r422919097
# Following is advised by GitLab CI https://docs.gitlab.com/ee/ci/yaml/#git-clean-flags
# Remove untracked files (files referenced into `.gitignore` include),
# but we exclude `node_modules`.
# Following command is advised by GitLab CI, read:
# https://docs.gitlab.com/ee/ci/yaml/#git-clean-flags
git clean -f -f -d -x -e node_modules


# ==============================================================================
# Private target (used by other targets above, but no sens to use outside)
# ==============================================================================

_common:
make clean
yarn install --network-timeout 3000 --prefer-offline
yarn lint
yarn prettier:check
# reboot.css
rm -f ./site/themes/sogilis/assets/css/reboot.min.css
cp ./node_modules/bootstrap-reboot/dist/reboot.min.css* ./site/themes/sogilis/assets/css/
# netlifh-cms
cp ./node_modules/netlify-cms/dist/netlify-cms.js* ./site/static/admin/
## fonts
# fonts
rm -rf ./site/themes/sogilis/static/css/typeface-montserrat
cp -R ./node_modules/typeface-montserrat ./site/themes/sogilis/static/css/typeface-montserrat
rm -rf ./site/themes/sogilis/static/css/typeface-eb-garamond
cp -R ./node_modules/typeface-eb-garamond ./site/themes/sogilis/static/css/typeface-eb-garamond
# COPY netlify-cms
rm -f ./site/static/admin/netlify-cms.js*
cp ./node_modules/netlify-cms/dist/netlify-cms.js* ./site/static/admin/
# Remove Hugo temp files
rm -rf site/resources/

_build_common:
_netlify-build-common:
# TESTS to know if repo is clean for build
# =========================================
# Test if we have unstaged changes is not a necessity
# (`git clean` does not checkout them) but it's a good practice.
@if ! git diff --quiet --exit-code ; \
then \
>&2 echo -e "\n\n\\033[4;31mERROR:" \
"You have changes not staged for commit" \
"(see them thanks \`git status')." \
"Use \`git add' to add changes into the git stagging area," \
"or remove this changes.\\033[0m\n\n" ; \
exit 10 ; \
else \
echo -e '\nCool, you have no unstaged changes\n' ; \
fi
# Following test is needed otherwise `git clean` remove also untracked files not
# added into (.gitignore).
@if [[ "$$(git ls-files --others --exclude-standard | wc -l)" -gt 0 ]] ; \
then \
>&2 echo -e "\n\n\\033[4;31mERROR:" \
"You have untracked files" \
"not added into '.gitignore' (see them thanks \`git status')." \
"Use \`git add' to add files into the git stagging area," \
"or remove this files.\\033[0m\n\n" ; \
exit 11 ; \
else \
echo -e "\nCool, you have no untracked files not included" \
"into '.gitignore'\n" ; \
fi
# We dont check if we have staged and not commited changes.
make clean
make _common
yarn lint
yarn prettier:check
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"scripts": {
"start": "make start",
"start:netlify": "make start_netlify",
"build": "make build",
"build:preview": "make build_preview",
"build": "make netlify-build",
"build:preview": "make netlify-build-preview",
"prettier:format": "prettier --write \"{,site/**/}*.{json,ts,css,scss,yml}\"",
"prettier:check": "prettier --check \"{,site/**/}*.{json,ts,css,scss,yml}\"",
"lint": "eslint . --ext .js,.ts",
Expand Down
2 changes: 2 additions & 0 deletions site/themes/sogilis/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
content="{{ .Summary | default .Site.Params.SiteDescription }}"
/>

<!-- TODO generate only one CSS file with Webpack. Use also auto-prefixer -->

<link
rel="stylesheet"
href="{{ "css/typeface-eb-garamond/index.css" | relURL }}"
Expand Down

0 comments on commit 8e9a409

Please sign in to comment.