From acc24ff3d14cf67365cb181dd28a0eb6ab097bba Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Fri, 29 Jun 2018 14:59:51 -0400 Subject: [PATCH 1/4] Compile assets to versioned file for production --- atst/assets.py | 16 ++++++++++++++++ atst/handler.py | 12 +----------- precompile.py | 11 +++++++++++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 atst/assets.py create mode 100644 precompile.py diff --git a/atst/assets.py b/atst/assets.py new file mode 100644 index 00000000..87a17c6d --- /dev/null +++ b/atst/assets.py @@ -0,0 +1,16 @@ +from webassets import Environment, Bundle +from atst.home import home + +assets = Environment( + directory=home.child("scss"), + url="/static" +) +print(assets.url_expire) +css = Bundle( + "atat.scss", + filters="scss", + output="../static/assets/out.%(version)s.css", + depends=("**/*.scss"), +) + +assets.register("css", css) diff --git a/atst/handler.py b/atst/handler.py index 6272743c..be7a5bf4 100644 --- a/atst/handler.py +++ b/atst/handler.py @@ -1,17 +1,7 @@ -from webassets import Environment, Bundle import tornado.web -from atst.home import home +from atst.assets import assets from atst.sessions import SessionNotFoundError -assets = Environment(directory=home.child("scss"), url="/static") -css = Bundle( - "atat.scss", - filters="scss", - output="../static/assets/out.css", - depends=("**/*.scss"), -) - -assets.register("css", css) helpers = {"assets": assets} diff --git a/precompile.py b/precompile.py new file mode 100644 index 00000000..898f8902 --- /dev/null +++ b/precompile.py @@ -0,0 +1,11 @@ +import logging +from atst.assets import assets +from webassets.script import CommandLineEnvironment + +# Setup a logger +log = logging.getLogger('webassets') +log.addHandler(logging.StreamHandler()) +log.setLevel(logging.DEBUG) + +cmdenv = CommandLineEnvironment(assets, log) +cmdenv.build() From 57334b41374a673497440b463d60fec701838585 Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Fri, 29 Jun 2018 15:11:59 -0400 Subject: [PATCH 2/4] Make precompilation part of bootstrapping --- script/bootstrap | 6 ++++++ script/setup | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/script/bootstrap b/script/bootstrap index f39656f0..a21d6fd6 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -1,5 +1,8 @@ #!/bin/bash +# script/bootstrap: Resolve all dependencies that the application requires to +# run. + # If a command fails, exit the script set -e @@ -13,3 +16,6 @@ pipenv install --dev # Install uswds node module and dependencies npm install + +# Precompile assets for deployment +pipenv run python ./precompile.py diff --git a/script/setup b/script/setup index 0ea6be6d..bf2088d5 100755 --- a/script/setup +++ b/script/setup @@ -1,5 +1,8 @@ #!/bin/bash +# script/setup: Set up application for the first time after cloning, or set it +# back to the initial first unused state. + # If a command fails, exit the script set -e @@ -25,5 +28,5 @@ fi script/bootstrap # Symlink uswds fonts into the /static directory -rm -f ./static/fonts +rm -rf ./static/fonts ln -s ../node_modules/uswds/src/fonts ./static/fonts From f423ee31b329a63f50f6c57bef520ba2eabac36c Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Fri, 29 Jun 2018 15:19:16 -0400 Subject: [PATCH 3/4] Use webassets' built-in command line builder --- atst/assets.py | 6 +++--- atst/handler.py | 4 ++-- precompile.py | 11 ----------- script/bootstrap | 2 +- 4 files changed, 6 insertions(+), 17 deletions(-) delete mode 100644 precompile.py diff --git a/atst/assets.py b/atst/assets.py index 87a17c6d..7f723f75 100644 --- a/atst/assets.py +++ b/atst/assets.py @@ -1,11 +1,11 @@ from webassets import Environment, Bundle from atst.home import home -assets = Environment( +environment = Environment( directory=home.child("scss"), url="/static" ) -print(assets.url_expire) + css = Bundle( "atat.scss", filters="scss", @@ -13,4 +13,4 @@ css = Bundle( depends=("**/*.scss"), ) -assets.register("css", css) +environment.register("css", css) diff --git a/atst/handler.py b/atst/handler.py index be7a5bf4..99ffa0f2 100644 --- a/atst/handler.py +++ b/atst/handler.py @@ -1,8 +1,8 @@ import tornado.web -from atst.assets import assets +from atst.assets import environment from atst.sessions import SessionNotFoundError -helpers = {"assets": assets} +helpers = {"assets": environment} class BaseHandler(tornado.web.RequestHandler): diff --git a/precompile.py b/precompile.py deleted file mode 100644 index 898f8902..00000000 --- a/precompile.py +++ /dev/null @@ -1,11 +0,0 @@ -import logging -from atst.assets import assets -from webassets.script import CommandLineEnvironment - -# Setup a logger -log = logging.getLogger('webassets') -log.addHandler(logging.StreamHandler()) -log.setLevel(logging.DEBUG) - -cmdenv = CommandLineEnvironment(assets, log) -cmdenv.build() diff --git a/script/bootstrap b/script/bootstrap index a21d6fd6..ad26fe47 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -18,4 +18,4 @@ pipenv install --dev npm install # Precompile assets for deployment -pipenv run python ./precompile.py +pipenv run webassets -m atst.assets build From 88ee60a8b102dfe9edc7b7f29a52a14f81289bf0 Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Fri, 29 Jun 2018 16:04:12 -0400 Subject: [PATCH 4/4] Revert forcing deletion of the fonts directory --- script/setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/setup b/script/setup index bf2088d5..76cd5301 100755 --- a/script/setup +++ b/script/setup @@ -28,5 +28,5 @@ fi script/bootstrap # Symlink uswds fonts into the /static directory -rm -rf ./static/fonts +rm -f ./static/fonts ln -s ../node_modules/uswds/src/fonts ./static/fonts