@@ -16,15 +16,16 @@ class ProjectData implements IProjectData {
16
16
public projectName : string ;
17
17
18
18
constructor ( private $fs : IFileSystem ,
19
+ private $errors : IErrors ,
19
20
private $projectHelper : IProjectHelper ,
20
- private $config ) {
21
+ private $config : IConfig ) {
21
22
this . initializeProjectData ( ) . wait ( ) ;
22
23
}
23
24
24
25
private initializeProjectData ( ) : IFuture < void > {
25
26
return ( ( ) => {
26
27
var projectDir = this . $projectHelper . projectDir ;
27
-
28
+ // If no project found, projectDir should be null
28
29
if ( projectDir ) {
29
30
this . projectDir = projectDir ;
30
31
this . projectName = path . basename ( projectDir ) ;
@@ -35,8 +36,9 @@ class ProjectData implements IProjectData {
35
36
var fileContent = this . $fs . readJson ( this . projectFilePath ) . wait ( ) ;
36
37
this . projectId = fileContent . id ;
37
38
}
39
+ } else {
40
+ this . $errors . fail ( "No project found at or above '%s' and neither was a --path specified." , process . cwd ( ) ) ;
38
41
}
39
-
40
42
} ) . future < void > ( ) ( ) ;
41
43
}
42
44
}
@@ -47,15 +49,15 @@ export class ProjectService implements IProjectService {
47
49
private $errors : IErrors ,
48
50
private $fs : IFileSystem ,
49
51
private $projectTemplatesService : IProjectTemplatesService ,
50
- private $projectData : IProjectData ,
52
+ private $projectHelper : IProjectHelper ,
51
53
private $config ) { }
52
54
53
55
public createProject ( projectName : string , projectId : string ) : IFuture < void > {
54
56
return ( ( ) => {
55
57
var projectDir = path . resolve ( options . path || "." ) ;
56
58
57
- projectId = projectId || constants . DEFAULT_PROJECT_ID ;
58
59
projectName = projectName || constants . DEFAULT_PROJECT_NAME ;
60
+ projectId = options . appid || this . $projectHelper . generateDefaultAppId ( projectName ) ;
59
61
60
62
projectDir = path . join ( projectDir , projectName ) ;
61
63
this . $fs . createDirectory ( projectDir ) . wait ( ) ;
@@ -79,9 +81,13 @@ export class ProjectService implements IProjectService {
79
81
80
82
// Make sure that the source app/ is not a direct ancestor of a target app/
81
83
var relativePathFromSourceToTarget = path . relative ( customAppPath , appDirectory ) ;
82
- var doesRelativePathGoUpAtLeastOneDir = relativePathFromSourceToTarget . split ( path . sep ) [ 0 ] == ".." ;
83
- if ( ! doesRelativePathGoUpAtLeastOneDir ) {
84
- this . $errors . fail ( "Project dir %s must not be created at/inside the template used to create the project %s." , projectDir , customAppPath ) ;
84
+ // path.relative returns second argument if the paths are located on different disks
85
+ // so in this case we don't need to make the check for direct ancestor
86
+ if ( relativePathFromSourceToTarget !== appDirectory ) {
87
+ var doesRelativePathGoUpAtLeastOneDir = relativePathFromSourceToTarget . split ( path . sep ) [ 0 ] === ".." ;
88
+ if ( ! doesRelativePathGoUpAtLeastOneDir ) {
89
+ this . $errors . fail ( "Project dir %s must not be created at/inside the template used to create the project %s." , projectDir , customAppPath ) ;
90
+ }
85
91
}
86
92
this . $logger . trace ( "Copying custom app into %s" , appDirectory ) ;
87
93
appPath = customAppPath ;
@@ -94,6 +100,8 @@ export class ProjectService implements IProjectService {
94
100
}
95
101
96
102
this . createProjectCore ( projectDir , appPath , projectId , false ) . wait ( ) ;
103
+
104
+ this . $logger . out ( "Project %s was successfully created" , projectName ) ;
97
105
} ) . future < void > ( ) ( ) ;
98
106
}
99
107
@@ -138,12 +146,6 @@ export class ProjectService implements IProjectService {
138
146
139
147
return customAppPath ;
140
148
}
141
-
142
- public ensureProject ( ) {
143
- if ( this . $projectData . projectDir === "" || ! this . $fs . exists ( this . $projectData . projectFilePath ) . wait ( ) ) {
144
- this . $errors . fail ( "No project found at or above '%s' and neither was a --path specified." , process . cwd ( ) ) ;
145
- }
146
- }
147
149
}
148
150
$injector . register ( "projectService" , ProjectService ) ;
149
151
0 commit comments