Skip to content

Instantly share code, notes, and snippets.

@crimeminister
Created December 22, 2017 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crimeminister/f4f57ef5eafb8d8a8d0a5e87e48403dc to your computer and use it in GitHub Desktop.
Save crimeminister/f4f57ef5eafb8d8a8d0a5e87e48403dc to your computer and use it in GitHub Desktop.
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

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