File tree Expand file tree Collapse file tree 3 files changed +28
-28
lines changed Expand file tree Collapse file tree 3 files changed +28
-28
lines changed Original file line number Diff line number Diff line change @@ -7,7 +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
+ const getConstConfig = require ( '../../utilities/get-const-config' ) . default ;
11
11
12
12
module . exports = {
13
13
description : '' ,
@@ -38,20 +38,8 @@ module.exports = {
38
38
39
39
this . dynamicPath = parsedPath ;
40
40
41
- var modulePrefix = '' ;
41
+ var modulePrefix = getConstConfig ( this . project , this . dynamicPath . dir , 'ModulePrefix' ) ;
42
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
-
55
43
var defaultPrefix = '' ;
56
44
if ( this . project . ngConfig &&
57
45
this . project . ngConfig . apps [ 0 ] &&
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 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' ) ;
9
+ const getConstConfig = require ( '../../utilities/get-const-config' ) . default ;
10
10
11
11
12
12
module . exports = {
@@ -34,19 +34,7 @@ module.exports = {
34
34
35
35
this . dynamicPath = parsedPath ;
36
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
- }
37
+ var modulePrefix = getConstConfig ( this . project , this . dynamicPath . dir , 'ModulePrefix' ) ;
50
38
51
39
var defaultPrefix = '' ;
52
40
if ( this . project . ngConfig &&
Original file line number Diff line number Diff line change
1
+ import findParentModule from './find-parent-module' ;
2
+ import * as astUtils from './ast-utils' ;
3
+ import * as ts from 'typescript' ;
4
+
5
+ export default function getConstConfig ( project : any , dir : string , identifier : string ) : string {
6
+ let modulePrefix = '' ;
7
+ try {
8
+ let pathToModule = findParentModule ( project , dir ) ;
9
+ console . log ( pathToModule ) ;
10
+
11
+ astUtils . getSourceNodes ( astUtils . getSource ( pathToModule ) )
12
+ . last ( ( node : ts . Node ) => {
13
+ // tslint:disable-next-line:no-bitwise
14
+ return ( node . flags & ts . NodeFlags . Export ) !== 0
15
+ && node . getText ( ) . includes ( identifier ) ;
16
+ } )
17
+ . subscribe ( ( node : ts . Node ) => {
18
+ modulePrefix = / = ? [ ' " ] ( [ \w - ] + ) [ " ' ] / . exec ( node . getText ( ) ) [ 1 ] ;
19
+ } ) ;
20
+ } catch ( e ) {
21
+ console . log ( `no const configuration found for ${ identifier } in the parent module\n\t` ) ;
22
+ }
23
+ return modulePrefix ;
24
+ }
You can’t perform that action at this time.
0 commit comments