From b306a00afc5c0ef522f94460f1d2a7ebe4df3fc4 Mon Sep 17 00:00:00 2001 From: Brian Porter Date: Sun, 24 Oct 2021 19:44:13 -0500 Subject: [PATCH] Add asset build pipeline to Vagrant (only). Builds on #91 to add the existing asset pipeline tooling to (only) the vagrant box. This work conflicts with #90 somewhat. In general, #90 is preferable as it moves things forward and this PR merely meets the project where it's at. If anything, I'd recommend merging this one first, then adapting #90 to: 1. Not use yarn. It's unnecessary. 2. Replace yarn.lock with package-lock.json. 3. Remove the unnecessary yui-compressor from the Vagrantfile provisioning block. --- README.md | 14 ++++++++++++++ Vagrantfile | 10 ++++++++++ build.sh | 15 +++++++++------ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d7911cb..6726f95 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,20 @@ The included `provision/boostrap.sh` script defines all other system-level depen Database credentials will be automatically configured in `cgi-bin/db_start.php` to work with Vagrant. This file is gitignore'd to prevent it from being committed back to the repo with sensitive credentials. +### Building Assets + +The source files for CSS, Javascript and images mostly live in `assets-src/`. + +After editing these files, you must compile them into the published files hosted in `assets/` using `./build.sh`. + +The associated vagrant VM provides all of the necessary depedencies to build assets. + +```shell +$ vagrant ssh -c build.sh +$ git add assets/* +$ git commit -m 'Build fresh assets.' +``` + ## License diff --git a/Vagrantfile b/Vagrantfile index 08378b5..c682c56 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -66,6 +66,16 @@ Vagrant.configure('2') do |config| echo 'cd #{conf[:PROJECT_ROOT]}' >> ~/.profile fi + echo '## Installing development dependencies.' + curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - + sudo apt-get -yqq install \ + yui-compressor \ + inkscape \ + nodejs + + sudo npm install -g less less-plugin-clean-css + + VAGRANTONLYSCRIPT # TODO: Define a safety trigger to export MySQL data before destroying the VM. diff --git a/build.sh b/build.sh index a6c661a..5bbaef3 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,8 @@ #!/bin/bash +#YUI=java -jar bin/yuicompressor-2.4.8.jar +YUI=yui-compressor + echo "Checking for folders and clearing them..." rm -r ./assets/css/ @@ -29,7 +32,7 @@ cat \ assets-src/css/style.less \ | sed "s/dc=0/dc=${spritedc}/" \ | lessc --clean-css - \ - | java -jar bin/yuicompressor-2.4.8.jar --type=css \ + | $YUI --type=css \ > ./assets/css/compiled.css echo "Converting print LESS and compressing output CSS..." @@ -37,7 +40,7 @@ echo "Converting print LESS and compressing output CSS..." cat \ assets-src/css/print.less \ | lessc --clean-css - \ - | java -jar bin/yuicompressor-2.4.8.jar --type=css \ + | $YUI --type=css \ > ./assets/css/compiled_print.css echo "Combining and compressing global JS..." @@ -46,7 +49,7 @@ cat \ assets-src/js/jquery-3.2.1.min.js \ assets-src/js/jquery-migrate-3.0.1.min.js \ assets-src/js/global.js \ - | java -jar bin/yuicompressor-2.4.8.jar --type=js \ + | $YUI --type=js \ > ./assets/js/global.js echo "Combining and compressing app JS..." @@ -58,14 +61,14 @@ cat \ assets-src/js/Mapper.js \ assets-src/js/GUI.js \ assets-src/js/mapping.js \ - | java -jar bin/yuicompressor-2.4.8.jar --type=js \ + | $YUI --type=js \ > ./assets/js/compiled_app.js echo "Combining and compressing keyboard shortcut JS..." cat \ assets-src/js/keyboard.js \ - | java -jar bin/yuicompressor-2.4.8.jar --type=js \ + | $YUI --type=js \ > ./assets/js/keyboard.js echo "Updating and compressing service worker JS..." @@ -77,7 +80,7 @@ indexsum="$(md5sum index.php | cut -c -5)" cat \ assets-src/js/service-worker.js \ | sed "s/my-site-cache-v1/${contentsum}-${assetssum}-${indexsum}/" \ - | java -jar bin/yuicompressor-2.4.8.jar --type=js \ + | $YUI --type=js \ > ./assets/js/service-worker.js echo "Build complete!"