fetch-content.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const chalk = require('chalk');
  2. var fetch_projects = require('./fetch-scripts/fetch-projects');
  3. var hasArg = function(arg){
  4. for (let i = 0; i < process.argv.length; i++) {
  5. if (arg == process.argv[i]) return true;
  6. }
  7. return false;
  8. }
  9. var isVerbose = function(){
  10. if(hasArg('-v') || hasArg('--verbose')) {
  11. global.isVerbose = true;
  12. return true;
  13. } else {
  14. global.isVerbose = false;
  15. return false;
  16. }
  17. }
  18. if(hasArg('help') || hasArg('-h')) {
  19. console.log();
  20. console.log('Usage: ' + chalk.bgWhite.black('node fetch-content <command>'));
  21. console.log();
  22. console.log('Copy files from codex to build the website content.');
  23. console.log();
  24. console.log(chalk.bold(' Command Description'));
  25. console.log(' projects Copy projects from Codex');
  26. console.log(' posts Copy blog posts from Codex');
  27. console.log(' test Test requirements for all projects');
  28. console.log(' test <project> Test requirements for a specific project');
  29. console.log(' -v, --verbose Log all output');
  30. console.log();
  31. console.log();
  32. return;
  33. }
  34. if(hasArg('test')){
  35. if(isVerbose()) console.log('Checking requirements:');
  36. var query = ""
  37. for (let i = 3; i < process.argv.length; i++) {
  38. if (process.argv[i] != '-v' && process.argv[i] != '--verbose' ) query += process.argv[i] + " ";
  39. }
  40. if(query != '') global.isVerbose = true;
  41. fetch_projects.showRequirements(query.replace(/\s+$/, ''))
  42. return;
  43. }
  44. if(hasArg('projects')) {
  45. if(isVerbose()) console.log('Copying projects from Codex');
  46. fetch_projects.all();
  47. return;
  48. }
  49. if(hasArg('posts')) {
  50. if(isVerbose()) console.log('Copying blog posts from Codex');
  51. return;
  52. }
  53. if(isVerbose()) console.log('Copying projects and blog posts from Codex');
  54. fetch_projects.all();