resetExampleRepos.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const path = require('path');
  2. const execAsync = require('./execAsync');
  3. const appRoot = path.normalize(__dirname + '/..');
  4. const isTesting = process.env.NODE_ENV === 'testing';
  5. const examplesDir = ! isTesting ? appRoot + '/exemples' :
  6. appRoot + '/test/integration/test-examples';
  7. // Promisified exec of git mv src dst
  8. function gitStatusAsync(src, dst) {
  9. var cmd = 'git status ' + examplesDir;
  10. return execAsync(cmd)
  11. // .then(({ stdout, stderr }) => {
  12. // // console.log(`stdout: ${stdout}`);
  13. // // console.log(`stderr: ${stderr}`);
  14. // })
  15. .catch(error => {
  16. console.error(`exec error: ${error}`);
  17. throw error;
  18. });
  19. }
  20. function getUntrackedReposAndExamples() {
  21. gitStatusAsync()
  22. .then(({ stdout }) => {
  23. let idx = stdout.indexOf('Untracked files:');
  24. const output = stdout.substr(idx);
  25. let lines = output.split('\n');
  26. lines.splice(0, 3);
  27. idx = 0;
  28. while(lines[idx]) idx++;
  29. lines.splice(idx, lines.length - idx);
  30. lines.forEach((line, i) => {
  31. lines[i] = line.trim();
  32. });
  33. console.log(lines);
  34. });
  35. }
  36. getUntrackedReposAndExamples()