-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinteractive.ts
More file actions
74 lines (68 loc) · 1.83 KB
/
interactive.ts
File metadata and controls
74 lines (68 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { cliux, validatePath } from '@contentstack/cli-utilities';
import * as path from 'path';
export const askPassword = async () => {
return cliux.inquire<string>({
type: 'input',
message: 'CLI_AUTH_LOGIN_ENTER_PASSWORD',
name: 'password',
transformer: (pswd: string) => {
let pswdMasked = '';
for (let i = 0; i < pswd.length; i++) {
pswdMasked += '*';
}
return pswdMasked;
},
});
};
export const askOTPChannel = async (): Promise<string> => {
return cliux.inquire<string>({
type: 'list',
name: 'otpChannel',
message: 'CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_OTP',
choices: [
{ name: 'Authy App', value: 'authy' },
{ name: 'SMS', value: 'sms' },
],
});
};
export const askOTP = async (): Promise<string> => {
return cliux.inquire({
type: 'input',
message: 'CLI_AUTH_LOGIN_ENTER_SECURITY_CODE',
name: 'tfaToken',
});
};
export const askUsername = async (): Promise<string> => {
return cliux.inquire<string>({
type: 'input',
message: 'CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS',
name: 'username',
});
};
export const askExportDir = async (): Promise<string> => {
let result = await cliux.inquire<string>({
type: 'input',
message: 'Enter the path for storing the content: (current folder)',
name: 'dir',
validate: validatePath,
});
if (!result) {
return process.cwd();
} else {
result = result.replace(/['"]/g, '');
return path.resolve(result);
}
};
export const askAPIKey = async (): Promise<string> => {
return await cliux.inquire<string>({
type: 'input',
message: 'Enter the stack api key',
name: 'apiKey',
validate: (input: string) => {
if (!input || !input.trim()) {
return 'Stack API key cannot be empty. Please enter a valid stack API key.';
}
return true;
},
});
};