-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apikeys.js): fixing #3 - assumed unix not considering windows
Fixed the issue where we assumed using unix ~ is not used in windows. This has now been fixed using os.homedir fix #3
- Loading branch information
Simen Daehlin
committed
Sep 4, 2022
1 parent
394c98a
commit 78388ae
Showing
1 changed file
with
16 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
const os = require(`os`); | ||
const shell = require(`shelljs`); | ||
const { setConfig } = require(`../../utils/config`); | ||
const { spinner } = require(`../../utils/config`); | ||
|
||
const getApiKey = async () => { | ||
const apiToken = await shell | ||
.cat(`~/.netrc `) | ||
.grep( | ||
`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}` | ||
) | ||
.substring(11, 47); | ||
setConfig({ apiToken }); | ||
try { | ||
const apiToken = await shell | ||
.cat(`${os.homedir()}/.netrc `) | ||
.grep( | ||
`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}` | ||
) | ||
.substring(11, 47); | ||
setConfig({ apiToken }); | ||
} catch (error) { | ||
spinner.stopAndPersist({ | ||
symbol: `❌`, | ||
text: `Unable to get API key from Heroku. Please make sure you are logged in to Heroku.` | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { getApiKey }; |