Skip to content

Commit 78388ae

Browse files
author
Simen Daehlin
committed
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
1 parent 394c98a commit 78388ae

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

providers/heroku/apiKey.js

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
const os = require(`os`);
12
const shell = require(`shelljs`);
23
const { setConfig } = require(`../../utils/config`);
4+
const { spinner } = require(`../../utils/config`);
35

46
const getApiKey = async () => {
5-
const apiToken = await shell
6-
.cat(`~/.netrc `)
7-
.grep(
8-
`[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}`
9-
)
10-
.substring(11, 47);
11-
setConfig({ apiToken });
7+
try {
8+
const apiToken = await shell
9+
.cat(`${os.homedir()}/.netrc `)
10+
.grep(
11+
`[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}`
12+
)
13+
.substring(11, 47);
14+
setConfig({ apiToken });
15+
} catch (error) {
16+
spinner.stopAndPersist({
17+
symbol: `❌`,
18+
text: `Unable to get API key from Heroku. Please make sure you are logged in to Heroku.`
19+
});
20+
}
1221
};
1322

1423
module.exports = { getApiKey };

0 commit comments

Comments
 (0)