1
- import { NodeHost } from '../../lib/ast-tools ' ;
2
- import { CliConfig } from '../../models/config ' ;
3
- import { getAppFromConfig } from '../../utilities/app-utils ' ;
4
- import { dynamicPathParser } from '../../utilities/dynamic-path-parser ' ;
5
-
6
- const path = require ( 'path' ) ;
7
- const fs = require ( 'fs' ) ;
8
- const chalk = require ( 'chalk' ) ;
1
+ import * as chalk from 'chalk ' ;
2
+ import * as path from 'path ' ;
3
+ import { NodeHost } from '../../lib/ast-tools ' ;
4
+ import { CliConfig } from '../../models/config ' ;
5
+ import { getAppFromConfig } from '../../utilities/app-utils' ;
6
+ import { resolveModulePath } from '../../utilities/resolve-module-file' ;
7
+ import { dynamicPathParser } from '../../utilities/dynamic-path-parser' ;
8
+
9
9
const stringUtils = require ( 'ember-cli-string-utils' ) ;
10
10
const astUtils = require ( '../../utilities/ast-utils' ) ;
11
11
const findParentModule = require ( '../../utilities/find-parent-module' ) . default ;
@@ -58,17 +58,11 @@ export default Blueprint.extend({
58
58
}
59
59
] ,
60
60
61
- beforeInstall : function ( options : any ) {
61
+ beforeInstall : function ( options : any ) {
62
62
const appConfig = getAppFromConfig ( this . options . app ) ;
63
63
if ( options . module ) {
64
- // Resolve path to module
65
- const modulePath = options . module . endsWith ( '.ts' ) ? options . module : `${ options . module } .ts` ;
66
- const parsedPath = dynamicPathParser ( this . project , modulePath , appConfig ) ;
67
- this . pathToModule = path . join ( this . project . root , parsedPath . dir , parsedPath . base ) ;
68
-
69
- if ( ! fs . existsSync ( this . pathToModule ) ) {
70
- throw ' ' ;
71
- }
64
+ this . pathToModule =
65
+ resolveModulePath ( options . module , this . project , this . project . root , appConfig ) ;
72
66
} else {
73
67
try {
74
68
this . pathToModule = findParentModule ( this . project . root , appConfig . root , this . generatePath ) ;
@@ -89,7 +83,7 @@ export default Blueprint.extend({
89
83
const defaultPrefix = ( appConfig && appConfig . prefix ) || '' ;
90
84
91
85
let prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
92
- ? '' : ( this . options . prefix || defaultPrefix ) ;
86
+ ? '' : ( this . options . prefix || defaultPrefix ) ;
93
87
prefix = prefix && `${ prefix } -` ;
94
88
95
89
@@ -111,7 +105,7 @@ export default Blueprint.extend({
111
105
} ;
112
106
} ,
113
107
114
- files : function ( ) {
108
+ files : function ( ) {
115
109
let fileList = getFiles . call ( this ) as Array < string > ;
116
110
117
111
if ( this . options && ! this . options . spec ) {
@@ -135,7 +129,7 @@ export default Blueprint.extend({
135
129
} ;
136
130
} ,
137
131
138
- afterInstall : function ( options : any ) {
132
+ afterInstall : function ( options : any ) {
139
133
const returns : Array < any > = [ ] ;
140
134
const className = stringUtils . classify ( `${ options . entity . name } Directive` ) ;
141
135
const fileName = stringUtils . dasherize ( `${ options . entity . name } .directive` ) ;
@@ -161,9 +155,9 @@ export default Blueprint.extend({
161
155
}
162
156
return result ;
163
157
} ) ) ;
164
- this . _writeStatusToUI ( chalk . yellow ,
165
- 'update' ,
166
- path . relative ( this . project . root , this . pathToModule ) ) ;
158
+ this . _writeStatusToUI ( chalk . yellow ,
159
+ 'update' ,
160
+ path . relative ( this . project . root , this . pathToModule ) ) ;
167
161
}
168
162
169
163
return Promise . all ( returns ) ;
0 commit comments