@@ -16,15 +16,16 @@ class ProjectData implements IProjectData {
1616 public projectName : string ;
1717
1818 constructor ( private $fs : IFileSystem ,
19+ private $errors : IErrors ,
1920 private $projectHelper : IProjectHelper ,
20- private $config ) {
21+ private $config : IConfig ) {
2122 this . initializeProjectData ( ) . wait ( ) ;
2223 }
2324
2425 private initializeProjectData ( ) : IFuture < void > {
2526 return ( ( ) => {
2627 var projectDir = this . $projectHelper . projectDir ;
27-
28+ // If no project found, projectDir should be null
2829 if ( projectDir ) {
2930 this . projectDir = projectDir ;
3031 this . projectName = path . basename ( projectDir ) ;
@@ -35,8 +36,9 @@ class ProjectData implements IProjectData {
3536 var fileContent = this . $fs . readJson ( this . projectFilePath ) . wait ( ) ;
3637 this . projectId = fileContent . id ;
3738 }
39+ } else {
40+ this . $errors . fail ( "No project found at or above '%s' and neither was a --path specified." , process . cwd ( ) ) ;
3841 }
39-
4042 } ) . future < void > ( ) ( ) ;
4143 }
4244}
@@ -47,15 +49,15 @@ export class ProjectService implements IProjectService {
4749 private $errors : IErrors ,
4850 private $fs : IFileSystem ,
4951 private $projectTemplatesService : IProjectTemplatesService ,
50- private $projectData : IProjectData ,
52+ private $projectHelper : IProjectHelper ,
5153 private $config ) { }
5254
5355 public createProject ( projectName : string , projectId : string ) : IFuture < void > {
5456 return ( ( ) => {
5557 var projectDir = path . resolve ( options . path || "." ) ;
5658
57- projectId = projectId || constants . DEFAULT_PROJECT_ID ;
5859 projectName = projectName || constants . DEFAULT_PROJECT_NAME ;
60+ projectId = options . appid || this . $projectHelper . generateDefaultAppId ( projectName ) ;
5961
6062 projectDir = path . join ( projectDir , projectName ) ;
6163 this . $fs . createDirectory ( projectDir ) . wait ( ) ;
@@ -79,9 +81,13 @@ export class ProjectService implements IProjectService {
7981
8082 // Make sure that the source app/ is not a direct ancestor of a target app/
8183 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+ }
8591 }
8692 this . $logger . trace ( "Copying custom app into %s" , appDirectory ) ;
8793 appPath = customAppPath ;
@@ -94,6 +100,8 @@ export class ProjectService implements IProjectService {
94100 }
95101
96102 this . createProjectCore ( projectDir , appPath , projectId , false ) . wait ( ) ;
103+
104+ this . $logger . out ( "Project %s was successfully created" , projectName ) ;
97105 } ) . future < void > ( ) ( ) ;
98106 }
99107
@@ -138,12 +146,6 @@ export class ProjectService implements IProjectService {
138146
139147 return customAppPath ;
140148 }
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- }
147149}
148150$injector . register ( "projectService" , ProjectService ) ;
149151
0 commit comments