Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatakeshi committed Feb 15, 2024
2 parents 6097fc0 + ff10f39 commit 1019729
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
43 changes: 27 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
],
"dependencies": {
"axios": "^1.6.3",
"cross-spawn": "^7.0.3",
"tar": "^6.2.0"
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.6",
"@types/shelljs": "^0.8.15",
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ export default interface GitlyOptions {
* Set the request headers (default: undefined)
*/
headers?: RawAxiosRequestHeaders | AxiosHeaders
/**
* Set the backend (default: undefined)
*
* @example
* ```markdown
* 'axios' - default behavior
* 'git' - use local git installation to clone the repository (allows for cloning private repositories as long as the local git installation has access)
* ```
*/
backend?: 'axios' | 'git'
}
16 changes: 16 additions & 0 deletions src/utils/backend.git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import GitlyOptions from '../interfaces/options'
import parse from './parse'
import spawn from 'cross-spawn'

/**
* Uses local git installation to clone a repository to the destination.
*/
export default async function gitClone(
repository: string,
destination: string,
options: GitlyOptions = {}
): Promise<[string, string]> {
const info = parse(repository, options)
spawn.sync('git', ['clone', info.href, destination])
return [info.href, destination]
}
4 changes: 4 additions & 0 deletions src/utils/gitly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import GitlyOptions from '../interfaces/options'
import gitClone from './backend.git'

import download from './download'
import extract from './extract'
Expand All @@ -14,6 +15,9 @@ export default async function gitly(
destination: string,
options: GitlyOptions
): Promise<[string, string]> {
if (options?.backend === 'git') {
return await gitClone(repository, destination, options)
}
const source = await download(repository, options)
return [source, await extract(source, destination, options)]
}

0 comments on commit 1019729

Please sign in to comment.