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

Added options to just git clone a url and leave .git alone if requested #82

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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ Now it will install to `node_modules/adifferentname`.
}
```

### Looking to just `git clone` a tagged release/a branch/a specific commit on github or git url?

```json
{
"scripts": {
"install": "napa"
},
"napa": {
"foo": "username/[email protected]",
"bar": "username/bar@some-branch",
"baz": "username/baz@347259472813400c7a982690acaa516292a8be40"
}
}
```

### Additional configuration

The application currently supports the following configuration options under a `napa-config` property in `package.json`.
Expand All @@ -91,13 +106,15 @@ Option name | Default value | Desctiption
`cache` | `true` | Set to `false` to completely disable package caching
`cache-path` | [`'<OS temp>/cache'`](https://github.com/shama/napa/blob/master/lib/pkg.js#L8) | Override default path to a specific location<br>(relative to the current working directory)
`log-level` | `'info'` | Set the log level: `'silent'`/`'error'`/`'warn'`/`'verbose'`/`'silly'`
`leave-git` | `false` | Set to `true` to leave the `.git` folder after cloning

```json
{
"napa-config": {
"cache": false,
"cache-path": "../.napa-cache",
"log-level": "error"
"log-level": "error",
"leave-git": false
}
}
```
Expand Down
11 changes: 10 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ napa.url = function (url) {
}
}

if (url.indexOf('@') !== -1) {
if (url.indexOf('://') === -1) {
var ss = url.split('@')
url = 'https://github.com/' + ss[0]
} else {
url = url.replace(/@.*?$/, '')
}
}

if (url.slice(0, 1) === '/') {
url = url.slice(1)
}
Expand Down Expand Up @@ -122,5 +131,5 @@ napa._loadFromPkg = function (property, defaults) {
}

napa.getref = function (url) {
return url.replace(/^[^#]*#?/, '')
return url.replace(/^[^#]*#?/, '') || url.replace(/^[^@]*@?/, '')
}
8 changes: 6 additions & 2 deletions lib/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function NapaPkg (url, name, opts) {
)
this._napaResolvedKey = '_napaResolved'
this.saveToPkgJson = opts.save
this.leaveGit = opts['leave-git'] || false

Object.defineProperty(self, 'installed', {
get: function () {
Expand Down Expand Up @@ -92,11 +93,14 @@ NapaPkg.prototype.install = function (done) {
var checkout
if (code) return cb(code, signal)
if (self.ref) {
checkout = spawn('git', ['checkout', self.ref], {cwd: self.installTo})
checkout = spawn('git', ['checkout', '-f', self.ref], {cwd: self.installTo})
checkout.stderr.on('data', log.info)
checkout.on('close', function () {
rimraf(path.resolve(self.installTo, '.git'), cb)
if (self.leaveGit) cb()
else rimraf(path.resolve(self.installTo, '.git'), cb)
})
} else if (self.leaveGit) {
cb()
} else {
rimraf(path.resolve(self.installTo, '.git'), cb)
}
Expand Down
20 changes: 19 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ function cleanPkgJson (path, json, name) {
}

test('args', function (t) {
t.plan(5)
t.plan(6)
t.deepEqual(napa.args('user/repo'), ['git://github.com/user/repo', 'repo', ''])
t.deepEqual(napa.args('https://github.com/user/repo:testing'), ['https://github.com/user/repo', 'testing', ''])
t.deepEqual(napa.args('git://github.com/user/repo2'), ['git://github.com/user/repo2', 'repo2', ''])
// when developing on windows, this returns zip, linux is tar.gz
t.deepEqual(napa.args('angular/angular.js#v1.2.3:angular'), ['https://github.com/angular/angular.js/archive/v1.2.3.' + ((process.platform === 'win32') ? 'zip' : 'tar.gz'), 'angular', 'v1.2.3:angular'])
// when specifying @, "git clone && git reset --hard" is used instead of downloading the .tar.gz (.git folder won't be removed)
t.deepEqual(napa.args('angular/[email protected]:angular'), ['https://github.com/angular/angular.js', 'angular', 'v1.2.3:angular'])
t.deepEqual(napa.args('https://github.com/angular/angular.js/archive/master.zip:angular'), ['https://github.com/angular/angular.js/archive/master.zip', 'angular', ''])
})

Expand Down Expand Up @@ -178,6 +180,22 @@ test('pkg install with ref', function (t) {
})
})

test('pkg install with ref', function (t) {
t.plan(5)
var pkg = new Pkg('https://github.com/gdsmith/jquery.easing', 'jquery.easing', {ref: '1.3.1', 'leave-git': true})

clean([pkg.cacheTo, pkg.installTo], function () {
pkg.install(function (err) {
var packagePath
t.notOk(err, 'no error should occur')
t.ok(fs.existsSync(path.resolve(pkg.installTo, '.git')), '.git directory was not deleted')
t.ok(fs.existsSync(packagePath = path.resolve(pkg.installTo, 'package.json')), 'package.json has been generated')
t.ok((pkg = require(packagePath)) && pkg.name && pkg.version, 'package.json has required fields')
t.ok(pkg && pkg.description && pkg.readme && pkg.repository && pkg.repository.type, 'package.json has recommended fields')
})
})
})

test('pkg install with --save', function (t) {
t.plan(2)
var pkg = new Pkg('https://github.com/gdsmith/jquery.easing', 'jquery.easing', {save: true})
Expand Down