Skip to content

Commit

Permalink
Fixed: Changes in package.json are not livesynced
Browse files Browse the repository at this point in the history
Implemented pt redictable livesync

Implement run command to use livesync

project changes info as a service
  • Loading branch information
Tsvetan Raikov committed Jan 9, 2017
1 parent 3effe5f commit 40d525c
Show file tree
Hide file tree
Showing 31 changed files with 841 additions and 548 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}/scratch",
"cwd": "${workspaceRoot}",
"sourceMaps": true,
"name": "Launch CLI (Node 6+)",
"program": "${workspaceRoot}/lib/nativescript-cli.js",
Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ $injector.requireCommand("platform|clean", "./commands/platform-clean");

$injector.requireCommand("livesync", "./commands/livesync");
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
$injector.require("iosPlatformLiveSyncServiceLocator", "./services/livesync/ios-platform-livesync-service");
$injector.require("iosLiveSyncServiceLocator", "./services/livesync/ios-device-livesync-service");
$injector.require("androidPlatformLiveSyncServiceLocator", "./services/livesync/android-platform-livesync-service");
$injector.require("androidLiveSyncServiceLocator", "./services/livesync/android-device-livesync-service");
$injector.require("platformLiveSyncService", "./services/livesync/platform-livesync-service");

$injector.require("sysInfo", "./sys-info");

Expand All @@ -123,3 +122,4 @@ $injector.requireCommand("post-install-cli", "./commands/post-install");
$injector.requireCommand("update", "./commands/update");

$injector.require("iOSLogFilter", "./services/ios-log-filter");
$injector.require("projectChangesService", "./services/project-changes-service");
5 changes: 3 additions & 2 deletions lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ export class PublishIOS implements ICommand {
};
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
this.$platformService.buildPlatform(platform, iOSBuildConfig, true).wait();
this.$platformService.preparePlatform(platform).wait();
this.$platformService.buildPlatform(platform, iOSBuildConfig).wait();
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice });
} else {
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
this.$platformService.preparePlatform(platform, true).wait();
this.$platformService.preparePlatform(platform).wait();

let platformData = this.$platformsData.getPlatformData(platform);
let iOSProjectService = <IOSProjectService>platformData.platformProjectService;
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export class BuildCommandBase {
executeCore(args: string[]): IFuture<void> {
return (() => {
let platform = args[0].toLowerCase();
this.$platformService.buildPlatform(platform, null, true).wait();
this.$platformService.preparePlatform(platform).wait();
this.$options.clean = true;
this.$platformService.buildPlatform(platform).wait();
if(this.$options.copyTo) {
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice});
}
Expand Down
45 changes: 22 additions & 23 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,32 @@
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $config: IConfiguration,
private $usbLiveSyncService: ILiveSyncService,
private $platformService: IPlatformService,
protected $options: IOptions) { }

execute(args: string[]): IFuture<void> {

if (this.$options.watch) {
this.$options.rebuild = false;
if (this.$options.start) {
return this.debugService.debug();
}

if (!this.$options.rebuild && !this.$options.start) {
this.$config.debugLivesync = true;
let applicationReloadAction = (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void> => {
return (() => {
let projectData: IProjectData = this.$injector.resolve("projectData");

this.debugService.debugStop().wait();
this.$platformService.deployPlatform(this.$devicesService.platform).wait();
this.$config.debugLivesync = true;
let applicationReloadAction = (deviceAppData: Mobile.IDeviceAppData): IFuture<void> => {
return (() => {
let projectData: IProjectData = this.$injector.resolve("projectData");

let applicationId = deviceAppData.appIdentifier;
if (deviceAppData.device.isEmulator && deviceAppData.platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
applicationId = projectData.projectName;
}
deviceAppData.device.applicationManager.stopApplication(applicationId).wait();
this.debugService.debugStop().wait();

this.debugService.debug().wait();
}).future<void>()();
};
let applicationId = deviceAppData.appIdentifier;
if (deviceAppData.device.isEmulator && deviceAppData.platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
applicationId = projectData.projectName;
}
deviceAppData.device.applicationManager.stopApplication(applicationId).wait();

return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
}
return this.debugService.debug();
this.debugService.debug().wait();
}).future<void>()();
};
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
}

allowedParameters: ICommandParameter[] = [];
Expand Down Expand Up @@ -69,8 +66,9 @@ export class DebugIOSCommand extends DebugPlatformCommand {
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$config: IConfiguration,
$usbLiveSyncService: ILiveSyncService,
$platformService: IPlatformService,
$options: IOptions) {
super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options);
}
}
$injector.registerCommand("debug|ios", DebugIOSCommand);
Expand All @@ -84,8 +82,9 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$config: IConfiguration,
$usbLiveSyncService: ILiveSyncService,
$platformService: IPlatformService,
$options: IOptions) {
super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options);
}
}
$injector.registerCommand("debug|android", DebugAndroidCommand);
2 changes: 1 addition & 1 deletion lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class DeployOnDeviceCommand implements ICommand {
private $mobileHelper: Mobile.IMobileHelper) { }

