@@ -13,11 +13,9 @@ import { green, red, yellow } from 'chalk';
13
13
import { CliConfig } from '../models/config' ;
14
14
import 'rxjs/add/operator/concatMap' ;
15
15
import 'rxjs/add/operator/map' ;
16
- import * as fs from 'fs' ;
17
16
import { getCollection , getSchematic } from '../utilities/schematics' ;
18
17
import { getAppFromConfig } from '../utilities/app-utils' ;
19
18
20
- const SilentError = require ( 'silent-error' ) ;
21
19
22
20
const Task = require ( '../ember-cli/lib/models/task' ) ;
23
21
@@ -49,27 +47,14 @@ export default Task.extend({
49
47
50
48
let modifiedFiles : string [ ] = [ ] ;
51
49
52
- let appDir = workingDir ;
53
50
let appConfig ;
54
51
try {
55
52
appConfig = getAppFromConfig ( taskOptions . app ) ;
56
53
} catch ( err ) { }
57
54
58
55
const projectRoot = ! ! this . project ? this . project . root : workingDir ;
59
56
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 ) ;
73
58
const opts = { ...taskOptions , ...preppedOptions } ;
74
59
75
60
const host = Observable . of ( new FileSystemTree ( new FileSystemHost ( workingDir ) ) ) ;
@@ -163,8 +148,7 @@ export default Task.extend({
163
148
}
164
149
} ) ;
165
150
166
- function prepOptions ( schematic : Schematic < { } , { } > , workingDirectory : string ,
167
- options : SchematicOptions , projectRoot : string ) : SchematicOptions {
151
+ function prepOptions ( schematic : Schematic < { } , { } > , options : SchematicOptions ) : SchematicOptions {
168
152
169
153
const properties = ( < any > schematic . description ) . schemaJson . properties ;
170
154
const keys = Object . keys ( properties ) ;
@@ -174,11 +158,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
174
158
? '' : options . prefix ;
175
159
}
176
160
177
- const filepathKeys = keys
178
- . filter ( key => {
179
- const prop = properties [ key ] ;
180
- return prop . type === 'string' && prop . subtype === 'filepath' ;
181
- } ) ;
182
161
let preppedOptions = {
183
162
...options ,
184
163
...readDefaults ( schematic . description . name , keys , options )
@@ -187,32 +166,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
187
166
...preppedOptions ,
188
167
...normalizeOptions ( schematic . description . name , keys , options )
189
168
} ;
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
- }
216
169
217
170
return preppedOptions ;
218
171
}
@@ -253,29 +206,3 @@ function readDefault(schematicName: String, key: string) {
253
206
const jsonPath = `defaults.${ schematicName } .${ key } ` ;
254
207
return CliConfig . getValue ( jsonPath ) ;
255
208
}
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