@@ -13,7 +13,7 @@ import { FileModificationCalculator } from '../generators/file-modification-calc
1313import { ModificationType } from '../generators/index.js' ;
1414import { FileUpdater } from '../generators/writer.js' ;
1515import { CodifyParser } from '../parser/index.js' ;
16- import { DependencyMap , PluginManager } from '../plugins/plugin-manager.js' ;
16+ import { PluginManager , ResourceInfoMap } from '../plugins/plugin-manager.js' ;
1717import { prettyFormatFileDiff } from '../ui/file-diff-pretty-printer.js' ;
1818import { PromptType , Reporter } from '../ui/reporters/reporter.js' ;
1919import { FileUtils } from '../utils/file.js' ;
@@ -27,7 +27,6 @@ export interface ImportArgs {
2727 typeIds ?: string [ ] ;
2828 path : string ;
2929 updateExisting ?: boolean ;
30- secureMode ?: boolean ;
3130 verbosityLevel ?: number ;
3231}
3332
@@ -56,10 +55,10 @@ export class ImportOrchestrator {
5655 }
5756
5857 static async autoImportAll ( reporter : Reporter , initializeResult : InitializationResult , args : ImportArgs ) {
59- const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult ;
58+ const { project, pluginManager, resourceInfoMap } = initializeResult ;
6059
6160 ctx . subprocessStarted ( SubProcessName . IMPORT_RESOURCE )
62- const importResults = await Promise . all ( [ ...typeIdsToDependenciesMap . keys ( ) ] . map ( async ( typeId ) => {
61+ const importResults = await Promise . all ( [ ...resourceInfoMap . keys ( ) ] . map ( async ( typeId ) => {
6362 try {
6463 return await pluginManager . importResource ( {
6564 core : { type : typeId } ,
@@ -82,28 +81,25 @@ export class ImportOrchestrator {
8281 const importedResources = flattenedResults . filter ( ( r ) => r && userSelectedTypes . includes ( r . core . type ) )
8382 . map ( ( r ) => ResourceConfig . fromJson ( r ! ) ) ;
8483
85- const resourceInfoList = await pluginManager . getMultipleResourceInfo (
86- [ ...project . resourceConfigs , ...importedResources ] . map ( ( r ) => r . type ) ,
87- ) ;
88-
8984 await ImportOrchestrator . saveResults (
9085 reporter ,
9186 { result : importedResources , errors : [ ] } ,
9287 project ,
93- resourceInfoList ,
88+ resourceInfoMap ,
9489 pluginManager ,
9590 args
9691 )
9792 }
9893
9994 /** Import new resources. Type ids supplied. This will ask for any required parameters */
10095 static async runNewImport ( typeIds : string [ ] , reporter : Reporter , initializeResult : InitializationResult , args : ImportArgs ) : Promise < void > {
101- const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult ;
96+ const { project, pluginManager, resourceInfoMap } = initializeResult ;
10297
103- const matchedTypes = this . matchTypeIds ( typeIds , [ ...typeIdsToDependenciesMap . keys ( ) ] )
104- await ImportOrchestrator . validate ( matchedTypes , project , pluginManager , typeIdsToDependenciesMap ) ;
98+ const matchedTypes = this . matchTypeIds ( typeIds , [ ...resourceInfoMap . keys ( ) ] )
99+ await ImportOrchestrator . validate ( matchedTypes , project , pluginManager , resourceInfoMap ) ;
105100
106- const resourceInfoList = ( await pluginManager . getMultipleResourceInfo ( matchedTypes ) )
101+ const resourceInfoList = [ ...resourceInfoMap . values ( ) ]
102+ . filter ( ( info ) => matchedTypes . includes ( info . type ) )
107103 . filter ( ( info ) => info . canImport )
108104
109105 const resourcesToImport = await ImportOrchestrator . getImportParameters ( reporter , project , resourceInfoList ) ;
@@ -113,10 +109,7 @@ export class ImportOrchestrator {
113109
114110 reporter . displayImportResult ( importResult , false ) ;
115111
116- resourceInfoList . push ( ...( await pluginManager . getMultipleResourceInfo (
117- project . resourceConfigs . map ( ( r ) => r . type )
118- ) ) ) ;
119- await ImportOrchestrator . saveResults ( reporter , importResult , project , resourceInfoList , pluginManager , args )
112+ await ImportOrchestrator . saveResults ( reporter , importResult , project , resourceInfoMap , pluginManager , args )
120113 }
121114
122115 static async import (
@@ -162,7 +155,7 @@ export class ImportOrchestrator {
162155 reporter : Reporter ,
163156 importResult : ImportResult ,
164157 project : Project ,
165- resourceInfoList : ResourceInfo [ ] ,
158+ resourceInfoMap : ResourceInfoMap ,
166159 pluginManager : PluginManager ,
167160 args : ImportArgs ,
168161 ) : Promise < void > {
@@ -177,7 +170,7 @@ export class ImportOrchestrator {
177170 const file = multipleCodifyFiles
178171 ? project . codifyFiles [ await reporter . promptOptions ( '\nIf new resources are added, where to write them?' , project . codifyFiles ) ]
179172 : project . codifyFiles [ 0 ] ;
180- await ImportOrchestrator . updateExistingFiles ( reporter , project , importResult , resourceInfoList , file , pluginManager ) ;
173+ await ImportOrchestrator . updateExistingFiles ( reporter , project , importResult , resourceInfoMap , file , pluginManager ) ;
181174 return ;
182175 }
183176
@@ -199,7 +192,7 @@ export class ImportOrchestrator {
199192 reporter : Reporter ,
200193 existingProject : Project ,
201194 importResult : ImportResult ,
202- resourceInfoList : ResourceInfo [ ] ,
195+ resourceInfoMap : ResourceInfoMap ,
203196 preferredFile : string , // File to write any new resources (unknown file path)
204197 pluginManager : PluginManager ,
205198 ) : Promise < void > {
@@ -218,8 +211,8 @@ export class ImportOrchestrator {
218211
219212 const diffs = await Promise . all ( Object . entries ( groupedResults ) . map ( async ( [ filePath , imported ] ) => {
220213 const existing = await CodifyParser . parse ( filePath ! ) ;
221- ImportOrchestrator . attachResourceInfo ( imported , resourceInfoList ) ;
222- ImportOrchestrator . attachResourceInfo ( existing . resourceConfigs , resourceInfoList ) ;
214+ ImportOrchestrator . attachResourceInfo ( imported , resourceInfoMap ) ;
215+ ImportOrchestrator . attachResourceInfo ( existing . resourceConfigs , resourceInfoMap ) ;
223216
224217 const modificationCalculator = new FileModificationCalculator ( existing ) ;
225218 const modification = await modificationCalculator . calculate (
@@ -364,10 +357,10 @@ ${JSON.stringify(unsupportedTypeIds)}`);
364357 return result ;
365358 }
366359
367- private static async validate ( typeIds : string [ ] , project : Project , pluginManager : PluginManager , dependencyMap : DependencyMap ) : Promise < void > {
368- project . validateTypeIds ( dependencyMap ) ;
360+ private static async validate ( typeIds : string [ ] , project : Project , pluginManager : PluginManager , resourceInfoMap : ResourceInfoMap ) : Promise < void > {
361+ project . validateTypeIds ( resourceInfoMap ) ;
369362
370- const unsupportedTypeIds = typeIds . filter ( ( type ) => ! dependencyMap . has ( type ) ) ;
363+ const unsupportedTypeIds = typeIds . filter ( ( type ) => ! resourceInfoMap . has ( type ) ) ;
371364 if ( unsupportedTypeIds . length > 0 ) {
372365 throw new Error ( `The following resources cannot be imported. No plugins found that support the following types:
373366${ JSON . stringify ( unsupportedTypeIds ) } `) ;
@@ -377,6 +370,7 @@ ${JSON.stringify(unsupportedTypeIds)}`);
377370 private static async getImportParameters ( reporter : Reporter , project : Project , resourceInfoList : ResourceInfo [ ] ) : Promise < Array < ResourceConfig > > {
378371 // Figure out which resources we need to prompt the user for additional info (based on the resource info)
379372 const [ noPrompt , askPrompt ] = resourceInfoList . reduce ( ( result , info ) => {
373+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
380374 info . getRequiredParameters ( ) . length === 0 ? result [ 0 ] . push ( info ) : result [ 1 ] . push ( info ) ;
381375 return result ;
382376 } , [ < ResourceInfo [ ] > [ ] , < ResourceInfo [ ] > [ ] ] )
@@ -472,6 +466,7 @@ ${JSON.stringify(unsupportedTypeIds)}`);
472466 let fileName = path . join ( folderPath , 'import.codify.jsonc' )
473467 let counter = 1 ;
474468
469+ // eslint-disable-next-line no-constant-condition
475470 while ( true ) {
476471 if ( ! ( await FileUtils . fileExists ( fileName ) ) ) {
477472 return fileName ;
@@ -483,9 +478,9 @@ ${JSON.stringify(unsupportedTypeIds)}`);
483478 }
484479
485480 // We have to attach additional info to the imported configs to make saving easier
486- private static attachResourceInfo ( resources : ResourceConfig [ ] , resourceInfoList : ResourceInfo [ ] ) : void {
481+ private static attachResourceInfo ( resources : ResourceConfig [ ] , resourceInfoMap : ResourceInfoMap ) : void {
487482 resources . forEach ( ( resource ) => {
488- const matchedInfo = resourceInfoList . find ( ( info ) => info . type === resource . type ) ! ;
483+ const matchedInfo = resourceInfoMap . get ( resource . type ) ;
489484 if ( ! matchedInfo ) {
490485 throw new Error ( `Could not find type ${ resource . type } in the resource info` ) ;
491486 }
0 commit comments