Skip to content

Playground #3853

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 43 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6d2aaf9
Initial version of preview command
Fatme Aug 15, 2018
94f9acc
Generate qr code
Fatme Aug 16, 2018
f278202
Add "Sync to Playground" option in prompts when env is not properly c…
Fatme Aug 17, 2018
5986b60
Skip copy of app_resources and tns_modules when preparing platform fo…
Fatme Aug 17, 2018
e7edf2d
Add warnings for plugins not presented in preview app on device
Fatme Aug 23, 2018
c91958d
Fix "Cannot find connected devices" error when the env is not properl…
Fatme Aug 23, 2018
ad822cd
Store only unique devices
Fatme Aug 23, 2018
d46fec2
Fix shouldStartWatcher check and fix lint errors
Fatme Aug 23, 2018
affbbea
fix: handle bigger files upload (temporary reuse the playground endpo…
Aug 23, 2018
04e741b
Add warnings for native files and add unit tests for preview-app-plug…
Fatme Aug 24, 2018
aac3668
Show qr codes for current app and playground app when keys from keybo…
Fatme Aug 24, 2018
ec4d21c
Add unit tests for preview-app-livesync-service
Fatme Aug 28, 2018
efb4e00
Fix checkEnvironmentRequirements tests and rename IValidateOutput to …
Fatme Aug 28, 2018
02090e2
Remove ios/testApp/.vscode/launch.json
Fatme Aug 28, 2018
0f3f7ed
Show QR code of the current application when pressing "c" instead of "q"
Fatme Aug 28, 2018
1e9c7a0
fix: use the CLI PubNub app instead of the playground one
Aug 28, 2018
01288cc
refactor: move the playground files upload url to the config
Aug 24, 2018
8c80d72
Hide "Sync to Playground" option when env is not properly configured …
Fatme Aug 28, 2018
9c34235
Fix non working ctrl+C when env is not properly configured and "Sync …
Fatme Aug 28, 2018
a0db691
feat: use the playground shortener in order to get smaller QR codes
Aug 29, 2018
4967b2c
Stop execution of current command when env is not properly configured…
Fatme Aug 30, 2018
3ad200a
fix: fix binary files sync to the preview app
Sep 3, 2018
d4f3d45
chore: regenerate shrinkwrap versions with the latest npm
Sep 3, 2018
be9aa07
fix: fix the shortener endpoint usage
Sep 3, 2018
13643d2
chore: use the preview sdk from npm
Sep 3, 2018
8a0e6c5
chore: update the shrinkwrap after referring the preview SDK from npm
Sep 3, 2018
e9ed5d9
Fix messages
Fatme Sep 3, 2018
7563753
chore: fix the shorURL casing from the shortener endpoint
Sep 3, 2018
226060d
fix: fix tslint errors
Sep 3, 2018
57cb647
Generate QR code from command not inside preview-app-livesync-service.js
Fatme Sep 4, 2018
748f753
Support for webpack
Fatme Sep 10, 2018
c30fbef
Fix tests and extract some messages as constants
Fatme Sep 11, 2018
d99972b
Fix lint errors
Fatme Sep 11, 2018
39622f6
Fix PR comments
Fatme Sep 11, 2018
8349ae2
Add base help for preview command
Fatme Sep 11, 2018
37daa75
Integrate version 0.2.0 of nativescript-preview-sdk
Fatme Sep 11, 2018
baa1295
fix: compare the major versions between the local and preview app dep…
Fatme Sep 11, 2018
d7bd815
fix: stop sending platform specific extensions in preview
Sep 11, 2018
660f9fc
Update preview sdk version
Fatme Sep 12, 2018
b05ac25
fix tests after removing the hack for platform specific files
Fatme Sep 12, 2018
c2ca17f
Update nativescript-preview-sdk to 0.2.2 version
Fatme Sep 12, 2018
6dacef8
chore: fix prepare
Fatme Sep 13, 2018
b7d42d7
fix: Implement backwards compatibility with old versions of nativescr…
Fatme Sep 14, 2018
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: 3 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"CI_LOGGER": false,
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
"USE_POD_SANDBOX": false,
"DISABLE_HOOKS": false
"DISABLE_HOOKS": false,
"UPLOAD_PLAYGROUND_FILES_ENDPOINT": "https://play.nativescript.org/api/files" ,
"SHORTEN_URL_ENDPOINT": "https://play.nativescript.org/api/shortenurl?longUrl=%s"
}
15 changes: 15 additions & 0 deletions docs/man_pages/project/testing/preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if (isJekyll) { %>---
title: tns preview
position: 1
---<% } %>
# tns preview


