smoonb 0.0.46 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/interactive/envMapper.js +37 -23
package/package.json
CHANGED
|
@@ -10,29 +10,40 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
10
10
|
for (const expected of expectedKeys) {
|
|
11
11
|
console.log(chalk.blue(`\n🔧 Mapeando variável: ${expected}`));
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
...allKeys.map((k, idx) => ({ name: `${idx + 1}. ${k}`, value: k })),
|
|
15
|
-
new inquirer.Separator(),
|
|
16
|
-
{ name: 'Adicionar nova chave com este nome', value: '__ADD_NEW__' }
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
const { chosen } = await inquirer.prompt([{
|
|
20
|
-
type: 'list',
|
|
21
|
-
name: 'chosen',
|
|
22
|
-
message: `Selecione a chave correspondente para: ${expected}`,
|
|
23
|
-
choices
|
|
24
|
-
}]);
|
|
13
|
+
let clientKey = undefined;
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
if (
|
|
15
|
+
// 3) Se existir chave exatamente igual, pular seleção e ir direto para confirmação
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(finalEnv, expected)) {
|
|
28
17
|
clientKey = expected;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
} else {
|
|
19
|
+
// 2) Remover o caractere '?' do início da pergunta definindo prefix: ''
|
|
20
|
+
// 4) Opção explícita para adicionar nova chave
|
|
21
|
+
const choices = [
|
|
22
|
+
...allKeys.map((k, idx) => ({ name: `${idx + 1}. ${k}`, value: k })),
|
|
23
|
+
new inquirer.Separator(),
|
|
24
|
+
{ name: 'Adicione uma nova chave para mim', value: '__ADD_NEW__' }
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const { chosen } = await inquirer.prompt([{
|
|
28
|
+
type: 'list',
|
|
29
|
+
name: 'chosen',
|
|
30
|
+
message: `Selecione a chave correspondente para: ${expected}`,
|
|
31
|
+
choices,
|
|
32
|
+
loop: false,
|
|
33
|
+
prefix: ''
|
|
34
|
+
}]);
|
|
35
|
+
|
|
36
|
+
clientKey = chosen;
|
|
37
|
+
if (chosen === '__ADD_NEW__') {
|
|
38
|
+
clientKey = expected;
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(finalEnv, clientKey)) {
|
|
40
|
+
// Evitar colisão: gerar sufixo incremental
|
|
41
|
+
let i = 2;
|
|
42
|
+
while (Object.prototype.hasOwnProperty.call(finalEnv, `${clientKey}_${i}`)) i++;
|
|
43
|
+
clientKey = `${clientKey}_${i}`;
|
|
44
|
+
}
|
|
45
|
+
finalEnv[clientKey] = '';
|
|
34
46
|
}
|
|
35
|
-
finalEnv[clientKey] = '';
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
const currentValue = finalEnv[clientKey] ?? '';
|
|
@@ -40,7 +51,8 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
40
51
|
type: 'confirm',
|
|
41
52
|
name: 'isCorrect',
|
|
42
53
|
message: `Valor atual: ${currentValue || '(vazio)'} Este é o valor correto do projeto alvo? (S/n):`,
|
|
43
|
-
default: true
|
|
54
|
+
default: true,
|
|
55
|
+
prefix: ''
|
|
44
56
|
}]);
|
|
45
57
|
|
|
46
58
|
let valueToWrite = currentValue;
|
|
@@ -48,7 +60,8 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
48
60
|
const { newValue } = await inquirer.prompt([{
|
|
49
61
|
type: 'input',
|
|
50
62
|
name: 'newValue',
|
|
51
|
-
message: `Cole o novo valor para ${clientKey}
|
|
63
|
+
message: `Cole o novo valor para ${clientKey}:`,
|
|
64
|
+
prefix: ''
|
|
52
65
|
}]);
|
|
53
66
|
valueToWrite = newValue || '';
|
|
54
67
|
}
|
|
@@ -57,7 +70,8 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
57
70
|
const { newValueRequired } = await inquirer.prompt([{
|
|
58
71
|
type: 'input',
|
|
59
72
|
name: 'newValueRequired',
|
|
60
|
-
message: `Valor obrigatório. Informe valor para ${clientKey}
|
|
73
|
+
message: `Valor obrigatório. Informe valor para ${clientKey}:`,
|
|
74
|
+
prefix: ''
|
|
61
75
|
}]);
|
|
62
76
|
valueToWrite = newValueRequired || '';
|
|
63
77
|
}
|