Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0d3f96d

Browse files
likun7981kazupon
authored andcommitted
add the package name custom validate to take effect (vuejs#276)
* add name validate function for user custom and add test for it* remove test only
1 parentf1c1db8 commit0d3f96d

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
functionsetValidateName(opts){
78-
opts.prompts.name.validate=function(name){
78+
varname=opts.prompts.name
79+
varcustomValidate=name.validate
80+
name.validate=function(name){
7981
varits=validateName(name)
8082
if(!its.validForNewPackages){
8183
varerrors=(its.errors||[]).concat(its.warnings||[])
8284
return'Sorry, '+errors.join(' and ')+'.'
8385
}
86+
if(typeofcustomValidate==='function')returncustomValidate(name)
8487
returntrue
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+
returninput==='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-
varinvalidName=extend({},answers,{name:'INVALID-NAME'})
160+
varinvalidName=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+
varinvalidName=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)

[8]ページ先頭

©2009-2025 Movatter.jp