Skip to content

Commit

Permalink
Better bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
swlkr committed Mar 21, 2020
1 parent 2aa07d6 commit 86b8f3e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
10 changes: 6 additions & 4 deletions joy
Expand Up @@ -22,16 +22,18 @@
(def action (get args 1))
(def options (drop 2 args))

(def database-url (joy/env :database-url))

(if (or (nil? action)
(empty? action))
(empty? action))
(print "joy" usage)
(case action
"create" (apply joy/generate options)
"help" (print "joy" usage)
"new" (joy/generate "project" ;options)
"migrate" (joy/migrate (joy/env :database-url))
"rollback" (joy/rollback (joy/env :database-url))
"migrate" (joy/migrate database-url)
"rollback" (joy/rollback database-url)
"server" (os/shell "jpm run server")
"watch" (os/shell "jpm run watch")
"version" (print joy/version)
"bundle" (joy/bundle options)))
"bundle" (joy/bundle)))
18 changes: 9 additions & 9 deletions project.janet
@@ -1,15 +1,15 @@
(declare-project
:name "joy"
:description "A full stack janet web framework"
:dependencies ["https://github.com/janet-lang/json"
{:repo "https://github.com/janet-lang/sqlite3" :tag "a3a254003c605cf4e048963feda70a60537057d9"}
{:repo "https://github.com/janet-lang/path" :tag "d8619960d428c45ebb784600771a7c584ae49431"}
{:repo "https://github.com/joy-framework/cipher" :tag "0.2.0"}
{:repo "https://github.com/joy-framework/codec" :tag "f50c00462b9d048034ee8bdd2f6af6e67bc5aff4"}
{:repo "https://github.com/joy-framework/halo" :tag "a276646d269fc8a8df5336015579219300378ac2"}
{:repo "https://github.com/andrewchambers/janet-uri" :tag "921c16d008444792ad262f7aaff87549acfc4240"}
{:repo "https://git.sr.ht/~bakpakin/temple" :tag "ed7e83e8779e2a54e23bbbcc75366ade2dd5372a"}
{:repo "https://github.com/joy-framework/tester"}]
:dependencies ["https://github.com/andrewchambers/janet-uri"
"https://github.com/janet-lang/json"
"https://github.com/janet-lang/path"
"https://github.com/janet-lang/sqlite3"
"https://github.com/joy-framework/cipher"
"https://github.com/joy-framework/codec"
"https://github.com/joy-framework/halo"
"https://github.com/joy-framework/bundler"
"https://github.com/joy-framework/tester"]
:author "Sean Walker"
:license "MIT"
:url "https://github.com/joy-framework/joy"
Expand Down
2 changes: 1 addition & 1 deletion src/joy.janet
Expand Up @@ -12,5 +12,5 @@
(import ./joy/cli :prefix "" :export true)
(import ./joy/form-helper :prefix "" :export true)
(import ./joy/http :as http :export true)
(import ./joy/bundler :prefix "" :export true)
(import bundler :prefix "" :export true)
(import halo :prefix "" :export true)
27 changes: 0 additions & 27 deletions src/joy/bundler.janet

This file was deleted.

37 changes: 26 additions & 11 deletions src/joy/html.janet
Expand Up @@ -148,14 +148,29 @@
[:script {:src src}])


(defn css [filenames]
(if env/development?
(map link filenames)
(link "/bundle.css")))


(defn js [filenames]
(if env/development?
(map script filenames)
(script "/bundle.js")))

(defn find-bundle [ext]
(let [bundle (as-> (os/dir "public") ?
(filter |(string/has-prefix? "bundle" $) ?)
(filter |(string/has-suffix? ext $) ?)
(get ? 0))]
(if (nil? bundle)
(printf "Warning: JOY_ENV is set to production but there was no bundled %s file. Run joy bundle to fix this." ext)
bundle)))


(defn css [& filenames]
(let [css-bundle (find-bundle ".css")]
(if env/development?
(map link filenames)
(if (nil? css-bundle)
(map link filenames)
(link (string "./" css-bundle))))))


(defn js [& filenames]
(let [js-bundle (find-bundle ".js")]
(if env/development?
(map script filenames)
(if (nil? js-bundle)
(map script filenames)
(script (string "./" js-bundle))))))

0 comments on commit 86b8f3e

Please sign in to comment.