@@ -87,19 +87,53 @@ export async function chooseApp(platform: Platform) {
8787 }
8888}
8989
90+ async function selectApp ( {
91+ args,
92+ options,
93+ } : {
94+ args : string [ ] ;
95+ options : { platform ?: Platform | '' } ;
96+ } ) {
97+ const platform = await getPlatform ( options . platform ) ;
98+ const id = args [ 0 ]
99+ ? Number . parseInt ( args [ 0 ] , 10 )
100+ : ( await chooseApp ( platform ) ) . id ;
101+
102+ let updateInfo : Partial < Record < Platform , { appId : number ; appKey : string } > > =
103+ { } ;
104+ try {
105+ updateInfo = JSON . parse ( await fs . promises . readFile ( 'update.json' , 'utf8' ) ) ;
106+ } catch ( e : any ) {
107+ if ( e . code !== 'ENOENT' ) {
108+ console . error ( t ( 'failedToParseUpdateJson' ) ) ;
109+ throw e ;
110+ }
111+ }
112+ const { appKey } = await get ( `/app/${ id } ` ) ;
113+ updateInfo [ platform ] = {
114+ appId : id ,
115+ appKey,
116+ } ;
117+ await fs . promises . writeFile (
118+ 'update.json' ,
119+ JSON . stringify ( updateInfo , null , 4 ) ,
120+ 'utf8' ,
121+ ) ;
122+ }
123+
90124export const appCommands = {
91- createApp : async function ( {
125+ createApp : async ( {
92126 options,
93127 } : {
94128 options : { name : string ; downloadUrl : string ; platform ?: Platform | '' } ;
95- } ) {
129+ } ) => {
96130 const name = options . name || ( await question ( t ( 'appNameQuestion' ) ) ) ;
97131 const { downloadUrl } = options ;
98132 const platform = await getPlatform ( options . platform ) ;
99133 const { id } = await post ( '/app/create' , { name, platform, downloadUrl } ) ;
100134 console . log ( t ( 'createAppSuccess' , { id } ) ) ;
101- await this . selectApp ( {
102- args : [ id ] ,
135+ await selectApp ( {
136+ args : [ String ( id ) ] ,
103137 options : { platform } ,
104138 } ) ;
105139 } ,
@@ -122,40 +156,5 @@ export const appCommands = {
122156 const { platform = '' } = options ;
123157 await listApp ( platform ) ;
124158 } ,
125- selectApp : async ( {
126- args,
127- options,
128- } : {
129- args : string [ ] ;
130- options : { platform ?: Platform | '' } ;
131- } ) => {
132- const platform = await getPlatform ( options . platform ) ;
133- const id = args [ 0 ]
134- ? Number . parseInt ( args [ 0 ] )
135- : ( await chooseApp ( platform ) ) . id ;
136-
137- let updateInfo : Partial <
138- Record < Platform , { appId : number ; appKey : string } >
139- > = { } ;
140- try {
141- updateInfo = JSON . parse (
142- await fs . promises . readFile ( 'update.json' , 'utf8' ) ,
143- ) ;
144- } catch ( e : any ) {
145- if ( e . code !== 'ENOENT' ) {
146- console . error ( t ( 'failedToParseUpdateJson' ) ) ;
147- throw e ;
148- }
149- }
150- const { appKey } = await get ( `/app/${ id } ` ) ;
151- updateInfo [ platform ] = {
152- appId : id ,
153- appKey,
154- } ;
155- await fs . promises . writeFile (
156- 'update.json' ,
157- JSON . stringify ( updateInfo , null , 4 ) ,
158- 'utf8' ,
159- ) ;
160- } ,
159+ selectApp,
161160} ;
0 commit comments