Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'npm-root'

  • Loading branch information...
commit c07c0c4c68918e4ef392bcd2ec6682d28bb9139d 2 parents ce1863e + 63ba7c1
@ninjudd authored
Showing with 30 additions and 6 deletions.
  1. +17 −0 README.md
  2. +13 −6 src/leiningen/npm.clj
View
17 README.md
@@ -65,6 +65,23 @@ If `:main` is a string that refers to a file that exists and ends with
install` if necessary. Any command line arguments following `lein run`
will be passed through to the Node process.
+## Changing the directory used
+
+npm does not allow you to put stuff anywhere besides `node_modules`, even
+if that name is [against your religion](https://www.npmjs.org/doc/faq.html),
+however, you can change the root used by lein-npm to be something other than
+your project root like this:
+
+```clojure
+:npm-root "resources/public/js"
+```
+
+Or you can use a keyword to look the path up in your project map:
+
+```clojure
+:npm-root :target-path
+```
+
## License
Copyright 2012 Bodil Stokke and Hoang Minh Thang
View
19 src/leiningen/npm.clj
@@ -9,9 +9,16 @@
[robert.hooke]
[leiningen.deps]))
+(defn- root [project]
+ (if-let [root (project :npm-root)]
+ (if (keyword? root)
+ (project root) ;; e.g. support using :target-path
+ root)
+ (project :root)))
+
(defn- json-file
[filename project]
- (io/file (project :root) filename))
+ (io/file (root project) filename))
(defn- locate-npm
[]
@@ -35,7 +42,7 @@
(defn- invoke
[project & args]
- (let [return-code (exec (project :root) (cons "npm" args))]
+ (let [return-code (exec (root project) (cons "npm" args))]
(when (> return-code 0)
(main/exit return-code))))
@@ -72,10 +79,10 @@
(finally (remove-json-file ~filename ~project))))
(defn npm-debug
- [project]
- (with-json-file "package.json" (project->package project) project
+ [project filename]
+ (with-json-file filename (project->package project) project
(println "lein-npm generated package.json:\n")
- (println (slurp "package.json"))))
+ (println (slurp (json-file filename project)))))
(defn npm
"Invoke the NPM package manager."
@@ -87,7 +94,7 @@
(environmental-consistency project "package.json")
(cond
(= ["pprint"] args)
- (npm-debug project)
+ (npm-debug project "package.json")
:else
(with-json-file "package.json" (project->package project) project
(apply invoke project args)))))
Please sign in to comment.
Something went wrong with that request. Please try again.