@@ -11,13 +11,9 @@ import {
1111 saveConfiguration
1212} from "../config" ;
1313import { build as buildCmd , exit as exitCmd } from "../lib/commandBuilder" ;
14+ import * as promptBuilder from "../lib/promptBuilder" ;
1415import { deepClone } from "../lib/util" ;
15- import {
16- hasValue ,
17- validateAccessToken ,
18- validateOrgName ,
19- validateProjectName
20- } from "../lib/validator" ;
16+ import { hasValue } from "../lib/validator" ;
2117import { logger } from "../logger" ;
2218import { ConfigYaml } from "../types" ;
2319import decorator from "./init.decorator.json" ;
@@ -31,6 +27,7 @@ interface Answer {
3127 azdo_org_name : string ;
3228 azdo_project_name : string ;
3329 azdo_pat : string ;
30+ toSetupIntrospectionConfig : boolean ;
3431}
3532
3633/**
@@ -52,34 +49,17 @@ export const handleFileConfig = (file: string): void => {
5249 */
5350export const prompt = async ( curConfig : ConfigYaml ) : Promise < Answer > => {
5451 const questions = [
55- {
56- default : curConfig . azure_devops ?. org || undefined ,
57- message : "Enter organization name\n" ,
58- name : "azdo_org_name" ,
59- type : "input" ,
60- validate : validateOrgName
61- } ,
62- {
63- default : curConfig . azure_devops ?. project || undefined ,
64- message : "Enter project name\n" ,
65- name : "azdo_project_name" ,
66- type : "input" ,
67- validate : validateProjectName
68- } ,
69- {
70- default : curConfig . azure_devops ?. access_token || undefined ,
71- mask : "*" ,
72- message : "Enter your AzDO personal access token\n" ,
73- name : "azdo_pat" ,
74- type : "password" ,
75- validate : validateAccessToken
76- }
52+ promptBuilder . azureOrgName ( curConfig . azure_devops ?. org ) ,
53+ promptBuilder . azureProjectName ( curConfig . azure_devops ?. project ) ,
54+ promptBuilder . azureAccessToken ( curConfig . azure_devops ?. access_token ) ,
55+ promptBuilder . askToSetupIntrospectionConfig ( false )
7756 ] ;
7857 const answers = await inquirer . prompt ( questions ) ;
7958 return {
8059 azdo_org_name : answers . azdo_org_name as string ,
8160 azdo_pat : answers . azdo_pat as string ,
82- azdo_project_name : answers . azdo_project_name as string
61+ azdo_project_name : answers . azdo_project_name as string ,
62+ toSetupIntrospectionConfig : answers . toSetupIntrospectionConfig
8363 } ;
8464} ;
8565
@@ -92,7 +72,7 @@ export const getConfig = (): ConfigYaml => {
9272 loadConfiguration ( ) ;
9373 return Config ( ) ;
9474 } catch ( _ ) {
95- // current config is not found.
75+ logger . info ( " current config is not found." ) ;
9676 return {
9777 azure_devops : {
9878 access_token : "" ,
@@ -134,20 +114,68 @@ export const validatePersonalAccessToken = async (
134114 }
135115} ;
136116
117+ export const isIntrospectionAzureDefined = ( curConfig : ConfigYaml ) : boolean => {
118+ if ( ! curConfig . introspection ) {
119+ return false ;
120+ }
121+ const intro = curConfig . introspection ;
122+ return intro . azure !== undefined ;
123+ } ;
124+
125+ export const handleIntrospectionInteractive = async (
126+ curConfig : ConfigYaml
127+ ) : Promise < void > => {
128+ if ( ! isIntrospectionAzureDefined ( curConfig ) ) {
129+ curConfig . introspection = {
130+ azure : { }
131+ } ;
132+ }
133+
134+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
135+ const azure = curConfig . introspection ! . azure ! ;
136+
137+ const ans = await inquirer . prompt ( [
138+ promptBuilder . azureStorageAccountName ( azure . account_name ) ,
139+ promptBuilder . azureStorageTableName ( azure . table_name ) ,
140+ promptBuilder . azureStoragePartitionKey ( azure . partition_key ) ,
141+ promptBuilder . azureStorageAccessKey ( azure . key ) ,
142+ promptBuilder . azureKeyVaultName ( curConfig . key_vault_name )
143+ ] ) ;
144+ azure [ "account_name" ] = ans . azdo_storage_account_name ;
145+ azure [ "table_name" ] = ans . azdo_storage_table_name ;
146+ azure [ "partition_key" ] = ans . azdo_storage_partition_key ;
147+ azure . key = ans . azdo_storage_access_key ;
148+
149+ const keyVaultName = ans . azdo_storage_key_vault_name . trim ( ) ;
150+ if ( keyVaultName ) {
151+ curConfig [ "key_vault_name" ] = keyVaultName ;
152+ } else {
153+ delete curConfig [ "key_vault_name" ] ;
154+ }
155+ } ;
156+
137157/**
138158 * Handles the interactive mode of the command.
139159 */
140160export const handleInteractiveMode = async ( ) : Promise < void > => {
141- const curConfig = deepClone ( getConfig ( ) ) ;
161+ const conf = getConfig ( ) ;
162+ if ( conf . introspection && conf . introspection . azure ) {
163+ delete conf . introspection . azure . key ;
164+ }
165+ const curConfig = deepClone ( conf ) ;
142166 const answer = await prompt ( curConfig ) ;
143-
144167 curConfig [ "azure_devops" ] = curConfig . azure_devops || { } ;
145168
146169 curConfig . azure_devops . org = answer . azdo_org_name ;
147170 curConfig . azure_devops . project = answer . azdo_project_name ;
148171 curConfig . azure_devops [ "access_token" ] = answer . azdo_pat ;
149172
173+ if ( answer . toSetupIntrospectionConfig ) {
174+ await handleIntrospectionInteractive ( curConfig ) ;
175+ }
176+
150177 const data = yaml . safeDump ( curConfig ) ;
178+
151179 fs . writeFileSync ( defaultConfigFile ( ) , data ) ;
152180 logger . info ( "Successfully constructed SPK configuration file." ) ;
153181 const ok = await validatePersonalAccessToken ( curConfig . azure_devops ) ;
0 commit comments