main.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. if (process.argv.length < 3) {
  2. console.error('Not enough arguments');
  3. process.exit();
  4. }
  5. const programs = require('./deploy.json').programs;
  6. let program = null;
  7. let list = [];
  8. programs.forEach(elt => {
  9. list.push(elt.name);
  10. if (elt.name === process.argv[2]) {
  11. program = elt;
  12. }
  13. });
  14. if (program === null) {
  15. console.error(process.argv[2], 'not found');
  16. console.error('Available programs:');
  17. list.forEach(elt => {
  18. console.error(' ' + elt);
  19. });
  20. process.exit();
  21. }
  22. let cmd = ['node', program.main];
  23. if (process.argv.length !== 3) {
  24. if (program.scripts[process.argv[3]] === undefined) {
  25. console.error(process.argv[2], 'script not found');
  26. process.exit();
  27. }
  28. cmd = program.scripts[process.argv[3]].split(' ');
  29. }
  30. let argv = [];
  31. argv.push(process.argv[0]);
  32. argv.push(process.argv[1].replace('main.js', cmd[1]));
  33. let longParam = false;
  34. let param = '';
  35. for (let i = 2; i < cmd.length; i++) {
  36. if (longParam) {
  37. param += ' ' + cmd[i];
  38. if (cmd[i][cmd[i].length - 1] === '"') {
  39. argv.push(param.replace(/^"+|"+$/g, ''));
  40. param = '';
  41. longParam = false;
  42. }
  43. } else if (cmd[i][0] === '"') {
  44. longParam = true;
  45. param = cmd[i];
  46. } else {
  47. argv.push(cmd[i]);
  48. }
  49. }
  50. process.argv = argv;
  51. require('./' + cmd[1]);