@@ -13,11 +13,9 @@ import { green, red, yellow } from 'chalk';
1313import { CliConfig } from '../models/config' ;
1414import 'rxjs/add/operator/concatMap' ;
1515import 'rxjs/add/operator/map' ;
16- import * as fs from 'fs' ;
1716import { getCollection , getSchematic } from '../utilities/schematics' ;
1817import { getAppFromConfig } from '../utilities/app-utils' ;
1918
20- const SilentError = require ( 'silent-error' ) ;
2119
2220const Task = require ( '../ember-cli/lib/models/task' ) ;
2321
@@ -49,27 +47,14 @@ export default Task.extend({
4947
5048 let modifiedFiles : string [ ] = [ ] ;
5149
52- let appDir = workingDir ;
5350 let appConfig ;
5451 try {
5552 appConfig = getAppFromConfig ( taskOptions . app ) ;
5653 } catch ( err ) { }
5754
5855 const projectRoot = ! ! this . project ? this . project . root : workingDir ;
5956
60- if ( appConfig ) {
61- const sourceRoot = path . join ( projectRoot , appConfig . root ) ;
62- const appRoot = path . join ( sourceRoot , 'app' ) ;
63- if ( workingDir . indexOf ( appRoot ) === 0 ) {
64- appDir = workingDir ;
65- } else if ( workingDir . indexOf ( sourceRoot ) === 0 ) {
66- appDir = path . join ( sourceRoot , 'app' ) ;
67- } else {
68- appDir = path . join ( projectRoot , appConfig . root , 'app' ) ;
69- }
70- }
71-
72- const preppedOptions = prepOptions ( schematic , appDir , taskOptions , projectRoot ) ;
57+ const preppedOptions = prepOptions ( schematic , taskOptions ) ;
7358 const opts = { ...taskOptions , ...preppedOptions } ;
7459
7560 const host = Observable . of ( new FileSystemTree ( new FileSystemHost ( workingDir ) ) ) ;
@@ -163,8 +148,7 @@ export default Task.extend({
163148 }
164149} ) ;
165150
166- function prepOptions ( schematic : Schematic < { } , { } > , workingDirectory : string ,
167- options : SchematicOptions , projectRoot : string ) : SchematicOptions {
151+ function prepOptions ( schematic : Schematic < { } , { } > , options : SchematicOptions ) : SchematicOptions {
168152
169153 const properties = ( < any > schematic . description ) . schemaJson . properties ;
170154 const keys = Object . keys ( properties ) ;
@@ -174,11 +158,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
174158 ? '' : options . prefix ;
175159 }
176160
177- const filepathKeys = keys
178- . filter ( key => {
179- const prop = properties [ key ] ;
180- return prop . type === 'string' && prop . subtype === 'filepath' ;
181- } ) ;
182161 let preppedOptions = {
183162 ...options ,
184163 ...readDefaults ( schematic . description . name , keys , options )
@@ -187,32 +166,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
187166 ...preppedOptions ,
188167 ...normalizeOptions ( schematic . description . name , keys , options )
189168 } ;
190- preppedOptions = {
191- ...preppedOptions ,
192- ...prepFilepaths ( filepathKeys , options , workingDirectory , projectRoot )
193- } ;
194-
195- if ( preppedOptions . module ) {
196- if ( ! preppedOptions . module . endsWith ( '.module.ts' ) ) {
197- let newModuleValue = preppedOptions . module ;
198- const fullPath = path . join ( projectRoot , preppedOptions . module ) ;
199- if ( fs . existsSync ( fullPath ) && fs . lstatSync ( fullPath ) . isDirectory ( ) ) {
200- const files = fs . readdirSync ( path . join ( projectRoot , preppedOptions . module ) ) ;
201- const moduleFiles = files . filter ( f => f . endsWith ( '.module.ts' ) ) ;
202- if ( moduleFiles . length === 1 ) {
203- newModuleValue = path . join ( preppedOptions . module , moduleFiles [ 0 ] ) ;
204- }
205- } else if ( preppedOptions . module . endsWith ( '.module' ) ) {
206- newModuleValue = `${ newModuleValue } .ts` ;
207- } else {
208- newModuleValue = `${ newModuleValue } .module.ts` ;
209- }
210- preppedOptions = {
211- ...preppedOptions ,
212- module : newModuleValue
213- } ;
214- }
215- }
216169
217170 return preppedOptions ;
218171}
@@ -253,29 +206,3 @@ function readDefault(schematicName: String, key: string) {
253206 const jsonPath = `defaults.${ schematicName } .${ key } ` ;
254207 return CliConfig . getValue ( jsonPath ) ;
255208}
256-
257- function prepFilepaths ( keys : string [ ] ,
258- options : SchematicOptions ,
259- workingDirectory : string ,
260- projectRoot : string ) : any {
261- return keys
262- . reduce ( ( acc : any , key ) => {
263- acc [ key ] = prepFilepath ( options [ key ] , workingDirectory , projectRoot ) ;
264- return acc ;
265- } , { } ) ;
266- }
267-
268- function prepFilepath ( value : string , workingDirectory : string , projectRoot : string ) : string {
269- if ( ! value ) {
270- return undefined ;
271- }
272- const modulePath = path . resolve ( workingDirectory , value ) ;
273-
274- // ensure it starts with projectRoot
275- if ( ! modulePath . startsWith ( projectRoot ) ) {
276- throw new SilentError ( 'invalid module path' ) ;
277- }
278-
279- return modulePath . substr ( projectRoot . length ) ;
280- }
281-
0 commit comments