@@ -3,20 +3,26 @@ import * as process from 'process';
3
3
import * as fs from 'fs' ;
4
4
const stringUtils = require ( 'ember-cli-string-utils' ) ;
5
5
6
- export function dynamicPathParser ( project : any , entityName : string , appConfig : any ,
7
- dryRun : boolean ) {
8
- const projectRoot = project . root ;
9
- const sourceDir = appConfig . root ;
6
+ export interface DynamicPathOptions {
7
+ project : any ;
8
+ entityName : string ;
9
+ appConfig : any ;
10
+ dryRun : boolean ;
11
+ }
12
+
13
+ export function dynamicPathParser ( options : DynamicPathOptions ) {
14
+ const projectRoot = options . project . root ;
15
+ const sourceDir = options . appConfig . root ;
10
16
const appRoot = path . join ( sourceDir , 'app' ) ;
11
17
const cwd = process . env . PWD ;
12
18
13
19
const rootPath = path . join ( projectRoot , appRoot ) ;
14
- let outputPath = path . join ( rootPath , entityName ) ;
20
+ let outputPath = path . join ( rootPath , options . entityName ) ;
15
21
16
- if ( entityName . indexOf ( path . sep ) === 0 ) {
17
- outputPath = path . join ( rootPath , entityName . substr ( 1 ) ) ;
22
+ if ( options . entityName . indexOf ( path . sep ) === 0 ) {
23
+ outputPath = path . join ( rootPath , options . entityName . substr ( 1 ) ) ;
18
24
} else if ( cwd . indexOf ( rootPath ) >= 0 ) {
19
- outputPath = path . join ( cwd , entityName ) ;
25
+ outputPath = path . join ( cwd , options . entityName ) ;
20
26
}
21
27
22
28
if ( ! fs . existsSync ( outputPath ) ) {
@@ -39,7 +45,7 @@ export function dynamicPathParser(project: any, entityName: string, appConfig: a
39
45
// Folder not found, create it, and return it
40
46
const dasherizedPart = stringUtils . dasherize ( part ) ;
41
47
const dasherizedDirName = path . join ( tempPath , dasherizedPart ) ;
42
- if ( ! dryRun ) {
48
+ if ( ! options . dryRun ) {
43
49
fs . mkdirSync ( dasherizedDirName ) ;
44
50
}
45
51
return dasherizedDirName ;
@@ -49,7 +55,7 @@ export function dynamicPathParser(project: any, entityName: string, appConfig: a
49
55
}
50
56
51
57
if ( outputPath . indexOf ( rootPath ) < 0 ) {
52
- throw `Invalid path: "${ entityName } " cannot be ` +
58
+ throw `Invalid path: "${ options . entityName } " cannot be ` +
53
59
`above the "${ appRoot } " directory` ;
54
60
}
55
61
0 commit comments