From cc8b0bd3c0cc81e2b3bf1ae7f066cf8ce6d59184 Mon Sep 17 00:00:00 2001 From: "voraton.l" Date: Fri, 1 Apr 2022 11:43:29 +0700 Subject: [PATCH] Add typedef and async function --- README.md | 4 ++++ index.d.ts | 14 ++++++++++++++ index.js | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 index.d.ts 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) + } + ) + ) +}