refactor(pre): use gitHead information from registry
				
					
				
			This commit is contained in:
		
							parent
							
								
									5c12e718cb
								
							
						
					
					
						commit
						53c0adb365
					
				
							
								
								
									
										26
									
								
								lib/npm-info.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								lib/npm-info.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| 'use strict' | ||||
| 
 | ||||
| var request = require('request') | ||||
| 
 | ||||
| var efh = require('./error').efh | ||||
| 
 | ||||
| module.exports = function (pkgName, cb) { | ||||
|   request(process.env.npm_config_registry + pkgName, efh(cb)(function (response, body) { | ||||
|     var pkg = JSON.parse(body) | ||||
| 
 | ||||
|     if (pkg.error && response.statusCode !== 404) return cb(pkg.error) | ||||
| 
 | ||||
|     var res = { | ||||
|       version: '', | ||||
|       gitHead: '', | ||||
|       pkg: pkg | ||||
|     } | ||||
| 
 | ||||
|     if (response.statusCode === 404) return cb(null, res) | ||||
| 
 | ||||
|     res.version = pkg['dist-tags'].latest | ||||
|     res.gitHead = pkg.versions[res.version].gitHead | ||||
| 
 | ||||
|     cb(null, res) | ||||
|   })) | ||||
| } | ||||
| @ -4,10 +4,8 @@ var git = require('conventional-changelog/lib/git') | ||||
| 
 | ||||
| var efh = require('../error').efh | ||||
| 
 | ||||
| module.exports = function (cb) { | ||||
|   git.latestTag(efh(cb)(function (from) { | ||||
|     git.getCommits({from: from}, efh(cb)(function (commits) { | ||||
|       cb(null, commits) | ||||
|     })) | ||||
| module.exports = function (from, cb) { | ||||
|   git.getCommits({from: from}, efh(cb)(function (commits) { | ||||
|     cb(null, commits) | ||||
|   })) | ||||
| } | ||||
|  | ||||
| @ -4,8 +4,8 @@ var analyze = require('./analyze') | ||||
| var commits = require('./commits') | ||||
| var efh = require('../error').efh | ||||
| 
 | ||||
| module.exports = function (cb) { | ||||
|   commits(efh(cb)(function (commits) { | ||||
| module.exports = function (gitHead, cb) { | ||||
|   commits(gitHead, efh(cb)(function (commits) { | ||||
|     cb(null, analyze(commits)) | ||||
|   })) | ||||
| } | ||||
|  | ||||
| @ -1,17 +0,0 @@ | ||||
| 'use strict' | ||||
| 
 | ||||
| var request = require('request') | ||||
| 
 | ||||
| var efh = require('./error').efh | ||||
| 
 | ||||
| module.exports = function (pkg, cb) { | ||||
|   if (!pkg.name) return cb(new Error('Package must have a name')) | ||||
| 
 | ||||
|   request(process.env.npm_config_registry + pkg.name, efh(cb)(function (response, body) { | ||||
|     var pkg = JSON.parse(body) | ||||
| 
 | ||||
|     if (response.statusCode === 404 || pkg.error) return cb(null, null, true) | ||||
| 
 | ||||
|     cb(null, pkg['dist-tags'].latest) | ||||
|   })) | ||||
| } | ||||
| @ -11,7 +11,7 @@ | ||||
|     "abbrev": "^1.0.5", | ||||
|     "conventional-changelog": "0.0.11", | ||||
|     "error-first-handler": "^1.0.1", | ||||
|     "git-head": "^1.0.1", | ||||
|     "git-head": "^1.2.1", | ||||
|     "github": "^0.2.3", | ||||
|     "github-url-from-git": "^1.4.0", | ||||
|     "ini": "^1.3.2", | ||||
|  | ||||
							
								
								
									
										16
									
								
								src/pre.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/pre.js
									
									
									
									
									
								
							| @ -5,17 +5,17 @@ var fs = require('fs') | ||||
| var semver = require('semver') | ||||
| 
 | ||||
| var type = require('../lib/type') | ||||
| var version = require('../lib/version') | ||||
| var npmInfo = require('../lib/npm-info') | ||||
| var efh = require('../lib/error').efh | ||||
| 
 | ||||
| module.exports = function (options, cb) { | ||||
|   type(efh(cb)(function (type) { | ||||
|     if (!type) return cb(null, null) | ||||
| 
 | ||||
|     var path = './package.json' | ||||
|     var pkg = JSON.parse(fs.readFileSync(path)) | ||||
|     version(pkg, efh(cb)(function (version, unpublished) { | ||||
|       pkg.version = unpublished ? '1.0.0' : semver.inc(version, type) | ||||
|   var path = './package.json' | ||||
|   var pkg = JSON.parse(fs.readFileSync(path)) | ||||
|   if (!pkg.name) return cb(new Error('Package must have a name')) | ||||
|   npmInfo(pkg.name, efh(cb)(function (res) { | ||||
|     type(res.gitHead, efh(cb)(function (type) { | ||||
|       if (!type) return cb(null, null) | ||||
|       pkg.version = !res.version ? '1.0.0' : semver.inc(res.version, type) | ||||
|       if (!options.debug) fs.writeFileSync(path, JSON.stringify(pkg, null, 2)) | ||||
| 
 | ||||
|       cb(null, pkg.version) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user