Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var fs = require('fs');
- var inquirer = require('inquirer');
- var readline = require('readline');
- var args = [];
- process.argv.slice(2).forEach(function(arg){
- args.push(arg);
- });
- var createFolder = function(dir){
- fs.mkdir(dir, function(err){
- if(err !== null){
- return console.log(true);
- }else{
- return console.log(false);
- }
- });
- };
- var generateAuth = [
- {
- type: "input",
- name: "environmentName",
- message: "Environment Name",
- validate: function(value){
- if(!(value.length = 0)){
- return true;
- }else{
- return "Please enter a valid environment name";
- }
- }
- },
- {
- type: "input",
- name: "environmentUsername",
- message: "Username",
- validate: function(value){
- if(!(value.length = 0)){
- return true;
- }else{
- return "Please enter a valid environment username";
- }
- }
- },
- {
- type: "password",
- name: "environmentPassword",
- message: "Password",
- validate: function(value){
- if(!(value.length = 0)){
- return true;
- }else{
- return "Please enter a valid environment password";
- }
- }
- },
- {
- type: "confirm",
- name: "addAddtlAuth",
- message: "Would you like to add another Environment?",
- default: true
- }
- ];
- var authe = [];
- };
- var processAuthDetails = function(choice){
- inquirer.prompt(generateAuth, function(authDetails){
- var authDetailsJSON = {
- "username" : authDetails.environmentUsername,
- "password" : authDetails.environmentPassword
- }
- authe[authDetails.environmentName] = authDetailsJSON;
- if(authDetails.addAddtlAuth === true){
- processAuthDetails();
- }else{
- console.log(authe);
- }
- });
- };
- var init = function(){
- createFolder("./config");
- if(!folderExists){
- inquirer.prompt({
- type: "input",
- name: "ProjectName",
- message: "Project Name",
- validate: function(value){
- if(!(value.length = 0)){
- return true;
- }else{
- return "Please enter a valid name";
- }
- }
- }, function( ProjectName ) {
- inquirer.prompt({
- type: "confirm",
- name: "generateAuth",
- message: "Would you like to generate and save Authentication details?",
- default: true
- }, function(choice){
- if(choice.generateAuth === true){
- processAuthDetails();
- }
- });
- }
- );
- }
- };
- if(args[0] === "init"){
- init();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement