Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into users/ashwanikumar/runtimePreviewECS
  • Loading branch information
priyanshu92 committed Dec 16, 2024
2 parents 8058619 + c048bb5 commit a83ce18
Show file tree
Hide file tree
Showing 20 changed files with 372 additions and 116 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ telemetry-generated
# tasks copy them to the correct location, but leave the originals where
# we do not want them checked in
l10n/package.nls.*.json

# Code Coverage Output
.nyc_output/
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@
"title": "Open in Power Pages",
"when": "never"
},
{
"command": "extension.createChatView",
"title": "Create Chat View"
},
{
"command": "pacCLI.openDocumentation",
"category": "Power Platform CLI",
Expand Down
71 changes: 2 additions & 69 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import * as vscode from "vscode";
import { AppTelemetryConfigUtility } from "../common/pp-tooling-telemetry-node";
import { vscodeExtAppInsightsResourceProvider } from "../common/telemetry-generated/telemetryConfiguration";
import { ITelemetryData } from "../common/TelemetryData";
import { CliAcquisition, ICliAcquisitionContext } from "./lib/CliAcquisition";
import { CliAcquisition } from "./lib/CliAcquisition";
import { PacTerminal } from "./lib/PacTerminal";
import { PortalWebView } from "./PortalWebView";
import { ITelemetry } from "../common/OneDSLoggerTelemetry/telemetry/ITelemetry";

import {
LanguageClient,
Expand Down Expand Up @@ -46,6 +45,7 @@ import { AadIdKey, EnvIdKey, TenantIdKey } from "../common/OneDSLoggerTelemetry/
import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/constants";
import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient";
import { getECSOrgLocationValue } from "../common/utilities/Utils";
import { CliAcquisitionContext } from "./lib/CliAcquisitionContext";
import { PreviewSite } from "./runtime-site-preview/PreviewSite";

let client: LanguageClient;
Expand Down Expand Up @@ -493,70 +493,3 @@ function showNotificationForCopilot(telemetry: TelemetryReporter, telemetryData:
}

}

// allow for DI without direct reference to vscode's d.ts file: that definintions file is being generated at VS Code runtime
class CliAcquisitionContext implements ICliAcquisitionContext {
public constructor(
private readonly _context: vscode.ExtensionContext,
private readonly _telemetry: ITelemetry
) { }

public get extensionPath(): string {
return this._context.extensionPath;
}
public get globalStorageLocalPath(): string {
return this._context.globalStorageUri.fsPath;
}
public get telemetry(): ITelemetry {
return this._telemetry;
}

showInformationMessage(message: string, ...items: string[]): void {
vscode.window.showInformationMessage(message, ...items);
}

showErrorMessage(message: string, ...items: string[]): void {
vscode.window.showErrorMessage(message, ...items);
}

showCliPreparingMessage(version: string): void {
vscode.window.showInformationMessage(
vscode.l10n.t({
message: "Preparing pac CLI (v{0})...",
args: [version],
comment: ["{0} represents the version number"]
})
);
}

showCliReadyMessage(): void {
vscode.window.showInformationMessage(
vscode.l10n.t('The pac CLI is ready for use in your VS Code terminal!'));
}

showCliInstallFailedError(err: string): void {
vscode.window.showErrorMessage(
vscode.l10n.t({
message: "Cannot install pac CLI: {0}",
args: [err],
comment: ["{0} represents the error message returned from the exception"]
})
);
}

showGeneratorInstallingMessage(version: string): void {
vscode.window.showInformationMessage(
vscode.l10n.t({
message: "Installing Power Pages generator(v{0})...",
args: [version],
comment: ["{0} represents the version number"]
}))
}

locDotnetNotInstalledOrInsufficient(): string {
return vscode.l10n.t({
message: "dotnet sdk 6.0 or greater must be installed",
comment: ["Do not translate 'dotnet' or 'sdk'"]
});
}
}
17 changes: 1 addition & 16 deletions src/client/lib/CliAcquisition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,17 @@ import * as fs from 'fs-extra';
import * as glob from 'glob';
import * as os from 'os';
import { Extract } from 'unzip-stream'
import { ITelemetry } from '../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';
import find from 'find-process';
import { spawnSync } from 'child_process';
import commandExists from 'command-exists';
import { oneDSLoggerWrapper } from '../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper';

// allow for DI without direct reference to vscode's d.ts file: that definintions file is being generated at VS Code runtime
export interface ICliAcquisitionContext {
readonly extensionPath: string;
readonly globalStorageLocalPath: string;
readonly telemetry: ITelemetry;
showInformationMessage(message: string, ...items: string[]): void;
showErrorMessage(message: string, ...items: string[]): void;
showCliPreparingMessage(version: string): void;
showCliReadyMessage(): void;
showCliInstallFailedError(err: string): void;
locDotnetNotInstalledOrInsufficient(): string;
}
import { ICliAcquisitionContext } from './CliAcquisitionContext';

export interface IDisposable {
dispose(): void;
}

export class CliAcquisition implements IDisposable {

private readonly _context: ICliAcquisitionContext;
private readonly _cliPath: string;
private readonly _cliVersion: string;
Expand Down Expand Up @@ -241,4 +227,3 @@ export class CliAcquisition implements IDisposable {
}
}
}

