11var path = require ( 'path' ) ;
22var process = require ( 'process' ) ;
33var fs = require ( 'fs' ) ;
4+ var stringUtils = require ( 'ember-cli-string-utils' ) ;
45
56module . exports = function dynamicPathParser ( project , entityName , appConfig ) {
67 var projectRoot = project . root ;
@@ -10,13 +11,13 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
1011
1112 var rootPath = path . join ( projectRoot , appRoot ) ;
1213 var outputPath = path . join ( rootPath , entityName ) ;
13-
14+
1415 if ( entityName . indexOf ( path . sep ) === 0 ) {
1516 outputPath = path . join ( rootPath , entityName . substr ( 1 ) ) ;
1617 } else if ( cwd . indexOf ( rootPath ) >= 0 ) {
1718 outputPath = path . join ( cwd , entityName ) ;
1819 }
19-
20+
2021 if ( ! fs . existsSync ( outputPath ) ) {
2122 // Verify the path exists on disk.
2223 var parsedOutputPath = path . parse ( outputPath ) ;
@@ -25,22 +26,24 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
2526 // if (tempPath === '') {
2627 // return part;
2728 // }
28- var withoutPlus = path . join ( tempPath , path . sep , part ) ;
29- var withPlus = path . join ( tempPath , path . sep , '+' + part ) ;
29+ var withoutPlus = path . join ( tempPath , part ) ;
30+ var withPlus = path . join ( tempPath , '+' + part ) ;
3031 if ( fs . existsSync ( withoutPlus ) ) {
3132 return withoutPlus ;
3233 } else if ( fs . existsSync ( withPlus ) ) {
3334 return withPlus ;
3435 }
3536
3637 // Folder not found, create it, and return it
37- fs . mkdirSync ( withoutPlus ) ;
38- return withoutPlus ;
38+ const dasherizedPart = stringUtils . dasherize ( part ) ;
39+ const dasherizedDirName = path . join ( tempPath , dasherizedPart ) ;
40+ fs . mkdirSync ( dasherizedDirName ) ;
41+ return dasherizedDirName ;
3942
4043 } , parsedOutputPath . root ) ;
4144 outputPath = path . join ( newPath , parsedOutputPath . name ) ;
4245 }
43-
46+
4447 if ( outputPath . indexOf ( rootPath ) < 0 ) {
4548 throw `Invalid path: "${ entityName } " cannot be ` +
4649 `above the "${ appRoot } " directory` ;
@@ -49,7 +52,7 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
4952 var adjustedPath = outputPath . replace ( projectRoot , '' ) ;
5053
5154 var parsedPath = path . parse ( adjustedPath ) ;
52-
55+
5356 if ( parsedPath . dir . indexOf ( path . sep ) === 0 ) {
5457 parsedPath . dir = parsedPath . dir . substr ( 1 ) ;
5558 }
0 commit comments