@dotenvx/dotenvx 0.30.2 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/actions/hub/logout.js +43 -0
- package/src/cli/commands/hub.js +6 -0
- package/src/shared/store.js +19 -0
package/package.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const openBrowser = require('open')
|
|
2
|
+
const confirm = require('@inquirer/confirm').default
|
|
3
|
+
|
|
4
|
+
const createSpinner = require('./../../../shared/createSpinner')
|
|
5
|
+
const store = require('./../../../shared/store')
|
|
6
|
+
const logger = require('./../../../shared/logger')
|
|
7
|
+
const sleep = require('./../../../lib/helpers/sleep')
|
|
8
|
+
|
|
9
|
+
const username = store.getUsername()
|
|
10
|
+
const usernamePart = username ? ` [${username}]` : ''
|
|
11
|
+
const spinner = createSpinner(`logging off machine${usernamePart}`)
|
|
12
|
+
|
|
13
|
+
async function logout () {
|
|
14
|
+
spinner.start()
|
|
15
|
+
await sleep(500) // better dx
|
|
16
|
+
|
|
17
|
+
// debug opts
|
|
18
|
+
const options = this.opts()
|
|
19
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
20
|
+
|
|
21
|
+
logger.debug('deleting settings.DOTENVX_TOKEN')
|
|
22
|
+
store.deleteToken()
|
|
23
|
+
|
|
24
|
+
logger.debug('deleting settings.DOTENVX_HOSTNAME')
|
|
25
|
+
store.deleteHostname()
|
|
26
|
+
|
|
27
|
+
spinner.done(`logged off machine${usernamePart}`)
|
|
28
|
+
|
|
29
|
+
const hostname = options.hostname
|
|
30
|
+
const logoutUrl = `${hostname}/logout`
|
|
31
|
+
|
|
32
|
+
// optionally allow user to open browser
|
|
33
|
+
const answer = await confirm({ message: `press Enter to also log off browser [${logoutUrl}]...` })
|
|
34
|
+
|
|
35
|
+
if (answer) {
|
|
36
|
+
spinner.start()
|
|
37
|
+
await sleep(500) // better dx
|
|
38
|
+
await openBrowser(logoutUrl)
|
|
39
|
+
spinner.done(`logged off browser${usernamePart}`)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = logout
|
package/src/cli/commands/hub.js
CHANGED
|
@@ -44,4 +44,10 @@ hub
|
|
|
44
44
|
.description('display logged in user')
|
|
45
45
|
.action(require('./../actions/hub/status'))
|
|
46
46
|
|
|
47
|
+
hub
|
|
48
|
+
.command('logout')
|
|
49
|
+
.description('log out this machine from dotenvx hub')
|
|
50
|
+
.option('-h, --hostname <url>', 'set hostname', store.getHostname())
|
|
51
|
+
.action(require('./../actions/hub/logout'))
|
|
52
|
+
|
|
47
53
|
module.exports = hub
|
package/src/shared/store.js
CHANGED
|
@@ -108,6 +108,23 @@ const setLatestVersionLastChecked = function (dateNow) {
|
|
|
108
108
|
return dateNow
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
const deleteToken = function () {
|
|
112
|
+
// memory user
|
|
113
|
+
const key = findFirstMatchingKey(confStore.store) // GH_MOTDOTLA_DOTENVX_TOKEN
|
|
114
|
+
confStore.delete(key)
|
|
115
|
+
|
|
116
|
+
// current logged in user
|
|
117
|
+
confStore.delete('DOTENVX_TOKEN')
|
|
118
|
+
|
|
119
|
+
return true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const deleteHostname = function () {
|
|
123
|
+
confStore.delete('DOTENVX_HOSTNAME')
|
|
124
|
+
|
|
125
|
+
return true
|
|
126
|
+
}
|
|
127
|
+
|
|
111
128
|
const configPath = function () {
|
|
112
129
|
return confStore.path
|
|
113
130
|
}
|
|
@@ -123,5 +140,7 @@ module.exports = {
|
|
|
123
140
|
setToken,
|
|
124
141
|
setLatestVersion,
|
|
125
142
|
setLatestVersionLastChecked,
|
|
143
|
+
deleteToken,
|
|
144
|
+
deleteHostname,
|
|
126
145
|
configPath
|
|
127
146
|
}
|