Skip to content

Commit 3a783e1

Browse files
author
Fatme
authored
Merge pull request #3853 from NativeScript/feature/playground
Playground
2 parents 78fda2a + b7d42d7 commit 3a783e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2642
-610
lines changed

config/config.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"CI_LOGGER": false,
55
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
66
"USE_POD_SANDBOX": false,
7-
"DISABLE_HOOKS": false
7+
"DISABLE_HOOKS": false,
8+
"UPLOAD_PLAYGROUND_FILES_ENDPOINT": "https://play.nativescript.org/api/files" ,
9+
"SHORTEN_URL_ENDPOINT": "https://play.nativescript.org/api/shortenurl?longUrl=%s"
810
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<% if (isJekyll) { %>---
2+
title: tns preview
3+
position: 1
4+
---<% } %>
5+
# tns preview
6+
7+
8+
Usage | Synopsis
9+
---|---
10+
Produces a QR code for deployment in the Preview app. | `tns preview`
11+
12+
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.
13+
14+
### Options
15+
`--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`

lib/bootstrap.ts

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ $injector.requireCommand("run|*all", "./commands/run");
5050
$injector.requireCommand("run|ios", "./commands/run");
5151
$injector.requireCommand("run|android", "./commands/run");
5252

53+
$injector.requireCommand("preview", "./commands/preview");
54+
5355
$injector.requireCommand("debug|ios", "./commands/debug");
5456
$injector.requireCommand("debug|android", "./commands/debug");
5557

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

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

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

173180
$injector.require("pacoteService", "./services/pacote-service");
181+
$injector.require("qrCodeTerminalService", "./services/qr-code-terminal-service");

lib/commands/add-platform.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
export class AddPlatformCommand implements ICommand {
1+
import { ValidatePlatformCommandBase } from "./command-base";
2+
3+
export class AddPlatformCommand extends ValidatePlatformCommandBase implements ICommand {
24
public allowedParameters: ICommandParameter[] = [];
35

4-
constructor(private $options: IOptions,
5-
private $platformService: IPlatformService,
6-
private $projectData: IProjectData,
7-
private $platformsData: IPlatformsData,
6+
constructor($options: IOptions,
7+
$platformService: IPlatformService,
8+
$projectData: IProjectData,
9+
$platformsData: IPlatformsData,
810
private $errors: IErrors) {
9-
this.$projectData.initializeProjectData();
11+
super($options, $platformsData, $platformService, $projectData);
12+
this.$projectData.initializeProjectData();
1013
}
1114

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

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

24+
let canExecute = true;
2125
for (const arg of args) {
2226
this.$platformService.validatePlatform(arg, this.$projectData);
23-
const platformData = this.$platformsData.getPlatformData(arg, this.$projectData);
24-
const platformProjectService = platformData.platformProjectService;
25-
await platformProjectService.validate(this.$projectData);
27+
const output = await super.canExecuteCommandBase(arg);
28+
canExecute = canExecute && output.canExecute;
2629
}
2730

28-
return true;
31+
return {
32+
canExecute,
33+
suppressCommandHelp: !canExecute
34+
};
2935
}
3036
}
3137

lib/commands/build.ts

+47-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
import { ValidatePlatformCommandBase } from "./command-base";
23

3-
export class BuildCommandBase {
4-
constructor(protected $options: IOptions,
4+
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
5+
constructor($options: IOptions,
56
protected $errors: IErrors,
6-
protected $projectData: IProjectData,
7-
protected $platformsData: IPlatformsData,
7+
$projectData: IProjectData,
8+
$platformsData: IPlatformsData,
89
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
9-
protected $platformService: IPlatformService,
10+
$platformService: IPlatformService,
1011
private $bundleValidatorHelper: IBundleValidatorHelper) {
12+
super($options, $platformsData, $platformService, $projectData);
1113
this.$projectData.initializeProjectData();
1214
}
1315

@@ -43,16 +45,29 @@ export class BuildCommandBase {
4345
}
4446
}
4547

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

5153
this.$bundleValidatorHelper.validate();
54+
}
55+
56+
protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
57+
const canExecute = await this.validateArgsCore(args, platform);
58+
return {
59+
canExecute,
60+
suppressCommandHelp: false
61+
};
62+
}
5263

