1
- import * as _ from "lodash" ;
2
1
import * as clc from "cli-color" ;
3
- import * as request from "request" ;
4
2
import * as semver from "semver" ;
5
3
4
+ import { Client } from "./apiv2" ;
6
5
import { configstore } from "./configstore" ;
7
- import * as api from "./api" ;
8
- import * as logger from "./logger" ;
6
+ import { realtimeOrigin } from "./api" ;
9
7
import * as utils from "./utils" ;
10
8
11
9
const pkg = require ( "../package.json" ) ; // eslint-disable-line @typescript-eslint/no-var-requires
@@ -21,7 +19,7 @@ export function fetchMOTD(): void {
21
19
22
20
if ( motd && motdFetched > Date . now ( ) - ONE_DAY_MS ) {
23
21
if ( motd . minVersion && semver . gt ( motd . minVersion , pkg . version ) ) {
24
- logger . error (
22
+ console . error (
25
23
clc . red ( "Error:" ) ,
26
24
"CLI is out of date (on" ,
27
25
clc . bold ( pkg . version ) ,
@@ -36,26 +34,19 @@ export function fetchMOTD(): void {
36
34
if ( motd . message && process . stdout . isTTY ) {
37
35
const lastMessage = configstore . get ( "motd.lastMessage" ) ;
38
36
if ( lastMessage !== motd . message ) {
39
- logger . info ( ) ;
40
- logger . info ( motd . message ) ;
41
- logger . info ( ) ;
37
+ console . log ( ) ;
38
+ console . log ( motd . message ) ;
39
+ console . log ( ) ;
42
40
configstore . set ( "motd.lastMessage" , motd . message ) ;
43
41
}
44
42
}
45
43
} else {
46
- request (
47
- {
48
- url : utils . addSubdomain ( api . realtimeOrigin , "firebase-public" ) + "/cli.json" ,
49
- json : true ,
50
- } ,
51
- ( err , res , body ) => {
52
- if ( err ) {
53
- return ;
54
- }
55
- motd = _ . assign ( { } , body ) ;
56
- configstore . set ( "motd" , motd ) ;
57
- configstore . set ( "motd.fetched" , Date . now ( ) ) ;
58
- }
59
- ) ;
44
+ const origin = utils . addSubdomain ( realtimeOrigin , "firebase-public" ) ;
45
+ const c = new Client ( { urlPrefix : origin , auth : false } ) ;
46
+ c . get ( "/cli.json" ) . then ( ( res ) => {
47
+ motd = Object . assign ( { } , res . body ) ;
48
+ configstore . set ( "motd" , motd ) ;
49
+ configstore . set ( "motd.fetched" , Date . now ( ) ) ;
50
+ } ) ;
60
51
}
61
52
}
0 commit comments