execute(args: string[]): IFuture<void> {
return this.$platformService.deployPlatform(args[0]);
return this.$platformService.deployPlatform(args[0], true);
}

public canExecute(args: string[]): IFuture<boolean> {
Expand Down
2 changes: 2 additions & 0 deletions lib/commands/livesync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export class LivesyncCommand implements ICommand {
private $usbLiveSyncService: ILiveSyncService,
private $mobileHelper: Mobile.IMobileHelper,
private $options: IOptions,
private $platformService: IPlatformService,
private $errors: IErrors) { }

public execute(args: string[]): IFuture<void> {
this.$platformService.deployPlatform(args[0]).wait();
return this.$usbLiveSyncService.liveSync(args[0]);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class PrepareCommand implements ICommand {

execute(args: string[]): IFuture<void> {
return (() => {
this.$platformService.preparePlatform(args[0], true).wait();
this.$platformService.preparePlatform(args[0]).wait();
}).future<void>()();
}

Expand Down
7 changes: 3 additions & 4 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ export class RunCommandBase {
protected $options: IOptions) { }

public executeCore(args: string[]): IFuture<void> {
if (this.$options.watch) {
this.$platformService.deployPlatform(args[0]).wait();
return this.$usbLiveSyncService.liveSync(args[0]);
} else {
this.$platformService.deployPlatform(args[0]).wait();
if (this.$options.release) {
return this.$platformService.runPlatform(args[0]);
}
return this.$usbLiveSyncService.liveSync(args[0]);
}
}

Expand Down
7 changes: 3 additions & 4 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ interface IOpener {
}

interface ILiveSyncService {
liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void>;
forceExecuteFullSync: boolean;
liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData) => IFuture<void>): IFuture<void>;
}

interface IPlatformLiveSyncService {
fullSync(postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void>;
partialSync(event: string, filePath: string, dispatcher: IFutureDispatcher, afterFileSyncAction: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): void;
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): IFuture<void>;
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], isFullSync: boolean): IFuture<void>;
}

