Skip to content

Commit 1765397

Browse files
rosen-vladimirovDimitar Kerezov
authored andcommitted
Update Public API interfaces
1 parent 19b7fca commit 1765397

File tree

5 files changed

+64
-11
lines changed

5 files changed

+64
-11
lines changed

lib/commands/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ export abstract class DebugPlatformCommand implements ICommand {
163163

164164
const liveSyncInfo: ILiveSyncInfo = {
165165
projectDir: this.$projectData.projectDir,
166-
shouldStartWatcher: this.$options.watch,
167-
syncAllFiles: this.$options.syncAllFiles
166+
skipWatcher: !this.$options.watch || this.$options.justlaunch,
167+
watchAllFiles: this.$options.syncAllFiles
168168
};
169169

170170
const debugLiveSyncService = this.$injector.resolve<ILiveSyncService>(DebugLiveSyncService, { debugService: this.debugService });

lib/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class RunCommandBase implements ICommand {
7676
// }
7777

7878
// TODO: Fix this call
79-
const liveSyncInfo: ILiveSyncInfo = { projectDir: this.$projectData.projectDir, shouldStartWatcher: this.$options.watch, syncAllFiles: this.$options.syncAllFiles };
79+
const liveSyncInfo: ILiveSyncInfo = { projectDir: this.$projectData.projectDir, skipWatcher: !this.$options.watch || this.$options.justlaunch, watchAllFiles: this.$options.syncAllFiles };
8080
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
8181
}
8282
}

lib/definitions/livesync.d.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,53 @@ interface ILiveSyncProcessInfo {
6262
isStopped: boolean;
6363
}
6464

65+
/**
66+
* Describes information for LiveSync on a device.
67+
*/
6568
interface ILiveSyncDeviceInfo {
69+
/**
70+
* Device identifier.
71+
*/
6672
identifier: string;
73+
74+
/**
75+
* Action that will rebuild the application. The action must return a Promise, which is resolved with at path to build artifact.
76+
* @returns {Promise<string>} Path to build artifact (.ipa, .apk or .zip).
77+
*/
6778
buildAction: () => Promise<string>;
79+
80+
/**
81+
* Path where the build result is located (directory containing .ipa, .apk or .zip).
82+
* This is required for initial checks where LiveSync will skip the rebuild in case there's already a build result and no change requiring rebuild is made since then.
83+
* In case it is not passed, the default output for local builds will be used.
84+
*/
6885
outputPath?: string;
6986
}
7087

88+
/**
89+
* Describes a LiveSync operation.
90+
*/
7191
interface ILiveSyncInfo {
92+
/**
93+
* Directory of the project that will be synced.
94+
*/
7295
projectDir: string;
73-
shouldStartWatcher: boolean;
74-
syncAllFiles?: boolean;
96+
97+
/**
98+
* Defines if the watcher should be skipped. If not passed, fs.Watcher will be started.
99+
*/
100+
skipWatcher?: boolean;
101+
102+
/**
103+
* Defines if all project files should be watched for changes. In case it is not passed, only `app` dir of the project will be watched for changes.
104+
* In case it is set to true, the package.json of the project and node_modules directory will also be watched, so any change there will be transferred to device(s).
105+
*/
106+
watchAllFiles?: boolean;
107+
108+
/**
109+
* Defines if the liveEdit functionality should be used, i.e. LiveSync of .js files without restart.
110+
* NOTE: Currently this is available only for iOS.
111+
*/
75112
useLiveEdit?: boolean;
76113
}
77114

@@ -81,8 +118,23 @@ interface ILiveSyncBuildInfo {
81118
pathToBuildItem: string;
82119
}
83120

121+
/**
122+
* Describes LiveSync operations.
123+
*/
84124
interface ILiveSyncService {
125+
/**
126+
* Starts LiveSync operation by rebuilding the application if necessary and starting watcher.
127+
* @param {ILiveSyncDeviceInfo[]} deviceDescriptors Describes each device for which we would like to sync the application - identifier, outputPath and action to rebuild the app.
128+
* @param {ILiveSyncInfo} liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
129+
* @returns {Promise<void>}
130+
*/
85131
liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise<void>;
132+
133+
/**
134+
* Stops LiveSync operation for specified directory.
135+
* @param {string} projectDir The directory for which to stop the operation.
136+
* @returns {Promise<void>}
137+
*/
86138
stopLiveSync(projectDir: string): Promise<void>;
87139
}
88140

@@ -93,6 +145,7 @@ interface ILiveSyncWatchInfo {
93145
isRebuilt: boolean;
94146
syncAllFiles: boolean;
95147
useLiveEdit?: boolean;
148+
96149
}
97150

98151
interface ILiveSyncResultInfo {

lib/services/livesync/livesync-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
4848
// Should be set after prepare
4949
this.$injector.resolve<DeprecatedUsbLiveSyncService>("usbLiveSyncService").isInitialized = true;
5050

51-
if (liveSyncData.shouldStartWatcher) {
51+
if (!liveSyncData.skipWatcher) {
5252
await this.startWatcher(projectData, deviceDescriptors, liveSyncData);
5353
}
5454
}
@@ -138,7 +138,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
138138
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
139139
await this.ensureLatestAppPackageIsInstalledOnDevice(device, preparedPlatforms, rebuiltInformation, projectData, deviceDescriptor);
140140

141-
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ projectData, device, syncAllFiles: liveSyncData.syncAllFiles, useLiveEdit: liveSyncData.useLiveEdit });
141+
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({ projectData, device, syncAllFiles: liveSyncData.watchAllFiles, useLiveEdit: liveSyncData.useLiveEdit });
142142
await this.refreshApplication(projectData, liveSyncResultInfo);
143143
//await device.applicationManager.restartApplication(projectData.projectId, projectData.projectName);
144144
};
@@ -152,7 +152,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
152152

153153
let pattern = ["app"];
154154

155-
if (liveSyncData.syncAllFiles) {
155+
if (liveSyncData.watchAllFiles) {
156156
const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
157157
pattern.push("package.json");
158158

@@ -206,7 +206,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
206206
filesToRemove: currentFilesToRemove,
207207
filesToSync: currentFilesToSync,
208208
isRebuilt: !!_.find(rebuiltInformation, info => info.isEmulator === device.isEmulator && info.platform === device.deviceInfo.platform),
209-
syncAllFiles: liveSyncData.syncAllFiles,
209+
syncAllFiles: liveSyncData.watchAllFiles,
210210
useLiveEdit: liveSyncData.useLiveEdit
211211
};
212212

lib/services/test-execution-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TestExecutionService implements ITestExecutionService {
110110
});
111111

112112
// TODO: Fix this call
113-
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, shouldStartWatcher: this.$options.watch, syncAllFiles: this.$options.syncAllFiles };
113+
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, skipWatcher: !this.$options.watch || this.$options.justlaunch, watchAllFiles: this.$options.syncAllFiles };
114114
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
115115
// TODO: Fix
116116
// await this.$liveSyncService.liveSync(platform, projectData, null, this.$options);
@@ -219,7 +219,7 @@ class TestExecutionService implements ITestExecutionService {
219219
});
220220

221221
// TODO: Fix this call
222-
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, shouldStartWatcher: this.$options.watch, syncAllFiles: this.$options.syncAllFiles };
222+
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, skipWatcher: !this.$options.watch || this.$options.justlaunch, watchAllFiles: this.$options.syncAllFiles };
223223
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
224224
}
225225
};

0 commit comments

Comments
 (0)