@@ -10,6 +10,7 @@ import { PromptType, Reporter } from '../ui/reporters/reporter.js';
1010import { FileUtils } from '../utils/file.js' ;
1111import { FileModificationCalculator , ModificationType } from '../utils/file-modification-calculator.js' ;
1212import { sleep } from '../utils/index.js' ;
13+ import { wildCardMatch } from '../utils/wild-card-match.js' ;
1314import { InitializeOrchestrator } from './initialize.js' ;
1415
1516export type RequiredParameters = Map < string , RequiredParameter [ ] > ;
@@ -51,16 +52,18 @@ export class ImportOrchestrator {
5152
5253 ctx . processStarted ( ProcessName . IMPORT )
5354
54- const { dependencyMap , pluginManager, project } = await InitializeOrchestrator . run (
55+ const { typeIdsToDependenciesMap , pluginManager, project } = await InitializeOrchestrator . run (
5556 { ...args , allowEmptyProject : true } ,
5657 reporter
5758 ) ;
58- await ImportOrchestrator . validate ( typeIds , project , pluginManager , dependencyMap )
59- const resourceInfoList = await pluginManager . getMultipleResourceInfo ( typeIds ) ;
6059
60+ const matchedTypes = this . matchTypeIds ( typeIds , [ ...typeIdsToDependenciesMap . keys ( ) ] )
61+ await ImportOrchestrator . validate ( matchedTypes , project , pluginManager , typeIdsToDependenciesMap ) ;
62+
63+ const resourceInfoList = await pluginManager . getMultipleResourceInfo ( matchedTypes ) ;
64+ // Figure out which resources we need to prompt the user for additional info (based on the resource info)
6165 const [ noPrompt , askPrompt ] = resourceInfoList . reduce ( ( result , info ) => {
6266 info . getRequiredParameters ( ) . length === 0 ? result [ 0 ] . push ( info ) : result [ 1 ] . push ( info ) ;
63-
6467 return result ;
6568 } , [ < ResourceInfo [ ] > [ ] , < ResourceInfo [ ] > [ ] ] )
6669
@@ -115,6 +118,39 @@ export class ImportOrchestrator {
115118 }
116119 }
117120
121+ private static matchTypeIds ( typeIds : string [ ] , validTypeIds : string [ ] ) : string [ ] {
122+ const result : string [ ] = [ ] ;
123+ const unsupportedTypeIds : string [ ] = [ ] ;
124+
125+ for ( const typeId of typeIds ) {
126+ if ( ! typeId . includes ( '*' ) && ! typeId . includes ( '?' ) ) {
127+ const matched = validTypeIds . includes ( typeId ) ;
128+ if ( ! matched ) {
129+ unsupportedTypeIds . push ( typeId ) ;
130+ continue ;
131+ }
132+
133+ result . push ( typeId )
134+ continue ;
135+ }
136+
137+ const matched = validTypeIds . filter ( ( valid ) => wildCardMatch ( valid , typeId ) )
138+ if ( matched . length === 0 ) {
139+ unsupportedTypeIds . push ( typeId ) ;
140+ continue ;
141+ }
142+
143+ result . push ( ...matched ) ;
144+ }
145+
146+ if ( unsupportedTypeIds . length > 0 ) {
147+ throw new Error ( `The following resources cannot be imported. No plugins found that support the following types:
148+ ${ JSON . stringify ( unsupportedTypeIds ) } `) ;
149+ }
150+
151+ return result ;
152+ }
153+
118154 private static async validate ( typeIds : string [ ] , project : Project , pluginManager : PluginManager , dependencyMap : DependencyMap ) : Promise < void > {
119155 ctx . subprocessStarted ( SubProcessName . VALIDATE )
120156
@@ -237,3 +273,4 @@ ${JSON.stringify(unsupportedTypeIds)}`);
237273 } )
238274 }
239275}
276+
0 commit comments