Skip to content

Commit

Permalink
refactor: activation time optimization + more (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-gilin authored Apr 11, 2024
1 parent 5d190f2 commit c465d0e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 93 deletions.
12 changes: 2 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,11 @@
"name": "frontend unit tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"./node_modules/@vue/cli-service/bin/vue-cli-service.js",
"test:unit",
"--runInBand"
],
"runtimeArgs": ["--inspect-brk", "./node_modules/jest/bin/jest.js", "-w 1", "--colors"],
"cwd": "${workspaceFolder}/packages/frontend",
"protocol": "inspector",
"disableOptimisticBPs": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceFolder}/packages/frontend/src/**/*.js"],
"port": 9229
"outFiles": ["${workspaceFolder}/packages/frontend/src/**/*.js"]
}
]
}
8 changes: 3 additions & 5 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"coverage": "nyc mocha",
"coverage:copy": "shx mkdir -p ../../coverage && shx cp -u ./coverage/lcov.info ../../coverage/lcov_backend.info",
"frontend:copy": "npm-run-all clean:frontend && shx cp -r ../frontend/dist/. ./dist/media/",
"package": "vsce package --yarn --allow-star-activation",
"package": "vsce package --yarn",
"test": "mocha",
"webpack": "webpack --mode development",
"webpack-dev:watch": "webpack --mode development --watch",
Expand Down Expand Up @@ -167,9 +167,7 @@
]
}
},
"activationEvents": [
"onStartupFinished"
],
"activationEvents": [],
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
Expand Down Expand Up @@ -220,7 +218,7 @@
"string-replace-loader": "3.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^9.1.1",
"vsce": "2.15.0",
"@vscode/vsce": "2.24.0",
"webpack": "^5.90.1",
"webpack-cli": "^5.1.4",
"ws": "8.2.3"
Expand Down
30 changes: 17 additions & 13 deletions packages/backend/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExtensionContext, window, WebviewPanel } from "vscode";
import { createExtensionLoggerAndSubscribeToLogSettingsChanges, getLogger } from "./logger/logger-wrapper";
import { createExtensionLoggerAndSubscribeToLogSettingsChanges } from "./logger/logger-wrapper";
import { AnalyticsWrapper } from "./usage-report/usage-analytics-wrapper";
import * as shellJsWorkarounds from "./utils/shellJsWorkarounds";
import { ExtCommands } from "./extCommands";
Expand All @@ -17,25 +17,29 @@ export function activate(context: ExtensionContext) {

try {
createExtensionLoggerAndSubscribeToLogSettingsChanges(context);
AnalyticsWrapper.createTracker(getLogger());
AnalyticsWrapper.createTracker(context);
} catch (error) {
console.error("Extension activation failed.", error.message);
return;
}

extCommands.registerAndSubscribeCommands();

window.registerWebviewPanelSerializer("yeomanui", {
async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) {
(await extCommands.getYeomanUIPanel()).setWebviewPanel(webViewPanel, state);
},
});

window.registerWebviewPanelSerializer("exploreGens", {
async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) {
(await extCommands.getExploreGensPanel()).setWebviewPanel(webViewPanel, state);
},
});
context.subscriptions.push(
window.registerWebviewPanelSerializer("yeomanui", {
async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) {
(await extCommands.getYeomanUIPanel()).setWebviewPanel(webViewPanel, state);
},
}),
);

context.subscriptions.push(
window.registerWebviewPanelSerializer("exploreGens", {
async deserializeWebviewPanel(webViewPanel: WebviewPanel, state?: unknown) {
(await extCommands.getExploreGensPanel()).setWebviewPanel(webViewPanel, state);
},
}),
);
}

export function deactivate() {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/panels/AbstractWebviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export abstract class AbstractWebviewPanel {
wizardStepName,
currentPromptCount,
numOfPromopts,
this.logger,
);
}
}
Expand Down
40 changes: 20 additions & 20 deletions packages/backend/src/usage-report/usage-analytics-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ExtensionContext } from "vscode";
import { initTelemetrySettings, BASClientFactory, BASTelemetryClient } from "@sap/swa-for-sapbas-vsx";
import { IChildLogger } from "@vscode-logging/logger";
import { getLogger } from "../logger/logger-wrapper";
import * as path from "path";