86 changes: 86 additions & 0 deletions src/client/lib/CliAcquisitionContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from 'vscode';
import { ITelemetry } from '../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';

export interface ICliAcquisitionContext {
readonly extensionPath: string;
readonly globalStorageLocalPath: string;
readonly telemetry: ITelemetry;
showInformationMessage(message: string, ...items: string[]): void;
showErrorMessage(message: string, ...items: string[]): void;
showCliPreparingMessage(version: string): void;
showCliReadyMessage(): void;
showCliInstallFailedError(err: string): void;
locDotnetNotInstalledOrInsufficient(): string;
}

// allow for DI without direct reference to vscode's d.ts file: that definintions file is being generated at VS Code runtime
export class CliAcquisitionContext implements ICliAcquisitionContext {
public constructor(
private readonly _context: vscode.ExtensionContext,
private readonly _telemetry: ITelemetry
) { }

public get extensionPath(): string {
return this._context.extensionPath;
}
public get globalStorageLocalPath(): string {
return this._context.globalStorageUri.fsPath;
}
public get telemetry(): ITelemetry {
return this._telemetry;
}

showInformationMessage(message: string, ...items: string[]): void {
vscode.window.showInformationMessage(message, ...items);
}

showErrorMessage(message: string, ...items: string[]): void {
vscode.window.showErrorMessage(message, ...items);
}

showCliPreparingMessage(version: string): void {
vscode.window.showInformationMessage(
vscode.l10n.t({
message: "Preparing pac CLI (v{0})...",
args: [version],
comment: ["{0} represents the version number"]
})
);
}

showCliReadyMessage(): void {
vscode.window.showInformationMessage(
vscode.l10n.t('The pac CLI is ready for use in your VS Code terminal!'));
}

showCliInstallFailedError(err: string): void {
vscode.window.showErrorMessage(
vscode.l10n.t({
message: "Cannot install pac CLI: {0}",
args: [err],
comment: ["{0} represents the error message returned from the exception"]
})
);
}

showGeneratorInstallingMessage(version: string): void {
vscode.window.showInformationMessage(
vscode.l10n.t({
message: "Installing Power Pages generator(v{0})...",
args: [version],
comment: ["{0} represents the version number"]
}))
}

locDotnetNotInstalledOrInsufficient(): string {
return vscode.l10n.t({
message: "dotnet sdk 6.0 or greater must be installed",
comment: ["Do not translate 'dotnet' or 'sdk'"]
});
}
}
2 changes: 1 addition & 1 deletion src/client/lib/GeneratorAcquisition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { PORTAL_YEOMAN_GENERATOR_PACKAGE_NAME, PORTAL_YEOMAN_GENERATOR_PACKAGE_TARBALL_NAME } from '../../common/constants';
import { ICliAcquisitionContext } from './CliAcquisition';
import { ICliAcquisitionContext } from './CliAcquisitionContext';
import { glob } from 'glob';
import commandExists from 'command-exists';
import { oneDSLoggerWrapper } from '../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper';
Expand Down
3 changes: 2 additions & 1 deletion src/client/test/Integration/CliAcquisition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import * as fs from 'fs-extra';
import * as path from 'path';
import { CliAcquisition, ICliAcquisitionContext } from '../../lib/CliAcquisition';
import { CliAcquisition } from '../../lib/CliAcquisition';
import { ICliAcquisitionContext } from '../../lib/CliAcquisitionContext';
import { expect } from 'chai';
import { ITelemetry } from '../../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';
import { NoopTelemetryInstance } from '../../telemetry/NoopTelemetry';
Expand Down
125 changes: 125 additions & 0 deletions src/client/test/Integration/CliAcquisitionContext.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from 'vscode';
import { ITelemetry } from '../../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';
import { CliAcquisitionContext } from '../../lib/CliAcquisitionContext';
import { expect } from 'chai';
import sinon from 'sinon';

