make.js 1.0 KB

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