-
-
Save crimeminister/f4f57ef5eafb8d8a8d0a5e87e48403dc to your computer and use it in GitHub Desktop.
Example Machfile (with issues) for extracting npm auth token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
;; 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")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, it seems as though I can use
mach.core/file?
in place oflumo.util/file?
. Progress.