Skip to content

Commit 9373722

Browse files
Use sync version of fs.writeFile
1 parent 981d19c commit 9373722

19 files changed

+248
-252
lines changed

lib/commands/test-init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TestInitCommand implements ICommand {
5555
.join(', ')
5656
});
5757

58-
this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf).wait();
58+
this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf);
5959

6060
let exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}.js`);
6161

lib/definitions/plugins.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,34 @@ interface IPluginVariablesService {
4848
* @return {IFuture<void>}
4949
*/
5050
savePluginVariablesInProjectFile(pluginData: IPluginData): IFuture<void>;
51+
5152
/**
5253
* Removes plugin variables from project package.json file.
5354
* @param {string} pluginName Name of the plugin.
5455
* @return {IFuture<void>}
5556
*/
5657
removePluginVariablesFromProjectFile(pluginName: string): IFuture<void>;
58+
5759
/**
5860
* Replaces all plugin variables with their corresponding values.
5961
* @param {IPluginData} pluginData for the plugin.
6062
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
6163
* @return {IFuture<void>}
6264
*/
6365
interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string): IFuture<void>;
66+
6467
/**
6568
* Replaces {nativescript.id} expression with the application identifier from package.json.
6669
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
67-
* @return {IFuture<void>}
70+
* @return {void}
6871
*/
69-
interpolateAppIdentifier(pluginConfigurationFilePath: string): IFuture<void>;
72+
interpolateAppIdentifier(pluginConfigurationFilePath: string): void;
73+
7074
/**
7175
* Replaces both plugin variables and appIdentifier
7276
*/
7377
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string): IFuture<void>;
78+
7479
/**
7580
* Returns the
7681
* @param {string} pluginName for the plugin.

lib/definitions/project.d.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,22 @@ interface IPlatformProjectService {
8989
*/
9090
isPlatformPrepared(projectRoot: string): boolean;
9191

92-
canUpdatePlatform(newInstalledModuleDir: string): IFuture<boolean>;
92+
/**
93+
* Checks if current platform can be updated to a newer versions.
94+
* @param {string} newInstalledModuleDir Path to the native project.
95+
* @return {boolean} True if platform can be updated. false otherwise.
96+
*/
97+
canUpdatePlatform(newInstalledModuleDir: string): boolean;
98+
9399
preparePluginNativeCode(pluginData: IPluginData, options?: any): IFuture<void>;
94-
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
100+
101+
/**
102+
* Removes native code of a plugin (CocoaPods, jars, libs, src).
103+
* @param {IPluginData} Plugins data describing the plugin which should be cleaned.
104+
* @returns {void}
105+
*/
106+
removePluginNativeCode(pluginData: IPluginData): void;
107+
95108
afterPrepareAllPlugins(): IFuture<void>;
96109
beforePrepareAllPlugins(dependencies?: IDictionary<IDependencyData>): IFuture<void>;
97110
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
@@ -134,7 +147,7 @@ interface ICocoaPodsService {
134147
* Merges the content of hooks with the provided name if there are more than one hooks with this name in the Podfile.
135148
* @param {string} hookName The name of the hook.
136149
* @param {string} pathToPodfile The path to the Podfile.
137-
* @return {IFuture<void>}
150+
* @return {void}
138151
*/
139-
mergePodfileHookContent(sectionName: string, pathToPodfile: string): IFuture<void>
152+
mergePodfileHookContent(sectionName: string, pathToPodfile: string): void
140153
}

lib/services/android-project-service.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
225225
return null;
226226
}
227227

228-
public canUpdatePlatform(newInstalledModuleDir: string): IFuture<boolean> {
229-
return Future.fromResult(true);
228+
public canUpdatePlatform(newInstalledModuleDir: string): boolean {
229+
return true;
230230
}
231231

232232
public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, addPlatform?: Function, removePlatforms?: (platforms: string[]) => IFuture<void>): IFuture<boolean> {
@@ -372,20 +372,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
372372
}).future<void>()();
373373
}
374374

375-
// TODO: Remove IFuture, reason: fs.deleteDirectory - blocked as the other implementation of the interface has async operations.
376-
public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
377-
return (() => {
378-
try {
379-
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "configurations", pluginData.name));
380-
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "src", pluginData.name));
381-
} catch (e) {
382-
if (e.code === "ENOENT") {
383-
this.$logger.debug("No native code jars found: " + e.message);
384-
} else {
385-
throw e;
386-
}
375+
public removePluginNativeCode(pluginData: IPluginData): void {
376+
try {
377+
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "configurations", pluginData.name));
378+
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "src", pluginData.name));
379+
} catch (e) {
380+
if (e.code === "ENOENT") {
381+
this.$logger.debug("No native code jars found: " + e.message);
382+
} else {
383+
throw e;
387384
}
388-
}).future<void>()();
385+
}
389386
}
390387

391388
public afterPrepareAllPlugins(): IFuture<void> {

lib/services/cocoapods-service.ts

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,52 @@ export class CocoaPodsService implements ICocoaPodsService {
1616
return `${EOL}end`;
1717
}
1818

19-
public mergePodfileHookContent(hookName: string, pathToPodfile: string): IFuture<void> {
20-
return (() => {
21-
if (!this.$fs.exists(pathToPodfile)) {
22-
throw new Error(`The Podfile ${pathToPodfile} does not exist.`);
19+
public mergePodfileHookContent(hookName: string, pathToPodfile: string): void {
20+
if (!this.$fs.exists(pathToPodfile)) {
21+
throw new Error(`The Podfile ${pathToPodfile} does not exist.`);
22+
}
23+
24+
let podfileContent = this.$fs.readText(pathToPodfile);
25+
let hookStart = `${hookName} do`;
26+
27+
let hookDefinitionRegExp = new RegExp(`${hookStart} *(\\|(\\w+)\\|)?`, "g");
28+
let newFunctionNameIndex = 1;
29+
let newFunctions: IRubyFunction[] = [];
30+
31+
let replacedContent = podfileContent.replace(hookDefinitionRegExp, (substring: string, firstGroup: string, secondGroup: string, index: number): string => {
32+
let newFunctionName = `${hookName}${newFunctionNameIndex++}`;
33+
let newDefinition = `def ${newFunctionName}`;
34+
35+
let rubyFunction: IRubyFunction = { functionName: newFunctionName };
36+
// firstGroup is the block parameter, secondGroup is the block parameter name.
37+
if (firstGroup && secondGroup) {
38+
newDefinition = `${newDefinition} (${secondGroup})`;
39+
rubyFunction.functionParameters = secondGroup;
2340
}
2441

25-
let podfileContent = this.$fs.readText(pathToPodfile);
26-
let hookStart = `${hookName} do`;
42+
newFunctions.push(rubyFunction);
43+
return newDefinition;
44+
});
2745

28-
let hookDefinitionRegExp = new RegExp(`${hookStart} *(\\|(\\w+)\\|)?`, "g");
29-
let newFunctionNameIndex = 1;
30-
let newFunctions: IRubyFunction[] = [];
46+
if (newFunctions.length > 1) {
47+
// Execute all methods in the hook and pass the parameter to them.
48+
let blokParameterName = "installer";
49+
let mergedHookContent = `${hookStart} |${blokParameterName}|${EOL}`;
3150

32-
let replacedContent = podfileContent.replace(hookDefinitionRegExp, (substring: string, firstGroup: string, secondGroup: string, index: number): string => {
33-
let newFunctionName = `${hookName}${newFunctionNameIndex++}`;
34-
let newDefinition = `def ${newFunctionName}`;
35-
36-
let rubyFunction: IRubyFunction = { functionName: newFunctionName };
37-
// firstGroup is the block parameter, secondGroup is the block parameter name.
38-
if (firstGroup && secondGroup) {
39-
newDefinition = `${newDefinition} (${secondGroup})`;
40-
rubyFunction.functionParameters = secondGroup;
51+
_.each(newFunctions, (rubyFunction: IRubyFunction) => {
52+
let functionExecution = rubyFunction.functionName;
53+
if (rubyFunction.functionParameters && rubyFunction.functionParameters.length) {
54+
functionExecution = `${functionExecution} ${blokParameterName}`;
4155
}
4256

43-
newFunctions.push(rubyFunction);
44-
return newDefinition;
57+
mergedHookContent = `${mergedHookContent} ${functionExecution}${EOL}`;
4558
});
4659

47-
if (newFunctions.length > 1) {
48-
// Execute all methods in the hook and pass the parameter to them.
49-
let blokParameterName = "installer";
50-
let mergedHookContent = `${hookStart} |${blokParameterName}|${EOL}`;
51-
52-
_.each(newFunctions, (rubyFunction: IRubyFunction) => {
53-
let functionExecution = rubyFunction.functionName;
54-
if (rubyFunction.functionParameters && rubyFunction.functionParameters.length) {
55-
functionExecution = `${functionExecution} ${blokParameterName}`;
56-
}
57-
58-
mergedHookContent = `${mergedHookContent} ${functionExecution}${EOL}`;
59-
});
60+
mergedHookContent = `${mergedHookContent}end`;
6061

61-
mergedHookContent = `${mergedHookContent}end`;
62-
63-
let newPodfileContent = `${replacedContent}${EOL}${mergedHookContent}`;
64-
this.$fs.writeFile(pathToPodfile, newPodfileContent).wait();
65-
}
66-
}).future<void>()();
62+
let newPodfileContent = `${replacedContent}${EOL}${mergedHookContent}`;
63+
this.$fs.writeFile(pathToPodfile, newPodfileContent);
64+
}
6765
}
6866
}
6967

lib/services/doctor-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class DoctorService implements IDoctorService {
193193
this.$fs.writeFile(
194194
path.join(iosDir, "Podfile"),
195195
`${this.$cocoapodsService.getPodfileHeader(DoctorService.PROJECT_NAME_PLACEHOLDER)}pod 'AFNetworking', '~> 1.0'${this.$cocoapodsService.getPodfileFooter()}`
196-
).wait();
196+
);
197197

198198
spinner.message("Verifying CocoaPods. This may take some time, please be patient.");
199199
spinner.start();

0 commit comments

Comments
 (0)