|
1 | | -import {AppLinkedInterface, CurrentAppConfiguration} from '../models/app/app.js' |
| 1 | +import {importDeclarativeDefinitions} from './generate/shop-import/declarative-definitions.js' |
| 2 | +import {AppLinkedInterface} from '../models/app/app.js' |
2 | 3 | import {updateAppIdentifiers, IdentifiersExtensions} from '../models/app/identifiers.js' |
3 | 4 | import {ExtensionRegistration} from '../api/graphql/all_app_extension_registrations.js' |
4 | 5 | import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js' |
5 | 6 | import {MAX_EXTENSION_HANDLE_LENGTH} from '../models/extensions/schemas.js' |
6 | | -import {OrganizationApp} from '../models/organization.js' |
7 | | -import {allMigrationChoices, getMigrationChoices} from '../prompts/import-extensions.js' |
| 7 | +import {Organization, OrganizationApp} from '../models/organization.js' |
| 8 | +import { |
| 9 | + allMigrationChoices, |
| 10 | + getMigrationChoices, |
| 11 | + MigrationChoice, |
| 12 | + ShopImportMigrationChoice, |
| 13 | +} from '../prompts/import-extensions.js' |
8 | 14 | import {configurationFileNames, blocks} from '../constants.js' |
| 15 | +import {RemoteAwareExtensionSpecification} from '../models/extensions/specification.js' |
9 | 16 | import {renderSelectPrompt, renderSuccess} from '@shopify/cli-kit/node/ui' |
10 | 17 | import {basename, joinPath} from '@shopify/cli-kit/node/path' |
11 | 18 | import {removeFile, writeFile, fileExists, mkdir, touchFile} from '@shopify/cli-kit/node/fs' |
12 | 19 | import {outputContent} from '@shopify/cli-kit/node/output' |
13 | 20 | import {slugify, hyphenate} from '@shopify/cli-kit/common/string' |
14 | | -import {AbortError, AbortSilentError} from '@shopify/cli-kit/node/error' |
| 21 | +import {AbortError, AbortSilentError, BugError} from '@shopify/cli-kit/node/error' |
15 | 22 |
|
16 | | -export const allExtensionTypes = allMigrationChoices.flatMap((choice) => choice.extensionTypes) |
| 23 | +export const allExtensionTypes = allMigrationChoices.flatMap((choice) => |
| 24 | + choice.mode === 'extension' ? choice.extensionTypes : [], |
| 25 | +) |
17 | 26 |
|
18 | 27 | interface ImportAllOptions { |
19 | 28 | app: AppLinkedInterface |
20 | 29 | remoteApp: OrganizationApp |
21 | 30 | developerPlatformClient: DeveloperPlatformClient |
22 | 31 | extensions: ExtensionRegistration[] |
| 32 | + organization: Organization |
| 33 | + specifications: RemoteAwareExtensionSpecification[] |
23 | 34 | } |
24 | 35 |
|
25 | 36 | interface ImportOptions extends ImportAllOptions { |
26 | | - extensionTypes: string[] |
27 | | - buildTomlObject: ( |
28 | | - ext: ExtensionRegistration, |
29 | | - allExtensions: ExtensionRegistration[], |
30 | | - appConfig: CurrentAppConfiguration, |
31 | | - ) => string |
| 37 | + migrationChoice: MigrationChoice |
32 | 38 | all?: boolean |
33 | 39 | } |
34 | 40 |
|
@@ -76,8 +82,23 @@ async function handleExtensionDirectory({ |
76 | 82 | return {directory: extensionDirectory, action: DirectoryAction.Write} |
77 | 83 | } |
78 | 84 |
|
| 85 | +async function importConfigurationFromShop(options: ImportOptions & {migrationChoice: ShopImportMigrationChoice}) { |
| 86 | + switch (options.migrationChoice.value) { |
| 87 | + case 'declarative definitions': |
| 88 | + return importDeclarativeDefinitions(options) |
| 89 | + default: |
| 90 | + throw new BugError(`Unsupported shop import source: ${options.migrationChoice.value}`) |
| 91 | + } |
| 92 | +} |
| 93 | + |
79 | 94 | export async function importExtensions(options: ImportOptions) { |
80 | | - const {app, remoteApp, developerPlatformClient, extensionTypes, extensions, buildTomlObject, all} = options |
| 95 | + const {app, remoteApp, developerPlatformClient, migrationChoice, extensions, all} = options |
| 96 | + |
| 97 | + if (migrationChoice.mode === 'shop-import') { |
| 98 | + return importConfigurationFromShop({...options, migrationChoice}) |
| 99 | + } |
| 100 | + |
| 101 | + const {extensionTypes, buildTomlObject} = migrationChoice |
81 | 102 |
|
82 | 103 | let extensionsToMigrate = extensions.filter((ext) => extensionTypes.includes(ext.type.toLowerCase())) |
83 | 104 | extensionsToMigrate = filterOutImportedExtensions(app, extensionsToMigrate) |
@@ -144,14 +165,15 @@ export function filterOutImportedExtensions(app: AppLinkedInterface, extensions: |
144 | 165 | export async function importAllExtensions(options: ImportAllOptions) { |
145 | 166 | const migrationChoices = getMigrationChoices(options.extensions) |
146 | 167 | await Promise.all( |
147 | | - migrationChoices.map(async (choice) => { |
148 | | - return importExtensions({ |
149 | | - ...options, |
150 | | - extensionTypes: choice.extensionTypes, |
151 | | - buildTomlObject: choice.buildTomlObject, |
152 | | - all: true, |
153 | | - }) |
154 | | - }), |
| 168 | + migrationChoices |
| 169 | + .filter((choice) => choice.mode === 'extension') |
| 170 | + .map(async (choice) => { |
| 171 | + return importExtensions({ |
| 172 | + ...options, |
| 173 | + migrationChoice: choice, |
| 174 | + all: true, |
| 175 | + }) |
| 176 | + }), |
155 | 177 | ) |
156 | 178 | } |
157 | 179 |
|
|
0 commit comments