title: File creation issues on node
body: <p>I am having issues generating files with node. The files show up out of sequence and after the loop that has created them finish throwing my automated git commits of out whack. Can someone help me please! github repo: <a href="https://github.com/wendellmva/cli3" rel="nofollow noreferrer">https://github.com/wendellmva/cli3</a></p>
  
  <pre><code>class Generator {
      constructor(){
          this.root = resolve(__dirname, 'generated');
      }   
  
      clean(done){
          if(fs.existsSync(this.root)){
              trash(this.root).then(done);
          } else {
              done();
          }
      }
  
      execute(){
          this.init()
          for(let i=0; i&lt;10; ++i) {
              const file = resolve(this.root, `file${i}.txt`);
              fs.writeFile(file, 'Hello world', (err)=&gt; {
                  if(err) console.error(err);
                  console.info('CREATE ', file);
                  if(fs.existsSync(file)) this.add(file);
                  if(i==9) this.commit();
              });
          }
  
      }
  
      init(){
          shelljs.exec(`mkdir ${this.root} &amp;&amp; cd ${this.root} &amp;&amp; git init`);
      }
      add(file){
          shelljs.exec(`cd ${this.root} &amp;&amp; git add ${file}`);
      }
      commit(){
          shelljs.exec(`cd ${this.root} &amp;&amp; git commit -m "chore: initial commit"`);
      }
  }
  
  const generator = new Generator();
  
  generator.clean(()=&gt;{
      generator.execute();
  });
  </code></pre>
  
  <p>problem 1: commit starts before execute has finished
  resulting in empty commit</p>
  
  <p>problem 2: when generated files exist execute starts before clean has finished 
  resulting in file already exist errors
  ===> SOLVED</p>
  
  <p>problem 3: files are created out of sequence</p>
  
  <pre><code>Initialized empty Git repository in D:/@cardstrip/cli3/generated/.git/
  CREATE  D:\@cardstrip\cli3\generated\file2.txt
  CREATE  D:\@cardstrip\cli3\generated\file3.txt
  CREATE  D:\@cardstrip\cli3\generated\file0.txt
  CREATE  D:\@cardstrip\cli3\generated\file1.txt
  CREATE  D:\@cardstrip\cli3\generated\file4.txt
  CREATE  D:\@cardstrip\cli3\generated\file5.txt
  CREATE  D:\@cardstrip\cli3\generated\file7.txt
  CREATE  D:\@cardstrip\cli3\generated\file9.txt
  [master (root-commit) 3442284] chore: initial commit
  8 files changed, 8 insertions(+)
  create mode 100644 file0.txt
  create mode 100644 file1.txt
  create mode 100644 file2.txt
  create mode 100644 file3.txt
  create mode 100644 file4.txt
  create mode 100644 file5.txt
  create mode 100644 file7.txt
  create mode 100644 file9.txt
  CREATE  D:\@cardstrip\cli3\generated\file6.txt
  CREATE  D:\@cardstrip\cli3\generated\file8.txt
  </code></pre>