node-server.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env node
  2. var server = require( './node_vwf' ),
  3. path = require( 'path' ),
  4. fs = require( 'fs' ),
  5. cli = require( './lib/nodejs/vwfCli.js' );
  6. var argv = require( 'optimist' ).argv;
  7. function printGeneralHelp() {
  8. console.log("Usage: vwf [--help] <command> [<args>]");
  9. console.log("");
  10. console.log("With no arguments, 'vwf' runs the application in the current");
  11. console.log("directory in local development mode.");
  12. console.log("");
  13. console.log("Use 'vwf create <name>' to create a new VWF project.");
  14. console.log("");
  15. console.log("Commands:");
  16. console.log(" run [default] Start the VWF server");
  17. console.log(" create Create a new VWF application");
  18. console.log("");
  19. console.log("Options:");
  20. console.log(" -a, --applicationPath Path to VWF application. Default: current directory.");
  21. console.log(" -v, --vwfPath Path to VWF support files. Default: current directory, then \"$HOME/.vwf\".");
  22. console.log(" -p, --port Port to start server on. Default: 3000");
  23. console.log(" -l, --log Log level for server. Default: 1");
  24. console.log(" -h, --help Output usage information");
  25. console.log(" -s, --ssl Enables SSL");
  26. console.log(" -k, --key Path to private key");
  27. console.log(" -c, --cert Path to certificate");
  28. }
  29. function printCreateHelp() {
  30. console.log("Usage: vwf create APP_PATH");
  31. console.log("");
  32. console.log("The `vwf create` command creates a new VWF application with a");
  33. console.log("default directory structure at the path you specified in APP_PATH.");
  34. console.log("");
  35. console.log("Example:");
  36. console.log(" vwf create ~/code/my-new-app");
  37. }
  38. if ( argv._[0] == 'create' && argv._.length == 1 ) {
  39. console.log("'create' requires a PATH to create the new VWF application.");
  40. console.log("");
  41. printCreateHelp();
  42. } else if ( argv._[0] == 'create' && argv._.length > 1 ) {
  43. var applicationPath = argv._[1];
  44. if ( cli.create( applicationPath ) ) {
  45. console.log("VWF application created at '" + applicationPath + "'.");
  46. console.log("");
  47. console.log("To get started quickly:");
  48. console.log(" $ cd " + applicationPath);
  49. console.log(" $ vwf");
  50. console.log("");
  51. console.log("See the Getting Started documentation at: ");
  52. console.log("https://virtual.wf/getting_started.html");
  53. } else {
  54. console.log("VWF application could not be created at '" + applicationPath + "'");
  55. }
  56. } else if ( argv.help || argv.h || ( argv._[0] == 'help' && argv._.length == 1 ) ) {
  57. printGeneralHelp();
  58. } else if ( argv._[0] == 'help' && argv._[1] == 'create' ) {
  59. printCreateHelp();
  60. } else if ( argv._[0] == 'help' && argv._[1] == 'run' ) {
  61. printGeneralHelp();
  62. } else if ( argv._[0] == 'help' ) {
  63. console.log("VWF can't find help on that command.");
  64. console.log("");
  65. printGeneralHelp();
  66. } else if ( argv._[0] == 'run' || argv._.length == 0 ) {
  67. server.startVWF();
  68. } else {
  69. console.log( "'" + argv._[0] + "' is not a VWF command. See 'vwf --help'." );
  70. }