From 31d7117b357ac4cffdb2c9ee38a23ebcb5be7f19 Mon Sep 17 00:00:00 2001 From: Sam Minton Date: Tue, 31 Oct 2017 15:53:14 +1100 Subject: [PATCH] Modify setup-django.sh to use yarn instead of bower and npm if available re #286, currently setup-django makes the assumption that yarn.lock exists which it may not initially. In order to use BS4 and compile from source, we need to move away from bower (at least to install bootstrap, since bower is deprecated), they recommend using yarn instead. Can we get away with simply using npm and django-compressor? The goal is to have: - bootstrap 3 available to the admin - bootstrap 4 available to the front end - icekit .scss files compiled into the project/overridable where necessary - project .scss files that allow for bootstrap variables and overrides and provide a platform to build on that simplifies frontend setups for icekit sites. - can we get away with using only django-compressor or is yarn/alternative a necessary step? - as simple a setup as possible to avoid painful edge cases and implementation nightmares - sourcemaps would be nice Yarn - use bower-away to convert bower.json to yarn (adds yarn specific syntax to package.json) - yarn requires Ruby > 2.3 - you might need to delete bower_components/.DS_Store if bower-away fails with ENOTDIR --- icekit/bin/setup-django.sh | 3 +++ icekit/bin/yarn.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 icekit/bin/yarn.sh diff --git a/icekit/bin/setup-django.sh b/icekit/bin/setup-django.sh index 6b573bdf..215fd611 100755 --- a/icekit/bin/setup-django.sh +++ b/icekit/bin/setup-django.sh @@ -23,11 +23,14 @@ if [[ -n "$WAITLOCK_ENABLE" ]]; then EOF fi +if [[ -f yarn.lock ]]; then + waitlock.sh yarn.sh "$ICEKIT_PROJECT_DIR" # Install Node modules. waitlock.sh npm-install.sh "$ICEKIT_PROJECT_DIR" # Install Bower components. waitlock.sh bower-install.sh "$ICEKIT_PROJECT_DIR" +fi # Install Python requirements. waitlock.sh pip-install.sh "$ICEKIT_PROJECT_DIR" diff --git a/icekit/bin/yarn.sh b/icekit/bin/yarn.sh new file mode 100644 index 00000000..be03bddb --- /dev/null +++ b/icekit/bin/yarn.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Install Node modules in the given directory via yarn, if they have changed. + +cat < package.json +{ + "name": "$ICEKIT_PROJECT_NAME", + "dependencies": { + }, + "private": true +} +EOF +fi + +touch package.json.md5 + +if [[ ! -s package.json.md5 ]] || ! md5sum --status -c package.json.md5 > /dev/null 2>&1; then + echo "Node modules in '$DIR' directory are out of date." + if [[ -d node_modules ]]; then + echo 'Removing old Node modules directory.' + rm -rf node_modules + fi + yarn + md5sum package.json > package.json.md5 +fi