Skip to content

Commit

Permalink
remove jquery, improve open in workspace button, improved initial tar…
Browse files Browse the repository at this point in the history
…get folder (#244)

* bugs_fixes

* update version

* Update .nycrc.json

* cr fixes

* Update tslint.yml

* update tests

* Update yeomanui.ts

* update test
  • Loading branch information
slavik-lvovsky authored Apr 30, 2020
1 parent c8eaca9 commit 3949a54
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 21 deletions.
8 changes: 4 additions & 4 deletions backend/.nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"temp-dir": "./reports/.nyc_output",
"report-dir": "./reports/coverage",
"check-coverage": true,
"branches": 83.7,
"lines": 88,
"functions": 81.9,
"statements": 87.7
"branches": 81.8,
"lines": 87.3,
"functions": 81.3,
"statements": 86.8
}
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache 2.0",
"description": "Provide rich user experience for Yeoman generators using VSCode extension or the browser",
"repository": "https://github.com/SAP/yeoman-ui",
"version": "0.0.78",
"version": "0.0.79",
"engines": {
"vscode": "^1.39.2"
},
Expand Down
7 changes: 6 additions & 1 deletion backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ export class YeomanUIPanel {
this.rpc = rpc;
const outputChannel: YouiLog = new OutputChannelLog(this.messages.channel_name);
const vscodeYouiEvents: YouiEvents = new VSCodeYouiEvents(this.rpc, this.panel, this.genFilter);
this.yeomanui = new YeomanUI(this.rpc, vscodeYouiEvents, outputChannel, this.logger, {genFilter: this.genFilter, messages: this.messages});
this.yeomanui = new YeomanUI(this.rpc,
vscodeYouiEvents,
outputChannel,
this.logger,
{genFilter: this.genFilter, messages: this.messages},
_.get(vscode, "workspace.workspaceFolders[0].uri.fsPath"));
this.yeomanui.registerCustomQuestionEventHandler("file-browser", "getFilePath", this.showOpenFileDialog.bind(this));
this.yeomanui.registerCustomQuestionEventHandler("folder-browser", "getPath", this.showOpenFolderDialog.bind(this));

Expand Down
8 changes: 4 additions & 4 deletions backend/src/vscode-youi-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class VSCodeYouiEvents implements YouiEvents {
this.genFilter = genFilter;
}

public doGeneratorDone(success: boolean, message: string, targetPath: string = ""): void {
public doGeneratorDone(success: boolean, message: string, targetFolderPath?: string): void {
this.doClose();
this.showDoneMessage(success, message, targetPath);
this.showDoneMessage(success, message, targetFolderPath);
}

public doGeneratorInstall(): void {
Expand Down Expand Up @@ -52,15 +52,15 @@ export class VSCodeYouiEvents implements YouiEvents {
});
}

private showDoneMessage(success: boolean, errorMmessage: string, targetPath: string): Thenable<any> {
private showDoneMessage(success: boolean, errorMmessage: string, targetFolderPath?: string): Thenable<any> {
VSCodeYouiEvents.installing = false;

if (success) {
const addToWorkspace: string = "Add to Workspace";
const openInNewWorkspace: any = "Open in New Workspace";
const items: string[] = [];

const targetFolderUri: vscode.Uri = vscode.Uri.file(targetPath);
const targetFolderUri: vscode.Uri = vscode.Uri.file(targetFolderPath);

if (this.genFilter.type !== GeneratorType.module) {
const workspacePath = _.get(vscode, "workspace.workspaceFolders[0].uri.fsPath");
Expand Down
39 changes: 33 additions & 6 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { GeneratorType, GeneratorFilter } from "./filter";
import { IChildLogger } from "@vscode-logging/logger";
import {IPrompt} from "@sap-devx/yeoman-ui-types";


export interface IQuestionsPrompt extends IPrompt{
questions: any[];
}
Expand Down Expand Up @@ -111,6 +110,24 @@ export class YeomanUI {
return promise;
}

private async getChildDirectories(folderPath: string) {
const childDirs: string[] = [];
const result = {targetFolderPath: folderPath, childDirs};

try {
for (const file of await fsextra.readdir(folderPath)) {
const resourcePath: string = path.join(folderPath, file);
if ((await fsextra.stat(resourcePath)).isDirectory()) {
result.childDirs.push(resourcePath);
}
}
} catch (error) {
result.childDirs = [];
}

return result;
}

public async runGenerator(generatorName: string) {
this.generatorName = generatorName;
// TODO: should create and set target dir only after user has selected a generator;
Expand All @@ -119,6 +136,7 @@ export class YeomanUI {
try {
const targetFolder = this.getCwd();
await fsextra.mkdirs(targetFolder);
const dirsBefore = await this.getChildDirectories(targetFolder);
const env: Environment = Environment.createEnv(undefined, {}, this.youiAdapter);
const meta: Environment.GeneratorMeta = this.getGenMetadata(generatorName);
// TODO: support sub-generators
Expand All @@ -141,9 +159,10 @@ export class YeomanUI {
https://yeoman.github.io/generator/Generator.html#run
... but .d.ts hasn't been updated for a while:
https://www.npmjs.com/package/@types/yeoman-generator */
this.gen.run((err) => {
this.gen.run(async (err) => {
if (!err) {
this.onGeneratorSuccess(generatorName, this.gen.destinationRoot());
const dirsAfter = await this.getChildDirectories(this.gen.destinationRoot());
this.onGeneratorSuccess(generatorName, dirsBefore, dirsAfter);
}
});
this.gen.on('error', (error: any) => {
Expand Down Expand Up @@ -253,10 +272,18 @@ export class YeomanUI {
return (firstQuestionName ? _.startCase(firstQuestionName) : `Step ${this.promptCount}`);
}

private onGeneratorSuccess(generatorName: string, destinationRoot: string) {
private onGeneratorSuccess(generatorName: string, reourcesBeforeGen?: any, resourcesAfterGen?: any) {
let targetFolderPath: string = _.get(resourcesAfterGen, "targetFolderPath");
if (_.get(reourcesBeforeGen, "targetFolderPath") === targetFolderPath) {
const newDirs: string[] = _.difference(_.get(resourcesAfterGen, "childDirs"), _.get(reourcesBeforeGen, "childDirs"));
if (_.size(newDirs) === 1) {
targetFolderPath = newDirs[0];
}
}

const message = `The '${generatorName}' project has been generated.`;
this.logger.debug("done running yeomanui! " + message + ` You can find it at ${destinationRoot}`);
this.youiEvents.doGeneratorDone(true, message, destinationRoot);
this.logger.debug("done running yeomanui! " + message + ` You can find it at ${targetFolderPath}`);
this.youiEvents.doGeneratorDone(true, message, targetFolderPath);
}

private async onGeneratorFailure(generatorName: string, error: any) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/youi-events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface YouiEvents {
doGeneratorDone(success: boolean, message: string, targetPath?: string): void;
doGeneratorDone(success: boolean, message: string, targetFolderPath?: string): void;
doGeneratorInstall(): void;
}
14 changes: 12 additions & 2 deletions backend/tests/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,18 @@ describe('yeomanui unit test', () => {
doGeneratorDoneSpy.restore();
});

it("onGeneratorSuccess", () => {
yeomanUi["onGeneratorSuccess"]("testGenName", "testDestinationRoot");
it("onGeneratorSuccess - one dir was created", () => {
const beforeGen = {targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1"]};
const afterGen = {targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1", "dirpath2"]};
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
// tslint:disable-next-line: no-unused-expression
expect(doGeneratorDoneSpy.calledWith(true, "The 'testGenName' project has been generated.", "dirpath2")).to.be.true;
});

it("onGeneratorSuccess - two dirs were created", () => {
const beforeGen = {targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1"]};
const afterGen = {targetFolderPath: "testDestinationRoot", childDirs: ["dirparh1", "dirpath2", "dirpath3"]};
yeomanUi["onGeneratorSuccess"]("testGenName", beforeGen, afterGen);
// tslint:disable-next-line: no-unused-expression
expect(doGeneratorDoneSpy.calledWith(true, "The 'testGenName' project has been generated.", "testDestinationRoot")).to.be.true;
});
Expand Down
2 changes: 1 addition & 1 deletion backend/tslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ linterOptions:
exclude:
# Not our own sources
- typings/**
- out/**
- out/**
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@sap-devx/inquirer-gui-login-plugin": "0.0.3",
"@sap-devx/inquirer-gui-tiles-plugin": "0.0.8",
"core-js": "2.6.6",
"jquery": "3.4.1",
"lodash": "^4.17.15",
"material-design-icons-iconfont": "^5.0.1",
"vue": "^2.6.10",
Expand Down

0 comments on commit 3949a54

Please sign in to comment.