@@ -44,10 +44,51 @@ export class ImportOrchestrator {
4444 }
4545
4646 await ( ! typeIds || typeIds . length === 0
47- ? ImportOrchestrator . runExistingProject ( reporter , initializationResult )
47+ ? ImportOrchestrator . autoImportAll ( reporter , initializationResult )
4848 : ImportOrchestrator . runNewImport ( typeIds , reporter , initializationResult ) ) ;
4949 }
5050
51+ static async autoImportAll ( reporter : Reporter , initializeResult : InitializationResult ) {
52+ const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult ;
53+
54+ ctx . subprocessStarted ( SubProcessName . IMPORT_RESOURCE )
55+ const importResults = await Promise . all ( [ ...typeIdsToDependenciesMap . keys ( ) ] . map ( async ( typeId ) => {
56+ try {
57+ return await pluginManager . importResource ( {
58+ core : { type : typeId } ,
59+ parameters : { }
60+ } , true ) ;
61+ } catch {
62+ return null ;
63+ }
64+ } ) )
65+
66+ ctx . subprocessFinished ( SubProcessName . IMPORT_RESOURCE ) ;
67+
68+ const flattenedResults = importResults . filter ( Boolean ) . flatMap ( p => p ?. result ) . filter ( Boolean )
69+
70+ const userSelectedTypes = await reporter . promptInitResultSelection ( [ ...new Set ( flattenedResults . map ( ( r ) => r ! . core . type ) ) ] )
71+ ctx . log ( 'Resource types were chosen to be imported.' )
72+
73+ ctx . processFinished ( ProcessName . IMPORT ) ;
74+
75+ const importedResources = flattenedResults . filter ( ( r ) => r && userSelectedTypes . includes ( r . core . type ) )
76+ . map ( ( r ) => ResourceConfig . fromJson ( r ! ) ) ;
77+
78+ const resourceInfoList = await pluginManager . getMultipleResourceInfo (
79+ [ ...project . resourceConfigs , ...importedResources ] . map ( ( r ) => r . type ) ,
80+ ) ;
81+
82+ await ImportOrchestrator . updateExistingFiles (
83+ reporter ,
84+ project ,
85+ { result : importedResources , errors : [ ] } ,
86+ resourceInfoList ,
87+ project . codifyFiles [ 0 ] ,
88+ pluginManager ,
89+ ) ;
90+ }
91+
5192 /** Import new resources. Type ids supplied. This will ask for any required parameters */
5293 static async runNewImport ( typeIds : string [ ] , reporter : Reporter , initializeResult : InitializationResult ) : Promise < void > {
5394 const { project, pluginManager, typeIdsToDependenciesMap } = initializeResult ;
@@ -71,31 +112,6 @@ export class ImportOrchestrator {
71112 await ImportOrchestrator . saveResults ( reporter , importResult , project , resourceInfoList , pluginManager )
72113 }
73114
74- /** Update an existing project. This will use the existing resources as the parameters (no user input required). */
75- static async runExistingProject ( reporter : Reporter , initializeResult : InitializationResult ) : Promise < void > {
76- const { pluginManager, project } = initializeResult ;
77-
78- await pluginManager . validate ( project ) ;
79- const importResult = await ImportOrchestrator . import ( pluginManager , project . resourceConfigs ) ;
80-
81- ctx . processFinished ( ProcessName . IMPORT ) ;
82-
83- reporter . displayImportResult ( importResult , false ) ;
84-
85- const resourceInfoList = await pluginManager . getMultipleResourceInfo (
86- project . resourceConfigs . map ( ( r ) => r . type ) ,
87- ) ;
88-
89- await ImportOrchestrator . updateExistingFiles (
90- reporter ,
91- project ,
92- importResult ,
93- resourceInfoList ,
94- project . codifyFiles [ 0 ] ,
95- pluginManager ,
96- ) ;
97- }
98-
99115 static async import (
100116 pluginManager : PluginManager ,
101117 resources : ResourceConfig [ ] ,
0 commit comments