index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env node
  2. /**
  3. * @author Toru Nagashima
  4. * @copyright 2016 Toru Nagashima. All rights reserved.
  5. * See LICENSE file in root directory for full license.
  6. */
  7. /* eslint no-console:0, no-process-exit:0 */
  8. "use strict";
  9. var _from = require("babel-runtime/core-js/array/from");
  10. var _from2 = _interopRequireDefault(_from);
  11. var _set = require("babel-runtime/core-js/set");
  12. var _set2 = _interopRequireDefault(_set);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. var subarg = require("subarg");
  15. //------------------------------------------------------------------------------
  16. // Parse arguments.
  17. var unknowns = new _set2.default();
  18. var args = subarg(process.argv.slice(2), {
  19. alias: {
  20. c: "command",
  21. C: "clean",
  22. h: "help",
  23. includeEmptyDirs: "include-empty-dirs",
  24. L: "dereference",
  25. p: "preserve",
  26. t: "transform",
  27. u: "update",
  28. v: "verbose",
  29. V: "version",
  30. w: "watch"
  31. },
  32. boolean: ["clean", "dereference", "help", "include-empty-dirs", "initial", "preserve", "update", "verbose", "version", "watch"],
  33. default: { initial: true },
  34. unknown: function unknown(arg) {
  35. if (arg[0] === "-") {
  36. unknowns.add(arg);
  37. }
  38. }
  39. });
  40. var source = args._[0];
  41. var outDir = args._[1];
  42. //------------------------------------------------------------------------------
  43. // Validate Options.
  44. if (unknowns.size > 0) {
  45. console.error("Unknown option(s): " + (0, _from2.default)(unknowns).join(", "));
  46. process.exit(1);
  47. }
  48. //------------------------------------------------------------------------------
  49. // Main.
  50. if (args.help) {
  51. require("./help")();
  52. } else if (args.version) {
  53. require("./version")();
  54. } else if (source == null || outDir == null || args._.length > 2) {
  55. require("./help")();
  56. process.exit(1);
  57. } else {
  58. require("./main")(source, outDir, args);
  59. }