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