Skip to content

Commit

Permalink
Add lessjs task
Browse files Browse the repository at this point in the history
This task uses npm in order to install and launch the lessc compiler against
the input .less file. The output will be included into the fileset by default.

At the moment only the --include-dirs option is handled and passed to lessc.
  • Loading branch information
arichiardi committed Nov 21, 2017
1 parent 60331bf commit d0d8776
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions boot.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOOT_VERSION=2.7.2
34 changes: 34 additions & 0 deletions build.boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(set-env! :dependencies '[[org.clojure/clojure "1.8.0" :scope "provided"]
[degree9/boot-npm "1.7.0-SNAPSHOT"]
[adzerk/bootlaces "0.1.13" :scope "test"]
[degree9/boot-semver "1.6.0" :scope "test"]]
:resource-paths #{"src"})

(require '[degree9.boot-semver :refer :all])

(task-options!
pom {:project 'degree9/boot-css
:description "CSS Preprocessors for boot-clj."
:url "https://github.com/degree9/boot-exec"
:scm {:url "https://github.com/degree9/boot-exec"}})

(deftask develop
"Build boot-css for development."
[]
(comp
(version :develop true
:minor 'inc
:patch 'zero
:pre-release 'snapshot)
(watch)
(target)
(build-jar)))

(deftask deploy
"Build boot-css and deploy to clojars."
[]
(comp
(version)
(target)
(build-jar)
(push-release)))
30 changes: 30 additions & 0 deletions src/degree9/boot_css.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns degree9.boot-css
(:require [boot.core :as boot]
[clojure.string :as str]
[clojure.java.io :as io]
[boot.util :as u]
[degree9.boot-npm :as npm]))

(boot/deftask lessc
"Compile CSS using the npm version of Less."
[l less-path PATH str "Path to the .less file to compile (relative to the fileset)."
i include-dirs PATH #{str} "Include directories for lessc."]
(let [tmp (boot/tmp-dir!)]
(boot/with-pre-wrap [fs]
(let [less-tmp (boot/tmp-get fs less-path)]
(assert less-tmp (format "Less-path (%s) should point to a file in the classpath." less-path))
(let [compiled-file (io/file tmp (str/replace less-path #"\.less$" ".css"))
include-dirs (->> [(boot/tmp-dir less-tmp)]
(into (or include-dirs #{}))
(str/join ":"))
mw (npm/exec :module "less"
:process "lessc"
:arguments [(str "--include-path=" include-dirs)
(-> less-tmp boot/tmp-file .getAbsolutePath)
(.getAbsolutePath compiled-file)])]
(u/dbug* "Less boot dir: %s\n" (boot/tmp-dir less-tmp))
(u/dbug* "Less boot file: %s\n" (-> less-tmp boot/tmp-file .getAbsolutePath))
(u/dbug* "Less boot target: %s\n" (.getAbsolutePath compiled-file))

((mw identity) fs) ;; only for side effects on tmp folder
(-> fs (boot/add-resource tmp) boot/commit!))))))
2 changes: 2 additions & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Mon May 01 18:58:18 MDT 2017
VERSION=1.0.0

0 comments on commit d0d8776

Please sign in to comment.