SHOW:
|
|
- or go back to the newest paste.
1 | #!/usr/bin/env node | |
2 | ||
3 | var fs = require('fs'); | |
4 | var inquirer = require('inquirer'); | |
5 | var readline = require('readline'); | |
6 | ||
7 | var args = []; | |
8 | ||
9 | process.argv.slice(2).forEach(function(arg){ | |
10 | args.push(arg); | |
11 | }); | |
12 | ||
13 | var createFolder = function(dir){ | |
14 | fs.mkdir(dir, function(err){ | |
15 | if(err !== null){ | |
16 | return console.log(true); | |
17 | }else{ | |
18 | return console.log(false); | |
19 | } | |
20 | }); | |
21 | }; | |
22 | ||
23 | ||
24 | var generateAuth = [ | |
25 | { | |
26 | type: "input", | |
27 | name: "environmentName", | |
28 | message: "Environment Name", | |
29 | validate: function(value){ | |
30 | if(!(value.length = 0)){ | |
31 | return true; | |
32 | }else{ | |
33 | return "Please enter a valid environment name"; | |
34 | } | |
35 | } | |
36 | }, | |
37 | { | |
38 | type: "input", | |
39 | name: "environmentUsername", | |
40 | message: "Username", | |
41 | validate: function(value){ | |
42 | if(!(value.length = 0)){ | |
43 | return true; | |
44 | }else{ | |
45 | return "Please enter a valid environment username"; | |
46 | } | |
47 | } | |
48 | }, | |
49 | { | |
50 | type: "password", | |
51 | name: "environmentPassword", | |
52 | message: "Password", | |
53 | validate: function(value){ | |
54 | if(!(value.length = 0)){ | |
55 | return true; | |
56 | }else{ | |
57 | return "Please enter a valid environment password"; | |
58 | } | |
59 | } | |
60 | }, | |
61 | { | |
62 | type: "confirm", | |
63 | name: "addAddtlAuth", | |
64 | message: "Would you like to add another Environment?", | |
65 | default: true | |
66 | } | |
67 | ]; | |
68 | ||
69 | var authe = []; | |
70 | ||
71 | }; | |
72 | var processAuthDetails = function(choice){ | |
73 | inquirer.prompt(generateAuth, function(authDetails){ | |
74 | var authDetailsJSON = { | |
75 | "username" : authDetails.environmentUsername, | |
76 | "password" : authDetails.environmentPassword | |
77 | } | |
78 | authe[authDetails.environmentName] = authDetailsJSON; | |
79 | if(authDetails.addAddtlAuth === true){ | |
80 | processAuthDetails(); | |
81 | }else{ | |
82 | console.log(authe); | |
83 | } | |
84 | }); | |
85 | }; | |
86 | ||
87 | var init = function(){ | |
88 | createFolder("./config"); | |
89 | ||
90 | if(!folderExists){ | |
91 | inquirer.prompt({ | |
92 | type: "input", | |
93 | name: "ProjectName", | |
94 | message: "Project Name", | |
95 | validate: function(value){ | |
96 | if(!(value.length = 0)){ | |
97 | return true; | |
98 | }else{ | |
99 | return "Please enter a valid name"; | |
100 | } | |
101 | } | |
102 | }, function( ProjectName ) { | |
103 | inquirer.prompt({ | |
104 | type: "confirm", | |
105 | name: "generateAuth", | |
106 | message: "Would you like to generate and save Authentication details?", | |
107 | default: true | |
108 | }, function(choice){ | |
109 | if(choice.generateAuth === true){ | |
110 | processAuthDetails(); | |
111 | } | |
112 | }); | |
113 | } | |
114 | ); | |
115 | } | |
116 | }; | |
117 | ||
118 | if(args[0] === "init"){ | |
119 | init(); | |
120 | } |