Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

make.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require('./global');
  2. global.config.fatal = true;
  3. global.target = {};
  4. var args = process.argv.slice(2),
  5. targetArgs,
  6. dashesLoc = args.indexOf('--');
  7. // split args, everything after -- if only for targets
  8. if (dashesLoc > -1) {
  9. targetArgs = args.slice(dashesLoc + 1, args.length);
  10. args = args.slice(0, dashesLoc);
  11. }
  12. // This ensures we only execute the script targets after the entire script has
  13. // been evaluated
  14. setTimeout(function() {
  15. var t;
  16. if (args.length === 1 && args[0] === '--help') {
  17. console.log('Available targets:');
  18. for (t in global.target)
  19. console.log(' ' + t);
  20. return;
  21. }
  22. // Wrap targets to prevent duplicate execution
  23. for (t in global.target) {
  24. (function(t, oldTarget){
  25. // Wrap it
  26. global.target[t] = function() {
  27. if (oldTarget.done)
  28. return;
  29. oldTarget.done = true;
  30. return oldTarget.apply(oldTarget, arguments);
  31. };
  32. })(t, global.target[t]);
  33. }
  34. // Execute desired targets
  35. if (args.length > 0) {
  36. args.forEach(function(arg) {
  37. if (arg in global.target)
  38. global.target[arg](targetArgs);
  39. else {
  40. console.log('no such target: ' + arg);
  41. }
  42. });
  43. } else if ('all' in global.target) {
  44. global.target.all(targetArgs);
  45. }
  46. }, 0);