@@ -8,8 +8,9 @@ import cac, { type CAC } from "cac";
88import ora , { type Ora } from "ora" ;
99
1010import {
11+ confirmAppStoreReleaseReview ,
1112 createAppStoreClient ,
12- resolveLatestAppStoreDownloadUrl ,
13+ resolveLatestAppStoreRelease ,
1314 resolvePluginAppStoreAppId ,
1415 resolvePluginUpdates ,
1516 resolvePluginUpgradeSource ,
@@ -41,6 +42,7 @@ interface PluginMutationOptions extends PluginCommandOptions {
4142}
4243
4344interface BatchUpgradeResult {
45+ cancelled ?: boolean ;
4446 upgraded : Array < { name : string ; fromVersion ?: string ; toVersion : string } > ;
4547 skipped : Array < {
4648 name : string ;
@@ -51,6 +53,13 @@ interface BatchUpgradeResult {
5153 failed : Array < { name : string ; error : string } > ;
5254}
5355
56+ interface PreparedPluginUpgradeCandidate {
57+ plugin : Plugin ;
58+ update : { latestVersion : string ; compatible : boolean } ;
59+ releaseUrl : string ;
60+ downloadUrl : string ;
61+ }
62+
5463interface BatchUpgradeProgressEvent {
5564 type :
5665 | "checking"
@@ -350,9 +359,56 @@ async function upgradeAllPlugins(
350359 } ) ;
351360 }
352361
353- onProgress ?.( { type : "queued" , count : selectedCandidates . length } ) ;
354-
362+ const preparedCandidates : PreparedPluginUpgradeCandidate [ ] = [ ] ;
355363 for ( const item of selectedCandidates ) {
364+ try {
365+ const appId = resolvePluginAppStoreAppId ( item . plugin ) ;
366+ const release = await resolveLatestAppStoreRelease ( appStoreClient , appId ) ;
367+ preparedCandidates . push ( {
368+ ...item ,
369+ releaseUrl : release . releaseUrl ,
370+ downloadUrl : release . downloadUrl ,
371+ } ) ;
372+ } catch ( error ) {
373+ result . failed . push ( {
374+ name : item . plugin . metadata . name ,
375+ error : error instanceof Error ? error . message : "Unknown upgrade error." ,
376+ } ) ;
377+
378+ onProgress ?.( {
379+ type : "failed" ,
380+ name : item . plugin . metadata . name ,
381+ fromVersion : item . plugin . spec . version ,
382+ toVersion : item . update . latestVersion ,
383+ error : error instanceof Error ? error . message : "Unknown upgrade error." ,
384+ } ) ;
385+ }
386+ }
387+
388+ if ( preparedCandidates . length === 0 ) {
389+ return result ;
390+ }
391+
392+ const confirmed = await confirmAppStoreReleaseReview (
393+ {
394+ commandPath : "halo plugin upgrade --all" ,
395+ actionLabel : "upgrading App Store plugins" ,
396+ items : preparedCandidates . map ( ( item ) => ( {
397+ name : item . plugin . spec . displayName ?? item . plugin . metadata . name ,
398+ releaseUrl : item . releaseUrl ,
399+ } ) ) ,
400+ } ,
401+ options ,
402+ ) ;
403+
404+ if ( ! confirmed ) {
405+ result . cancelled = true ;
406+ return result ;
407+ }
408+
409+ onProgress ?.( { type : "queued" , count : preparedCandidates . length } ) ;
410+
411+ for ( const item of preparedCandidates ) {
356412 const { plugin, update } = item ;
357413
358414 if ( ! update . compatible ) {
@@ -380,11 +436,9 @@ async function upgradeAllPlugins(
380436 toVersion : update . latestVersion ,
381437 } ) ;
382438
383- const appId = resolvePluginAppStoreAppId ( plugin ) ;
384- const downloadUrl = await resolveLatestAppStoreDownloadUrl ( appStoreClient , appId ) ;
385439 await clients . console . plugin . plugin . upgradePluginFromUri ( {
386440 name : plugin . metadata . name ,
387- upgradeFromUriRequest : { uri : downloadUrl } ,
441+ upgradeFromUriRequest : { uri : item . downloadUrl } ,
388442 } ) ;
389443
390444 onProgress ?.( {
@@ -475,6 +529,13 @@ function reportBatchUpgradeProgress(
475529}
476530
477531function printBatchUpgradeResult ( result : BatchUpgradeResult , json = false ) : void {
532+ if ( result . cancelled ) {
533+ if ( ! json ) {
534+ process . stdout . write ( "Cancelled upgrading App Store plugins.\n" ) ;
535+ }
536+ return ;
537+ }
538+
478539 if ( json ) {
479540 printJson ( result ) ;
480541 return ;
@@ -644,7 +705,6 @@ function buildPluginCli(runtime: RuntimeContext): CAC {
644705 . option ( "-y, --yes" , "Skip selection and upgrade all compatible plugins" )
645706 . action ( async ( name : string | undefined , options : PluginCommandOptions ) => {
646707 const spinner = createSpinnerReporter ( options . json ) ;
647- const { clients } = await runtime . getClientsForOptions ( options ) ;
648708 const target = resolvePluginUpgradeTarget ( name , options ) ;
649709
650710 if ( target . mode === "all" ) {
@@ -661,6 +721,7 @@ function buildPluginCli(runtime: RuntimeContext): CAC {
661721 return ;
662722 }
663723
724+ const { clients } = await runtime . getClientsForOptions ( options ) ;
664725 const source = resolvePluginUpgradeSource ( options ) ;
665726
666727 let response ;
@@ -685,12 +746,32 @@ function buildPluginCli(runtime: RuntimeContext): CAC {
685746 const pluginResponse = await clients . core . plugin . plugin . getPlugin ( { name : target . name } ) ;
686747 const appId = resolvePluginAppStoreAppId ( pluginResponse . data ) ;
687748 const appStoreClient = await createAppStoreClient ( clients ) ;
688- const downloadUrl = await resolveLatestAppStoreDownloadUrl ( appStoreClient , appId ) ;
749+ const release = await resolveLatestAppStoreRelease ( appStoreClient , appId ) ;
689750
690- spinner . update ( `Upgrading plugin ${ target . name } from Halo App Store...` ) ;
751+ spinner . stop ( ) ;
752+ const confirmed = await confirmAppStoreReleaseReview (
753+ {
754+ commandPath : "halo plugin upgrade" ,
755+ actionLabel : `upgrading plugin ${ target . name } ` ,
756+ items : [
757+ {
758+ name : pluginResponse . data . spec ?. displayName ?? target . name ,
759+ releaseUrl : release . releaseUrl ,
760+ } ,
761+ ] ,
762+ requireTypedYes : true ,
763+ } ,
764+ options ,
765+ ) ;
766+
767+ if ( ! confirmed ) {
768+ return ;
769+ }
770+
771+ spinner . start ( `Upgrading plugin ${ target . name } from Halo App Store...` ) ;
691772 response = await clients . console . plugin . plugin . upgradePluginFromUri ( {
692773 name : target . name ,
693- upgradeFromUriRequest : { uri : downloadUrl } ,
774+ upgradeFromUriRequest : { uri : release . downloadUrl } ,
694775 } ) ;
695776 spinner . succeed ( `Upgraded plugin ${ target . name } .` ) ;
696777 }
0 commit comments