preview.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (function() {
  2. var Config, async, commonOptions, commonUsage, extendOptions, loadEnv, logger, options, preview, ref, usage, util;
  3. async = require('async');
  4. util = require('util');
  5. Config = require('./../core/config').Config;
  6. logger = require('./../core/logger').logger;
  7. ref = require('./common'), loadEnv = ref.loadEnv, commonUsage = ref.commonUsage, commonOptions = ref.commonOptions, extendOptions = ref.extendOptions;
  8. usage = "\nusage: wintersmith preview [options]\n\noptions:\n\n -p, --port [port] port to run server on (defaults to " + Config.defaults.port + ")\n -H, --hostname [host] host to bind server onto (defaults to INADDR_ANY)\n " + commonUsage + "\n\n all options can also be set in the config file\n\nexamples:\n\n preview using a config file (assuming config.json is found in working directory):\n $ wintersmith preview\n";
  9. options = {
  10. string: ['port', 'hostname'],
  11. alias: {
  12. port: 'p',
  13. hostname: 'H'
  14. }
  15. };
  16. extendOptions(options, commonOptions);
  17. preview = function(argv) {
  18. logger.info('starting preview server');
  19. return async.waterfall([
  20. function(callback) {
  21. return loadEnv(argv, callback);
  22. }, function(env, callback) {
  23. return env.preview(callback);
  24. }
  25. ], function(error) {
  26. if (error) {
  27. logger.error(error.message, error);
  28. return process.exit(1);
  29. }
  30. });
  31. };
  32. module.exports = preview;
  33. module.exports.usage = usage;
  34. module.exports.options = options;
  35. }).call(this);