Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and use node 14 #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
node_modules
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {type ExecaReturnValue} from 'execa';

export type FileOptions = {
strip: number; // Default 1
};

export type UrlOptions = {
strip: number; // Default 1
extract: boolean; // Default true
};

export function directory(dir: string, cmd: string[]): Promise<Array<ExecaReturnValue<string>>>;
export function file(file: string, cmd: string[], options: FileOptions): Promise<Array<ExecaReturnValue<string>>>;
export function url(file: string, cmd: string[], options: UrlOptions): Promise<Array<ExecaReturnValue<string>>>;
46 changes: 26 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
'use strict';
const decompress = require('decompress');
const download = require('download');
const execa = require('execa');
const pMapSeries = require('p-map-series');
const tempfile = require('tempfile');
import download from 'download';
import decompress from 'decompress';
import {execa} from 'execa';
import pMapSeries from 'p-map-series';
import tempfile from 'tempfile';

const exec = (cmd, cwd) => pMapSeries(cmd, x => execa.shell(x, {cwd}));
const exec = (cmd, cwd) => pMapSeries(cmd, x => execa(x, {cwd, shell: true}));

exports.directory = (dir, cmd) => {
export function directory(dir, cmd) {
if (typeof dir !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof dir}\``));
}

return exec(cmd, dir);
};
}

exports.file = (file, cmd, opts) => {
opts = Object.assign({strip: 1}, opts);
export function file(file, cmd, options) {
options = Object.assign({strip: 1}, options);

if (typeof file !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof file}\``));
}

const tmp = tempfile();
const temporary = tempfile();

return decompress(file, tmp, opts).then(() => exec(cmd, tmp));
};
return decompress(file, temporary, options).then(() => exec(cmd, temporary));
}

exports.url = (url, cmd, opts) => {
opts = Object.assign({
export function url(url, cmd, options) {
options = Object.assign({
extract: true,
strip: 1
}, opts);
strip: 1,
}, options);

if (typeof url !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof url}\``));
}

const tmp = tempfile();
const temporary = tempfile();

return download(url, temporary, options).then(() => exec(cmd, temporary));
}

return download(url, tmp, opts).then(() => exec(cmd, tmp));
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
directory,
file,
url,
};
Loading