@@ -7,6 +7,10 @@ var isTypeInSingleTypeCollection = require('../utils/is-type-in-single-type-coll
77var defaultTypeForCollection = require ( '../utils/default-type-for-collection' ) ;
88var calculateCollectionInfo = require ( '../utils/calculate-collection-info' ) ;
99var importDeclarationsTransform = require ( '../transforms/import-declarations' ) ;
10+ var inflection = require ( 'inflection' ) ;
11+ var PodsSupport = require ( '../utils/pods-support' ) ;
12+ var typeForPodFile = PodsSupport . typeForPodFile ;
13+ var hasPodNamespace = PodsSupport . hasPodNamespace ;
1014
1115var FileInfo = CoreObject . extend ( {
1216 type : 'FileInfo' ,
@@ -17,6 +21,7 @@ var FileInfo = CoreObject.extend({
1721 var options = _options || { } ;
1822 this . options = options ;
1923 this . projectRoot = options . projectRoot ;
24+ this . podModulePrefix = options . podModulePrefix ;
2025
2126 this . sourceRelativePath = options . sourceRelativePath ;
2227 this . type = options . type ;
@@ -70,10 +75,70 @@ var FileInfo = CoreObject.extend({
7075 var pathParts = this . sourceRelativePath . split ( '/' ) ;
7176 var typeFolder = pathParts [ 1 ] ;
7277
73- var strippedRelativePath = this . sourceRelativePath
74- . replace ( new RegExp ( '^' + this . sourceRoot + '/' + typeFolder + '/' ) , '' ) // remove leading type dir
78+
79+
80+ var podType = typeForPodFile ( this . sourceRelativePath ) ;
81+ var arePodsNamespaced = hasPodNamespace ( this . podModulePrefix ) ;
82+
83+ var strippedRelativePath ;
84+ var pathRootRegex ;
85+ var fileName ;
86+ var type ;
87+
88+ if ( typeFolder === this . podModulePrefix ) {
89+ if ( pathParts [ 2 ] === 'components' ) {
90+ typeFolder = 'components' ;
91+ } else {
92+ fileName = pathParts [ pathParts . length - 1 ] ;
93+ type = fileName . split ( '.' ) [ 0 ] ;
94+ typeFolder = inflection . pluralize ( type ) ;
95+ }
96+ }
97+
98+ // default/classic/namespaced-pods
99+ pathRootRegex = new RegExp ( '(app\/)?' + this . podModulePrefix + '\/(components\/)?' ) ;
100+
101+ strippedRelativePath = this . sourceRelativePath
102+ . replace ( pathRootRegex , '' ) // don't care if path begins with pods
103+ . replace ( new RegExp ( '^' + this . sourceRoot + '/' + typeFolder + '/' ) , '' ) // remove leading type dir
104+ . replace ( new RegExp ( this . ext + '$' ) , '' ) // remove extension
105+ . replace ( new RegExp ( '/' + this . type + '$' ) , '' ) ; // remove trailing type
106+
107+
108+ if ( ! arePodsNamespaced ) {
109+ if ( podType ) {
110+ fileName = pathParts [ pathParts . length - 1 ] ;
111+ type = fileName . split ( '.' ) [ 0 ] ;
112+ typeFolder = inflection . pluralize ( type ) ;
113+
114+ pathRootRegex = new RegExp ( '(app\/)?' ) ;
115+ var podTypeRegex = new RegExp ( '(components\/)?' ) ;
116+
117+ strippedRelativePath = this . sourceRelativePath
118+ . replace ( pathRootRegex , '' )
119+ . replace ( podTypeRegex , '' )
120+ . replace ( new RegExp ( typeFolder + '/' ) , '' ) // remove leading type dir
75121 . replace ( new RegExp ( this . ext + '$' ) , '' ) // remove extension
76122 . replace ( new RegExp ( '/' + this . type + '$' ) , '' ) ; // remove trailing type
123+ }
124+
125+ // for other files (adapters, serializers, helpers, initializers, etc)
126+ if ( type === undefined ) {
127+ pathRootRegex = new RegExp ( '(app\/)?' ) ;
128+ type = pathParts [ 1 ] ;
129+ fileName = pathParts [ pathParts . length - 1 ] ;
130+ typeFolder = inflection . pluralize ( type ) ;
131+
132+
133+ strippedRelativePath = this . sourceRelativePath
134+ . replace ( pathRootRegex , '' )
135+ . replace ( new RegExp ( type + '/' ) , '' )
136+ . replace ( new RegExp ( '^' + this . sourceRoot + '/' + typeFolder + '/' ) , '' ) // remove leading type dir
137+ . replace ( new RegExp ( this . ext + '$' ) , '' ) // remove extension
138+ . replace ( new RegExp ( '/' + this . type ) , '' ) ; // remove trailing type
139+
140+ }
141+ }
77142
78143 var parts = strippedRelativePath . split ( '/' ) ;
79144 this . name = parts . pop ( ) ;
@@ -213,7 +278,7 @@ Object.defineProperty(FileInfo.prototype, 'destRelativePath', {
213278 }
214279 var destRelativePath ;
215280
216- if ( this . shouldUseDotFormNaming ( ) ) {
281+ if ( this . shouldUseDotFormNaming ( ) && this . type !== 'component' ) {
217282 destRelativePath = path . join (
218283 baseRelativePath ,
219284 this . namespace ,
0 commit comments