diff --git a/backend/.nycrc.json b/backend/.nycrc.json index 51aa60a5..ea3e725c 100644 --- a/backend/.nycrc.json +++ b/backend/.nycrc.json @@ -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 } diff --git a/backend/package.json b/backend/package.json index 579bb061..769e72e9 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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" }, diff --git a/backend/src/extension.ts b/backend/src/extension.ts index 88c8c253..8c89e45c 100644 --- a/backend/src/extension.ts +++ b/backend/src/extension.ts @@ -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)); diff --git a/backend/src/vscode-youi-events.ts b/backend/src/vscode-youi-events.ts index 6ad9729c..68e08d27 100644 --- a/backend/src/vscode-youi-events.ts +++ b/backend/src/vscode-youi-events.ts @@ -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 { @@ -52,7 +52,7 @@ export class VSCodeYouiEvents implements YouiEvents { }); } - private showDoneMessage(success: boolean, errorMmessage: string, targetPath: string): Thenable { + private showDoneMessage(success: boolean, errorMmessage: string, targetFolderPath?: string): Thenable { VSCodeYouiEvents.installing = false; if (success) { @@ -60,7 +60,7 @@ export class VSCodeYouiEvents implements YouiEvents { 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"); diff --git a/backend/src/yeomanui.ts b/backend/src/yeomanui.ts index fa5248cf..a3037e89 100644 --- a/backend/src/yeomanui.ts +++ b/backend/src/yeomanui.ts @@ -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[]; } @@ -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; @@ -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 @@ -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) => { @@ -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) { diff --git a/backend/src/youi-events.ts b/backend/src/youi-events.ts index df469d00..1c1c8fa9 100644 --- a/backend/src/youi-events.ts +++ b/backend/src/youi-events.ts @@ -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; } diff --git a/backend/tests/yeomanui.spec.ts b/backend/tests/yeomanui.spec.ts index 547e97bd..55c3597f 100644 --- a/backend/tests/yeomanui.spec.ts +++ b/backend/tests/yeomanui.spec.ts @@ -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; }); diff --git a/backend/tslint.yml b/backend/tslint.yml index ecf4496d..49c3d693 100644 --- a/backend/tslint.yml +++ b/backend/tslint.yml @@ -40,4 +40,4 @@ linterOptions: exclude: # Not our own sources - typings/** - - out/** \ No newline at end of file + - out/** diff --git a/frontend/package.json b/frontend/package.json index 15d1d32a..8d0c8459 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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",