@@ -23,24 +23,34 @@ module.exports = class extends Generator {
2323 type : 'input' ,
2424 name : 'libraryName' ,
2525 message : "What is the npm module's name?" ,
26+ validate : ( libraryName , answers ) => {
27+ this . spawnCommand ( 'yarn' , [ 'add' , libraryName ] , {
28+ stdio : 'ignore' ,
29+ } ) ;
30+
31+ return packageJson ( libraryName , {
32+ fullMetadata : true ,
33+ } )
34+ . then ( pkg => {
35+ answers . pkg = pkg ;
36+ if ( pkg . repository && pkg . repository . url ) {
37+ answers . githubUrl = pkg . repository . url
38+ . replace ( / ^ g i t (?: \+ h t t p s ? ) ? : / , 'https:' )
39+ . replace ( / \. g i t $ / , '' ) ;
40+ }
41+ } )
42+ . then (
43+ ( ) => true ,
44+ err =>
45+ `There was an error retrieving metadata for npm package ${ libraryName } \n ${ err } `
46+ ) ;
47+ } ,
2648 } ,
2749 {
2850 type : 'input' ,
2951 name : 'friendlyName' ,
3052 message : "What is the library's friendly name?" ,
31- default : answers =>
32- packageJson ( answers . libraryName , {
33- fullMetadata : true ,
34- } ) . then ( pkg => {
35- answers . pkg = pkg ;
36- if ( pkg . repository && pkg . repository . url ) {
37- answers . githubUrl = pkg . repository . url
38- . replace ( / ^ g i t (?: \+ h t t p s ? ) ? : / , 'https:' )
39- . replace ( / \. g i t $ / , '' ) ;
40- }
41-
42- return pkg . name ;
43- } ) ,
53+ default : answers => answers . pkg . name ,
4454 } ,
4555 {
4656 type : 'input' ,
@@ -91,13 +101,17 @@ module.exports = class extends Generator {
91101 )
92102 )
93103 . map ( path . normalize )
104+ . map ( file => file . replace ( / \\ / g, '/' ) )
94105 . concat ( [ new inquirer . Separator ( ) , 'Other' ] ) ;
95106 } catch ( e ) {
96107 console . error ( e ) ;
97108 }
98109 } ,
99110 default : answers =>
100- path . normalize ( answers . pkg . browser || answers . pkg . main ) ,
111+ path
112+ . normalize ( answers . pkg . browser || answers . pkg . main )
113+ . replace ( / \\ / g, '/' ) ,
114+ filter : libraryPath => libraryPath . replace ( / \\ / g, '/' ) ,
101115 } ,
102116 {
103117 type : 'input' ,
@@ -131,7 +145,7 @@ module.exports = class extends Generator {
131145 }
132146
133147 writing ( ) {
134- const folder = ` ${ this . props . libraryName } _ ${ this . props . version } ` ;
148+ const folder = this . props . libraryName ;
135149 this . fs . copyTpl (
136150 this . templatePath ( '{libraryName}.dnn' ) ,
137151 this . destinationPath ( `${ folder } /${ this . props . libraryName } .dnn` ) ,
0 commit comments