mirror of
https://gitee.com/dcloud/uni-preset-vue
synced 2026-04-22 00:00:04 +08:00
add node_modules
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
|
||||
node_modules: package.json
|
||||
@npm install
|
||||
|
||||
test: node_modules
|
||||
@node_modules/.bin/mocha --reporter spec
|
||||
|
||||
.PHONY: test
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
# download-git-repo
|
||||
|
||||
Download and extract a git repository (GitHub, GitLab, Bitbucket) from node.
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install download-git-repo
|
||||
|
||||
## API
|
||||
|
||||
### download(repository, destination, options, callback)
|
||||
|
||||
Download a git `repository` to a `destination` folder with `options`, and `callback`.
|
||||
|
||||
#### repository
|
||||
The shorthand repository string to download the repository from:
|
||||
|
||||
- **GitHub** - `github:owner/name` or simply `owner/name`
|
||||
- **GitLab** - `gitlab:owner/name`
|
||||
- **Bitbucket** - `bitbucket:owner/name`
|
||||
|
||||
The `repository` parameter defaults to the `master` branch, but you can specify a branch or tag as a URL fragment like `owner/name#my-branch`.
|
||||
In addition to specifying the type of where to download, you can also specify a custom origin like `gitlab:custom.com:owner/name`.
|
||||
Custom origin will default to `https` or `git@` for http and clone downloads respectively, unless protocol is specified.
|
||||
Feel free to submit an issue or pull request for additional origin options.
|
||||
|
||||
In addition to having the shorthand for supported git hosts, you can also hit a repository directly with:
|
||||
|
||||
- **Direct** - `direct:url`
|
||||
|
||||
This will bypass the shorthand normalizer and pass `url` directly.
|
||||
If using `direct` without clone, you must pass the full url to the zip file, including paths to branches if needed.
|
||||
If using `direct` with clone, you must pass the full url to the git repo and you can specify a branch like `direct:url#my-branch`.
|
||||
|
||||
#### destination
|
||||
The file path to download the repository to.
|
||||
|
||||
#### options
|
||||
An optional options object parameter with download options. Options include:
|
||||
|
||||
- `clone` - boolean default `false` - If true use `git clone` instead of an http download. While this can be a bit slower, it does allow private repositories to be used if the appropriate SSH keys are setup.
|
||||
|
||||
#### callback
|
||||
The callback function as `function (err)`.
|
||||
|
||||
## Examples
|
||||
### Shorthand
|
||||
Using http download from Github repository at master.
|
||||
```javascript
|
||||
download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
Using git clone from Bitbucket repository at my-branch.
|
||||
```javascript
|
||||
download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
Using http download from GitLab repository with custom origin.
|
||||
```javascript
|
||||
download('gitlab:mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
Using git clone from GitLab repository with custom origin and protocol.
|
||||
Note that the repository type (`github`, `gitlab` etc.) is not required if cloning from a custom origin.
|
||||
```javascript
|
||||
download('https://mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
### Direct
|
||||
Using http download from direct url.
|
||||
```javascript
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip', 'test/tmp', function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
Using git clone from direct url at master.
|
||||
```javascript
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git', 'test/tmp', { clone: true }, function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
Using git clone from direct url at my-branch.
|
||||
```javascript
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git#my-branch', 'test/tmp', { clone: true }, function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
})
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
var downloadUrl = require('download')
|
||||
var gitclone = require('git-clone')
|
||||
var rm = require('rimraf').sync
|
||||
|
||||
/**
|
||||
* Expose `download`.
|
||||
*/
|
||||
|
||||
module.exports = download
|
||||
|
||||
/**
|
||||
* Download `repo` to `dest` and callback `fn(err)`.
|
||||
*
|
||||
* @param {String} repo
|
||||
* @param {String} dest
|
||||
* @param {Object} opts
|
||||
* @param {Function} fn
|
||||
*/
|
||||
|
||||
function download (repo, dest, opts, fn) {
|
||||
if (typeof opts === 'function') {
|
||||
fn = opts
|
||||
opts = null
|
||||
}
|
||||
opts = opts || {}
|
||||
var clone = opts.clone || false
|
||||
|
||||
repo = normalize(repo)
|
||||
var url = repo.url || getUrl(repo, clone)
|
||||
|
||||
if (clone) {
|
||||
gitclone(url, dest, { checkout: repo.checkout, shallow: repo.checkout === 'master' }, function (err) {
|
||||
if (err === undefined) {
|
||||
rm(dest + '/.git')
|
||||
fn()
|
||||
} else {
|
||||
fn(err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
downloadUrl(url, dest, { extract: true, strip: 1, mode: '666', headers: { accept: 'application/zip' } })
|
||||
.then(function (data) {
|
||||
fn()
|
||||
})
|
||||
.catch(function (err) {
|
||||
fn(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a repo string.
|
||||
*
|
||||
* @param {String} repo
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
function normalize (repo) {
|
||||
var regex = /^(?:(direct):([^#]+)(?:#(.+))?)$/
|
||||
var match = regex.exec(repo)
|
||||
|
||||
if (match) {
|
||||
var url = match[2]
|
||||
var checkout = match[3] || 'master'
|
||||
|
||||
return {
|
||||
type: 'direct',
|
||||
url: url,
|
||||
checkout: checkout
|
||||
}
|
||||
} else {
|
||||
regex = /^(?:(github|gitlab|bitbucket):)?(?:(.+):)?([^\/]+)\/([^#]+)(?:#(.+))?$/
|
||||
match = regex.exec(repo)
|
||||
var type = match[1] || 'github'
|
||||
var origin = match[2] || null
|
||||
var owner = match[3]
|
||||
var name = match[4]
|
||||
var checkout = match[5] || 'master'
|
||||
|
||||
if (origin == null) {
|
||||
if (type === 'github')
|
||||
origin = 'github.com'
|
||||
else if (type === 'gitlab')
|
||||
origin = 'gitlab.com'
|
||||
else if (type === 'bitbucket')
|
||||
origin = 'bitbucket.com'
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
origin: origin,
|
||||
owner: owner,
|
||||
name: name,
|
||||
checkout: checkout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds protocol to url in none specified
|
||||
*
|
||||
* @param {String} url
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function addProtocol (origin, clone) {
|
||||
if (!/^(f|ht)tps?:\/\//i.test(origin)) {
|
||||
if (clone)
|
||||
origin = 'git@' + origin
|
||||
else
|
||||
origin = 'https://' + origin
|
||||
}
|
||||
|
||||
return origin
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a zip or git url for a given `repo`.
|
||||
*
|
||||
* @param {Object} repo
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function getUrl (repo, clone) {
|
||||
var url
|
||||
|
||||
// Get origin with protocol and add trailing slash or colon (for ssh)
|
||||
var origin = addProtocol(repo.origin, clone)
|
||||
if (/^git\@/i.test(origin))
|
||||
origin = origin + ':'
|
||||
else
|
||||
origin = origin + '/'
|
||||
|
||||
// Build url
|
||||
if (clone) {
|
||||
url = origin + repo.owner + '/' + repo.name + '.git'
|
||||
} else {
|
||||
if (repo.type === 'github')
|
||||
url = origin + repo.owner + '/' + repo.name + '/archive/' + repo.checkout + '.zip'
|
||||
else if (repo.type === 'gitlab')
|
||||
url = origin + repo.owner + '/' + repo.name + '/repository/archive.zip?ref=' + repo.checkout
|
||||
else if (repo.type === 'bitbucket')
|
||||
url = origin + repo.owner + '/' + repo.name + '/get/' + repo.checkout + '.zip'
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../rimraf/bin.js
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "download-git-repo",
|
||||
"version": "1.1.0",
|
||||
"license": "MIT",
|
||||
"repository": "git://github.com/flipxfx/download-git-repo",
|
||||
"description": "Download and extract a git repository (GitHub, GitLab, Bitbucket) from node.",
|
||||
"keywords": [
|
||||
"download",
|
||||
"github",
|
||||
"bitbucket",
|
||||
"repo",
|
||||
"repository",
|
||||
"tar",
|
||||
"extract",
|
||||
"tarball"
|
||||
],
|
||||
"dependencies": {
|
||||
"download": "^5.0.3",
|
||||
"git-clone": "^0.1.0",
|
||||
"rimraf": "^2.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^3.2.0",
|
||||
"fs-readdir-recursive": "1.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
node_modules/download-git-repo/test/fixtures/bitbucket/my-branch-with-slashes/bitbucket-only-file.md
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch with slashes!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch!
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch with slashes!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch!
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch with slashes!
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
+1
@@ -0,0 +1 @@
|
||||
A sample repo for testing the [download-git-repo](https://github.com/flipxfx/download-git-repo) node module.
|
||||
+1
@@ -0,0 +1 @@
|
||||
hi there
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the branch!
|
||||
+1
@@ -0,0 +1 @@
|
||||
hello again
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
I only exist in the type!
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
var assert = require('assert')
|
||||
var download = require('..')
|
||||
var read = require('fs-readdir-recursive')
|
||||
var rm = require('rimraf').sync
|
||||
|
||||
describe('download-git-repo', function () {
|
||||
this.timeout(20000)
|
||||
|
||||
beforeEach(function () {
|
||||
rm('test/tmp')
|
||||
})
|
||||
|
||||
var filter = function (x) {
|
||||
return x[0] !== '.' || x === '.git'
|
||||
}
|
||||
|
||||
var runStyle = function (type, style) {
|
||||
var clone = false
|
||||
if (style === 'clones') clone = true
|
||||
|
||||
it(style + ' master branch by default', function (done) {
|
||||
download(type + ':flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it(style + ' a branch', function (done) {
|
||||
download(type + ':flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: clone }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/my-branch')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it(style + ' a branch with slashes', function (done) {
|
||||
download(type + ':flipxfx/download-git-repo-fixture#my/branch/with/slashes', 'test/tmp', { clone: clone }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/my-branch-with-slashes')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it(style + ' master branch with specific origin', function (done) {
|
||||
download(type + ':' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it(style + ' master branch with specific origin and protocol', function (done) {
|
||||
download(type + ':https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: clone }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var runType = function (type) {
|
||||
runStyle(type, 'downloads')
|
||||
|
||||
runStyle(type, 'clones')
|
||||
|
||||
it('clones master branch with specific origin without type', function (done) {
|
||||
download(type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('clones master branch with specific origin and protocol without type', function (done) {
|
||||
download('https://' + type + '.com:flipxfx/download-git-repo-fixture', 'test/tmp', { clone: true }, function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/' + type + '/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('via github', function () {
|
||||
runType('github')
|
||||
|
||||
it('downloads from github by default', function (done) {
|
||||
download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
|
||||
if (err) return done(err)
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/github/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('via gitlab', function () {
|
||||
runType('gitlab')
|
||||
})
|
||||
|
||||
describe('via bitbucket', function () {
|
||||
runType('bitbucket')
|
||||
})
|
||||
|
||||
describe('via direct', function () {
|
||||
it('downloads master branch', function (done) {
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip', 'test/tmp', function (err) {
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/gitlab/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('downloads a branch', function (done) {
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture/repository/archive.zip?ref=my-branch', 'test/tmp', function (err) {
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/gitlab/my-branch')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('clones master branch', function (done) {
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git', 'test/tmp', { clone: true }, function (err) {
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/gitlab/master')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('clones a branch', function (done) {
|
||||
download('direct:https://gitlab.com/flipxfx/download-git-repo-fixture.git#my-branch', 'test/tmp', { clone: true }, function (err) {
|
||||
var actual = read('test/tmp', filter)
|
||||
var expected = read('test/fixtures/gitlab/my-branch')
|
||||
assert.deepEqual(actual, expected)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user