Usage | Synopsis
---|---
Produces a QR code for deployment in the Preview app. | `tns preview`

Enjoy NativeScript without any local setup. All you need is a couple of companion apps installed on your devices. When you save changes to the project, the changes are automatically synchronized to Preview app on your device.

### Options
`--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`
8 changes: 8 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ $injector.requireCommand("run|*all", "./commands/run");
$injector.requireCommand("run|ios", "./commands/run");
$injector.requireCommand("run|android", "./commands/run");

$injector.requireCommand("preview", "./commands/preview");

$injector.requireCommand("debug|ios", "./commands/debug");
$injector.requireCommand("debug|android", "./commands/debug");

Expand Down Expand Up @@ -120,13 +122,18 @@ $injector.requireCommand("platform|clean", "./commands/platform-clean");
$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");
$injector.require("previewCommandHelper", "./helpers/preview-command-helper");

$injector.requirePublicClass("localBuildService", "./services/local-build-service");
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
$injector.requirePublicClass("androidLivesyncTool", "./services/livesync/android-livesync-tool");
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
$injector.require("previewAppLiveSyncService", "./services/livesync/playground/preview-app-livesync-service");
$injector.require("previewAppPluginsService", "./services/livesync/playground/preview-app-plugins-service");
$injector.require("previewSdkService", "./services/livesync/playground/preview-sdk-service");
$injector.require("playgroundQrCodeGenerator", "./services/livesync/playground/qr-code-generator");
$injector.requirePublic("sysInfo", "./sys-info");

$injector.require("iOSNotificationService", "./services/ios-notification-service");
Expand Down Expand Up @@ -171,3 +178,4 @@ $injector.require("iOSLogParserService", "./services/ios-log-parser-service");
$injector.require("iOSDebuggerPortService", "./services/ios-debugger-port-service");

$injector.require("pacoteService", "./services/pacote-service");
$injector.require("qrCodeTerminalService", "./services/qr-code-terminal-service");
28 changes: 17 additions & 11 deletions lib/commands/add-platform.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
export class AddPlatformCommand implements ICommand {
import { ValidatePlatformCommandBase } from "./command-base";

export class AddPlatformCommand extends ValidatePlatformCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(private $options: IOptions,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $platformsData: IPlatformsData,
constructor($options: IOptions,
$platformService: IPlatformService,
$projectData: IProjectData,
$platformsData: IPlatformsData,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData, this.$options, this.$options.frameworkPath);
}

public async canExecute(args: string[]): Promise<boolean> {
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
if (!args || args.length === 0) {
this.$errors.fail("No platform specified. Please specify a platform to add");
}

let canExecute = true;
for (const arg of args) {
this.$platformService.validatePlatform(arg, this.$projectData);
const platformData = this.$platformsData.getPlatformData(arg, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
const output = await super.canExecuteCommandBase(arg);
canExecute = canExecute && output.canExecute;
}

return true;
return {
canExecute,
suppressCommandHelp: !canExecute
};
}
}

Expand Down
64 changes: 47 additions & 17 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { ValidatePlatformCommandBase } from "./command-base";

export class BuildCommandBase {
constructor(protected $options: IOptions,
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
constructor($options: IOptions,
protected $errors: IErrors,
protected $projectData: IProjectData,
protected $platformsData: IPlatformsData,
$projectData: IProjectData,
$platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformService: IPlatformService,
$platformService: IPlatformService,
private $bundleValidatorHelper: IBundleValidatorHelper) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

Expand Down Expand Up @@ -43,16 +45,29 @@ export class BuildCommandBase {
}
}

protected async validatePlatform(platform: string): Promise<void> {
protected validatePlatform(platform: string): void {
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
}

this.$bundleValidatorHelper.validate();
}

protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
const canExecute = await this.validateArgsCore(args, platform);
return {
canExecute,
suppressCommandHelp: false
};
}

const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
private async validateArgsCore(args: string[], platform: string): Promise<boolean> {
if (args.length !== 0) {
return false;
}

const result = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
return result;
}
}

