File tree 2 files changed +35
-2
lines changed
packages/angular-cli/blueprints
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const getFiles = Blueprint.prototype.files;
7
7
const stringUtils = require ( 'ember-cli-string-utils' ) ;
8
8
const astUtils = require ( '../../utilities/ast-utils' ) ;
9
9
const NodeHost = require ( '@angular-cli/ast-tools' ) . NodeHost ;
10
+ const ts = require ( 'typescript' ) ;
10
11
11
12
module . exports = {
12
13
description : '' ,
@@ -37,14 +38,29 @@ module.exports = {
37
38
38
39
this . dynamicPath = parsedPath ;
39
40
41
+ var modulePrefix = '' ;
42
+
43
+ // TODO : make it generic and move it to utilities
44
+ try {
45
+ let pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
46
+ astUtils . getSourceNodes ( astUtils . getSource ( pathToModule ) )
47
+ . last ( node => ( node . flags & ts . NodeFlags . Export ) !== 0 && node . getText ( ) . indexOf ( 'ModulePrefix' ) > - 1 )
48
+ . subscribe ( node => {
49
+ modulePrefix = / = ? [ ' " ] ( [ \w - ] + ) [ " ' ] / . exec ( node . getText ( ) ) [ 1 ] ;
50
+ } ) ;
51
+ } catch ( e ) {
52
+ console . log ( `there isn't any module for this component\n\t` ) ;
53
+ }
54
+
40
55
var defaultPrefix = '' ;
41
56
if ( this . project . ngConfig &&
42
57
this . project . ngConfig . apps [ 0 ] &&
43
58
this . project . ngConfig . apps [ 0 ] . prefix ) {
44
59
defaultPrefix = this . project . ngConfig . apps [ 0 ] . prefix ;
45
60
}
46
61
47
- var prefix = ( this . options . prefix === 'false' || this . options . prefix === '' ) ? '' : ( this . options . prefix || defaultPrefix ) ;
62
+ var prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
63
+ ? '' : ( this . options . prefix || modulePrefix || defaultPrefix ) ;
48
64
prefix = prefix && `${ prefix } -` ;
49
65
50
66
this . selector = stringUtils . dasherize ( prefix + parsedPath . name ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ const findParentModule = require('../../utilities/find-parent-module').default;
6
6
const NodeHost = require ( '@angular-cli/ast-tools' ) . NodeHost ;
7
7
const Blueprint = require ( '../../ember-cli/lib/models/blueprint' ) ;
8
8
const getFiles = Blueprint . prototype . files ;
9
+ const ts = require ( 'typescript' ) ;
10
+
9
11
10
12
module . exports = {
11
13
description : '' ,
@@ -32,14 +34,29 @@ module.exports = {
32
34
33
35
this . dynamicPath = parsedPath ;
34
36
37
+ var modulePrefix = '' ;
38
+
39
+ // TODO : make it generic and move it to utilities
40
+ try {
41
+ let pathToModule = findParentModule ( this . project , this . dynamicPath . dir ) ;
42
+ astUtils . getSourceNodes ( astUtils . getSource ( pathToModule ) )
43
+ . last ( node => ( node . flags & ts . NodeFlags . Export ) !== 0 && node . getText ( ) . indexOf ( 'ModulePrefix' ) > - 1 )
44
+ . subscribe ( node => {
45
+ modulePrefix = / = ? [ ' " ] ( [ \w - ] + ) [ " ' ] / . exec ( node . getText ( ) ) [ 1 ] ;
46
+ } ) ;
47
+ } catch ( e ) {
48
+ console . log ( `there isn't any module for this directive\n\t` ) ;
49
+ }
50
+
35
51
var defaultPrefix = '' ;
36
52
if ( this . project . ngConfig &&
37
53
this . project . ngConfig . apps [ 0 ] &&
38
54
this . project . ngConfig . apps [ 0 ] . prefix ) {
39
55
defaultPrefix = this . project . ngConfig . apps [ 0 ] . prefix ;
40
56
}
41
57
42
- var prefix = ( this . options . prefix === 'false' || this . options . prefix === '' ) ? '' : ( this . options . prefix || defaultPrefix ) ;
58
+ var prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
59
+ ? '' : ( this . options . prefix || modulePrefix || defaultPrefix ) ;
43
60
prefix = prefix && `${ prefix } -` ;
44
61
45
62
You can’t perform that action at this time.
0 commit comments