interface IOptions extends ICommonOptions {
Expand Down Expand Up @@ -93,10 +92,10 @@ interface IOptions extends ICommonOptions {
sdk: string;
tnsModulesVersion: string;
teamId: string;
rebuild: boolean;
syncAllFiles: boolean;
liveEdit: boolean;
chrome: boolean;
clean: boolean;
}

interface IInitService {
Expand Down
87 changes: 83 additions & 4 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,78 @@ interface IPlatformService {
removePlatforms(platforms: string[]): void;

updatePlatforms(platforms: string[]): IFuture<void>;
preparePlatform(platform: string, force?: boolean, skipModulesAndResources?: boolean): IFuture<boolean>;
buildPlatform(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture<void>;
deployPlatform(platform: string): IFuture<void>;

/**
* Ensures that the specified platform and its dependencies are installed.
* When there are changes to be prepared, it prepares the native project for the specified platform.
* When finishes, prepare saves the .nsprepareinfo file in platform folder.
* This file contains information about current project configuration and allows skipping unnecessary build, deploy and livesync steps.
* @param {string} platform The platform to be prepared.
* @returns {boolean} true indicates that the platform was prepared.
*/
preparePlatform(platform: string, changesInfo?: IProjectChangesInfo): IFuture<boolean>;

/**
* Determines whether a build is necessary. A build is necessary when one of the following is true:
* - there is no previous build.
* - the .nsbuildinfo file in product folder points to an old prepare.
* @param {string} platform The platform to build.
* @param {IBuildConfig} buildConfig Indicates whether the build is for device or emulator.
* @returns {boolean} true indicates that the platform should be build.
*/
shouldBuild(platform: string, buildConfig?: IBuildConfig): IFuture<boolean>;

/**
* Builds the native project for the specified platform for device or emulator.
* When finishes, build saves the .nsbuildinfo file in platform product folder.
* This file points to the prepare that was used to build the project and allows skipping unnecessary builds and deploys.
* @param {string} platform The platform to build.
* @param {IBuildConfig} buildConfig Indicates whether the build is for device or emulator.
* @returns {void}
*/
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;

/**
* Determines whether installation is necessary. It is necessary when one of the following is true:
* - the application is not installed.
* - the .nsbuildinfo file located in application root folder is different than the local .nsbuildinfo file
* @param {Mobile.IDevice} device The device where the application should be installed.
* @returns {boolean} true indicates that the application should be installed.
*/
shouldInstall(device: Mobile.IDevice): boolean;

/**
* Installs the application on specified device.
* When finishes, saves .nsbuildinfo in application root folder to indicate the prepare that was used to build the app.
* * .nsbuildinfo is not persisted when building for release.
* @param {Mobile.IDevice} device The device where the application should be installed.
* @returns {void}
*/
installApplication(device: Mobile.IDevice): IFuture<void>;

/**
* Executes prepare, build and installOnPlatform when necessary to ensure that the latest version of the app is installed on specified platform.
* - When --clean option is specified it builds the app on every change. If not, build is executed only when there are native changes.
* @param {string} platform The platform to deploy.
* @param {boolean} forceInstall When true, installs the application unconditionally.
* @returns {void}
*/
deployPlatform(platform: string, forceInstall?: boolean): IFuture<void>;

/**
* Runs the application on specified platform. Assumes that the application is already build and installed. Fails if this is not true.
* @param {string} platform The platform where to start the application.
* @returns {void}
*/
runPlatform(platform: string): IFuture<void>;

/**
* The emulate command. In addition to `run --emulator` command, it handles the `--available-devices` option to show the available devices.
* @param {string} platform The platform to emulate.
* @returns {void}
*/
emulatePlatform(platform: string): IFuture<void>;

cleanDestinationApp(platform: string): IFuture<void>;
validatePlatformInstalled(platform: string): void;
validatePlatform(platform: string): void;
Expand Down Expand Up @@ -60,7 +127,14 @@ interface IPlatformService {
copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): void;

lastOutputPath(platform: string, settings: { isForDevice: boolean }): string;
ensurePlatformInstalled(platform: string): IFuture<void>;

/**
* Reads contents of a file on device.
* @param {Mobile.IDevice} device The device to read from.
* @param {string} deviceFilePath The file path.
* @returns {string} The contents of the file or null when there is no such file.
*/
readFile(device: Mobile.IDevice, deviceFilePath: string): IFuture<string>;
}

interface IPlatformData {
Expand Down Expand Up @@ -97,4 +171,9 @@ interface INodeModulesBuilder {

interface INodeModulesDependenciesBuilder {
getProductionDependencies(projectPath: string): void;
}

interface IBuildInfo {
prepareTime: string;
buildTime: string;
}
26 changes: 26 additions & 0 deletions lib/definitions/project-changes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
interface IPrepareInfo {
time: string;
bundle: boolean;
release: boolean;
changesRequireBuild: boolean;
changesRequireBuildTime: string;
}

interface IProjectChangesInfo {
appFilesChanged: boolean;
appResourcesChanged: boolean;
modulesChanged: boolean;
configChanged: boolean;
packageChanged: boolean;
nativeChanged: boolean;
hasChanges: boolean;
changesRequireBuild: boolean;
}

interface IProjectChangesService {
checkForChanges(platform: string): IProjectChangesInfo;
getPrepareInfo(platform: string): IPrepareInfo;
savePrepareInfo(platform: string): void;
getPrepareInfoFilePath(platform: string): string;
currentChanges: IProjectChangesInfo;
}
5 changes: 3 additions & 2 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ export class Options extends commonOptionsLibPath.OptionsBase {
bundle: { type: OptionType.Boolean },
all: { type: OptionType.Boolean },
teamId: { type: OptionType.String },
rebuild: { type: OptionType.Boolean, default: true },
syncAllFiles: { type: OptionType.Boolean },
liveEdit: { type: OptionType.Boolean },
chrome: { type: OptionType.Boolean }
chrome: { type: OptionType.Boolean },
clean: { type: OptionType.Boolean },
watch: { type: OptionType.Boolean, default: true }
},
path.join($hostInfo.isWindows ? process.env.AppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
$errors, $staticConfig);
Expand Down
Loading

0 comments on commit 40d525c

Please sign in to comment.