Skip to content

Commit 0f3f7ed

Browse files
committed
Show QR code of the current application when pressing "c" instead of "q"
Pass correct arguments to checkEnvironmentRequirements
1 parent 02090e2 commit 0f3f7ed

File tree

11 files changed

+65
-38
lines changed

11 files changed

+65
-38
lines changed

lib/commands/platform-clean.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ export class CleanCommand implements ICommand {
2626
this.$platformService.validatePlatformInstalled(platform, this.$projectData);
2727

2828
const currentRuntimeVersion = this.$platformService.getCurrentPlatformVersion(platform, this.$projectData);
29-
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(platform, this.$projectData.projectDir, currentRuntimeVersion);
29+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
30+
platform,
31+
projectDir: this.$projectData.projectDir,
32+
runtimeVersion: currentRuntimeVersion,
33+
options: this.$options
34+
});
3035
}
3136

3237
return true;

lib/commands/update-platform.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ export class UpdatePlatformCommand implements ICommand {
2525

2626
for (const arg of args) {
2727
const [ platform, versionToBeInstalled ] = arg.split("@");
28-
const argsToCheckEnvironmentRequirements: string[] = [ platform ];
28+
const checkEnvironmentRequirementsInput: ICheckEnvironmentRequirementsInput = { platform, options: this.$options };
2929
// If version is not specified, we know the command will install the latest compatible Android runtime.
3030
// The latest compatible Android runtime supports Java version, so we do not need to pass it here.
3131
// Passing projectDir to the nativescript-doctor validation will cause it to check the runtime from the current package.json
3232
// So in this case, where we do not want to validate the runtime, just do not pass both projectDir and runtimeVersion.
3333
if (versionToBeInstalled) {
34-
argsToCheckEnvironmentRequirements.push(this.$projectData.projectDir, versionToBeInstalled);
34+
checkEnvironmentRequirementsInput.projectDir = this.$projectData.projectDir;
35+
checkEnvironmentRequirementsInput.runtimeVersion = versionToBeInstalled;
3536
}
3637

37-
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(...argsToCheckEnvironmentRequirements);
38+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(checkEnvironmentRequirementsInput);
3839
}
3940

4041
return true;

lib/definitions/platform.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,14 @@ interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove
391391
}
392392

393393
interface IPlatformEnvironmentRequirements {
394-
checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<ICheckEnvironmentRequirementsOutput>;
394+
checkEnvironmentRequirements(input: ICheckEnvironmentRequirementsInput): Promise<ICheckEnvironmentRequirementsOutput>;
395+
}
396+
397+
interface ICheckEnvironmentRequirementsInput {
398+
platform?: string;
399+
projectDir?: string;
400+
runtimeVersion?: string;
401+
options?: IOptions;
395402
}
396403

397404
interface ICheckEnvironmentRequirementsOutput {

lib/definitions/project.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ interface ICleanNativeAppData extends IProjectDir, IPlatform { }
319319

320320
interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectServiceBase {
321321
getPlatformData(projectData: IProjectData): IPlatformData;
322-
validate(projectData: IProjectData): Promise<IValidatePlatformOutput>;
322+
validate(projectData: IProjectData, options?: IOptions): Promise<IValidatePlatformOutput>;
323323
createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, config: ICreateProjectOptions): Promise<void>;
324324
interpolateData(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
325325
interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): void;

lib/helpers/preview-command-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
5353
await this.$playgroundQrCodeGenerator.generateQrCodeForiOS();
5454
this.printUsage();
5555
return;
56-
case "q":
56+
case "c":
5757
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
5858
this.printUsage();
5959
return;
@@ -64,7 +64,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
6464
this.$logger.info(`
6565
-> Press ${this.underlineBoldCyan("a")} to show the QR code of NativeScript Playground app for ${this.underlineBoldCyan("Android")} devices
6666
-> Press ${this.underlineBoldCyan("i")} to show the QR code of NativeScript Playground app for ${this.underlineBoldCyan("iOS")} devices
67-
-> Press ${this.underlineBoldCyan("q")} to display the QR code of the current application.
67+
-> Press ${this.underlineBoldCyan("c")} to display the QR code of the ${this.underlineBoldCyan("current application")}.
6868
`);
6969
}
7070

lib/services/android-project-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
118118
}
119119
}
120120

121-
public async validate(projectData: IProjectData): Promise<IValidatePlatformOutput> {
121+
public async validate(projectData: IProjectData, options?: IOptions): Promise<IValidatePlatformOutput> {
122122
this.validatePackageName(projectData.projectId);
123123
this.validateProjectName(projectData.projectName);
124124

125-
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName, projectData.projectDir);
125+
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
126+
platform: this.getPlatformData(projectData).normalizedPlatformName,
127+
projectDir: projectData.projectDir,
128+
options
129+
});
126130
this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true });
127131

