Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mololab
GitHub Repository: mololab/json-translator
Path: blob/master/src/cli/prompt.ts
235 views
1
import {
2
translationModuleKeys,
3
getTranslationModuleByKey,
4
} from '../modules/helpers';
5
import { messages } from '../utils/console';
6
import { default_concurrency_limit } from '../utils/micro';
7
var inquirer = require('inquirer');
8
9
export async function promptModuleKey(): Promise<string> {
10
const module_key_choices = translationModuleKeys().map(key => {
11
return {
12
name:
13
getTranslationModuleByKey(key).altName +
14
(getTranslationModuleByKey(key).requirements
15
? ' | requirements: ' +
16
(getTranslationModuleByKey(key).requirements as string[]).join(
17
' | '
18
)
19
: ''),
20
value: key,
21
short: key,
22
};
23
});
24
25
let selectedModuleKey = '';
26
27
await inquirer
28
.prompt([
29
{
30
type: 'list',
31
name: 'moduleKey',
32
message: messages.cli.select_module_message,
33
pageSize: 20,
34
choices: [...module_key_choices, new inquirer.Separator()],
35
},
36
])
37
.then((answers: any) => {
38
selectedModuleKey = answers.moduleKey;
39
});
40
41
return selectedModuleKey;
42
}
43
44
export async function promptFrom(languages: Record<string, string>) {
45
const fromLanguageKeys = Object.keys(languages);
46
47
const answers = await inquirer.prompt([
48
{
49
type: 'list',
50
name: 'from',
51
message: messages.cli.from_message,
52
pageSize: 20,
53
choices: [...fromLanguageKeys, new inquirer.Separator()],
54
},
55
]);
56
57
return answers.from;
58
}
59
60
export async function promptTo(
61
languages: Record<string, string>,
62
default_languages?: string[]
63
) {
64
let toLanguageKeys = Object.keys(languages);
65
toLanguageKeys = toLanguageKeys.filter(key => key !== `Automatic`);
66
67
const answers = await inquirer.prompt([
68
{
69
type: 'checkbox',
70
name: 'to',
71
pageSize: 20,
72
message: messages.cli.to_message,
73
choices: toLanguageKeys,
74
default: default_languages ? default_languages : [],
75
},
76
]);
77
78
return answers.to;
79
}
80
81
export async function promptName() {
82
const answers = await inquirer.prompt([
83
{
84
type: 'string',
85
name: 'name',
86
message: messages.cli.new_file_name_message,
87
// default: default_name ? default_name : undefined,
88
},
89
]);
90
91
return answers.name;
92
}
93
94
export async function promptFallback() {
95
const answers = await inquirer.prompt([
96
{
97
type: 'string',
98
name: 'fallback',
99
message: messages.cli.fallback_message,
100
default: '',
101
},
102
]);
103
104
if (answers.fallback === '') {
105
return 'no';
106
}
107
108
return answers.fallback;
109
}
110
111
export async function promptCacheEnabled() {
112
const answers = await inquirer.prompt([
113
{
114
type: 'string',
115
name: 'cache_enabled',
116
message: messages.cli.cache_enabled,
117
default: 'no',
118
},
119
]);
120
121
if (answers.cache_enabled === '') {
122
return 'no';
123
}
124
125
return answers.cache_enabled;
126
}
127
128
export async function promptConcurrencyLimit() {
129
const answers = await inquirer.prompt([
130
{
131
type: 'number',
132
name: 'concurrencylimit',
133
message: messages.cli.concurrency_limit_message,
134
default: '',
135
},
136
]);
137
138
if (answers.concurrencylimit === '') {
139
return default_concurrency_limit;
140
}
141
142
return answers.concurrencylimit;
143
}
144
145