53-
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
54-
const platformProjectService = platformData.platformProjectService;
55-
await platformProjectService.validate(this.$projectData);
64+
private async validateArgsCore(args: string[], platform: string): Promise<boolean> {
65+
if (args.length !== 0) {
66+
return false;
67+
}
68+
69+
const result = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
70+
return result;
5671
}
5772
}
5873

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

76-
public async canExecute(args: string[]): Promise<boolean> {
77-
await super.validatePlatform(this.$devicePlatformsConstants.iOS);
78-
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
91+
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
92+
const platform = this.$devicePlatformsConstants.iOS;
93+
94+
super.validatePlatform(platform);
95+
96+
let result = await super.canExecuteCommandBase(platform);
97+
if (result.canExecute) {
98+
result = await super.validateArgs(args, platform);
99+
}
100+
101+
return result;
79102
}
80103
}
81104

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

101-
public async canExecute(args: string[]): Promise<boolean> {
102-
await super.validatePlatform(this.$devicePlatformsConstants.Android);
103-
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
104-
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
124+
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
125+
const platform = this.$devicePlatformsConstants.Android;
126+
super.validatePlatform(platform);
127+
128+
let result = await super.canExecuteCommandBase(platform);
129+
if (result.canExecute) {
130+
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
131+
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
132+
}
133+
134+
result = await super.validateArgs(args, platform);
105135
}
106136

107-
return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.Android);
137+
return result;
108138
}
109139
}
110140

lib/commands/clean-app.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
export class CleanAppCommandBase implements ICommand {
1+
import { ValidatePlatformCommandBase } from "./command-base";
2+
3+
export class CleanAppCommandBase extends ValidatePlatformCommandBase implements ICommand {
24
public allowedParameters: ICommandParameter[] = [];
35

46
protected platform: string;
57

6-
constructor(protected $options: IOptions,
7-
protected $projectData: IProjectData,
8-
protected $platformService: IPlatformService,
8+
constructor($options: IOptions,
9+
$projectData: IProjectData,
10+
$platformService: IPlatformService,
911
protected $errors: IErrors,
1012
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
11-
protected $platformsData: IPlatformsData) {
12-
13-
this.$projectData.initializeProjectData();
13+
$platformsData: IPlatformsData) {
14+
super($options, $platformsData, $platformService, $projectData);
15+
this.$projectData.initializeProjectData();
1416
}
1517

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

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

35-
const platformData = this.$platformsData.getPlatformData(this.platform, this.$projectData);
36-
const platformProjectService = platformData.platformProjectService;
37-
await platformProjectService.validate(this.$projectData);
38-
return true;
37+
const result = await super.canExecuteCommandBase(this.platform);
38+
return result;
3939
}
4040
}
4141

lib/commands/command-base.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export abstract class ValidatePlatformCommandBase {
2+
constructor(protected $options: IOptions,
3+
protected $platformsData: IPlatformsData,
4+
protected $platformService: IPlatformService,
5+
protected $projectData: IProjectData) { }
6+
7+
abstract allowedParameters: ICommandParameter[];
8+
abstract execute(args: string[]): Promise<void>;
9+
10+
public async canExecuteCommandBase(platform: string, options?: ICanExecuteCommandOptions): Promise<ICanExecuteCommandOutput> {
11+
options = options || {};
12+
const validatePlatformOutput = await this.validatePlatformBase(platform, options.notConfiguredEnvOptions);
13+
const canExecute = this.canExecuteCommand(validatePlatformOutput);
14+
let result = { canExecute, suppressCommandHelp: !canExecute };
15+
16+
if (canExecute && options.validateOptions) {
17+
const validateOptionsOutput = await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform);
18+
result = { canExecute: validateOptionsOutput, suppressCommandHelp: false };
19+
}
20+
21+
return result;
22+
}
23+
24+
private async validatePlatformBase(platform: string, notConfiguredEnvOptions: INotConfiguredEnvOptions): Promise<IValidatePlatformOutput> {
25+
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
26+
const platformProjectService = platformData.platformProjectService;
27+
const result = await platformProjectService.validate(this.$projectData, this.$options, notConfiguredEnvOptions);
28+
return result;
29+
}
30+
31+
private canExecuteCommand(validatePlatformOutput: IValidatePlatformOutput): boolean {
32+
return validatePlatformOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput && validatePlatformOutput.checkEnvironmentRequirementsOutput.canExecute;
33+
}
34+
}

0 commit comments

Comments
 (0)