1 | const homedir = require( 'os' ).homedir();
|
2 | const nconf = require( 'nconf' );
|
3 | const chalk = require( 'chalk' );
|
4 | const fs = require( 'fs' );
|
5 | const p = require( 'path' );
|
6 | const config = require( './config' );
|
7 | const util = require( './util' );
|
8 | const app = require( './app' );
|
9 | const validate = require( './validate' );
|
10 | const sanitize = require( './sanitize' );
|
11 |
|
12 | const prompt = {
|
13 |
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | getProjPrompt( dataProjects ) {
|
20 | const choices = dataProjects.map( ( project, index ) => ({
|
21 | key : index,
|
22 | name : chalk`${project.name} {gray ${project.slug}}`,
|
23 | value : project.slug,
|
24 | short : project.slug,
|
25 | }) );
|
26 |
|
27 | Object.keys( dataProjects ).forEach( ( key ) => {
|
28 | const { slug } = dataProjects[key];
|
29 | const path = nconf.get( `local_projects:${slug}:path` );
|
30 | const choice = choices.filter( obj => obj.value === slug );
|
31 |
|
32 | if ( path !== undefined ) {
|
33 |
|
34 | choice[0].name = chalk`{green.bold ⬤ }${choice[0].name}`;
|
35 | } else {
|
36 |
|
37 | choice[0].name = chalk`{gray.bold ⬤ }${choice[0].name}`;
|
38 | }
|
39 | });
|
40 |
|
41 | return {
|
42 | type : 'list',
|
43 | name : 'answer',
|
44 | message : 'Choose a project:',
|
45 | choices,
|
46 | };
|
47 | },
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 | getprofileOptionPrompt() {
|
54 | const choices = [
|
55 | {
|
56 | name : 'Change profiles',
|
57 | value : 'change',
|
58 | short : 'change',
|
59 | },
|
60 | {
|
61 | name : 'Create new profile',
|
62 | value : 'create',
|
63 | short : 'create',
|
64 | },
|
65 | {
|
66 | name : 'Remove a profile',
|
67 | value : 'remove',
|
68 | short : 'remove',
|
69 | },
|
70 | ];
|
71 | return {
|
72 | type : 'list',
|
73 | name : 'answer',
|
74 | message : 'What do you want to do?',
|
75 | choices,
|
76 | };
|
77 | },
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 | getChangeProfilePrompt() {
|
84 | let name;
|
85 | const choices = [];
|
86 | const profiles = util.getProfiles();
|
87 | const currentProfileName = util.getCurrentProfileName();
|
88 |
|
89 | profiles.forEach( ( profilePath ) => {
|
90 | const profileName = util.getProfileName( profilePath );
|
91 |
|
92 | if ( currentProfileName === profileName ) {
|
93 | name = chalk`{green.bold ⬤ }${profileName}`;
|
94 | } else {
|
95 | name = chalk`{gray.bold ⬤ }${profileName}`;
|
96 | }
|
97 |
|
98 | choices.push({
|
99 | name,
|
100 | value : profilePath,
|
101 | short : profileName,
|
102 | });
|
103 | });
|
104 |
|
105 | return {
|
106 | type : 'list',
|
107 | name : 'answer',
|
108 | message : 'Select a profile',
|
109 | choices,
|
110 | };
|
111 | },
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 | getAvailableProjectsPrompt() {
|
118 | const projectList = util.getLocalProjects();
|
119 | const choices = [];
|
120 |
|
121 | Object.keys( projectList ).forEach( ( key, i ) => {
|
122 | const choice = {
|
123 | key : i,
|
124 | name : chalk`${projectList[key].name} {gray ${key}}`,
|
125 | value : key,
|
126 | short : key,
|
127 | };
|
128 | choices.push( choice );
|
129 | });
|
130 |
|
131 | return {
|
132 | type : 'list',
|
133 | name : 'answer',
|
134 | message : 'Choose a project:',
|
135 | choices,
|
136 | };
|
137 | },
|
138 |
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | getEnvPrompt( dataProjects, prj ) {
|
146 | const project = util.getProjectInfo( dataProjects, prj );
|
147 | const envs = project.env;
|
148 | const choices = envs.map( ( env, index ) => ({
|
149 | key : index,
|
150 | name : chalk`${env.name.toUpperCase()} {gray ${env.url}}`,
|
151 | value : env.name,
|
152 | }) );
|
153 |
|
154 | return {
|
155 | type : 'list',
|
156 | name : 'answer',
|
157 | message : 'Choose an environment:',
|
158 | choices,
|
159 | };
|
160 | },
|
161 |
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 | getTypePrompt( dataProjectTypes ) {
|
168 | const choices = dataProjectTypes.map( ( type, index ) => ({
|
169 | key : index,
|
170 | name : type.name,
|
171 | value : type.name,
|
172 | short : type.name,
|
173 | }) );
|
174 |
|
175 | return {
|
176 | type : 'list',
|
177 | name : 'answer',
|
178 | message : 'Choose a project type:',
|
179 | choices,
|
180 | };
|
181 | },
|
182 |
|
183 | |
184 |
|
185 |
|
186 |
|
187 | getDirPrompt() {
|
188 | return {
|
189 | type : 'input',
|
190 | name : 'answer',
|
191 | message : 'Choose a directory:',
|
192 | default : nconf.get( 'default_clone_path' ),
|
193 | validate : validate.path,
|
194 | filter : sanitize.path,
|
195 | };
|
196 | },
|
197 |
|
198 | |
199 |
|
200 |
|
201 |
|
202 | getNamePrompt() {
|
203 | return {
|
204 | type : 'input',
|
205 | name : 'answer',
|
206 | message : 'Project Name:',
|
207 | validate : validate.name,
|
208 | };
|
209 | },
|
210 |
|
211 | |
212 |
|
213 |
|
214 |
|
215 | getEmailPrompt() {
|
216 | return {
|
217 | type : 'input',
|
218 | name : 'answer',
|
219 | message : 'Enter your email:',
|
220 | validate : validate.email,
|
221 | };
|
222 | },
|
223 |
|
224 | |
225 |
|
226 |
|
227 |
|
228 | getProfileNamePrompt() {
|
229 | return {
|
230 | type : 'input',
|
231 | name : 'answer',
|
232 | message : 'Enter a name for this profile:',
|
233 | validate : validate.profileName,
|
234 | };
|
235 | },
|
236 |
|
237 | |
238 |
|
239 |
|
240 |
|
241 | getProjectsUrlPrompt() {
|
242 | return {
|
243 | type : 'input',
|
244 | name : 'answer',
|
245 | message : chalk`Enter url to json {green projects} config:`,
|
246 | validate : validate.jsonUrl,
|
247 | };
|
248 | },
|
249 |
|
250 | |
251 |
|
252 |
|
253 |
|
254 | getTypesUrlPrompt() {
|
255 | return {
|
256 | type : 'input',
|
257 | name : 'answer',
|
258 | message : chalk`Enter url to json {green types} config:`,
|
259 | validate : validate.jsonUrl,
|
260 | default : 'https://masonitedoors.github.io/slab-cli/data/default_project_types.json',
|
261 | };
|
262 | },
|
263 |
|
264 | |
265 |
|
266 |
|
267 |
|
268 | getConfirmPrompt() {
|
269 | return {
|
270 | type : 'confirm',
|
271 | name : 'answer',
|
272 | message : 'Are you sure?',
|
273 | };
|
274 | },
|
275 |
|
276 | |
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 | getAlreadyExistsPrompt( existingSlug, newSlug ) {
|
283 | return {
|
284 | type : 'confirm',
|
285 | name : 'answer',
|
286 | message : chalk`A project with this name already exists. Continue as a new project? {yellow ${newSlug}}`,
|
287 | };
|
288 | },
|
289 |
|
290 | |
291 |
|
292 |
|
293 |
|
294 | getDefaultDirPrompt() {
|
295 | return {
|
296 | type : 'input',
|
297 | name : 'answer',
|
298 | message : 'Enter default clone directory:',
|
299 | default : homedir,
|
300 | validate : validate.path,
|
301 | filter : sanitize.path,
|
302 | };
|
303 | },
|
304 |
|
305 | };
|
306 |
|
307 | module.exports = prompt;
|