@@ -3,20 +3,26 @@ import * as process from 'process';
33import  *  as  fs  from  'fs' ; 
44const  stringUtils  =  require ( 'ember-cli-string-utils' ) ; 
55
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 ; 
1016  const  appRoot  =  path . join ( sourceDir ,  'app' ) ; 
1117  const  cwd  =  process . env . PWD ; 
1218
1319  const  rootPath  =  path . join ( projectRoot ,  appRoot ) ; 
14-   let  outputPath  =  path . join ( rootPath ,  entityName ) ; 
20+   let  outputPath  =  path . join ( rootPath ,  options . entityName ) ; 
1521
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 ) ) ; 
1824  }  else  if  ( cwd . indexOf ( rootPath )  >=  0 )  { 
19-     outputPath  =  path . join ( cwd ,  entityName ) ; 
25+     outputPath  =  path . join ( cwd ,  options . entityName ) ; 
2026  } 
2127
2228  if  ( ! fs . existsSync ( outputPath ) )  { 
@@ -39,7 +45,7 @@ export function dynamicPathParser(project: any, entityName: string, appConfig: a
3945      // Folder not found, create it, and return it 
4046      const  dasherizedPart  =  stringUtils . dasherize ( part ) ; 
4147      const  dasherizedDirName  =  path . join ( tempPath ,  dasherizedPart ) ; 
42-       if  ( ! dryRun )  { 
48+       if  ( ! options . dryRun )  { 
4349        fs . mkdirSync ( dasherizedDirName ) ; 
4450      } 
4551      return  dasherizedDirName ; 
@@ -49,7 +55,7 @@ export function dynamicPathParser(project: any, entityName: string, appConfig: a
4955  } 
5056
5157  if  ( outputPath . indexOf ( rootPath )  <  0 )  { 
52-     throw  `Invalid path: "${ entityName }  " cannot be `  + 
58+     throw  `Invalid path: "${ options . entityName }  " cannot be `  + 
5359        `above the "${ appRoot }  " directory` ; 
5460  } 
5561
0 commit comments