Skip to content

Commit

Permalink
Validate version field immediately and ask for reentry
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde authored and iarna committed May 21, 2015
1 parent 17721cb commit 487153d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion default-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path')
var validateLicense = require('validate-npm-package-license')
var validateName = require('validate-npm-package-name')
var npa = require('npm-package-arg')
var semver = require('semver')

// more popular packages should go here, maybe?
function isTestPkg (p) {
Expand Down Expand Up @@ -65,7 +66,15 @@ var version = package.version ||
config.get('init.version') ||
config.get('init-version') ||
'1.0.0'
exports.version = yes ? version : prompt('version', version)
exports.version = yes ?
version :
prompt('version', version, function (version) {
if (semver.valid(version)) return version
var er = new Error('Invalid version: "' + version + '"')
er.notValid = true
er.again = true
return er
})

if (!package.description) {
exports.description = yes ? '' : prompt('description')
Expand Down

0 comments on commit 487153d

Please sign in to comment.