-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync.d.ts
601 lines (538 loc) · 17.3 KB
/
livesync.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
import { EventEmitter } from "events";
import {
INativePrepare,
IValidatePlatformOutput,
IProjectData,
} from "./project";
import { IBuildPlatformAction } from "./platform";
import { IDebugOptions } from "./debug";
import { IBuildData } from "./build";
import { IEnvOptions } from "../declarations";
import {
IPlatform,
IProjectDir,
IRelease,
IQrCodeImageData,
IDictionary,
} from "../common/declarations";
declare global {
interface ILiveSyncProcessData {
timer: NodeJS.Timer;
actionsChain: Promise<any>;
isStopped: boolean;
deviceDescriptors: ILiveSyncDeviceDescriptor[];
currentSyncAction: Promise<any>;
platforms: string[];
}
interface IOptionalOutputPath {
/**
* Path where the build result is located (directory containing .ipa, .apk or .zip).
* 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.
* In case it is not passed, the default output for local builds will be used.
*/
outputPath?: string;
}
/**
* Describes action used whenever building a project.
*/
interface IBuildAction {
/**
* @returns {Promise<string>} Path to build artifact (.ipa, .apk or .zip).
*/
(): Promise<string>;
}
/**
* Describes options that can be passed in order to specify the exact location of the built package.
*/
interface IOutputDirectoryOptions extends IPlatform {
/**
* Directory where the project is located.
*/
projectDir: string;
/**
* Whether the build is for emulator or not.
*/
emulator?: boolean;
}
/**
* Describes information for LiveSync on a device.
*/
interface ILiveSyncDeviceDescriptor extends IOptionalDebuggingOptions {
/**
* Device identifier.
*/
identifier: string;
/**
* Action that will rebuild the application. The action must return a Promise, which is resolved with at path to build artifact.
*/
buildAction: IBuildAction;
/**
* Whether to skip preparing the native platform.
*/
skipNativePrepare?: boolean;
/**
* Whether debugging has been enabled for this device or not
*/
debuggingEnabled?: boolean;
/**
* Describes the data used for building the application
*/
buildData: IBuildData;
}
/**
* Describes a LiveSync operation.
*/
interface ILiveSyncInfo
extends IProjectDir,
IEnvOptions,
IRelease,
IHasUseHotModuleReloadOption {
emulator?: boolean;
/**
* Defines if the watcher should be skipped. If not passed, fs.Watcher will be started.
*/
skipWatcher?: boolean;
/**
* Forces a build before the initial livesync.
*/
clean?: boolean;
/**
* Defines if initial sync will be forced.
* In case it is true, transfers all project's directory on device
* In case it is false, transfers only changed files.
*/
force?: boolean;
/**
* Defines the timeout in seconds {N} CLI will wait to find the inspector socket port from device's logs.
* If not provided, defaults to 10seconds.
*/
timeout?: string;
nativePrepare?: INativePrepare;
}
interface IHasUseHotModuleReloadOption {
/**
* Defines if the hot module reload should be used.
*/
useHotModuleReload: boolean;
}
interface ILiveSyncEventData {
deviceIdentifier: string;
applicationIdentifier?: string;
projectDir: string;
syncedFiles?: string[];
error?: Error;
notification?: string;
isFullSync?: boolean;
keepProcessAlive?: boolean;
}
interface IIsEmulator {
isEmulator: boolean;
}
interface IProjectDataComposition {
projectData: IProjectData;
}
/**
* Describes LiveSync operations.
*/
interface ILiveSyncService extends EventEmitter {
/**
* Starts LiveSync operation by rebuilding the application if necessary and starting watcher.
* @param {ILiveSyncDeviceDescriptor[]} deviceDescriptors Describes each device for which we would like to sync the application - identifier, outputPath and action to rebuild the app.
* @param {ILiveSyncInfo} liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
* @returns {Promise<void>}
*/
liveSync(
deviceDescriptors: ILiveSyncDeviceDescriptor[],
liveSyncData: ILiveSyncInfo
): Promise<void>;
/**
* Stops LiveSync operation for specified directory.
* @param {string} projectDir The directory for which to stop the operation.
* @param {string[]} @optional deviceIdentifiers Device ids for which to stop the application. In case nothing is passed, LiveSync operation will be stopped for all devices.
* @param { shouldAwaitAllActions: boolean } @optional stopOptions Specifies whether we should await all actions.
* @returns {Promise<void>}
*/
stopLiveSync(
projectDir: string,
deviceIdentifiers?: string[],
stopOptions?: { shouldAwaitAllActions: boolean }
): Promise<void>;
/**
* Returns the device information for current LiveSync operation of specified project.
* In case LiveSync has been started on many devices, but stopped for some of them at a later point,
* calling the method after that will return information only for devices for which LiveSync operation is in progress.
* @param {string} projectDir The path to project for which the LiveSync operation is executed
* @returns {ILiveSyncDeviceDescriptor[]} Array of elements describing parameters used to start LiveSync on each device.
*/
getLiveSyncDeviceDescriptors(
projectDir: string
): ILiveSyncDeviceDescriptor[];
}
/**
* Describes settings used when disabling debugging.
*/
interface IDisableDebuggingDeviceOptions extends Mobile.IDeviceIdentifier {}
interface IOptionalDebuggingOptions {
/**
* Optional debug options - can be used to control the start of a debug process.
*/
debugOptions?: IDebugOptions;
}
interface IEnableDebuggingData
extends IProjectDir,
IOptionalDebuggingOptions {
deviceIdentifiers: string[];
}
interface IDisableDebuggingData extends IProjectDir {
deviceIdentifiers: string[];
}
interface IAttachDebuggerData
extends IProjectDir,
Mobile.IDeviceIdentifier,
IOptionalDebuggingOptions,
IIsEmulator,
IPlatform,
IOptionalOutputPath {}
/**
* Describes settings passed to livesync service in order to control event emitting during refresh application.
*/
interface IRefreshApplicationSettings {
shouldSkipEmitLiveSyncNotification: boolean;
shouldCheckDeveloperDiscImage: boolean;
}
interface IConnectTimeoutOption {
/**
* Time to wait for successful connection. Defaults to 30000 miliseconds.
*/
connectTimeout?: number;
}
interface ILiveSyncWatchInfo
extends IProjectDataComposition,
IHasUseHotModuleReloadOption,
IConnectTimeoutOption {
filesToRemove: string[];
filesToSync: string[];
liveSyncDeviceData: ILiveSyncDeviceDescriptor;
hmrData: IPlatformHmrData;
force?: boolean;
}
interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption {
modifiedFilesData: Mobile.ILocalToDevicePathData[];
isFullSync: boolean;
waitForDebugger?: boolean;
deviceAppData: Mobile.IDeviceAppData;
didRecover?: boolean;
forceRefreshWithSocket?: boolean;
}
interface IAndroidLiveSyncResultInfo
extends ILiveSyncResultInfo,
IAndroidLivesyncSyncOperationResult {}
interface IFullSyncInfo
extends IProjectDataComposition,
IHasUseHotModuleReloadOption,
IConnectTimeoutOption {
device: Mobile.IDevice;
watch: boolean;
liveSyncDeviceData: ILiveSyncDeviceDescriptor;
force?: boolean;
}
interface IPlatformHmrData {
hash: string;
fallbackFiles: string[];
}
interface ITransferFilesOptions {
isFullSync: boolean;
force?: boolean;
}
interface IPlatformLiveSyncService {
fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo>;
liveSyncWatchAction(
device: Mobile.IDevice,
liveSyncInfo: ILiveSyncWatchInfo
): Promise<ILiveSyncResultInfo>;
tryRefreshApplication(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<boolean>;
restartApplication(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<void>;
shouldRestart(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<boolean>;
getDeviceLiveSyncService(
device: Mobile.IDevice,
projectData: IProjectData
): INativeScriptDeviceLiveSyncService;
getAppData(syncInfo: IFullSyncInfo): Promise<Mobile.IDeviceAppData>;
syncAfterInstall(
device: Mobile.IDevice,
liveSyncInfo: ILiveSyncWatchInfo
): Promise<void>;
}
interface IRestartApplicationInfo {
didRestart: boolean;
}
interface INativeScriptDeviceLiveSyncService {
/**
* Specifies some action that will be executed before every sync operation
*/
beforeLiveSyncAction?(deviceAppData: Mobile.IDeviceAppData): Promise<void>;
/**
* Tries to refresh the application's content on the device
*/
tryRefreshApplication(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<boolean>;
/**
* Restarts the specified application
*/
restartApplication(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<void>;
/**
* Returns if the application have to be restarted in order to apply the specified livesync changes
*/
shouldRestart(
projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo
): Promise<boolean>;
/**
* Removes specified files from a connected device
* @param {Mobile.IDeviceAppData} deviceAppData Data about device and app.
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
* @param {string} projectFilesPath The Path to the app folder inside platforms folder
* @return {Promise<void>}
*/
removeFiles(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
projectFilesPath?: string
): Promise<void>;
/**
* Transfers specified files to a connected device
* @param {Mobile.IDeviceAppData} deviceAppData Data about device and app.
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
* @param {string} projectFilesPath The Path to the app folder inside platforms folder
* @param {boolean} isFullSync Indicates if the operation is part of a fullSync
* @return {Promise<Mobile.ILocalToDevicePathData[]>} Returns the ILocalToDevicePathData of all transfered files
*/
transferFiles(
deviceAppData: Mobile.IDeviceAppData,
localToDevicePaths: Mobile.ILocalToDevicePathData[],
projectFilesPath: string,
projectData: IProjectData,
liveSyncDeviceData: ILiveSyncDeviceDescriptor,
options: ITransferFilesOptions
): Promise<Mobile.ILocalToDevicePathData[]>;
}
interface IAndroidNativeScriptDeviceLiveSyncService
extends INativeScriptDeviceLiveSyncService {
/**
* Guarantees all remove/update operations have finished
* @param {ILiveSyncResultInfo} liveSyncInfo Describes the LiveSync operation - for which project directory is the operation and other settings.
* @return {Promise<IAndroidLiveSyncResultInfo>}
*/
finalizeSync(
liveSyncInfo: ILiveSyncResultInfo,
projectData: IProjectData
): Promise<IAndroidLivesyncSyncOperationResult>;
}
interface ILiveSyncSocket extends INetSocket {
uid: string;
writeAsync(data: Buffer): Promise<Boolean>;
}
interface IAndroidLivesyncTool {
/**
* The protocol version the current app(adnroid runtime) is using.
*/
protocolVersion: string;
/**
* Creates new socket connection.
* @param configuration - The configuration to the socket connection.
* @returns {Promise<void>}
*/
connect(configuration: IAndroidLivesyncToolConfiguration): Promise<void>;
/**
* Sends a file through the socket.
* @param filePath - The full path to the file.
* @returns {Promise<void>}
*/
sendFile(filePath: string): Promise<void>;
/**
* Sends files through the socket.
* @param filePaths - Array of files that will be send by the socket.
* @returns {Promise<void>}
*/
sendFiles(filePaths: string[]): Promise<void>;
/**
* Sends all files from directory by the socket.
* @param directoryPath - The path to the directory which files will be send by the socket.
* @returns {Promise<void>}
*/
sendDirectory(directoryPath: string): Promise<void>;
/**
* Removes file
* @param filePath - The full path to the file.
* @returns {Promise<boolean>}
*/
removeFile(filePath: string): Promise<void>;
/**
* Removes files
* @param filePaths - Array of files that will be removed.
* @returns {Promise<boolean[]>}
*/
removeFiles(filePaths: string[]): Promise<void>;
/**
* Sends doSyncOperation that will be handled by the runtime.
* @param options
* @returns {Promise<void>}
*/
sendDoSyncOperation(
options?: IDoSyncOperationOptions
): Promise<IAndroidLivesyncSyncOperationResult>;
/**
* Generates new operation identifier.
*/
generateOperationIdentifier(): string;
/**
* Checks if the current operation is in progress.
* @param operationId - The identifier of the operation.
*/
isOperationInProgress(operationId: string): boolean;
/**
* Closes the current socket connection.
* @param error - Optional error for rejecting pending sync operations
*/
end(error?: Error): void;
/**
* Returns true if a connection has been already established
*/
hasConnection(): boolean;
}
/**
* doRefresh - Indicates if the application should be refreshed. Defaults to true.
* operationId - The identifier of the operation
* timeout - The timeout in milliseconds
*/
interface IDoSyncOperationOptions {
doRefresh?: boolean;
timeout?: number;
operationId?: string;
}
interface IAndroidLivesyncToolConfiguration extends IConnectTimeoutOption {
/**
* The application identifier.
*/
appIdentifier: string;
/**
* The device identifier.
*/
deviceIdentifier: string;
/**
* The path to app folder inside platforms folder: platforms/android/app/src/main/assets/app/
*/
appPlatformsPath: string;
/**
* If not provided, defaults to 127.0.0.1
*/
localHostAddress?: string;
/**
* If provider will call it when an error occurs.
*/
errorHandler?: any;
}
interface IAndroidLivesyncSyncOperationResult {
operationId: string;
didRefresh: boolean;
}
interface IDeviceProjectRootOptions {
appIdentifier: string;
getDirname?: boolean;
watch?: boolean;
}
interface IDevicePathProvider {
getDeviceProjectRootPath(
device: Mobile.IDevice,
options: IDeviceProjectRootOptions
): Promise<string>;
getDeviceSyncZipPath(device: Mobile.IDevice): string;
}
/**
* Describes additional options, that can be passed to LiveSyncCommandHelper.
*/
interface ILiveSyncCommandHelperAdditionalOptions
extends IBuildPlatformAction,
INativePrepare {
/**
* A map representing devices which have debugging enabled initially.
*/
deviceDebugMap?: IDictionary<boolean>;
/**
* Returns the path to the directory where the build output may be found.
* @param {IOutputDirectoryOptions} options Options that are used to determine the build output directory.
* @returns {string} The build output directory.
*/
getOutputDirectory?(options: IOutputDirectoryOptions): string;
}
interface ILiveSyncCommandHelper {
/**
* Method sets up configuration, before calling livesync and expects that devices are already discovered.
* @param {Mobile.IDevice[]} devices List of discovered devices
* @param {string} platform The platform for which the livesync will be ran
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
* @returns {Promise<void>}
*/
executeLiveSyncOperation(
devices: Mobile.IDevice[],
platform: string,
additionalOptions?: ILiveSyncCommandHelperAdditionalOptions
): Promise<void>;
getPlatformsForOperation(platform: string): string[];
/**
* Validates the given platform's data - bundle identifier, etc.
* @param {string} platform The platform to be validated.
* @return {Promise<void>}
*/
validatePlatform(
platform: string
): Promise<IDictionary<IValidatePlatformOutput>>;
/**
* Executes livesync operation. Meant to be called from within a command.
* @param {string} platform @optional platform for whith to run the livesync operation
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
* @returns {Promise<void>}
*/
executeCommandLiveSync(
platform?: string,
additionalOptions?: ILiveSyncCommandHelperAdditionalOptions
): Promise<void>;
createDeviceDescriptors(
devices: Mobile.IDevice[],
platform: string,
additionalOptions?: ILiveSyncCommandHelperAdditionalOptions
): Promise<ILiveSyncDeviceDescriptor[]>;
getDeviceInstances(platform?: string): Promise<Mobile.IDevice[]>;
getLiveSyncData(projectDir: string): ILiveSyncInfo;
stop(): Promise<void>;
}
interface ILiveSyncServiceResolver {
resolveLiveSyncService(platform: string): IPlatformLiveSyncService;
}
interface ILiveSyncProcessDataService {
getPersistedData(projectDir: string): ILiveSyncProcessData;
getDeviceDescriptors(projectDir: string): ILiveSyncDeviceDescriptor[];
getAllPersistedData(): IDictionary<ILiveSyncProcessData>;
persistData(
projectDir: string,
deviceDescriptors: ILiveSyncDeviceDescriptor[],
platforms: string[]
): void;
hasDeviceDescriptors(projectDir: string): boolean;
getPlatforms(projectDir: string): string[];
}
}