0

function   initNpm (){
          //services()
          const spawn_option ={ cwd:'./'+projet ,detached:true}
          var child = exec('npm init' , spawn_option,function (err, stdout, stderr){
              if(err){console.log(err)}
              //console.log('over');
          });
          child.stdout.on('data', function(data) {
              process.stdout.write(data);
              process.stdin.resume();
          });
          process.stdin.on('readable', function() {
              var chunk = process.stdin.read();
              if(chunk !== null) {
                  child.stdin.write(chunk);
              }
          });
          
          exec( 'npm install express mongoose nodemon',      spawn_option,function (err, stdout, stderr){
            if(err){console.log(err)}
          });
          
      }


function services(callback){
        for(let i = 0; i < name.fonctionnalites.length; i++) {
          if (name.fonctionnalites[i] == 'Authentification') {
            console.log("Yesss authentication");
            const security = async () => {
            const auth = await inquirer.authentification();
            console.log(auth)
            //const auth=authh.answers;
            //const auth = await authh.authentification();
            //console.log(auth.prompts)
            //let parser = JSON.stringify(auth);
            let donnees =       auth.name+":{"+'\n'+
                                  "type:  "+auth.type+","+'\n'+
                                  "required: "+auth.required+","+'\n'+
                                  "unique: "+auth.unique+'\n'+
                                "}"     
            authDatabase="DATABASE_URLAUTH=mongodb://localhost/users";   
            fs.writeFile('./'+projet+'/models/authentification.js',donnees , function(err) {
              if(err) return console.error(err);
            });
            fs.appendFile('./'+projet+'/.env', authDatabase, function (err) {
              if (err) throw err;
            });
            /*do
              {
                const securityRepeated = async () => {
                const authRepeated = await inquirer.authentification();
                console.log(auth);
                let donneesRepeated =","+
                                      authRepeated.name+":{"+'\n'+
                                      "type:  "+authRepeated.type+","+'\n'+
                                      "required: "+authRepeated.required+","+'\n'+
                                      "unique: "+authRepeated.unique+'\n'+
                                      "}"
                fs.appendFile('./'+projet+'/models/authentification.js', donneesRepeated, function (err) {
                  if (err) throw err;
                });
                }
                securityRepeated()
              }
            while(auth.addAttribute==true);*/
            /*exec('svn checkout https://github.com/morseck00/PROTO_BOX/trunk/AuthentificationJWT', {cwd: './'+projet+'/routes'}, function(err, stdout, stderr) {
              if (err) {
                console.log(`error: ${err.message}`);
                return;
            }
            if (stderr) {
                console.log(`stderr: ${stderr}`);
                return;
            }
            console.log(`stdout: ${stdout}`);
            });*/
            }
            security()
            
          }
callback();
}

i'm working in a project where i'm building a CLI and from answers i'm executing some things like making a npm init automatically i my code .i put the exec with on npm init in a function but when i call the function the execution of all others functions stops! can you help me pleaz? I've tried to put the function where i execute the npm init in a callback in an other function but the same happens!!! and i'M NEW TO NODE JS SOOOO...lol

lokho
  • 1
  • 1
  • Hi - welcome to StackOverflow! We're not going to be able to help you unless you post the code you're currently working on. If you can add this to your question then hopefully someone will be able to point you in the right direction. – Sternjobname Mar 02 '20 at 11:23
  • yeah you'e right! i added the code! – lokho Mar 02 '20 at 11:35

1 Answers1

0

I think i've resolved it! I put the initNpm function as a callback in the services function and added "-y" in the 'npm init' command so thet it does'nt appear in the console! tks

lokho
  • 1
  • 1