0bd83a8e2051655dadf3148d55728e0b9b2a93766c570c27ceac8462e0b6f8c7752a8a9d948b0b4965f407fd008687897ad8389cc1812abd090df09218027a 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.makeCommand = void 0;
  4. const options_js_1 = require("./options.js");
  5. const makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) => {
  6. return Object.assign((opt_ = [], entries, cb) => {
  7. if (Array.isArray(opt_)) {
  8. entries = opt_;
  9. opt_ = {};
  10. }
  11. if (typeof entries === 'function') {
  12. cb = entries;
  13. entries = undefined;
  14. }
  15. if (!entries) {
  16. entries = [];
  17. }
  18. else {
  19. entries = Array.from(entries);
  20. }
  21. const opt = (0, options_js_1.dealias)(opt_);
  22. validate?.(opt, entries);
  23. if ((0, options_js_1.isSyncFile)(opt)) {
  24. if (typeof cb === 'function') {
  25. throw new TypeError('callback not supported for sync tar functions');
  26. }
  27. return syncFile(opt, entries);
  28. }
  29. else if ((0, options_js_1.isAsyncFile)(opt)) {
  30. const p = asyncFile(opt, entries);
  31. // weirdness to make TS happy
  32. const c = cb ? cb : undefined;
  33. return c ? p.then(() => c(), c) : p;
  34. }
  35. else if ((0, options_js_1.isSyncNoFile)(opt)) {
  36. if (typeof cb === 'function') {
  37. throw new TypeError('callback not supported for sync tar functions');
  38. }
  39. return syncNoFile(opt, entries);
  40. }
  41. else if ((0, options_js_1.isAsyncNoFile)(opt)) {
  42. if (typeof cb === 'function') {
  43. throw new TypeError('callback only supported with file option');
  44. }
  45. return asyncNoFile(opt, entries);
  46. /* c8 ignore start */
  47. }
  48. else {
  49. throw new Error('impossible options??');
  50. }
  51. /* c8 ignore stop */
  52. }, {
  53. syncFile,
  54. asyncFile,
  55. syncNoFile,
  56. asyncNoFile,
  57. validate,
  58. });
  59. };
  60. exports.makeCommand = makeCommand;
  61. //# sourceMappingURL=make-command.js.map