codekingpro/portable-devtools
115k
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 entries = !entries ? [] : Array.from(entries);
13 const opt = dealias(opt_);
14 validate?.(opt, entries);
15 if (isSyncFile(opt)) {
16 if (typeof cb === 'function') {
17 throw new TypeError('callback not supported for sync tar functions');
18 }
19 return syncFile(opt, entries);
20 }
21 else if (isAsyncFile(opt)) {
22 const p = asyncFile(opt, entries);
23 return cb ? p.then(() => cb(), cb) : p;
24 }
25 else if (isSyncNoFile(opt)) {
26 if (typeof cb === 'function') {
27 throw new TypeError('callback not supported for sync tar functions');
28 }
29 return syncNoFile(opt, entries);
30 }
31 else if (isAsyncNoFile(opt)) {
32 if (typeof cb === 'function') {
33 throw new TypeError('callback only supported with file option');
34 }
35 return asyncNoFile(opt, entries);
36 /* c8 ignore start */
37 }
38 throw new Error('impossible options??');
39 /* c8 ignore stop */
40 }, {
41 syncFile,
42 asyncFile,
43 syncNoFile,
44 asyncNoFile,
45 validate,
46 });
47};
48//# sourceMappingURL=make-command.js.map