1
1
var path = require ( 'path' ) ;
2
2
var process = require ( 'process' ) ;
3
3
var fs = require ( 'fs' ) ;
4
+ var stringUtils = require ( 'ember-cli-string-utils' ) ;
4
5
5
6
module . exports = function dynamicPathParser ( project , entityName , appConfig ) {
6
7
var projectRoot = project . root ;
@@ -10,13 +11,13 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
10
11
11
12
var rootPath = path . join ( projectRoot , appRoot ) ;
12
13
var outputPath = path . join ( rootPath , entityName ) ;
13
-
14
+
14
15
if ( entityName . indexOf ( path . sep ) === 0 ) {
15
16
outputPath = path . join ( rootPath , entityName . substr ( 1 ) ) ;
16
17
} else if ( cwd . indexOf ( rootPath ) >= 0 ) {
17
18
outputPath = path . join ( cwd , entityName ) ;
18
19
}
19
-
20
+
20
21
if ( ! fs . existsSync ( outputPath ) ) {
21
22
// Verify the path exists on disk.
22
23
var parsedOutputPath = path . parse ( outputPath ) ;
@@ -25,22 +26,24 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
25
26
// if (tempPath === '') {
26
27
// return part;
27
28
// }
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 ) ;
30
31
if ( fs . existsSync ( withoutPlus ) ) {
31
32
return withoutPlus ;
32
33
} else if ( fs . existsSync ( withPlus ) ) {
33
34
return withPlus ;
34
35
}
35
36
36
37
// 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 ;
39
42
40
43
} , parsedOutputPath . root ) ;
41
44
outputPath = path . join ( newPath , parsedOutputPath . name ) ;
42
45
}
43
-
46
+
44
47
if ( outputPath . indexOf ( rootPath ) < 0 ) {
45
48
throw `Invalid path: "${ entityName } " cannot be ` +
46
49
`above the "${ appRoot } " directory` ;
@@ -49,7 +52,7 @@ module.exports = function dynamicPathParser(project, entityName, appConfig) {
49
52
var adjustedPath = outputPath . replace ( projectRoot , '' ) ;
50
53
51
54
var parsedPath = path . parse ( adjustedPath ) ;
52
-
55
+
53
56
if ( parsedPath . dir . indexOf ( path . sep ) === 0 ) {
54
57
parsedPath . dir = parsedPath . dir . substr ( 1 ) ;
55
58
}
0 commit comments