UNPKG

1.8 kBJavaScriptView Raw
1'use strict';
2const prompts = require('prompts');
3
4module.exports = async config => {
5 const stages = Object.keys(config.stages);
6 const stagesObj = stages.map(i => ({title: i, value: i}));
7
8 const {selectedStages} = await prompts(
9 [
10 {
11 type: 'multiselect',
12 name: 'selectedStages',
13 message: 'Pick stages to work with',
14 choices: stagesObj,
15 min: 1,
16 hint: '- Space to select. Return to submit'
17 }
18 ]
19 );
20
21 const microservices = Object.keys(config.microservices);
22 const microservicesObj = microservices.map(i => ({title: i, value: i}));
23
24 const {selectedMicroservices} = await prompts(
25 [
26 {
27 type: 'multiselect',
28 name: 'selectedMicroservices',
29 message: 'Pick microservices to work with',
30 choices: microservicesObj,
31 min: 1,
32 hint: '- Space to select. Return to submit'
33 }
34 ]
35 );
36
37 const neededVars = getNeededVariables(selectedStages, config);
38
39 const allVariables = {};
40 for (const vari of neededVars) {
41 if (vari) {
42 const values = config.variables[vari];
43 const valuesObj = values.map(i => ({title: i, value: i}));
44 /* eslint-disable-next-line no-await-in-loop */
45 const {selectedVariable} = await prompts(
46 [
47 {
48 type: 'select',
49 name: 'selectedVariable',
50 message: `Pick the value of variable "${vari}":`,
51 choices: valuesObj
52 }
53 ]
54 );
55 allVariables[vari] = selectedVariable;
56 }
57 }
58
59 return {stages: selectedStages, input: selectedMicroservices, options: allVariables};
60};
61
62function getNeededVariables(selectedStages, config) {
63 let neededVars = [];
64 for (const stage of selectedStages) {
65 if (config.stages[stage].variables) {
66 const newVars = config.stages[stage].variables.filter(i => !neededVars.includes(i));
67 neededVars = neededVars.concat(newVars);
68 }
69 }
70
71 return neededVars;
72}
73