Skip to content

Instantly share code, notes, and snippets.

Created Dec 22, 2017
What would you like to do?
Example Machfile (with issues) for extracting npm auth token
;; Perform initialization steps.
mach/init (do
(require 'fs)
(require '[lumo.util]))
;; Initialize data for later use.
mach/props [;; Read the auth token from a local .npmrc file.
npm-token (let [file-name (str js/process.env.HOME "/.npmrc")
;; TODO this is (lumo.util/file?); prefer to use that
;; instead. Right now it is not available in spite of
;; that namespace being required.
is-file? (fn [path]
(.isFile (fs/lstatSync path))
(catch :default _
;; TODO Figure out why this doesn't work.
;; (lumo.util/file? file-name)
npmrc-contents (if (is-file? file-name)
( file-name)
;; TODO figure out why using regex reader literal b0rks
;;token-pattern #"_authToken=(.+)"
token-pattern (js/RegExp. "_authToken=(.+)")
token (second (re-find token-pattern npmrc-contents))]
check-npm-token (if (string? npm-token)
(println "npm-token:" npm-token)
(println "Please run 'npm login' to obtain an auth token"))
Copy link

crimeminister commented Dec 22, 2017

So, it seems as though I can use mach.core/file? in place of lumo.util/file?. Progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment