1
1
import clean from 'clean-deep'
2
- import { OptionValues } from 'commander'
2
+ import type { OptionValues } from 'commander'
3
3
import prettyjson from 'prettyjson'
4
4
5
- import { chalk , logAndThrowError , exit , getToken , log , logJson , warn , APIError } from '../../utils/command-helpers.js'
6
- import BaseCommand from '../base-command.js'
5
+ import {
6
+ chalk ,
7
+ logAndThrowError ,
8
+ exit ,
9
+ getToken ,
10
+ log ,
11
+ logJson ,
12
+ warn ,
13
+ type APIError ,
14
+ } from '../../utils/command-helpers.js'
15
+ import type BaseCommand from '../base-command.js'
7
16
8
17
export const status = async ( options : OptionValues , command : BaseCommand ) => {
9
18
const { accounts, api, globalConfig, site, siteInfo } = command . netlify
10
- const current = globalConfig . get ( 'userId' )
19
+ const currentUserId = globalConfig . get ( 'userId' ) as string | undefined
11
20
const [ accessToken ] = await getToken ( )
12
21
13
22
if ( ! accessToken ) {
14
23
log ( `Not logged in. Please log in to see site status.` )
15
24
log ( )
16
25
log ( 'Login with "netlify login" command' )
17
- exit ( )
26
+ return exit ( )
18
27
}
19
28
20
29
const siteId = site . id
@@ -37,16 +46,21 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
37
46
}
38
47
}
39
48
40
- const ghuser = command . netlify . globalConfig . get ( `users.${ current } .auth.github.user` )
49
+ const ghuser =
50
+ currentUserId != null
51
+ ? ( globalConfig . get ( `users.${ currentUserId } .auth.github.user` ) as string | undefined )
52
+ : undefined
41
53
const accountData = {
42
54
Name : user . full_name ,
43
55
Email : user . email ,
44
56
GitHub : ghuser ,
45
57
Teams : accounts . map ( ( { name } ) => name ) ,
46
58
}
47
59
48
- // @ts -expect-error
49
- const cleanAccountData = clean ( accountData )
60
+ const cleanAccountData =
61
+ // TODO(serhalp) `deep-clean` type declaration is invalid (this is obscured by `skipLibCheck`). Open a PR or use
62
+ // another lib.
63
+ ( clean as unknown as < T extends Record < string | number | symbol , unknown > > ( obj : T ) => Partial < T > ) ( accountData )
50
64
51
65
log ( prettyjson . render ( cleanAccountData ) )
52
66
@@ -55,11 +69,6 @@ export const status = async (options: OptionValues, command: BaseCommand) => {
55
69
return logAndThrowError ( `You don't appear to be in a folder that is linked to a site` )
56
70
}
57
71
58
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- XXX(serhalp): fixed in stacked PR.
59
- if ( ! siteInfo ) {
60
- return logAndThrowError ( `No site info found for site ${ siteId } ` )
61
- }
62
-
63
72
// Json only logs out if --json flag is passed
64
73
if ( options . json ) {
65
74
logJson ( {
0 commit comments