Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generate): implement UI for ng generate #75

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f595733
feat(generate): implement UI for ng generate
sumitparakh Nov 26, 2018
352c61d
Merge branch 'master' of https://github.com/sumitparakh/klingon into …
sumitparakh Nov 26, 2018
d49d41d
feat(generate): implement UI for ng generate
sumitparakh Nov 27, 2018
23a8891
feat(generate): implement UI for ng generate
sumitparakh Nov 28, 2018
ee095b2
Merge branch 'master' of https://github.com/sumitparakh/klingon into …
sumitparakh Nov 28, 2018
bc51c4c
feat(generate): generate multiple components
sumitparakh Dec 9, 2018
603a5fa
Merge branch 'master' of https://github.com/sumitparakh/klingon into …
sumitparakh Dec 9, 2018
4a3af52
feat(generate): some refactoring
sumitparakh Dec 9, 2018
36d943d
Merge branch 'master' of https://github.com/sumitparakh/klingon into …
sumitparakh Dec 14, 2018
ae6b980
feat(generate): do not enable generate tab while running in dry mode
sumitparakh Dec 14, 2018
f793bd7
Merge branch 'master' of https://github.com/angular-klingon/klingon i…
sumitparakh Dec 14, 2018
68f2fb8
feat(generate): classes generate support added
sumitparakh Dec 16, 2018
f453263
feat(generate): generate feature added for directives
sumitparakh Dec 17, 2018
de08554
feat(ui): generate feature for enum added
sumitparakh Dec 17, 2018
df0b77c
feat(ui): interface generate support added
sumitparakh Dec 17, 2018
faa18c1
feat(ui): module generate feature added
sumitparakh Dec 17, 2018
dcec136
feat(ui): pipe and service generate feature done
sumitparakh Dec 17, 2018
096b361
feat(generate): ng components
sumitparakh Feb 2, 2019
d22f41d
Merge branch 'master' of https://github.com/angular-klingon/klingon i…
sumitparakh Feb 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
selector: 'app-drop-down',
template: `
<mat-accordion>
<mat-expansion-panel [expanded]="open" (opened)="open=true" (closed)="open=false">
<mat-expansion-panel [expanded]="open" [disabled]="disabled" (opened)="open=true" (closed)="open=false">
<mat-expansion-panel-header>
<mat-panel-title>
<ng-content select="mat-icon"></ng-content>
Expand Down Expand Up @@ -70,9 +70,13 @@ import {
]
})
export class DropDownComponent implements OnInit {

@Input()
open: boolean = false;

@Input()
disabled: boolean = false;

ngOnInit() {
}

Expand Down
3 changes: 2 additions & 1 deletion packages/klingon-ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
<ng-template mat-tab-label>New</ng-template>
<app-cli-create #appCli (onStdOut)="onSuccess($event)" (onStdErr)="onError($event)"></app-cli-create>
</mat-tab>
<mat-tab [disabled]="true">
<mat-tab [disabled]="!klingon.generate">
<ng-template mat-tab-label>Generate</ng-template>
<app-cli-generate (onStdOut)="onSuccess($event)" (onStdErr)="onError($event)"></app-cli-generate>
</mat-tab>
<mat-tab>
<ng-template mat-tab-label>Serve</ng-template>
Expand Down
33 changes: 29 additions & 4 deletions packages/klingon-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { FormGroup, FormControl, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { OnInit } from '@angular/core/src/metadata/lifecycle_hooks';
import { CliCreateComponent } from './cli/create/create.component';
import { CliService, CommandResult } from './cli/cli.service';
import { Subject } from 'rxjs';

@Component({
selector: 'app-snack-bar-error',
Expand All @@ -26,7 +28,7 @@ import { CliCreateComponent } from './cli/create/create.component';
template:
'<mat-icon>error</mat-icon><span>An error has occured. Check the logs tab.</span>'
})
export class SnackBarErrorComponent {}
export class SnackBarErrorComponent { }

@Component({
selector: 'app-snack-bar-success',
Expand All @@ -50,7 +52,7 @@ export class SnackBarErrorComponent {}
template:
'<mat-icon>verified_user</mat-icon><span>Command executed successfully.</span>'
})
export class SnackBarSuccessComponent {}
export class SnackBarSuccessComponent { }

@Component({
selector: 'app-root',
Expand All @@ -60,19 +62,42 @@ export class SnackBarSuccessComponent {}
export class AppComponent implements OnInit {
selectedIndex = 0;

klingon = { generate: false };

@ViewChild('appCli') appCli: CliCreateComponent;

constructor(
public snackBarError: MatSnackBar,
public snackBarSuccess: MatSnackBar
) {}
public snackBarSuccess: MatSnackBar,
private cliService: CliService
) { }

ngOnInit() {
this.selectedIndex = parseInt(
localStorage.getItem('ui.selectedIndex') || '0',
10
);
localStorage.setItem('ui.selectedIndex', `${this.selectedIndex}`);

this.subscribeToNgCreate();
}

subscribeToNgCreate() {
this.cliService.onNgCreate.subscribe((data: Subject<CommandResult>) => {
data.subscribe((response: any) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try and use a flatMap here, to avoid the double subscription.

Copy link
Member Author

@sumitparakh sumitparakh Dec 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manekinekko Added. And multiple component generate feature is also added.

/**
* exit event of ng command returns exit code (0/1). So if it returns 0, means ng command executed successfully. Only then
* we enable generate tab.
*/
if (response.exit === 0) {
manekinekko marked this conversation as resolved.
Show resolved Hide resolved
console.log('onNgCreate event fired', response);
this.klingon.generate = true;
}
});
});
}

onNgCreateEvent(response: any) {
}

storeIndex(index: number) {
Expand Down
4 changes: 3 additions & 1 deletion packages/klingon-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { LogComponent } from './_shared/log/log.component';
import { MatExpansionModule } from '@angular/material/expansion';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { CliGenerateComponent } from './cli/generate/generate.component';

@NgModule({
declarations: [
Expand All @@ -36,7 +37,8 @@ import { environment } from '../environments/environment';
CliTestComponent,
LogComponent,
SnackBarSuccessComponent,
SnackBarErrorComponent
SnackBarErrorComponent,
CliGenerateComponent
],
entryComponents: [SnackBarSuccessComponent, SnackBarErrorComponent],
imports: [
Expand Down
24 changes: 23 additions & 1 deletion packages/klingon-ui/src/app/cli/cli.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, Output, EventEmitter } from '@angular/core';
import { Subject } from 'rxjs';
import { environment } from '../../environments/environment';

Expand All @@ -14,6 +14,8 @@ export class CliService {
ws: WebSocket;
isConnectionOn;

@Output() onNgCreate: EventEmitter<Subject<CommandResult>> = new EventEmitter<Subject<CommandResult>>();

constructor() {
this.response$ = new Subject();
this.ws = new WebSocket(`ws://` + environment.host + `:` + environment.port + `/cli`);
Expand All @@ -40,6 +42,7 @@ export class CliService {
key !== 'app-name' &&
key !== 'root-dir' &&
key !== 'dir' &&
key !== 'component-name' &&
key !== 'app'
)
.map(key => `--${key}=${values[key]}`)
Expand All @@ -57,10 +60,29 @@ export class CliService {
runNgCommand(stdin, dir = undefined) {
if (this.isConnectionOn) {
this._send(stdin, dir);
this.detectEvents(stdin, this.response$);
}
return this.response$;
}

/**
* Detect ng operations such as new, serve, build, generate etc.
* @param stdin string
*/
private detectEvents(stdin: string, response: Subject<CommandResult>) {
if (!stdin) {
return;
}

const commandArray = stdin.split(' ');

if (commandArray.length > 1) {
if (commandArray[0] === 'new') {
this.onNgCreate.emit(response);
}
}
}

_send(stdin, dir) {
console.log(stdin);

Expand Down
25 changes: 24 additions & 1 deletion packages/klingon-ui/src/app/cli/flags/flags.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class FlagsComponent implements OnInit {
CREATE: 0,
SERVE: 1,
BUILD: 2,
TEST: 3
TEST: 3,
GENERATE: 4
};

@Output()
Expand Down Expand Up @@ -138,6 +139,28 @@ export class FlagsComponent implements OnInit {
sourcemap: new FormControl(true),
watch: new FormControl(false)
});
} else if (flag === FlagsComponent.Flags.GENERATE) {
return new FormGroup({
'app-name': new FormControl('', Validators.required),
'root-dir': new FormControl(lastUsedRootDirectory),
'component-name': new FormControl(''),
'change-detection': new FormControl(''),
'dryRun': new FormControl(false),
'entry-component': new FormControl(false),
'export': new FormControl(false),
'flat': new FormControl(false),
'force': new FormControl(false),
'module': new FormControl(''),
'prefix': new FormControl(''),
'project': new FormControl(''),
'selector': new FormControl(''),
'styleext': new FormControl(''),
'inline-style': new FormControl(false),
'inline-template': new FormControl(false),
'lint-fix': new FormControl(false),
'skip-import': new FormControl(false),
'spec': new FormControl(false)
});
}
}
}
Empty file.
Loading