@@ -6,14 +6,14 @@ import {ExtensionRegistration} from '../api/graphql/all_app_extension_registrati
66import { DeveloperPlatformClient } from '../utilities/developer-platform-client.js'
77import { MAX_EXTENSION_HANDLE_LENGTH } from '../models/extensions/schemas.js'
88import { OrganizationApp } from '../models/organization.js'
9- import { getMigrationChoices } from '../prompts/import-extensions.js'
9+ import { allMigrationChoices } from '../prompts/import-extensions.js'
1010import { renderSelectPrompt , renderSuccess } from '@shopify/cli-kit/node/ui'
1111import { basename , joinPath } from '@shopify/cli-kit/node/path'
1212import { writeFile } from '@shopify/cli-kit/node/fs'
1313import { outputContent } from '@shopify/cli-kit/node/output'
1414import { slugify } from '@shopify/cli-kit/common/string'
1515
16- const allExtensionTypes = getMigrationChoices ( ) . map ( ( choice ) => choice . value )
16+ const allExtensionTypes = allMigrationChoices . flatMap ( ( choice ) => choice . extensionTypes )
1717
1818export async function pendingExtensions (
1919 remoteApp : OrganizationApp ,
@@ -40,6 +40,8 @@ interface ImportOptions {
4040 remoteApp : OrganizationApp
4141 developerPlatformClient : DeveloperPlatformClient
4242 extensionTypes : string [ ]
43+ extensions : ExtensionRegistration [ ]
44+ extensionRegistrations : ExtensionRegistration [ ]
4345 buildTomlObject : (
4446 ext : ExtensionRegistration ,
4547 allExtensions : ExtensionRegistration [ ] ,
@@ -48,36 +50,29 @@ interface ImportOptions {
4850}
4951
5052export async function importExtensions ( options : ImportOptions ) {
51- const { remoteApp, developerPlatformClient} = options
53+ const { app, remoteApp, developerPlatformClient, extensionTypes, extensions, extensionRegistrations, buildTomlObject} =
54+ options
5255
53- const { extensions, extensionRegistrations} = await pendingExtensions (
54- remoteApp ,
55- developerPlatformClient ,
56- options . extensionTypes ,
57- )
58-
59- if ( extensions . length === 0 ) {
60- renderSuccess ( { headline : [ 'No extensions to migrate.' ] } )
61- return
62- }
56+ let extensionsToMigrate = extensions . filter ( ( ext ) => extensionTypes . includes ( ext . type . toLowerCase ( ) ) )
6357
64- const choices = extensions . map ( ( ext ) => {
58+ const choices = extensionsToMigrate . map ( ( ext ) => {
6559 return { label : ext . title , value : ext . uuid }
6660 } )
6761
68- if ( extensions . length > 1 ) {
62+ if ( extensionsToMigrate . length > 1 ) {
6963 choices . push ( { label : 'All' , value : 'All' } )
7064 }
7165 const promptAnswer = await renderSelectPrompt ( { message : 'Extensions to migrate' , choices} )
7266
73- const extensionsToMigrate =
67+ if ( promptAnswer !== 'All' ) {
7468 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75- promptAnswer === 'All' ? extensions : [ extensions . find ( ( ext ) => ext ?. uuid === promptAnswer ) ! ]
69+ extensionsToMigrate = [ extensionsToMigrate . find ( ( ext ) => ext ?. uuid === promptAnswer ) ! ]
70+ }
7671
7772 const extensionUuids : IdentifiersExtensions = { }
7873 const importPromises = extensionsToMigrate . map ( async ( ext ) => {
79- const directory = await ensureExtensionDirectoryExists ( { app : options . app , name : ext . title } )
80- const tomlObject = options . buildTomlObject ( ext , extensionRegistrations , options . app . configuration )
74+ const directory = await ensureExtensionDirectoryExists ( { app, name : ext . title } )
75+ const tomlObject = buildTomlObject ( ext , extensionRegistrations , app . configuration )
8176 const path = joinPath ( directory , 'shopify.extension.toml' )
8277 await writeFile ( path , tomlObject )
8378 const handle = slugify ( ext . title . substring ( 0 , MAX_EXTENSION_HANDLE_LENGTH ) )
@@ -88,7 +83,7 @@ export async function importExtensions(options: ImportOptions) {
8883 const generatedExtensions = await Promise . all ( importPromises )
8984 renderSuccessMessages ( generatedExtensions )
9085 await updateAppIdentifiers ( {
91- app : options . app ,
86+ app,
9287 identifiers : {
9388 extensions : extensionUuids ,
9489 app : remoteApp . apiKey ,
0 commit comments