describe('CliAcquisitionContext', () => {
let context: vscode.ExtensionContext;
let telemetry: ITelemetry;
let showInformationMessageSpy: sinon.SinonSpy;
let showErrorMessageSpy: sinon.SinonSpy;

beforeEach(() => {
context = {
extensionPath: 'testExtensionPath',
globalStorageUri: {
fsPath: 'testGlobalStorageUri'
}
} as vscode.ExtensionContext;

telemetry = {} as ITelemetry;

showInformationMessageSpy = sinon.spy(vscode.window, "showInformationMessage");
showErrorMessageSpy = sinon.spy(vscode.window, "showErrorMessage");
});

afterEach(() => {
showInformationMessageSpy.restore();
showErrorMessageSpy.restore();
});

it('should return the extension path', () => {
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

expect(cliAcquisitionContext.extensionPath).to.equal('testExtensionPath');
});

it('should return the global storage local path', () => {
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

expect(cliAcquisitionContext.globalStorageLocalPath).to.equal('testGlobalStorageUri');
});

it('should return the telemetry', () => {
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

expect(cliAcquisitionContext.telemetry).to.equal(telemetry);
});

it('should show information message', () => {
const message = 'testMessage';
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showInformationMessage(message);

const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args;

expect(showInformationMessageArgs[0]).eq("testMessage");
});

it('should show error message', () => {
const message = 'testMessage';
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showErrorMessage(message);

const showErrorMessageArgs = showErrorMessageSpy.getCalls()[0].args;

expect(showErrorMessageArgs[0]).eq("testMessage");
});

it('should show cli preparing message', () => {
const version = 'testVersion';
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showCliPreparingMessage(version);

const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args;

expect(showInformationMessageArgs[0]).eq("Preparing pac CLI (vtestVersion)...");
});

it('should show cli ready message', () => {
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showCliReadyMessage();

const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args;

expect(showInformationMessageArgs[0]).eq("The pac CLI is ready for use in your VS Code terminal!");
});

it('should show cli install failed error', () => {
const err = 'testError';
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showCliInstallFailedError(err);

const showErrorMessageArgs = showErrorMessageSpy.getCalls()[0].args;

expect(showErrorMessageArgs[0]).eq("Cannot install pac CLI: testError");
});

it('should show generator installing message', () => {
const version = 'testVersion';
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

cliAcquisitionContext.showGeneratorInstallingMessage(version);

const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args;

expect(showInformationMessageArgs[0]).eq("Installing Power Pages generator(vtestVersion)...");
});

it('should return loc dotnet not installed or insufficient', () => {
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry);

expect(cliAcquisitionContext.locDotnetNotInstalledOrInsufficient()).eq("dotnet sdk 6.0 or greater must be installed");
});
});
Loading

0 comments on commit a83ce18

Please sign in to comment.