Skip to content

Commit a5360b1

Browse files
author
Dimitar Kerezov
committed
Rebase onto master
1 parent a409ffd commit a5360b1

10 files changed

+31
-32
lines changed

lib/commands/platform-clean.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class CleanCommand implements ICommand {
99
}
1010

1111
public async execute(args: string[]): Promise<void> {
12-
this.$platformService.removePlatforms(args, this.$projectData);
12+
await this.$platformService.removePlatforms(args, this.$projectData);
1313
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
1414
}
1515

lib/commands/remove-platform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class RemovePlatformCommand implements ICommand {
77
this.$projectData.initializeProjectData();
88
}
99

10-
public async execute(args: string[]): Promise<void> {
11-
this.$platformService.removePlatforms(args, this.$projectData);
10+
public execute(args: string[]): Promise<void> {
11+
return this.$platformService.removePlatforms(args, this.$projectData);
1212
}
1313

1414
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class UpdateCommand implements ICommand {
7272
}
7373
}
7474

75-
this.$platformService.removePlatforms(platforms, this.$projectData);
75+
await this.$platformService.removePlatforms(platforms, this.$projectData);
7676
await this.$pluginsService.remove("tns-core-modules", this.$projectData);
7777
await this.$pluginsService.remove("tns-core-modules-widgets", this.$projectData);
7878

lib/common

lib/definitions/platform.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ interface IPlatformService extends NodeJS.EventEmitter {
2626
* Remove platforms from specified project (`<project dir>/platforms/<platform>` dir).
2727
* @param {string[]} platforms Platforms to be removed.
2828
* @param {IProjectData} projectData DTO with information about the project.
29-
* @returns {void}
29+
* @returns {Promise<void>}
3030
*/
31-
removePlatforms(platforms: string[], projectData: IProjectData): void;
31+
removePlatforms(platforms: string[], projectData: IProjectData): Promise<void>;
3232

3333
updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData): Promise<void>;
3434

lib/definitions/project.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ interface IProjectTemplatesService {
115115
prepareTemplate(templateName: string, projectDir: string): Promise<string>;
116116
}
117117

118-
interface Ceco extends NodeJS.EventEmitter {
119-
120-
}
121-
122118
interface IPlatformProjectServiceBase {
123119
getPluginPlatformsFolderPath(pluginData: IPluginData, platform: string): string;
124120
}
@@ -241,15 +237,19 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
241237
/**
242238
* Stops all running processes that might hold a lock on the filesystem.
243239
* Android: Gradle daemon processes are terminated.
240+
* @param {string} projectRoot The root directory of the native project.
244241
* @returns {void}
245242
*/
246-
stopServices(): Promise<ISpawnResult>;
243+
stopServices(projectRoot: string): Promise<ISpawnResult>;
247244

248245
/**
249246
* Removes build artifacts specific to the platform
247+
* @param {string} projectRoot The root directory of the native project.
248+
* @param {string[]} options Options that can be passed to clean command.
249+
* @param {IProjectData} projectData DTO with information about the project.
250250
* @returns {void}
251251
*/
252-
cleanProject(projectRoot: string, options: string[]): Promise<void>
252+
cleanProject(projectRoot: string, options: string[], projectData: IProjectData): Promise<void>
253253
}
254254

