Skip to content

Commit

Permalink
Add asset build pipeline to Vagrant (only).
Browse files Browse the repository at this point in the history
Builds on davmillar#91 to add the existing asset pipeline tooling to (only) the vagrant box.

This work conflicts with davmillar#90 somewhat. In general, davmillar#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 davmillar#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.
  • Loading branch information
beporter committed Oct 25, 2021
1 parent 40e5603 commit 3d6ad8a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 10 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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.
Expand Down
15 changes: 9 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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/
Expand Down Expand Up @@ -29,15 +32,15 @@ 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..."

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..."
Expand All @@ -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..."
Expand All @@ -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..."
Expand All @@ -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!"

0 comments on commit 3d6ad8a

Please sign in to comment.