DRY up the config a little bit more

pull/1104/head
Rick Carlino 2019-02-05 16:38:37 -06:00
parent 58b12e6c1d
commit 3104180445
3 changed files with 32 additions and 17 deletions

22
.gitignore vendored
View File

@ -3,21 +3,11 @@
.vscode
*.log
*.pem
*scratchpad*
/config/master.key
api_docs.md
config/application.yml
config/credentials.yml.enc
coverage
coverage_api
coverage_fe
dist/ # Parcel "accidents" happen here.
docker_volumes
erd_diagram.png
erd.pdf
latest_corpus.ts
log/
mqtt/
node_modules
package-lock.json
public/assets/
@ -25,3 +15,15 @@ public/direct_upload/temp/*.jpg
public/dist
public/system
tmp
api_docs.md
erd_diagram.png
erd.pdf
*scratchpad*
scratchpad.rb
/config/master.key
config/credentials.yml.enc
# === Legacy
config/application.yml
coverage
mqtt/

View File

@ -1,7 +1,10 @@
class DashboardController < ApplicationController
before_action :set_global_config
OUTPUT_URL_PATH = "/assets/parcel"
# === THESE CONSTANTS ARE CONFIGURABLE: ===
OUTPUT_URL = "/" + File.join("assets", "parcel") # <= served from public/ dir
# <= See PUBLIC_OUTPUT_DIR
CACHE_DIR = File.join(".cache")
CSS_INPUTS = HashWithIndifferentAccess.new({
front_page: "/css/laptop_splash.scss",
@ -15,20 +18,24 @@ class DashboardController < ApplicationController
tos_update: "/tos_update/index.tsx",
})
# === THESE CONSTANTS ARE NON-CONFIGURABLE. ===
# They are calculated based on config above.
PUBLIC_OUTPUT_DIR = File.join("public", OUTPUT_URL)
CSS_OUTPUTS = HashWithIndifferentAccess.new(CSS_INPUTS.reduce({}) do |acc, (key, value)|
acc[key] = OUTPUT_URL_PATH + value.gsub(/\.scss$/, ".css")
acc[key] = File.join(OUTPUT_URL, value.gsub(/\.scss$/, ".css"))
acc
end)
JS_OUTPUTS = HashWithIndifferentAccess.new(JS_INPUTS.reduce({}) do |acc, (key, value)|
acc[key] = OUTPUT_URL_PATH + value.gsub(/\.tsx?$/, ".js")
acc[key] = File.join(OUTPUT_URL, value.gsub(/\.tsx?$/, ".js"))
acc
end)
PARCEL_ASSET_LIST = (CSS_INPUTS.values + JS_INPUTS.values)
.sort
.uniq
.map { |x| "frontend" + x }
.map { |x| File.join("frontend", x) }
.join(" ")
PARCEL_HMR_OPTS = [

View File

@ -54,15 +54,21 @@ namespace :api do
intro = [ "node_modules/parcel-bundler/bin/cli.js",
cmd,
DashboardController::PARCEL_ASSET_LIST,
"--out-dir public#{DashboardController::OUTPUT_URL_PATH}",
"--public-url /dist" ].join(" ")
"--out-dir",
DashboardController::PUBLIC_OUTPUT_DIR,
"--public-url",
DashboardController::OUTPUT_URL,
].join(" ")
sh [intro, opts, DashboardController::PARCEL_CLI_OUTRO].join(" ")
end
desc "Serve javascript assets (via Parcel bundler)"
task serve_assets: :environment do
# Clear out cache and previous builds on initial load.
sh "rm -rf .cache/ public/dist/"
sh ["rm -rf",
DashboardController::CACHE_DIR,
DashboardController::PUBLIC_OUTPUT_DIR
].join(" ")
parcel "watch", DashboardController::PARCEL_HMR_OPTS
end