Skip to content

Commit

Permalink
simplify generator on install logic (#344)
Browse files Browse the repository at this point in the history
* simplify on generator install step

* Update .nycrc.json
  • Loading branch information
slavik-lvovsky authored Aug 17, 2020
1 parent 5e57db1 commit 6d0a712
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 47 deletions.
4 changes: 2 additions & 2 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": 84,
"branches": 83,
"lines": 89,
"functions": 85,
"functions": 84,
"statements": 89
}
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yeoman-ui",
"version": "1.1.10",
"version": "1.1.11",
"displayName": "Application Wizard",
"publisher": "SAPOS",
"author": {
Expand Down
24 changes: 6 additions & 18 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,13 @@ export class YeomanUI {
setPromptsCallback(this.setPromptList.bind(this));
}

this.setGenInstall(gen, generatorName);
this.promptCount = 0;
this.gen = (gen as Generator);
this.gen.destinationRoot(targetFolder);
// notifies ui wether generator is in writing state
this.setGenInWriting(this.gen);
// handles generator install step if exists
this.onGenInstall(this.gen);
// handles generator errors
this.handleErrors(env, this.gen, generatorName);

Expand Down Expand Up @@ -359,23 +360,10 @@ export class YeomanUI {
this.youiEvents.doGeneratorDone(false, errorMessage);
}

private setGenInstall(gen: any, generatorName: string) {
const originalPrototype = Object.getPrototypeOf(gen);
const originalGenInstall = _.get(originalPrototype, "install");
if (originalGenInstall && !originalPrototype._uiInstall) {
originalPrototype._uiInstall = true;
originalPrototype.install = async () => {
try {
this.youiEvents.doGeneratorInstall();
await originalGenInstall.call(gen);
} catch (error) {
this.onGeneratorFailure(generatorName, error);
} finally {
originalPrototype.install = originalGenInstall;
delete originalPrototype._uiInstall;
}
};
}
private onGenInstall(gen: any) {
gen.on("method:install", () => {
this.youiEvents.doGeneratorInstall();
});
}

private getErrorInfo(error: any = "") {
Expand Down
34 changes: 9 additions & 25 deletions backend/tests/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,31 +595,15 @@ describe('yeomanui unit test', () => {
});
});

describe("setGenInstall", () => {
it("install method not exist", () => {
const yeomanUiInstance: YeomanUI = new YeomanUI(rpc, youiEvents, outputChannel, testLogger, GeneratorFilter.create());
const gen: any = {};
yeomanUiInstance["setGenInstall"](gen, "testgen");
expect(gen.__proto__.install).to.be.undefined;
});

it("install method exists", () => {
const yeomanUiInstance: YeomanUI = new YeomanUI(rpc, youiEvents, outputChannel, testLogger, GeneratorFilter.create());
class GenTest {
public install(): any{
return "original_install";
}
}
const gen: any = new GenTest();
expect(gen.__proto__.install).to.be.not.undefined;

const installSpy = sandbox.spy(youiEvents,"doGeneratorInstall");
yeomanUiInstance["setGenInstall"](gen, "testgen");
gen.install();
expect(installSpy.called).to.be.true;
installSpy.restore();
});
});
it("onGenInstall", () => {
const yeomanUiInstance: YeomanUI = new YeomanUI(rpc, youiEvents, outputChannel, testLogger, GeneratorFilter.create());
const gen: any = {on: () => {}};
const genMock = sandbox.mock(gen);

genMock.expects("on").withArgs("method:install");
yeomanUiInstance["onGenInstall"](gen);
genMock.verify();
});

describe("showPrompt", () => {
it("returns answers", async () => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@
:disabled="promptIndex<1 || isReplaying"
@click="back"
v-show="promptIndex > 0"
style="min-width:90px;"
>
<v-icon left>mdi-chevron-left</v-icon>Back
</v-btn>
<v-btn id="next" :disabled="!stepValidated" @click="next" style="min-width:100px;">
<v-btn id="next" :disabled="!stepValidated" @click="next" style="min-width:90px;">
{{nextButtonText}}
<v-icon right v-if="nextButtonText !== `Finish`">mdi-chevron-right</v-icon>
</v-btn>
Expand Down

0 comments on commit 6d0a712

Please sign in to comment.