feat(setup): setup package.json
This commit is contained in:
		
							parent
							
								
									44eb633458
								
							
						
					
					
						commit
						fee6d6baba
					
				| @ -69,6 +69,12 @@ if (~argv._.indexOf('post')) { | ||||
|   })) | ||||
| } | ||||
| 
 | ||||
| if (~argv._.indexOf('setup')) { | ||||
|   require('../src/setup')() | ||||
|   console.log('"package.json" is set up properly. Now configure your CI server.') | ||||
|   console.log('https://github.com/boennemann/semantic-release#ci-server') | ||||
| } | ||||
| 
 | ||||
| function isAbbrev (argv, command) { | ||||
|   return argv._.some(Object.prototype.hasOwnProperty.bind(abbrev(command))) | ||||
| } | ||||
|  | ||||
| @ -14,6 +14,7 @@ | ||||
|     "git-node": "^0.1.1", | ||||
|     "github": "^0.2.3", | ||||
|     "github-url-from-git": "^1.4.0", | ||||
|     "ini": "^1.3.2", | ||||
|     "minimist": "^1.1.0", | ||||
|     "parse-github-repo-url": "^1.0.0", | ||||
|     "request": "^2.53.0", | ||||
|  | ||||
							
								
								
									
										45
									
								
								src/setup.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/setup.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| 'use strict' | ||||
| 
 | ||||
| var fs = require('fs') | ||||
| 
 | ||||
| var ini = require('ini') | ||||
| var ghUrl = require('github-url-from-git') | ||||
| 
 | ||||
| module.exports = function () { | ||||
|   var pkg = JSON.parse(fs.readFileSync('./package.json') + '') | ||||
| 
 | ||||
|   // ensure a yet unpublished version
 | ||||
|   pkg.version = '0.0.0-semantically-released' | ||||
| 
 | ||||
|   // set up scripts
 | ||||
|   var pre = 'semantic-release pre' | ||||
|   var post = 'semantic-release post' | ||||
| 
 | ||||
|   if (!pkg.scripts) pkg.scripts = {} | ||||
| 
 | ||||
|   if (!pkg.scripts.prepublish) pkg.scripts.prepublish = pre | ||||
|   else if (!(new RegExp(pre).test(pkg.scripts.prepublish))) pkg.scripts.prepublish += ' && ' + pre | ||||
| 
 | ||||
|   if (!pkg.scripts.postpublish) pkg.scripts.postpublish = post | ||||
|   else if (!(new RegExp(post).test(pkg.scripts.postpublish))) pkg.scripts.postpublish += ' && ' + post | ||||
| 
 | ||||
|   // set up repository
 | ||||
|   if (!pkg.repository || !pkg.repository.url) { | ||||
|     var config = ini.decode(fs.readFileSync('./.git/config') + '') | ||||
|     var repo = config['remote "origin"'].url | ||||
| 
 | ||||
|     if (repo) pkg.repository = { | ||||
|       type: 'git', | ||||
|       url: ghUrl(repo) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   // set up devDependency
 | ||||
|   if (!pkg.devDependencies) pkg.devDependencies = {} | ||||
| 
 | ||||
|   if (!pkg.devDependencies['semantic-release']) { | ||||
|     pkg.devDependencies['semantic-release'] = '^' + require('../package.json').version | ||||
|   } | ||||
| 
 | ||||
|   fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2)) | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user