-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlivesync.d.ts
604 lines (530 loc) · 21.4 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
602
603
604
// This interface is a mashup of NodeJS' along with Chokidar's event watchers
interface IFSWatcher extends NodeJS.EventEmitter {
// from fs.FSWatcher
close(): void;
/**
* events.EventEmitter
* 1. change
* 2. error
*/
addListener(event: string, listener: Function): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (code: number, signal: string) => void): this;
on(event: string, listener: Function): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (code: number, signal: string) => void): this;
once(event: string, listener: Function): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (code: number, signal: string) => void): this;
prependListener(event: string, listener: Function): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (code: number, signal: string) => void): this;
prependOnceListener(event: string, listener: Function): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this;
// From chokidar FSWatcher
/**
* Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
* string.
*/
add(paths: string | string[]): void;
/**
* Stop watching files, directories, or glob patterns. Takes an array of strings or just one
* string.
*/
unwatch(paths: string | string[]): void;
/**
* Returns an object representing all the paths on the file system being watched by this
* `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
* the `cwd` option was used), and the values are arrays of the names of the items contained in
* each directory.
*/
getWatched(): IDictionary<string[]>;
/**
* Removes all listeners from watched files.
*/
close(): void;
}
interface ILiveSyncProcessInfo {
timer: NodeJS.Timer;
watcherInfo: {
watcher: IFSWatcher,
patterns: string[]
};
actionsChain: Promise<any>;
isStopped: boolean;
deviceDescriptors: ILiveSyncDeviceInfo[];
currentSyncAction: Promise<any>;
syncToPreviewApp: boolean;
}
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 ILiveSyncDeviceInfo extends IOptionalOutputPath, 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
*/
debugggingEnabled?: boolean;
/**
* Describes options specific for each platform, like provision for iOS, target sdk for Android, etc.
*/
platformSpecificOptions?: IPlatformOptions;
}
interface IOptionalSkipWatcher {
/**
* Defines if the watcher should be skipped. If not passed, fs.Watcher will be started.
*/
skipWatcher?: boolean;
}
/**
* Describes a LiveSync operation.
*/
interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOptionalSkipWatcher, IHasUseHotModuleReloadOption, IHasSyncToPreviewAppOption {
/**
* 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.
* 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).
*/
watchAllFiles?: 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;
}
interface IHasSyncToPreviewAppOption {
/**
* Defines if the livesync should be executed in preview app on device.
*/
syncToPreviewApp?: boolean;
}
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
}
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
interface IIsEmulator {
isEmulator: boolean;
}
interface ILiveSyncBuildInfo extends IIsEmulator, IPlatform {
pathToBuildItem: string;
}
interface IProjectDataComposition {
projectData: IProjectData;
}
/**
* Desribes object that can be passed to ensureLatestAppPackageIsInstalledOnDevice method.
*/
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions extends IProjectDataComposition, IEnvOptions, IBundle, IRelease, ISkipNativeCheckOptional, IOptionalFilesToRemove, IOptionalFilesToSync {
device: Mobile.IDevice;
preparedPlatforms: string[];
rebuiltInformation: ILiveSyncBuildInfo[];
deviceBuildInfoDescriptor: ILiveSyncDeviceInfo;
settings: ILatestAppPackageInstalledSettings;
liveSyncData?: ILiveSyncInfo;
modifiedFiles?: string[];
}
/**
* Describes the action that has been executed during ensureLatestAppPackageIsInstalledOnDevice execution.
*/
interface IAppInstalledOnDeviceResult {
/**
* Defines if the app has been installed on device from the ensureLatestAppPackageIsInstalledOnDevice method.
*/
appInstalled: boolean;
}
/**
* Describes LiveSync operations.
*/
interface ILiveSyncService {
/**
* Starts LiveSync operation by rebuilding the application if necessary and starting watcher.
* @param {ILiveSyncDeviceInfo[]} 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: ILiveSyncDeviceInfo[], 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 {ILiveSyncDeviceInfo[]} Array of elements describing parameters used to start LiveSync on each device.
*/
getLiveSyncDeviceDescriptors(projectDir: string): ILiveSyncDeviceInfo[];
}
/**
* Describes LiveSync operations while debuggging.
*/
interface IDebugLiveSyncService extends ILiveSyncService {
/**
* Method used to retrieve the glob patterns which CLI will watch for file changes. Defaults to the whole app directory.
* @param {ILiveSyncInfo} liveSyncData Information needed for livesync - for example if bundle is passed or if a release build should be performed.
* @param {IProjectData} projectData Project data.
* @param {string[]} platforms Platforms to start the watcher for.
* @returns {Promise<string[]>} The glob patterns.
*/
getWatcherPatterns(liveSyncData: ILiveSyncInfo, projectData: IProjectData, platforms: string[]): Promise<string[]>;
/**
* Prints debug information.
* @param {IDebugInformation} debugInformation Information to be printed.
* @returns {IDebugInformation} Full url and port where the frontend client can be connected.
*/
printDebugInformation(debugInformation: IDebugInformation): IDebugInformation;
/**
* Enables debugging for the specified devices
* @param {IEnableDebuggingDeviceOptions[]} deviceOpts Settings used for enabling debugging for each device.
* @param {IDebuggingAdditionalOptions} enableDebuggingOptions Settings used for enabling debugging.
* @returns {Promise<IDebugInformation>[]} Array of promises for each device.
*/
enableDebugging(deviceOpts: IEnableDebuggingDeviceOptions[], enableDebuggingOptions: IDebuggingAdditionalOptions): Promise<IDebugInformation>[];
/**
* Disables debugging for the specified devices
* @param {IDisableDebuggingDeviceOptions[]} deviceOptions Settings used for disabling debugging for each device.
* @param {IDebuggingAdditionalOptions} debuggingAdditionalOptions Settings used for disabling debugging.
* @returns {Promise<void>[]} Array of promises for each device.
*/
disableDebugging(deviceOptions: IDisableDebuggingDeviceOptions[], debuggingAdditionalOptions: IDebuggingAdditionalOptions): Promise<void>[];
/**
* Attaches a debugger to the specified device.
* @param {IAttachDebuggerOptions} settings Settings used for controling the attaching process.
* @returns {Promise<IDebugInformation>} Full url and port where the frontend client can be connected.
*/
attachDebugger(settings: IAttachDebuggerOptions): Promise<IDebugInformation>;
}
/**
* Describes additional debugging settings.
*/
interface IDebuggingAdditionalOptions extends IProjectDir { }
/**
* 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;
}
/**
* Describes settings used when enabling debugging.
*/
interface IEnableDebuggingDeviceOptions extends Mobile.IDeviceIdentifier, IOptionalDebuggingOptions { }
/**
* Describes settings passed to livesync service in order to control event emitting during refresh application.
*/
interface IShouldSkipEmitLiveSyncNotification {
/**
* Whether to skip emitting an event during refresh. Default is false.
*/
shouldSkipEmitLiveSyncNotification: boolean;
}
/**
* Describes settings used for attaching a debugger.
*/
interface IAttachDebuggerOptions extends IDebuggingAdditionalOptions, IEnableDebuggingDeviceOptions, IIsEmulator, IPlatform, IOptionalOutputPath {
}
interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleReloadOption {
filesToRemove: string[];
filesToSync: string[];
isReinstalled: boolean;
syncAllFiles: boolean;
liveSyncDeviceInfo: ILiveSyncDeviceInfo;
force?: boolean;
}
interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption {
modifiedFilesData: Mobile.ILocalToDevicePathData[];
isFullSync: boolean;
deviceAppData: Mobile.IDeviceAppData;
}
interface IAndroidLiveSyncResultInfo extends ILiveSyncResultInfo, IAndroidLivesyncSyncOperationResult { }
interface IFullSyncInfo extends IProjectDataComposition, IHasUseHotModuleReloadOption {
device: Mobile.IDevice;
watch: boolean;
syncAllFiles: boolean;
liveSyncDeviceInfo: ILiveSyncDeviceInfo;
force?: boolean;
}
interface ITransferFilesOptions {
isFullSync: boolean;
force?: boolean;
}
interface IPlatformLiveSyncService {
fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo>;
liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo>;
refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
prepareForLiveSync(device: Mobile.IDevice, data: IProjectDir, liveSyncInfo: ILiveSyncInfo, debugOptions: IDebugOptions): Promise<void>;
getDeviceLiveSyncService(device: Mobile.IDevice, projectData: IProjectData): INativeScriptDeviceLiveSyncService;
}
interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase {
/**
* Refreshes the application's content on a device
* @param {Mobile.IDeviceAppData} deviceAppData Information about the application and the device.
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
* @param {boolean} forceExecuteFullSync If this is passed a full LiveSync is performed instead of an incremental one.
* @param {IProjectData} projectData Project data.
* @return {Promise<void>}
*/
refreshApplication(projectData: IProjectData,
liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
/**
* 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, liveSyncDeviceInfo: ILiveSyncDeviceInfo, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]>;
}
interface IAndroidNativeScriptDeviceLiveSyncService extends INativeScriptDeviceLiveSyncService {
/**
* Retrieves the android device's hash service.
* @param {string} appIdentifier Application identifier.
* @return {Promise<Mobile.IAndroidDeviceHashService>} The hash service
*/
getDeviceHashService(appIdentifier: string): Mobile.IAndroidDeviceHashService;
/**
* 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 {
/**
* 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;
/**
* Time to wait for successful connection. Defaults to 30000 miliseconds.
*/
connectTimeout?: number;
}
interface IAndroidLivesyncSyncOperationResult {
operationId: string,
didRefresh: boolean
}
interface IDeviceProjectRootOptions {
appIdentifier: string;
getDirname?: boolean;
syncAllFiles?: 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, IHasSyncToPreviewAppOption {
/**
* 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>;
}