255255
interface IAndroidProjectPropertiesManager {

lib/services/android-project-service.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
257257
await this.spawn(gradleBin,
258258
buildOptions,
259259
{ stdio: buildConfig.buildOutputStdio || "inherit", cwd: this.getPlatformData(projectData).projectRoot },
260-
{ emitOptions: { shouldEmit: true, eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
260+
{ emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
261261
} else {
262262
this.$errors.failWithoutHelp("Cannot complete build because this project is ANT-based." + EOL +
263263
"Run `tns platform remove android && tns platform add android` to switch to Gradle and try again.");
@@ -407,8 +407,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
407407
}
408408
}
409409

410-
public async stopServices(): Promise<ISpawnResult> {
411-
let projectRoot = this.platformData.projectRoot;
410+
public stopServices(projectRoot: string): Promise<ISpawnResult> {
412411
let gradleBin = path.join(projectRoot, "gradlew");
413412
if (this.$hostInfo.isWindows) {
414413
gradleBin += ".bat";

lib/services/ios-project-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
326326
args,
327327
"exit",
328328
{ stdio: buildConfig.buildOutputStdio || "inherit", cwd: this.getPlatformData(projectData).projectRoot },
329-
{ emitOptions: { shouldEmit: true, eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
329+
{ emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
330330
// this.$logger.out("xcodebuild build succeded.");
331331

332332
await this.createIpa(projectRoot, projectData, buildConfig.buildOutputStdio);
@@ -413,7 +413,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
413413

414414
await this.$childProcess.spawnFromEvent("xcodebuild", args, "exit",
415415
{ stdio: buildOutputStdio || "inherit", cwd: this.getPlatformData(projectData).projectRoot },
416-
{ emitOptions: { shouldEmit: true, eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
416+
{ emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
417417
}
418418

419419
private async createIpa(projectRoot: string, projectData: IProjectData, buildOutputStdio?: string): Promise<void> {
@@ -430,7 +430,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
430430
// this.$logger.out("Packaging project...");
431431
await this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit",
432432
{ stdio: buildOutputStdio || "inherit", cwd: this.getPlatformData(projectData).projectRoot },
433-
{ emitOptions: { shouldEmit: true, eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
433+
{ emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME }, throwError: false });
434434
// this.$logger.out("Project package succeeded.");
435435
}
436436

@@ -647,7 +647,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
647647
}
648648

649649
public async stopServices(): Promise<ISpawnResult> {
650-
return Promise.resolve({stderr: "", stdout: "", exitCode: 0});
650+
return { stderr: "", stdout: "", exitCode: 0 };
651651
}
652652

653653
public async cleanProject(projectRoot: string, options: string[]): Promise<void> {

lib/services/platform-service.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
117117
let installedVersion = coreModuleData.version;
118118
let coreModuleName = coreModuleData.name;
119119

120-
let customTemplateOptions = await this.getPathToPlatformTemplate(platformTemplate, platformData.frameworkPackageName);
120+
let customTemplateOptions = await this.getPathToPlatformTemplate(platformTemplate, platformData.frameworkPackageName, projectData.projectDir);
121121
let pathToTemplate = customTemplateOptions && customTemplateOptions.pathToTemplate;
122122
await platformData.platformProjectService.createProject(path.resolve(frameworkDir), installedVersion, projectData, pathToTemplate);
123123
platformData.platformProjectService.ensureConfigurationFileInAppResources(projectData);
@@ -129,17 +129,17 @@ export class PlatformService extends EventEmitter implements IPlatformService {
129129
frameworkPackageNameData.template = customTemplateOptions.selectedTemplate;
130130
}
131131

132-
this.$projectDataService.setNSValue(this.$projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
132+
this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
133133

134134
return coreModuleName;
135135

136136
}
137137

138-
private async getPathToPlatformTemplate(selectedTemplate: string, frameworkPackageName: string): Promise<{ selectedTemplate: string, pathToTemplate: string }> {
138+
private async getPathToPlatformTemplate(selectedTemplate: string, frameworkPackageName: string, projectDir: string): Promise<{ selectedTemplate: string, pathToTemplate: string }> {
139139
if (!selectedTemplate) {
140140
// read data from package.json's nativescript key
141141
// check the nativescript.tns-<platform>.template value
142-
const nativescriptPlatformData = this.$projectDataService.getNSValue(this.$projectData.projectDir, frameworkPackageName);
142+
const nativescriptPlatformData = this.$projectDataService.getNSValue(projectDir, frameworkPackageName);
143143
selectedTemplate = nativescriptPlatformData && nativescriptPlatformData.template;
144144
}
145145

@@ -217,16 +217,16 @@ export class PlatformService extends EventEmitter implements IPlatformService {
217217
if (changesInfo.hasChanges) {
218218
// android build artifacts need to be cleaned up when switching from release to debug builds
219219
if (platform.toLowerCase() === "android") {
220-
let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform);
220+
let previousPrepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
221221
// clean up prepared plugins when not building for release
222-
if (previousPrepareInfo && previousPrepareInfo.release !== this.$options.release) {
223-
let platformData = this.$platformsData.getPlatformData(platform);
224-
await platformData.platformProjectService.cleanProject(platformData.projectRoot, []);
222+
if (previousPrepareInfo && previousPrepareInfo.release !== appFilesUpdaterOptions.release) {
223+
let platformData = this.$platformsData.getPlatformData(platform, projectData);
224+
await platformData.platformProjectService.cleanProject(platformData.projectRoot, [], projectData);
225225
}
226226
}
227227

228-
await this.preparePlatformCore(platform, changesInfo);
229-
this.$projectChangesService.savePrepareInfo(platform);
228+
await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, provision);
229+
this.$projectChangesService.savePrepareInfo(platform, projectData);
230230
} else {
231231
this.$logger.out("Skipping prepare.");
232232
}
@@ -586,7 +586,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
586586
this.validatePlatformInstalled(platform, projectData);
587587
let platformData = this.$platformsData.getPlatformData(platform, projectData);
588588

589-
await this.$platformsData.getPlatformData(platform).platformProjectService.stopServices();
589+
await platformData.platformProjectService.stopServices(platformData.projectRoot);
590590

591591
let platformDir = path.join(projectData.platformsDir, platform);
592592
this.$fs.deleteDirectory(platformDir);

test/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('Platform Service Tests', () => {
199199
await platformService.addPlatforms(["android"], "", projectData);
200200

201201
testInjector.resolve("fs").exists = () => true;
202-
platformService.removePlatforms(["android"], projectData);
202+
await platformService.removePlatforms(["android"], projectData);
203203
});
204204
});
205205

0 commit comments

Comments
 (0)