128132
return {

lib/services/doctor-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DoctorService implements IDoctorService {
1717
private $terminalSpinnerService: ITerminalSpinnerService,
1818
private $versionsService: IVersionsService) { }
1919

20-
public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string, runtimeVersion?: string }): Promise<void> {
20+
public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string, runtimeVersion?: string, options?: IOptions }): Promise<void> {
2121
const infos = await this.$terminalSpinnerService.execute<NativeScriptDoctor.IInfo[]>({
2222
text: `Getting environment information ${EOL}`
2323
}, () => doctor.getInfos({ projectDir: configOptions && configOptions.projectDir, androidRuntimeVersion: configOptions && configOptions.runtimeVersion }));
@@ -47,7 +47,12 @@ class DoctorService implements IDoctorService {
4747
this.$logger.error("Cannot get the latest versions information from npm. Please try again later.");
4848
}
4949

50-
await this.$injector.resolve("platformEnvironmentRequirements").checkEnvironmentRequirements(null, configOptions && configOptions.projectDir);
50+
await this.$injector.resolve<IPlatformEnvironmentRequirements>("platformEnvironmentRequirements").checkEnvironmentRequirements({
51+
platform: null,
52+
projectDir: configOptions && configOptions.projectDir,
53+
runtimeVersion: configOptions && configOptions.runtimeVersion,
54+
options: configOptions && configOptions.options
55+
});
5156
}
5257

5358
public async runSetupScript(): Promise<ISpawnResult> {

lib/services/ios-project-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,16 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
133133
return path.join(this.getPlatformData(projectData).projectRoot, projectData.projectName, "Resources");
134134
}
135135

136-
public async validate(projectData: IProjectData): Promise<IValidatePlatformOutput> {
136+
public async validate(projectData: IProjectData, options?: IOptions): Promise<IValidatePlatformOutput> {
137137
if (!this.$hostInfo.isDarwin) {
138138
return;
139139
}
140140

141-
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName, projectData.projectDir);
141+
const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
142+
platform: this.getPlatformData(projectData).normalizedPlatformName,
143+
projectDir: projectData.projectDir,
144+
options
145+
});
142146

143147
const xcodeBuildVersion = await this.getXcodeVersion();
144148
if (helpers.versionCompare(xcodeBuildVersion, IOSProjectService.XCODEBUILD_MIN_VERSION) < 0) {

lib/services/platform-environment-requirements.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
4040
"deploy": "tns cloud deploy"
4141
};
4242

43-
public async checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<ICheckEnvironmentRequirementsOutput> {
43+
public async checkEnvironmentRequirements(input: ICheckEnvironmentRequirementsInput): Promise<ICheckEnvironmentRequirementsOutput> {
44+
const { platform, projectDir, runtimeVersion, options } = input;
4445
let selectedOption = null;
4546

4647
if (process.env.NS_SKIP_ENV_CHECK) {
@@ -84,7 +85,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
8485

8586
await this.processCloudBuildsIfNeeded(selectedOption, platform);
8687
this.processManuallySetupIfNeeded(selectedOption, platform);
87-
await this.processSyncToPreviewAppIfNeeded(selectedOption, projectDir);
88+
await this.processSyncToPreviewAppIfNeeded(selectedOption, projectDir, options);
8889

8990
if (selectedOption === PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME) {
9091
await this.$doctorService.runSetupScript();
@@ -182,7 +183,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
182183
}
183184
}
184185

185-
private async processSyncToPreviewAppIfNeeded(selectedOption: string, projectDir: string) {
186+
private async processSyncToPreviewAppIfNeeded(selectedOption: string, projectDir: string, options: IOptions) {
186187
if (selectedOption === PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME) {
187188
if (!projectDir) {
188189
this.$errors.failWithoutHelp(`No project found. In order to sync to playground you need to go to project directory or specify --path option.`);
@@ -191,10 +192,10 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
191192
await this.$previewAppLiveSyncService.initialSync({
192193
projectDir,
193194
appFilesUpdaterOptions: {
194-
bundle: false,
195-
release: false
195+
bundle: !!options.bundle,
196+
release: options.release
196197
},
197-
env: null
198+
env: options.env
198199
});
199200
}
200201
}

test/helpers/preview-command-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ describe("previewCommandHelper", () => {
112112
qrCodeProperty: "isGeneratedForiOS",
113113
},
114114
{
115-
name: "should generate qr code for current app when q key is pressed",
116-
stdinData: "q",
115+
name: "should generate qr code for current app when c key is pressed",
116+
stdinData: "c",
117117
qrCodeProperty: "isGeneratedForCurrentApp",
118118
}
119119
];
@@ -140,8 +140,8 @@ describe("previewCommandHelper", () => {
140140
stdinData: "i"
141141
},
142142
{
143-
name: "should not generate qr code for current app when q key is pressed",
144-
stdinData: "q"
143+
name: "should not generate qr code for current app when c key is pressed",
144+
stdinData: "c"
145145
}
146146
];
147147

0 commit comments

Comments
 (0)