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+
99const stringUtils = require ( 'ember-cli-string-utils' ) ;
1010const astUtils = require ( '../../utilities/ast-utils' ) ;
1111const findParentModule = require ( '../../utilities/find-parent-module' ) . default ;
@@ -58,17 +58,11 @@ export default Blueprint.extend({
5858 }
5959 ] ,
6060
61- beforeInstall : function ( options : any ) {
61+ beforeInstall : function ( options : any ) {
6262 const appConfig = getAppFromConfig ( this . options . app ) ;
6363 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 ) ;
7266 } else {
7367 try {
7468 this . pathToModule = findParentModule ( this . project . root , appConfig . root , this . generatePath ) ;
@@ -89,7 +83,7 @@ export default Blueprint.extend({
8983 const defaultPrefix = ( appConfig && appConfig . prefix ) || '' ;
9084
9185 let prefix = ( this . options . prefix === 'false' || this . options . prefix === '' )
92- ? '' : ( this . options . prefix || defaultPrefix ) ;
86+ ? '' : ( this . options . prefix || defaultPrefix ) ;
9387 prefix = prefix && `${ prefix } -` ;
9488
9589
@@ -111,7 +105,7 @@ export default Blueprint.extend({
111105 } ;
112106 } ,
113107
114- files : function ( ) {
108+ files : function ( ) {
115109 let fileList = getFiles . call ( this ) as Array < string > ;
116110
117111 if ( this . options && ! this . options . spec ) {
@@ -135,7 +129,7 @@ export default Blueprint.extend({
135129 } ;
136130 } ,
137131
138- afterInstall : function ( options : any ) {
132+ afterInstall : function ( options : any ) {
139133 const returns : Array < any > = [ ] ;
140134 const className = stringUtils . classify ( `${ options . entity . name } Directive` ) ;
141135 const fileName = stringUtils . dasherize ( `${ options . entity . name } .directive` ) ;
@@ -161,9 +155,9 @@ export default Blueprint.extend({
161155 }
162156 return result ;
163157 } ) ) ;
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 ) ) ;
167161 }
168162
169163 return Promise . all ( returns ) ;
0 commit comments