8000 add the package name custom validate to take effect (#276) · vuejs/vue-cli@0d3f96d · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d3f96d

Browse files
likun7981kazupon
authored andcommitted
add the package name custom validate to take effect (#276)
* add name validate function for user custom and add test for it * remove test only
1 parent f1c1db8 commit 0d3f96d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/options.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ function setDefault (opts, key, val) {
7575
}
7676

7777
function setValidateName (opts) {
78-
opts.prompts.name.validate = function (name) {
78+
var name = opts.prompts.name
79+
var customValidate = name.validate
80+
name.validate = function (name) {
7981
var its = validateName(name)
8082
if (!its.validForNewPackages) {
8183
var errors = (its.errors || []).concat(its.warnings || [])
8284
return 'Sorry, ' + errors.join(' and ') + '.'
8385
}
86+
if (typeof customValidate === 'function') return customValidate(name)
8487
return true
8588
}
8689
}

test/e2e/mock-metadata-repo-js/meta.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ module.exports = {
44
type: 'string',
55
required: true,
66
message: 'Project description'
7+
},
8+
name: {
9+
type: 'string',
10+
required: true,
11+
label: 'Project name',
12+
validate: function (input) {
13+
return input === 'custom' ? 'can not input `custom`' : true
14+
}
715
}
816
},
917
helpers: {

test/e2e/test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,20 @@ describe('vue-cli', () => {
157157

158158
it('validate input value', done => {
159159
// deep copy
160-
var invalidName = extend({}, answers, {name: 'INVALID-NAME'})
160+
var invalidName = extend({}, answers, { name: 'INVALID-NAME' })
161161
monkeyPatchInquirer(invalidName)
162162
generate('INVALID-NAME', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
163163
expect(err).to.be.an('error')
164164
done()
165165
})
166166
})
167+
168+
it('custom validate', done => {
169+
var invalidName = extend({}, answers, { name: 'custom' })
170+
monkeyPatchInquirer(invalidName)
171+
generate('test', MOCK_METADATA_REPO_JS_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
172+
expect(err).to.be.an('error')
173+
done()
174+
})
175+
})
167176
})

0 commit comments

Comments
 (0)
0