You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.catch(err=>console.log(`Unable to start debug operation, reason: ${err.message}.`));
499
525
```
500
526
527
+
## liveSyncService
528
+
Used to LiveSync changes on devices. The operation can be started for multiple devices and stopped for each of them. During LiveSync operation, the service will emit different events based on the action that's executing.
529
+
530
+
### liveSync
531
+
Starts a LiveSync operation for specified devices. During the operation, application may have to be rebuilt (for example in case a change in App_Resources is detected).
532
+
By default the LiveSync operation will start file system watcher for `<project dir>/app` directory and any change in it will trigger a LiveSync operation.
533
+
After calling the method once, you can add new devices to the same LiveSync operation by calling the method again with the new device identifiers.
534
+
535
+
> NOTE: Consecutive calls to `liveSync` method for the same project will execute the initial sync (deploy and fullSync) only for new device identifiers. So in case the first call is for devices with ids [ 'A' , 'B' ] and the second one is for devices with ids [ 'B', 'C' ], the initial sync will be executed only for device with identifier 'C'.
536
+
537
+
> NOTE: In case a consecutive call to `liveSync` method requires change in the pattern for watching files (i.e. `liveSyncData.syncAllFiles` option has changed), current watch operation will be stopped and a new one will be started.
538
+
539
+
* Definition
540
+
```TypeScript
541
+
/**
542
+
* Starts LiveSync operation by rebuilding the application if necessary and starting watcher.
543
+
* @param{ILiveSyncDeviceInfo[]}deviceDescriptors Describes each device for which we would like to sync the application - identifier, outputPath and action to rebuild the app.
544
+
* @param{ILiveSyncInfo}liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
console.log("An error occurred during LiveSync", err);
581
+
});
582
+
```
583
+
584
+
### stopLiveSync
585
+
Stops LiveSync operation. In case deviceIdentifires are passed, the operation will be stopped only for these devices.
586
+
587
+
* Definition
588
+
```TypeScript
589
+
/**
590
+
* Stops LiveSync operation for specified directory.
591
+
* @param{string}projectDir The directory for which to stop the operation.
592
+
* @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.
console.log("An error occurred during stopage.", err);
607
+
});
608
+
```
609
+
610
+
### Events
611
+
`liveSyncService` raises several events in order to provide information for current state of the operation.
612
+
* liveSyncStarted - raised whenever CLI starts a LiveSync operation for specific device. When `liveSync` method is called, the initial LiveSync operation will emit `liveSyncStarted` for each specified device. After that the event will be emitted only in case when liveSync method is called again with different device instances. The event is raised with the following data:
console.log(`Started LiveSync on ${data.deviceIdentifier} for ${data.applicationIdentifier}.`);
625
+
});
626
+
```
627
+
628
+
* liveSyncExecuted - raised whenever CLI finishes a LiveSync operation for specific device. When `liveSync` method is called, the initial LiveSync operation will emit `liveSyncExecuted` for each specified device once it finishes the operation. After that the event will be emitted whenever a change is detected (in case file system watcher is started) and the LiveSync operation is executed for each device. The event is raised with the following data:
629
+
```TypeScript
630
+
{
631
+
projectDir: string;
632
+
deviceIdentifier: string;
633
+
applicationIdentifier: string;
634
+
/**
635
+
* Full paths to files synced during the operation. In case the `syncedFiles.length` is 0, the operation is "fullSync" (i.e. all project files are synced).
console.log(`Executed LiveSync on ${data.deviceIdentifier} for ${data.applicationIdentifier}. Uploaded files are: ${data.syncedFiles.join("")}.`);
645
+
});
646
+
```
647
+
648
+
* liveSyncStopped - raised when LiveSync operation is stopped. The event will be raised when the operation is stopped for each device and will be raised when the whole operation is stopped. The event is raised with the following data:
649
+
```TypeScript
650
+
{
651
+
projectDir: string;
652
+
/**
653
+
* Passed only when the LiveSync operation is stopped for a specific device. In case it is not passed, the whole LiveSync operation is stopped.
console.log(`Stopped LiveSync on ${data.deviceIdentifier} for ${data.projectDir}.`);
664
+
} else {
665
+
console.log(`Stopped LiveSync for ${data.projectDir}.`);
666
+
}
667
+
});
668
+
```
669
+
670
+
* liveSyncError - raised whenever an error is detected during LiveSync operation. The event is raised for specific device. Once an error is detected, the event will be raised and the LiveSync operation will be stopped for this device, i.e. `liveSyncStopped` event will be raised for it. The event is raised with the following data:
671
+
```TypeScript
672
+
{
673
+
projectDir: string;
674
+
deviceIdentifier: string;
675
+
applicationIdentifier: string;
676
+
error:Error;
677
+
}
678
+
```
679
+
680
+
Example:
681
+
```JavaScript
682
+
tns.liveSyncService.on("liveSyncError", data=> {
683
+
console.log(`Error detected during LiveSync on ${data.deviceIdentifier} for ${data.projectDir}. Error: ${data.error.message}.`);
684
+
});
685
+
```
686
+
687
+
* notify - raised when LiveSync operation has some data that is important for the user. The event is raised for specific device. The event is raised with the following data:
688
+
```TypeScript
689
+
{
690
+
projectDir: string;
691
+
deviceIdentifier: string;
692
+
applicationIdentifier: string;
693
+
notification: string;
694
+
}
695
+
```
696
+
697
+
Example:
698
+
```JavaScript
699
+
tns.liveSyncService.on("notify", data=> {
700
+
console.log(`Notification: ${data.notification} for LiveSync operation on ${data.deviceIdentifier} for ${data.projectDir}. `);
701
+
});
702
+
```
703
+
501
704
## How to add a new method to Public API
502
705
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
503
706
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.
$injector.require("usbLiveSyncService","./services/livesync/livesync-service");// The name is used in https://github.com/NativeScript/nativescript-dev-typescript
0 commit comments