/**
Expand All @@ -26,54 +27,54 @@ export class AnalyticsWrapper {
return BASClientFactory.getBASTelemetryClient();
}

public static createTracker(logger?: IChildLogger): void {
public static createTracker(context: ExtensionContext): void {
try {
const packageJson = require(path.join(__dirname, "..", "package.json"));
const packageJson = require(path.join(context.extensionPath, "package.json"));
const vscodeExtentionFullName = `${packageJson.publisher}.${packageJson.name}`;
initTelemetrySettings(vscodeExtentionFullName, packageJson.version);
logger?.info(`SAP Web Analytics tracker was created for ${vscodeExtentionFullName}`);
getLogger().info(`SAP Web Analytics tracker was created for ${vscodeExtentionFullName}`);
} catch (error) {
logger?.error(error);
getLogger().error(error);
}
}

private static report(opt: { eventName: string; properties?: any; logger?: IChildLogger }): void {
private static report(opt: { eventName: string; properties?: any }): void {
// We want to report only if we are not in Local VSCode environment
const eventName = opt.eventName;
if (process.env.LANDSCAPE_ENVIRONMENT) {
void AnalyticsWrapper.getTracker().report(opt.eventName, opt.properties);
opt.logger?.trace("SAP Web Analytics tracker was called", {
getLogger().trace("SAP Web Analytics tracker was called", {
eventName,
});
} else {
opt.logger?.trace("SAP Web Analytics tracker was not called because LANDSCAPE_ENVIRONMENT is not set", {
getLogger().trace("SAP Web Analytics tracker was not called because LANDSCAPE_ENVIRONMENT is not set", {
eventName,
});
}
}

public static updateGeneratorStarted(logger?: IChildLogger): void {
public static updateGeneratorStarted(): void {
try {
const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATION_STARTED;
AnalyticsWrapper.startTime = Date.now();
AnalyticsWrapper.report({ eventName, logger });
AnalyticsWrapper.report({ eventName });
} catch (error) {
logger?.error(error);
getLogger().error(error);
}
}

public static updateGeneratorSelected(generatorName: string, logger?: IChildLogger): void {
public static updateGeneratorSelected(generatorName: string): void {
try {
const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATOR_SELECTED;
AnalyticsWrapper.startTime = Date.now();
const properties = { generatorName };
AnalyticsWrapper.report({ eventName, properties, logger });
AnalyticsWrapper.report({ eventName, properties });
} catch (error) {
logger?.error(error);
getLogger().error(error);
}
}

public static updateGeneratorEnded(generatorName: string, logger?: IChildLogger): void {
public static updateGeneratorEnded(generatorName: string): void {
try {
const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATED_SUCCESSFULLY;
const endTime = Date.now();
Expand All @@ -83,9 +84,9 @@ export class AnalyticsWrapper {
generatorName,
generationTime: generationTimeSec.toString(),
};
AnalyticsWrapper.report({ eventName, properties, logger });
AnalyticsWrapper.report({ eventName, properties });
} catch (error) {
logger?.error(error);
getLogger().error(error);
}
}

Expand All @@ -94,7 +95,6 @@ export class AnalyticsWrapper {
wizardStepName: string,
currentStep: number,
totalNumOfSteps: number,
logger?: IChildLogger,
): void {
try {
const eventName = AnalyticsWrapper.EVENT_TYPES.PROJECT_GENERATOR_CLOSED;
Expand All @@ -104,9 +104,9 @@ export class AnalyticsWrapper {
currentStep,
totalNumOfSteps,
};
AnalyticsWrapper.report({ eventName, properties, logger });
AnalyticsWrapper.report({ eventName, properties });
} catch (error) {
logger?.error(error);
getLogger().error(error);
}
}
}
6 changes: 3 additions & 3 deletions packages/backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ export class YeomanUI {
this.resetHeaderTitle();
const generators: IQuestionsPrompt = await this.getGeneratorsPrompt();
await this._notifyGeneratorsInstall(this.uiOptions.installGens, true);
AnalyticsWrapper.updateGeneratorStarted(this.logger);
AnalyticsWrapper.updateGeneratorStarted();
const response: any = await this.rpc.invoke("showPrompt", [generators.questions, "select_generator"]);
generatorId = response.generator;
}
this.replayUtils.clear();
AnalyticsWrapper.updateGeneratorSelected(generatorId, this.logger);
AnalyticsWrapper.updateGeneratorSelected(generatorId);
await this.runGenerator(generatorId);
} catch (error) {
this.logError(error, "receiveIsWebviewReady");
Expand Down Expand Up @@ -446,7 +446,7 @@ export class YeomanUI {
const message = this.uiOptions.messages.artifact_with_name_generated(generatorName);
const generatedTemplatePath = targetFolderPath ? targetFolderPath : targetFolderPathBeforeGen;
this.logger.debug(`done running yeomanui! ${message} You can find it at ${generatedTemplatePath}`);
AnalyticsWrapper.updateGeneratorEnded(generatorName, this.logger);
AnalyticsWrapper.updateGeneratorEnded(generatorName);
this.youiEvents.doGeneratorDone(true, message, selectedWorkspace, type, targetFolderPath);
this.setInitialProcessDir();
this.flowState.resolve();
Expand Down
1 change: 0 additions & 1 deletion packages/backend/test/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe("extension unit test", () => {
describe("activate", () => {
it("commands registration", () => {
loggerWrapperMock.expects("createExtensionLoggerAndSubscribeToLogSettingsChanges");
loggerWrapperMock.expects("getLogger");
trackerWrapperMock.expects("createTracker");

const applySpy = sandbox.spy(shellJsWorkarounds, "apply");
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/test/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ describe("yeomanui unit test", () => {
targetFolderPath: "testDestinationRoot",
childDirs: ["dirparh1", "dirpath2"],
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves();
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand All @@ -1148,7 +1148,7 @@ describe("yeomanui unit test", () => {
targetFolderPath: "testDestinationRoot",
childDirs: ["dirparh1", "dirpath2", "dirpath3"],
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves();
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand All @@ -1171,7 +1171,7 @@ describe("yeomanui unit test", () => {
targetFolderPath: "testDestinationRoot",
childDirs: ["dirparh1"],
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves();
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand All @@ -1190,7 +1190,7 @@ describe("yeomanui unit test", () => {
const afterGen = {
targetFolderPath: "testDestinationRoot/generatedProject",
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("testGenName").resolves();
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand Down Expand Up @@ -1219,7 +1219,7 @@ describe("yeomanui unit test", () => {
const afterGen = {
targetFolderPath: "testDestinationRoot/generatedProject",
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("foodq:app", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("foodq:app").resolves();
yeomanUi["onGeneratorSuccess"]("foodq:app", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand All @@ -1241,7 +1241,7 @@ describe("yeomanui unit test", () => {
const afterGen = {
targetFolderPath: "testDestinationRoot/generatedProject",
};
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("fiori-generator:app", testLogger).resolves();
trackerWrapperMock.expects("updateGeneratorEnded").withArgs("fiori-generator:app").resolves();
yeomanUi["onGeneratorSuccess"]("fiori-generator:app", beforeGen, afterGen);
expect(
doGeneratorDoneSpy.calledWith(
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
collectCoverageFrom: [
"src/**/*.{js,vue}",
"!**/node_modules/**",
"!<rootDir>/src/utils/utils.js",
"!<rootDir>/src/exploregens/**",
"!<rootDir>/src/youi/main.js",
"!<rootDir>/src/plugins/**",
Expand All @@ -31,7 +30,7 @@ module.exports = {
coverageThreshold: {
global: {
branches: 91,
functions: 98,
functions: 97,
lines: 97,
statements: 97,
},
Expand Down
Loading

0 comments on commit c465d0e

Please sign in to comment.