Skip to content

Commit f11d405

Browse files
author
Dimitar Kerezov
committed
Expose saveBuildInfoFile
Expose * saveBuildInfoFile - method which should be used in cloud builds * livesyncService - which can be used to perform livesync with require-d tns
1 parent 4d6b990 commit f11d405

File tree

7 files changed

+53
-21
lines changed

7 files changed

+53
-21
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $injector.require("devicePathProvider", "./device-path-provider");
104104

105105
$injector.requireCommand("platform|clean", "./commands/platform-clean");
106106

107-
$injector.require("liveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
107+
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
108108
$injector.require("debugLiveSyncService", "./services/livesync/debug-livesync-service");
109109
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
110110
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");

lib/common

lib/definitions/platform.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ interface IPlatformService extends NodeJS.EventEmitter {
195195
* @returns {Promise<void>}
196196
*/
197197
trackActionForPlatform(actionData: ITrackPlatformAction): Promise<void>;
198+
199+
/**
200+
* Saves build information in a proprietary file.
201+
* @param {string} platform The build platform.
202+
* @param {string} projectDir The project's directory.
203+
* @param {string} buildInfoFileDirname The directory where the build file should be written to.
204+
* @returns {void}
205+
*/
206+
saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void
198207
}
199208

200209
interface IAddPlatformCoreOptions extends IPlatformSpecificData, ICreateProjectOptions { }

lib/services/livesync/livesync-service.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from "path";
22
import * as choki from "chokidar";
33
import { EventEmitter } from "events";
4-
import { exported } from "../../common/decorators";
54
import { hook } from "../../common/helpers";
5+
import { FileExtensions } from "../../common/constants";
66

77
const LiveSyncEvents = {
88
liveSyncStopped: "liveSyncStopped",
@@ -30,8 +30,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
3030
super();
3131
}
3232

33-
// TODO: Add finishLivesync method in the platform specific services
34-
@exported("liveSyncService")
3533
@hook("liveSync")
3634
public async liveSync(deviceDescriptors: ILiveSyncDeviceInfo[],
3735
liveSyncData: ILiveSyncInfo): Promise<void> {
@@ -54,7 +52,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
5452
}
5553
}
5654

57-
@exported("liveSyncService")
5855
public async stopLiveSync(projectDir: string, deviceIdentifiers?: string[], ): Promise<void> {
5956
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectDir];
6057

@@ -91,7 +88,12 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
9188

9289
// Kill typescript watcher
9390
// TODO: Pass the projectDir in hooks args.
94-
await this.$hooksService.executeAfterHooks('watch');
91+
const projectData = this.$projectDataService.getProjectData(projectDir);
92+
await this.$hooksService.executeAfterHooks('watch', {
93+
hookArgs: {
94+
projectData
95+
}
96+
});
9597

9698
this.emit(LiveSyncEvents.liveSyncStopped, { projectDir });
9799
}
@@ -155,7 +157,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
155157
if (preparedPlatforms.indexOf(platform) === -1) {
156158
preparedPlatforms.push(platform);
157159
// TODO: fix args cast to any
158-
await this.$platformService.preparePlatform(platform, <any>{}, null, projectData, <any>{}, modifiedFiles);
160+
await this.$platformService.preparePlatform(platform, {
161+
bundle: false,
162+
release: false,
163+
}, null, projectData, <any>{}, modifiedFiles);
159164
}
160165

161166
const rebuildInfo = _.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === platform);
@@ -169,18 +174,16 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
169174

170175
// TODO: fix args cast to any
171176
const shouldBuild = await this.$platformService.shouldBuild(platform, projectData, <any>{ buildForDevice: !device.isEmulator }, deviceBuildInfoDescriptor.outputPath);
177+
let pathToBuildItem = null;
172178
if (shouldBuild) {
173-
const pathToBuildItem = await deviceBuildInfoDescriptor.buildAction();
179+
pathToBuildItem = await deviceBuildInfoDescriptor.buildAction();
174180
// Is it possible to return shouldBuild for two devices? What about android device and android emulator?
175181
rebuiltInformation.push({ isEmulator: device.isEmulator, platform, pathToBuildItem });
176-
await this.$platformService.installApplication(device, { release: false }, projectData, pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
177-
178182
}
179183

180184
const shouldInstall = await this.$platformService.shouldInstall(device, projectData, deviceBuildInfoDescriptor.outputPath);
181185
if (shouldInstall) {
182-
183-
await this.$platformService.installApplication(device, { release: false }, projectData, null, deviceBuildInfoDescriptor.outputPath);
186+
await this.$platformService.installApplication(device, { release: false }, projectData, pathToBuildItem, deviceBuildInfoDescriptor.outputPath);
184187
}
185188
}
186189

