@@ -29,6 +29,7 @@ import {
2929} from '../common-ext/createComponentHelpers' ;
3030import { loadWebviewHtml , validateGitURL } from '../common-ext/utils' ;
3131import { Devfile , DevfileRegistry , TemplateProjectIdentifier } from '../common/devfile' ;
32+ import { DevfileV1 } from '../../util/devfileV1Type' ;
3233
3334interface CloneProcess {
3435 status : boolean ;
@@ -281,11 +282,19 @@ export default class CreateComponentLoader {
281282 action : 'cloneFailed' ,
282283 } ) ;
283284 } else {
285+ const isGirDevfileExists = await isDevfileExists ( tmpFolder ) ;
284286 void CreateComponentLoader . panel . webview . postMessage ( {
285287 action : 'devfileExists' ,
286- data : await isDevfileExists ( tmpFolder ) ,
288+ data : isGirDevfileExists ,
287289 } ) ;
288- void CreateComponentLoader . getRecommendedDevfile ( tmpFolder ) ;
290+
291+ if ( isGirDevfileExists ) {
292+ // Use the Devfile existing in Gir-repo
293+ void CreateComponentLoader . getExistingDevfile ( tmpFolder ) ;
294+ } else {
295+ // Use recommended Devfile
296+ void CreateComponentLoader . getRecommendedDevfile ( tmpFolder ) ;
297+ }
289298 }
290299 break ;
291300 }
@@ -424,6 +433,55 @@ export default class CreateComponentLoader {
424433 }
425434 }
426435
436+ static async getExistingDevfile ( uri : Uri ) : Promise < void > {
437+ const devFileYamlPath = path . join ( tmpFolder . fsPath , 'devfile.yaml' ) ;
438+ let rawDevfile : any ;
439+ let supportsDebug = false ; // Initial value
440+ let supportsDeploy = false ; // Initial value
441+ try {
442+ void CreateComponentLoader . panel . webview . postMessage ( {
443+ action : 'getRecommendedDevfileStart'
444+ } ) ;
445+ const componentDescription = await Odo . Instance . describeComponent ( uri . fsPath ) ;
446+ if ( componentDescription ) {
447+ rawDevfile = componentDescription . devfileData . devfile ;
448+ supportsDebug = componentDescription . devfileData . supportedOdoFeatures . debug ;
449+ supportsDeploy = componentDescription . devfileData . supportedOdoFeatures . deploy ;
450+ }
451+ } catch ( Error ) {
452+ // Will try reading the raw devfile
453+ } finally {
454+ if ( ! rawDevfile ) {
455+ //Try reading the raw devfile
456+ const file = await fs . readFile ( devFileYamlPath , 'utf8' ) ;
457+ rawDevfile = JSYAML . load ( file . toString ( ) ) ;
458+ }
459+
460+ void CreateComponentLoader . panel . webview . postMessage ( {
461+ action : 'getRecommendedDevfile'
462+ } ) ;
463+
464+ const devfile : Devfile = {
465+ description : rawDevfile . metadata . description ,
466+ registryName : devFileYamlPath ,
467+ name : rawDevfile . metadata . displayName ? rawDevfile . metadata . displayName : rawDevfile . metadata . name ,
468+ id : rawDevfile . metadata . name ,
469+ starterProjects : rawDevfile . starterProjects ,
470+ tags : [ ] ,
471+ yaml : JSYAML . dump ( rawDevfile ) ,
472+ supportsDebug,
473+ supportsDeploy,
474+ } as Devfile ;
475+
476+ void CreateComponentLoader . panel . webview . postMessage ( {
477+ action : 'recommendedDevfile' ,
478+ data : {
479+ devfile,
480+ } ,
481+ } ) ;
482+ }
483+ }
484+
427485 static async getRecommendedDevfile ( uri : Uri ) : Promise < void > {
428486 let analyzeRes : AnalyzeResponse [ ] = [ ] ;
429487 let compDescriptions : ComponentTypeDescription [ ] = [ ] ;
@@ -444,7 +502,7 @@ export default class CreateComponentLoader {
444502 try {
445503 const devFileV1Path = path . join ( uri . fsPath , 'devfile.yaml' ) ;
446504 const file = await fs . readFile ( devFileV1Path , 'utf8' ) ;
447- const devfileV1 = JSYAML . load ( file . toString ( ) ) ;
505+ const devfileV1 = JSYAML . load ( file . toString ( ) ) as DevfileV1 ;
448506 await fs . unlink ( devFileV1Path ) ;
449507 analyzeRes = await Odo . Instance . analyze ( uri . fsPath ) ;
450508 compDescriptions = getCompDescription ( analyzeRes ) ;
@@ -475,7 +533,7 @@ export default class CreateComponentLoader {
475533 } ) ;
476534 const devfileRegistry : DevfileRegistry [ ] = getDevfileRegistries ( ) ;
477535 const allDevfiles : Devfile [ ] = devfileRegistry . flatMap ( ( registry ) => registry . devfiles ) ;
478- const devfile : Devfile =
536+ const devfile : Devfile | undefined =
479537 compDescriptions . length !== 0
480538 ? allDevfiles . find (
481539 ( devfile ) => devfile . name === compDescriptions [ 0 ] . displayName ,
@@ -515,7 +573,8 @@ function getDevfileType(devfileDisplayName: string): string {
515573 const devfileDescription : ComponentTypeDescription = Array . from ( compDescriptions ) . find (
516574 ( description ) => description . displayName === devfileDisplayName ,
517575 ) ;
518- return devfileDescription . name ;
576+ // TODO: What value to return in case of custom devfile that comes, f.i., from a Git-repo?
577+ return devfileDescription ? devfileDescription . name : devfileDisplayName ;
519578}
520579
521580function getEndPoints ( compDescription : ComponentTypeDescription ) : Endpoint [ ] {
0 commit comments