55import * as vscode from 'vscode' ;
66import * as path from 'path' ;
77import { readFile } from 'fs-extra'
8- import { Snippet , getTknTasksSnippets } from './tkn-tasks-provider' ;
8+ import { getTknTasksSnippets } from './tkn-tasks-provider' ;
99import { schemeStorage } from './tkn-scheme-storage'
1010import { pipelineYaml } from './tkn-yaml' ;
11+ import { Snippet } from './snippet' ;
12+ import { getTknConditionsSnippets } from './tkn-conditions-provider' ;
1113
1214let context : vscode . ExtensionContext ;
1315export function generateScheme ( extContext : vscode . ExtensionContext , vsDocument : vscode . TextDocument ) : Promise < string > {
@@ -18,7 +20,7 @@ export function generateScheme(extContext: vscode.ExtensionContext, vsDocument:
1820
1921
2022// eslint-disable-next-line @typescript-eslint/no-explicit-any
21- function injectTaskSnippets ( templateObj : any , snippets : Snippet [ ] ) : { } {
23+ function injectTaskSnippets ( templateObj : any , snippets : Snippet < { } > [ ] ) : { } {
2224 templateObj . definitions . PipelineSpec . properties . tasks . defaultSnippets = snippets ;
2325 return templateObj ;
2426}
@@ -45,9 +47,17 @@ function injectResourceName(templateObj: any, resNames: string[]): {} {
4547 return templateObj ;
4648}
4749
50+ function injectConditionRefs ( templateObj : any , conditions : string [ ] ) : { } {
51+ if ( conditions && conditions . length > 0 ) {
52+ templateObj . definitions . PipelineTaskCondition . properties . conditionRef . enum = conditions ;
53+ }
54+ return templateObj ;
55+ }
56+
4857async function generate ( doc : vscode . TextDocument ) : Promise < string > {
4958 const template = await readFile ( path . join ( context . extensionPath , 'scheme' , 'pipeline.json' ) , 'UTF8' ) ;
5059 const snippets = await getTknTasksSnippets ( ) ;
60+ const conditions = await getTknConditionsSnippets ( ) ;
5161 const definedTasks = pipelineYaml . getPipelineTasksName ( doc ) ;
5262 const declaredResources = pipelineYaml . getDeclaredResources ( doc ) ;
5363
@@ -57,5 +67,6 @@ async function generate(doc: vscode.TextDocument): Promise<string> {
5767 const tasksRef = snippets . map ( value => value . body . taskRef . name ) ;
5868 templateWithSnippets = injectTasksName ( templateWithSnippets , definedTasks , tasksRef ) ;
5969 templateWithSnippets = injectResourceName ( templateWithSnippets , resNames ) ;
70+ templateWithSnippets = injectConditionRefs ( templateWithSnippets , conditions ) ;
6071 return JSON . stringify ( templateWithSnippets ) ;
6172}
0 commit comments