Skip to content

Commit 9d4bf13

Browse files
Make fs.writeJson sync
1 parent 5a8e036 commit 9d4bf13

32 files changed

+427
-448
lines changed

lib/commands/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class InstallCommand implements ICommand {
2828
this.$projectDataService.initialize(this.$projectData.projectDir);
2929
_.each(this.$platformsData.platformsNames, platform => {
3030
let platformData = this.$platformsData.getPlatformData(platform);
31-
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
31+
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName);
3232
if (frameworkPackageData && frameworkPackageData.version) {
3333
try {
3434
this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`]).wait();

lib/commands/platform-clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class CleanCommand implements ICommand {
44

55
public execute(args: string[]): IFuture<void> {
66
return (() => {
7-
this.$platformService.removePlatforms(args).wait();
7+
this.$platformService.removePlatforms(args);
88
this.$platformService.addPlatforms(args).wait();
99
}).future<void>()();
1010
}

lib/commands/remove-platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class RemovePlatformCommand implements ICommand {
44

55
execute(args: string[]): IFuture<void> {
66
return (() => {
7-
this.$platformService.removePlatforms(args).wait();
7+
this.$platformService.removePlatforms(args);
88
}).future<void>()();
99
}
1010

lib/commands/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export class UpdateCommand implements ICommand {
6060
this.$projectDataService.initialize(this.$projectData.projectDir);
6161
for (let platform of availablePlatforms) {
6262
let platformData = this.$platformsData.getPlatformData(platform);
63-
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait();
63+
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName);
6464
if (platformVersion) {
6565
packagePlatforms.push(platform);
66-
this.$projectDataService.removeProperty(platformData.frameworkPackageName).wait();
66+
this.$projectDataService.removeProperty(platformData.frameworkPackageName);
6767
}
6868
}
6969

70-
this.$platformService.removePlatforms(platforms).wait();
70+
this.$platformService.removePlatforms(platforms);
7171
this.$pluginsService.remove("tns-core-modules").wait();
7272
this.$pluginsService.remove("tns-core-modules-widgets").wait();
7373

lib/definitions/platform.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ interface IPlatformService {
1919
*/
2020
getPreparedPlatforms(): string[];
2121

22-
removePlatforms(platforms: string[]): IFuture<void>;
22+
/**
23+
* Remove platforms from specified project (`<project dir>/platforms/<platform>` dir).
24+
* @param {string[]} platforms Platforms to be removed.
25+
* @returns {void}
26+
*/
27+
removePlatforms(platforms: string[]): void;
28+
2329
updatePlatforms(platforms: string[]): IFuture<void>;
2430
preparePlatform(platform: string, force?: boolean, skipModulesAndResources?: boolean): IFuture<boolean>;
2531
buildPlatform(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture<void>;

lib/definitions/plugins.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ interface IPluginVariablesService {
5252
/**
5353
* Removes plugin variables from project package.json file.
5454
* @param {string} pluginName Name of the plugin.
55-
* @return {IFuture<void>}
55+
* @return {void}
5656
*/
57-
removePluginVariablesFromProjectFile(pluginName: string): IFuture<void>;
57+
removePluginVariablesFromProjectFile(pluginName: string): void;
5858

5959
/**
6060
* Replaces all plugin variables with their corresponding values.

lib/definitions/project.d.ts

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,35 @@ interface IProjectData {
1616

1717
interface IProjectDataService {
1818
initialize(projectDir: string): void;
19-
getValue(propertyName: string): IFuture<any>;
20-
setValue(key: string, value: any): IFuture<void>;
21-
removeProperty(propertyName: string): IFuture<void>;
22-
removeDependency(dependencyName: string): IFuture<void>;
19+
20+
/**
21+
* Returns a value from `nativescript` key in project's package.json.
22+
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
23+
* @returns {any} The value of the property.
24+
*/
25+
getValue(propertyName: string): any;
26+
27+
/**
28+
* Sets a value in the `nativescript` key in a project's package.json.
29+
* @param {string} key Key to be added to `nativescript` key in project's package.json.
30+
* @param {any} value Value of the key to be added to `nativescript` key in project's package.json.
31+
* @returns {void}
32+
*/
33+
setValue(key: string, value: any): void;
34+
35+
/**
36+
* Removes a property from `nativescript` key in project's package.json.
37+
* @param {string} propertyName The name of the property to be removed from `nativescript` key.
38+
* @returns {void}
39+
*/
40+
removeProperty(propertyName: string): void;
41+
42+
/**
43+
* Removes dependency from package.json
44+
* @param {string} dependencyName Name of the dependency that has to be removed.
45+
* @returns {void}
46+
*/
47+
removeDependency(dependencyName: string): void;
2348
}
2449

2550
/**
@@ -79,8 +104,19 @@ interface IPlatformProjectService {
79104
afterCreateProject(projectRoot: string): void;
80105

81106
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
82-
prepareProject(): IFuture<void>;
83-
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
107+
108+
/**
109+
* Prepares images in Native project (for iOS).
110+
* @returns {void}
111+
*/
112+
prepareProject(): void;
113+
114+
/**
115+
* Prepares App_Resources in the native project by clearing data from other platform and applying platform specific rules.
116+
* @param {string} appResourcesDirectoryPath The place in the native project where the App_Resources are copied first.
117+
* @returns {void}
118+
*/
119+
prepareAppResources(appResourcesDirectoryPath: string): void;
84120

85121
/**
86122
* Defines if current platform is prepared (i.e. if <project dir>/platforms/<platform> dir exists).
@@ -107,7 +143,13 @@ interface IPlatformProjectService {
107143

108144
afterPrepareAllPlugins(): IFuture<void>;
109145
beforePrepareAllPlugins(dependencies?: IDictionary<IDependencyData>): IFuture<void>;
110-
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
146+
147+
/**
148+
* Gets the path wheren App_Resources should be copied.
149+
* @returns {string} Path to native project, where App_Resources should be copied.
150+
*/
151+
getAppResourcesDestinationDirectoryPath(): string;
152+
111153
deploy(deviceIdentifier: string): IFuture<void>;
112154
processConfigurationFilesFromAppResources(): IFuture<void>;
113155
/**

lib/project-data.ts

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,82 +20,76 @@ export class ProjectData implements IProjectData {
2020
private $projectHelper: IProjectHelper,
2121
private $staticConfig: IStaticConfig,
2222
private $options: IOptions) {
23-
this.initializeProjectData().wait();
23+
this.initializeProjectData();
2424
}
2525

26-
private initializeProjectData(): IFuture<void> {
27-
return (() => {
28-
let projectDir = this.$projectHelper.projectDir;
29-
// If no project found, projectDir should be null
30-
if (projectDir) {
31-
this.initializeProjectDataCore(projectDir);
32-
let data: any = null;
26+
private initializeProjectData(): void {
27+
let projectDir = this.$projectHelper.projectDir;
28+
// If no project found, projectDir should be null
29+
if (projectDir) {
30+
this.initializeProjectDataCore(projectDir);
31+
let data: any = null;
3332

34-
if (this.$fs.exists(this.projectFilePath)) {
35-
let fileContent: any = null;
36-
try {
37-
fileContent = this.$fs.readJson(this.projectFilePath);
38-
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
39-
} catch (err) {
40-
this.$errors.fail({
41-
formatStr: "The project file %s is corrupted." + EOL +
42-
"Consider restoring an earlier version from your source control or backup." + EOL +
43-
"Additional technical info: %s",
44-
suppressCommandHelp: true
45-
},
46-
this.projectFilePath, err.toString());
47-
}
33+
if (this.$fs.exists(this.projectFilePath)) {
34+
let fileContent: any = null;
35+
try {
36+
fileContent = this.$fs.readJson(this.projectFilePath);
37+
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
38+
} catch (err) {
39+
this.$errors.fail({
40+
formatStr: "The project file %s is corrupted." + EOL +
41+
"Consider restoring an earlier version from your source control or backup." + EOL +
42+
"Additional technical info: %s",
43+
suppressCommandHelp: true
44+
},
45+
this.projectFilePath, err.toString());
46+
}
4847

49-
if (data) {
50-
this.projectId = data.id;
51-
this.dependencies = fileContent.dependencies;
52-
} else { // This is the case when we have package.json file but nativescipt key is not presented in it
53-
this.tryToUpgradeProject().wait();
54-
}
48+
if (data) {
49+
this.projectId = data.id;
50+
this.dependencies = fileContent.dependencies;
51+
} else { // This is the case when we have package.json file but nativescipt key is not presented in it
52+
this.tryToUpgradeProject();
5553
}
56-
} else { // This is the case when no project file found
57-
this.tryToUpgradeProject().wait();
5854
}
59-
}).future<void>()();
55+
} else { // This is the case when no project file found
56+
this.tryToUpgradeProject();
57+
}
6058
}
6159

6260
private throwNoProjectFoundError(): void {
6361
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", this.$options.path || path.resolve("."));
6462
}
6563

66-
private tryToUpgradeProject(): IFuture<void> {
67-
return (() => {
68-
let projectDir = this.projectDir || path.resolve(this.$options.path || ".");
69-
let oldProjectFilePath = path.join(projectDir, ProjectData.OLD_PROJECT_FILE_NAME);
70-
if (this.$fs.exists(oldProjectFilePath)) {
71-
this.upgrade(projectDir, oldProjectFilePath).wait();
72-
} else {
73-
this.throwNoProjectFoundError();
74-
}
75-
}).future<void>()();
64+
private tryToUpgradeProject(): void {
65+
let projectDir = this.projectDir || path.resolve(this.$options.path || ".");
66+
let oldProjectFilePath = path.join(projectDir, ProjectData.OLD_PROJECT_FILE_NAME);
67+
if (this.$fs.exists(oldProjectFilePath)) {
68+
this.upgrade(projectDir, oldProjectFilePath);
69+
} else {
70+
this.throwNoProjectFoundError();
71+
}
7672
}
7773

78-
private upgrade(projectDir: string, oldProjectFilePath: string): IFuture<void> {
79-
return (() => {
80-
try {
81-
let oldProjectData = this.$fs.readJson(oldProjectFilePath);
74+
private upgrade(projectDir: string, oldProjectFilePath: string): void {
75+
try {
76+
let oldProjectData = this.$fs.readJson(oldProjectFilePath);
8277

83-
let newProjectFilePath = this.projectFilePath || path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
84-
let newProjectData = this.$fs.exists(newProjectFilePath) ? this.$fs.readJson(newProjectFilePath) : {};
85-
newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] = oldProjectData;
86-
this.$fs.writeJson(newProjectFilePath, newProjectData).wait();
87-
this.projectId = newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE].id;
78+
let newProjectFilePath = this.projectFilePath || path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
79+
let newProjectData = this.$fs.exists(newProjectFilePath) ? this.$fs.readJson(newProjectFilePath) : {};
80+
newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE] = oldProjectData;
81+
this.$fs.writeJson(newProjectFilePath, newProjectData);
82+
this.projectId = newProjectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE].id;
8883

89-
this.$fs.deleteFile(oldProjectFilePath);
90-
} catch (err) {
91-
this.$logger.out("An error occurred while upgrading your project.");
92-
throw err;
93-
}
84+
this.$fs.deleteFile(oldProjectFilePath);
85+
} catch (err) {
86+
this.$logger.out("An error occurred while upgrading your project.");
87+
throw err;
88+
}
9489

95-
this.initializeProjectDataCore(projectDir);
90+
this.initializeProjectDataCore(projectDir);
9691

97-
this.$logger.out("Successfully upgraded your project file.");
98-
}).future<void>()();
92+
this.$logger.out("Successfully upgraded your project file.");
9993
}
10094

10195
private initializeProjectDataCore(projectDir: string): void {

lib/providers/project-files-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase {
2828
if (parsedFilePath.indexOf(platformSpecificAppResourcesDirectoryPath) > -1) {
2929
let appResourcesRelativePath = path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME,
3030
platformData.normalizedPlatformName), parsedFilePath);
31-
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait(), appResourcesRelativePath);
31+
mappedFilePath = path.join(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath(), appResourcesRelativePath);
3232
}
3333

3434
return mappedFilePath;

0 commit comments

Comments
 (0)