@@ -319,7 +322,11 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
319322
this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer;
320323
};
321324

322-
await this.$hooksService.executeBeforeHooks('watch');
325+
await this.$hooksService.executeBeforeHooks('watch', {
326+
hookArgs: {
327+
projectData
328+
}
329+
});
323330

324331
const watcherOptions: choki.WatchOptions = {
325332
ignoreInitial: true,
@@ -345,7 +352,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
345352
filesToRemove.push(filePath);
346353
}
347354

348-
startTimeout();
355+
// Do not sync typescript files directly - wait for javascript changes to occur in order to restart the app only once
356+
if (path.extname(filePath) !== FileExtensions.TYPESCRIPT_FILE) {
357+
startTimeout();
358+
}
349359
});
350360

351361
this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo = { watcher, pattern };

lib/services/platform-service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,23 +438,31 @@ export class PlatformService extends EventEmitter implements IPlatformService {
438438

439439
await attachAwaitDetach(constants.BUILD_OUTPUT_EVENT_NAME, platformData.platformProjectService, handler, platformData.platformProjectService.buildProject(platformData.projectRoot, projectData, buildConfig));
440440

441-
let prepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData);
442-
let buildInfoFilePath = this.getBuildOutputPath(platform, platformData, buildConfig);
443-
let buildInfoFile = path.join(buildInfoFilePath, buildInfoFileName);
444-
let buildInfo: IBuildInfo = {
441+
const buildInfoFilePath = this.getBuildOutputPath(platform, platformData, buildConfig);
442+
this.saveBuildInfoFile(platform, projectData.projectDir, buildInfoFilePath);
443+
444+
this.$logger.out("Project successfully built.");
445+
}
446+
447+
public saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void {
448+
let buildInfoFile = path.join(buildInfoFileDirname, buildInfoFileName);
449+
450+
let prepareInfo = this.$projectChangesService.getPrepareInfo(platform, this.$projectDataService.getProjectData(projectDir));
451+
let buildInfo = {
445452
prepareTime: prepareInfo.changesRequireBuildTime,
446453
buildTime: new Date().toString()
447454
};
455+
448456
this.$fs.writeJson(buildInfoFile, buildInfo);
449-
this.$logger.out("Project successfully built.");
450457
}
451458

452459
public async shouldInstall(device: Mobile.IDevice, projectData: IProjectData, outputPath?: string): Promise<boolean> {
453460
let platform = device.deviceInfo.platform;
454-
let platformData = this.$platformsData.getPlatformData(platform, projectData);
455461
if (!(await device.applicationManager.isApplicationInstalled(projectData.projectId))) {
456462
return true;
457463
}
464+
465+
let platformData = this.$platformsData.getPlatformData(platform, projectData);
458466
let deviceBuildInfo: IBuildInfo = await this.getDeviceBuildInfo(device, projectData);
459467
let localBuildInfo = this.getBuildInfo(platform, platformData, { buildForDevice: !device.isEmulator }, outputPath);
460468
return !localBuildInfo || !deviceBuildInfo || deviceBuildInfo.buildTime !== localBuildInfo.buildTime;

test/nativescript-cli-lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe("nativescript-cli-lib", () => {
2020
deviceLogProvider: null,
2121
npm: ["install", "uninstall", "view", "search"],
2222
extensibilityService: ["loadExtensions", "loadExtension", "getInstalledExtensions", "installExtension", "uninstallExtension"],
23+
liveSyncService: ["liveSync", "stopLiveSync"],
2324
analyticsService: ["startEqatecMonitor"],
2425
debugService: ["debug"]
2526
};

test/stubs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
623623
return [];
624624
}
625625

626+
public saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void {
627+
return;
628+
}
629+
626630
public async removePlatforms(platforms: string[]): Promise<void> {
627631

628632
}

0 commit comments

Comments
 (0)