Skip to content

Fixed: TNS run command broken with using --watch #2305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/nativescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

"use strict";
require("../lib/nativescript-cli.js");
2 changes: 1 addition & 1 deletion lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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.prepareAndBuild(platform, iOSBuildConfig, true).wait();
this.$platformService.buildPlatform(platform, iOSBuildConfig, true).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.");
Expand Down
5 changes: 2 additions & 3 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ export class BuildCommandBase {
constructor(protected $options: IOptions,
private $platformService: IPlatformService) { }

executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
executeCore(args: string[]): IFuture<void> {
return (() => {
let platform = args[0].toLowerCase();
this.$platformService.preparePlatform(platform, true).wait();
this.$platformService.buildPlatform(platform, buildConfig).wait();
this.$platformService.buildPlatform(platform, null, true).wait();
if(this.$options.copyTo) {
this.$platformService.copyLastOutput(platform, this.$options.copyTo, {isForDevice: this.$options.forDevice}).wait();
}
Expand Down
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.deployOnDevice(args[0]);
return this.$platformService.deployPlatform(args[0]);
}

public canExecute(args: string[]): IFuture<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/emulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class EmulateCommandBase {
constructor(private $platformService: IPlatformService) { }

executeCore(args: string[]): IFuture<void> {
return this.$platformService.deployOnEmulator(args[0]);
return this.$platformService.emulatePlatform(args[0]);
}
}

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

public executeCore(args: string[], buildConfig?: IBuildConfig): IFuture<void> {
public executeCore(args: string[]): IFuture<void> {
if (this.$options.watch) {
this.$platformService.deployPlatform(args[0]).wait();
return this.$usbLiveSyncService.liveSync(args[0]);
} else {
return this.$platformService.runPlatform(args[0], buildConfig);
return this.$platformService.runPlatform(args[0]);
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ interface IPlatformService {
getPreparedPlatforms(): IFuture<string[]>;
removePlatforms(platforms: string[]): IFuture<void>;
updatePlatforms(platforms: string[]): IFuture<void>;
runPlatform(platform: string, buildConfig?: IBuildConfig): 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>;
runPlatform(platform: string): IFuture<void>;
emulatePlatform(platform: string): IFuture<void>;
cleanDestinationApp(platform: string): IFuture<void>;
buildPlatform(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
installOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
deployOnDevice(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
startOnDevice(platform: string): IFuture<void>;
deployOnEmulator(platform: string, buildConfig?: IBuildConfig): IFuture<void>;
validatePlatformInstalled(platform: string): void;
validatePlatform(platform: string): void;

Expand All @@ -22,8 +19,6 @@ interface IPlatformService {
copyLastOutput(platform: string, targetPath: string, settings: {isForDevice: boolean}): IFuture<void>;
lastOutputPath(platform: string, settings: { isForDevice: boolean }): string;
ensurePlatformInstalled(platform: string): IFuture<void>;

prepareAndBuild(platform: string, buildConfig?: IBuildConfig, forceBuild?: boolean): IFuture<void>;
}

interface IPlatformData {
Expand Down
1 change: 0 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ interface IPlatformProjectService {
interpolateConfigurationFile(configurationFilePath?: string): IFuture<void>;
afterCreateProject(projectRoot: string): IFuture<void>;
buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void>;
prepareProject(): IFuture<void>;
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void>;
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion lib/providers/livesync-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class LiveSyncProvider implements ILiveSyncProvider {

public buildForDevice(device: Mobile.IDevice): IFuture<string> {
return (() => {
this.$platformService.buildForDeploy(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
this.$platformService.buildPlatform(device.deviceInfo.platform, {buildForDevice: !device.isEmulator}).wait();
let platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform);
if (device.isEmulator) {
return this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait().packageName;
Expand Down
4 changes: 2 additions & 2 deletions lib/services/android-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AndroidDebugService implements IDebugService {

private debugOnEmulator(): IFuture<void> {
return (() => {
this.$platformService.deployOnEmulator(this.platform).wait();
this.$platformService.deployPlatform(this.platform).wait();
// Assure we've detected the emulator as device
// For example in case deployOnEmulator had stated new emulator instance
// we need some time to detect it. Let's force detection.
Expand Down Expand Up @@ -111,7 +111,7 @@ class AndroidDebugService implements IDebugService {
let cachedDeviceOption = this.$options.forDevice;
this.$options.forDevice = true;
if (this.$options.rebuild) {
this.$platformService.prepareAndBuild(this.platform).wait();
this.$platformService.buildPlatform(this.platform).wait();
}
this.$options.forDevice = !!cachedDeviceOption;

Expand Down
4 changes: 0 additions & 4 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
return buildOptions;
}

public buildForDeploy(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
return this.buildProject(projectRoot, buildConfig);
}

public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
return this.$fs.exists(path.join(this.platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class IOSDebugService implements IDebugService {
return (() => {
let platformData = this.$platformsData.getPlatformData(this.platform);
if (this.$options.rebuild) {
this.$platformService.prepareAndBuild(this.platform).wait();
this.$platformService.buildPlatform(this.platform).wait();
}
let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait();

Expand Down Expand Up @@ -159,9 +159,9 @@ class IOSDebugService implements IDebugService {
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
let action: IFuture<void>;
if (this.$config.debugLivesync) {
action = this.$platformService.startOnDevice(this.platform);
action = this.$platformService.runPlatform(this.platform);
} else {
action = this.$platformService.deployOnDevice(this.platform);
action = this.$platformService.deployPlatform(this.platform);
}
this.debugBrkCore(device, shouldBreak).wait();
action.wait();
Expand Down
131 changes: 71 additions & 60 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
"build",
'SHARED_PRECOMPS_DIR=' + path.join(projectRoot, 'build', 'sharedpch')
];

basicArgs = basicArgs.concat(this.xcbuildProjectArgs(projectRoot));

// Starting from tns-ios 1.4 the xcconfig file is referenced in the project template
Expand All @@ -253,37 +252,58 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
basicArgs.push("-xcconfig", path.join(projectRoot, this.$projectData.projectName, "build.xcconfig"));
}

let args: string[] = [];
let buildForDevice = this.$options.forDevice || (buildConfig && buildConfig.buildForDevice);
if (buildForDevice) {
let defaultArchitectures = [
'ARCHS=armv7 arm64',
'VALID_ARCHS=armv7 arm64'
];

args = basicArgs.concat([
"-sdk", "iphoneos",
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device")
]);
this.buildForDevice(projectRoot, basicArgs, buildConfig).wait();
} else {
this.buildForSimulator(projectRoot, basicArgs, buildConfig).wait();
}
}).future<void>()();
}

args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures);
private buildForDevice(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture<void> {
return (() => {
let defaultArchitectures = [
'ARCHS=armv7 arm64',
'VALID_ARCHS=armv7 arm64'
];

let xcodeBuildVersion = this.getXcodeVersion();
if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) {
let teamId = this.getDevelopmentTeam();
if (teamId) {
args = args.concat("DEVELOPMENT_TEAM=" + teamId);
// build only for device specific architecture
if (!this.$options.release && !(buildConfig && buildConfig.architectures)) {
this.$devicesService.initialize({ platform: this.$devicePlatformsConstants.iOS.toLowerCase(), deviceId: this.$options.device }).wait();
let instances = this.$devicesService.getDeviceInstances();
let devicesArchitectures = _(instances)
.filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform) && d.deviceInfo.activeArchitecture)
.map(d => d.deviceInfo.activeArchitecture)
.uniq()
.value();
if (devicesArchitectures.length > 0) {
let architectures = [
`ARCHS=${devicesArchitectures.join(" ")}`,
`VALID_ARCHS=${devicesArchitectures.join(" ")}`
];
if (devicesArchitectures.length > 1) {
architectures.push('ONLY_ACTIVE_ARCH=NO');
}
if (!buildConfig) {
buildConfig = {};
}
buildConfig.architectures = architectures;
}
}
args = args.concat((buildConfig && buildConfig.architectures) || defaultArchitectures);

args = args.concat([
"-sdk", "iphoneos",
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "device")
]);

let xcodeBuildVersion = this.getXcodeVersion();
if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) {
let teamId = this.getDevelopmentTeam();
if (teamId) {
args = args.concat("DEVELOPMENT_TEAM=" + teamId);
}
} else {
args = basicArgs.concat([
"-sdk", "iphonesimulator",
"ARCHS=i386 x86_64",
"VALID_ARCHS=i386 x86_64",
"ONLY_ACTIVE_ARCH=NO",
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"),
"CODE_SIGN_IDENTITY="
]);
}

if (buildConfig && buildConfig.codeSignIdentity) {
Expand All @@ -295,47 +315,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}

this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
this.createIpa(projectRoot).wait();

if (buildForDevice) {
let buildOutputPath = path.join(projectRoot, "build", "device");

// Produce ipa file
let xcrunArgs = [
"-sdk", "iphoneos",
"PackageApplication",
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
];

this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
}
}).future<void>()();
}

public buildForDeploy(platform: string, buildConfig?: IBuildConfig): IFuture<void> {
if (this.$options.release) {
return this.buildProject(this.platformData.projectRoot, buildConfig);
}

let devicesArchitectures = _(this.$devicesService.getDeviceInstances())
.filter(d => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform))
.map(d => d.deviceInfo.activeArchitecture)
.uniq()
.value();

let architectures = [
`ARCHS=${devicesArchitectures.join(" ")}`,
`VALID_ARCHS=${devicesArchitectures.join(" ")}`
];
private buildForSimulator(projectRoot: string, args: string[], buildConfig?: IiOSBuildConfig): IFuture<void> {
return (() => {
args = args.concat([
"-sdk", "iphonesimulator",
"ARCHS=i386 x86_64",
"VALID_ARCHS=i386 x86_64",
"ONLY_ACTIVE_ARCH=NO",
"CONFIGURATION_BUILD_DIR=" + path.join(projectRoot, "build", "emulator"),
"CODE_SIGN_IDENTITY="
]);

if (devicesArchitectures.length > 1) {
architectures.push('ONLY_ACTIVE_ARCH=NO');
}
this.$childProcess.spawnFromEvent("xcodebuild", args, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();

buildConfig = buildConfig || {};
buildConfig.architectures = architectures;
}).future<void>()();
}

return this.buildProject(this.platformData.projectRoot, buildConfig);
private createIpa(projectRoot: string): IFuture<void> {
return (() => {
let buildOutputPath = path.join(projectRoot, "build", "device");
let xcrunArgs = [
"-sdk", "iphoneos",
"PackageApplication",
"-v", path.join(buildOutputPath, this.$projectData.projectName + ".app"),
"-o", path.join(buildOutputPath, this.$projectData.projectName + ".ipa")
];
this.$childProcess.spawnFromEvent("xcrun", xcrunArgs, "exit", { cwd: this.$options, stdio: 'inherit' }).wait();
}).future<void>()();
}

public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
Expand Down
Loading