Expand All @@ -73,9 +88,17 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
}

public async canExecute(args: string[]): Promise<boolean> {
await super.validatePlatform(this.$devicePlatformsConstants.iOS);
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
const platform = this.$devicePlatformsConstants.iOS;

super.validatePlatform(platform);

let result = await super.canExecuteCommandBase(platform);
if (result.canExecute) {
result = await super.validateArgs(args, platform);
}

return result;
}
}

Expand All @@ -98,13 +121,20 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
}

public async canExecute(args: string[]): Promise<boolean> {
await super.validatePlatform(this.$devicePlatformsConstants.Android);
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
const platform = this.$devicePlatformsConstants.Android;
super.validatePlatform(platform);

let result = await super.canExecuteCommandBase(platform);
if (result.canExecute) {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
}

result = await super.validateArgs(args, platform);
}

return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.Android);
return result;
}
}

Expand Down
24 changes: 12 additions & 12 deletions lib/commands/clean-app.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
export class CleanAppCommandBase implements ICommand {
import { ValidatePlatformCommandBase } from "./command-base";

export class CleanAppCommandBase extends ValidatePlatformCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

protected platform: string;

constructor(protected $options: IOptions,
protected $projectData: IProjectData,
protected $platformService: IPlatformService,
constructor($options: IOptions,
$projectData: IProjectData,
$platformService: IPlatformService,
protected $errors: IErrors,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformsData: IPlatformsData) {

this.$projectData.initializeProjectData();
$platformsData: IPlatformsData) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -27,15 +29,13 @@ export class CleanAppCommandBase implements ICommand {
return this.$platformService.cleanDestinationApp(platformInfo);
}

public async canExecute(args: string[]): Promise<boolean> {
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
if (!this.$platformService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
}

const platformData = this.$platformsData.getPlatformData(this.platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
return true;
const result = await super.canExecuteCommandBase(this.platform);
return result;
}
}

Expand Down
34 changes: 34 additions & 0 deletions lib/commands/command-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export abstract class ValidatePlatformCommandBase {
constructor(protected $options: IOptions,
protected $platformsData: IPlatformsData,
protected $platformService: IPlatformService,
protected $projectData: IProjectData) { }

abstract allowedParameters: ICommandParameter[];
abstract execute(args: string[]): Promise<void>;

public async canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise<ICanExecuteCommandOutput> {
options = options || {};
const validatePlatformOutput = await this.validatePlatformBase(platform, options.notConfiguredEnvOptions);
const canExecute = this.canExecuteCommand(validatePlatformOutput);
let result = { canExecute, suppressCommandHelp: !canExecute };

if (canExecute && options.validateOptions) {
const validateOptionsOutput = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
}

return result;
}

private async validatePlatformBase(platform: string, notConfiguredEnvOptions: INotConfiguredEnvOptions): Promise<IValidatePlatformOutput> {
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
const result = await platformProjectService.validate(this.$projectData, this.$options, notConfiguredEnvOptions);
return result;
}

private canExecuteCommand(validatePlatformOutput: IValidatePlatformOutput): boolean {
return validatePlatformOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput.canExecute;
}
}
Loading