diff --git a/README.md b/README.md index 654ed72..ca65a4e 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ The git repo is shallowly cloned by default. To make a complete clone, set `opti When the operation is finished, `callback` is called. The first argument to `callback` is either `null` or an `Error` object if an error occurred. +### `gitPullOrClone.async(url, outPath[, options])` + +Work as same as `gitPullOrClone(url, outPath[, options], callback)` but handle callback as async function + ## License MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c1d784a --- /dev/null +++ b/index.d.ts @@ -0,0 +1,14 @@ +interface Options { + depth?: number +} + +type Callback = (error?: Error) => void + +type GitPullOrClone = { + (url: string, outPath: string, opts?: Options | Callback, cb?: Callback): void + async: (url: string, outPath: string, opts?: Options) => Promise +} + +const gitPullOrClone: GitPullOrClone + +export = gitPullOrClone diff --git a/index.js b/index.js index c38c84d..2f4f03a 100644 --- a/index.js +++ b/index.js @@ -57,3 +57,20 @@ function spawn (command, args, opts, cb) { }) return child } + +gitPullOrClone.async = function(url, outPath, opts) { + return new Promise( + (resolve, reject) => + gitPullOrClone( + url, + outPath, + opts || {}, + err => { + if (!err) { + resolve() + } + reject(err) + } + ) + ) +}