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