Skip to content

Instantly share code, notes, and snippets.

@crimeminister
Created Dec 22, 2017
Embed
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]
(try
(.isFile (fs/lstatSync path))
(catch :default _
false)))
;; TODO Figure out why this doesn't work.
;; (lumo.util/file? file-name)
npmrc-contents (if (is-file? file-name)
(lumo.io/slurp file-name)
:not-found)
;; 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))]
token)]
check-npm-token (if (string? npm-token)
(println "npm-token:" npm-token)
(println "Please run 'npm login' to obtain an auth token"))
}
@crimeminister
Copy link
Author

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