-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathproject-data.ts
49 lines (44 loc) · 1.63 KB
/
project-data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
///<reference path=".d.ts"/>
"use strict";
import path = require("path");
import os = require("os");
export class ProjectData implements IProjectData {
public projectDir: string;
public platformsDir: string;
public projectFilePath: string;
public projectId: string;
public projectName: string;
constructor(private $fs: IFileSystem,
private $errors: IErrors,
private $projectHelper: IProjectHelper,
private $staticConfig: IStaticConfig) {
this.initializeProjectData().wait();
}
private initializeProjectData(): IFuture<void> {
return(() => {
var projectDir = this.$projectHelper.projectDir;
// If no project found, projectDir should be null
if(projectDir) {
this.projectDir = projectDir;
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
this.platformsDir = path.join(projectDir, "platforms");
this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
if (this.$fs.exists(this.projectFilePath).wait()) {
try {
var fileContent = this.$fs.readJson(this.projectFilePath).wait();
this.projectId = fileContent.id;
} catch (err) {
this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL +
"Consider restoring an earlier version from your source control or backup." + os.EOL +
"Additional technical info: %s",
suppressCommandHelp: true},
this.projectFilePath, err.toString());
}
}
} else {
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());
}
}).future<void>()();
}
}
$injector.register("projectData", ProjectData);