-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.ts
More file actions
120 lines (107 loc) · 3.01 KB
/
interactive.ts
File metadata and controls
120 lines (107 loc) · 3.01 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import inquirer from 'inquirer';
import { cliux, pathValidator } from '@contentstack/cli-utilities';
import messageHandler from '../messages';
/**
* @description Inquire starter app
*/
export async function inquireApp(apps: Array<any>): Promise<any> {
const appsPreview = apps.map((app) => {
return {
name: app.displayName,
value: app,
};
});
const actions = [
{
type: 'list',
name: 'app',
message: messageHandler.parse('CLI_BOOTSTRAP_APP_SELECTION_ENQUIRY'),
choices: [...appsPreview, 'Exit'],
},
];
const selectedApp = await inquirer.prompt(actions);
if (selectedApp.app === 'Exit') {
cliux.print('Exiting...');
throw new Error('Exit');
}
return selectedApp.app;
}
/**
* @description Inquire clone destination directory
*/
export async function inquireCloneDirectory(): Promise<string> {
const actions = [
{
type: 'list',
name: 'path',
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_TYPE_ENQUIRY'),
choices: ['Current Folder', 'Other'],
},
];
const selectedPath = await inquirer.prompt(actions);
if (selectedPath.path === 'Current Folder') {
return process.cwd();
}
// Ask for the custom path
const selectedCustomPath = await inquirer.prompt([
{
type: 'input',
name: 'path',
message: messageHandler.parse('CLI_BOOTSTRAP_APP_COPY_SOURCE_CODE_DESTINATION_ENQUIRY'),
},
]);
return pathValidator(selectedCustomPath.path);
}
export async function inquireGithubAccessToken(): Promise<any> {
// Ask for the access token
const accessToken = await inquirer.prompt([
{
type: 'string',
name: 'token',
message: messageHandler.parse('CLI_BOOTSTRAP_NO_ACCESS_TOKEN_CREATED'),
},
]);
return accessToken.token;
}
export async function inquireAppType(): Promise<string> {
const actions = [
{
type: 'list',
name: 'type',
message: messageHandler.parse('CLI_BOOTSTRAP_TYPE_OF_APP_ENQUIRY'),
choices: [
{ name: 'Sample App', value: 'sampleapp' },
{ name: 'Starter App', value: 'starterapp' },
],
},
];
const appType = await inquirer.prompt(actions);
return appType.type;
}
export async function inquireLivePreviewSupport() {
const { livePreviewEnabled } = await inquirer.prompt({
type: 'confirm',
name: 'livePreviewEnabled',
message: 'Enable live preview?',
});
return livePreviewEnabled;
}
export async function inquireRunDevServer() {
const { runDevServer } = await inquirer.prompt({
type: 'confirm',
name: 'runDevServer',
message: messageHandler.parse('CLI_BOOTSTRAP_RUN_DEV_SERVER_ENQUIRY'),
default: true,
});
return runDevServer;
}
export async function continueBootstrapCommand() {
const { shouldContinue } = await inquirer.prompt({
type: 'list',
name: 'shouldContinue',
message: `To continue with the Bootstrap command without Live Preview, please select Yes.`,
choices: ['yes', 'no'],
loop: false,
});
return shouldContinue;
}