Skip to content

Commit

Permalink
feat: add support for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Nov 9, 2018
1 parent 070e22a commit 0bfae75
Show file tree
Hide file tree
Showing 24 changed files with 748 additions and 1,777 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
src="https://img.shields.io/npm/l/@nrwl/schematics.svg"></a>
</p>


<hr>


Expand Down
55 changes: 55 additions & 0 deletions libs/feature-generate/src/lib/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ export namespace SchematicCollectionsByName {
};
}

export namespace SchematicDocs {
export type Variables = {
path: string;
collectionName: string;
name: string;
};

export type Query = {
__typename?: 'Query';
workspace: Workspace;
};

export type Workspace = {
__typename?: 'Workspace';
docs: Docs;
};

export type Docs = {
__typename?: 'Docs';
schematicDocs: SchematicDocs[];
};

export type SchematicDocs = {
__typename?: 'Doc';
id: string;
description?: string | null;
prop?: string | null;
};
}

export namespace SchematicCollections {
export type Variables = {
path: string;
Expand Down Expand Up @@ -157,6 +187,31 @@ export class SchematicCollectionsByNameGQL extends Apollo.Query<
@Injectable({
providedIn: 'root'
})
export class SchematicDocsGQL extends Apollo.Query<
SchematicDocs.Query,
SchematicDocs.Variables
> {
document: any = gql`
query SchematicDocs(
$path: String!
$collectionName: String!
$name: String!
) {
workspace(path: $path) {
docs {
schematicDocs(collectionName: $collectionName, name: $name) {
id
description
prop
}
}
}
}
`;
}
@Injectable({
providedIn: 'root'
})
export class SchematicCollectionsGQL extends Apollo.Query<
SchematicCollections.Query,
SchematicCollections.Variables
Expand Down
11 changes: 11 additions & 0 deletions libs/feature-generate/src/lib/graphql/schematic-docs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query SchematicDocs($path: String!, $collectionName: String!, $name: String!) {
workspace(path: $path) {
docs {
schematicDocs(collectionName: $collectionName, name: $name) {
id
description
prop
}
}
}
}
38 changes: 35 additions & 3 deletions libs/feature-generate/src/lib/schematic/schematic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import {
IncrementalCommandOutput,
CommandRunner,
Serializer,
CommandStatus
CommandStatus,
Settings
} from '@angular-console/utils';
import {
ChangeDetectionStrategy,
Component,
ElementRef,
OnInit,
ViewChild
ViewChild,
OnDestroy
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ContextualActionBarService } from '@nrwl/angular-console-enterprise-frontend';
Expand All @@ -32,7 +34,8 @@ import {
} from 'rxjs/operators';
import {
GenerateGQL,
SchematicCollectionsByNameGQL
SchematicCollectionsByNameGQL,
SchematicDocsGQL
} from '../generated/graphql';

const DEBOUNCE_TIME = 300;
Expand All @@ -59,6 +62,8 @@ export class SchematicComponent implements OnInit {
@ViewChild(TaskRunnerComponent) taskRunner: TaskRunnerComponent;
@ViewChild(FlagsComponent) flags: FlagsComponent;

docs: Observable<any[]>;

private readonly ngGen$ = new Subject<void>();
readonly ngGenDisabled$ = new BehaviorSubject(true);

Expand All @@ -69,6 +74,8 @@ export class SchematicComponent implements OnInit {
private readonly elementRef: ElementRef,
private readonly contextActionService: ContextualActionBarService,
private readonly generateGQL: GenerateGQL,
private readonly schematicDocsGQL: SchematicDocsGQL,
private readonly settings: Settings,
private readonly schematicCollectionsByNameGQL: SchematicCollectionsByNameGQL
) {}

Expand Down Expand Up @@ -221,6 +228,31 @@ export class SchematicComponent implements OnInit {
);
})
);

if (this.settings.showDocs) {
this.docs = schematicDescription$.pipe(
switchMap(d => {
if (d === null) {
return of(null);
} else {
return this.schematicDocsGQL.fetch({
path: d.path,
collectionName: d.collection,
name: d.schematic
});
}
}),
map(r => {
if (!r) {
return [];
} else {
return r.data.workspace.docs.schematicDocs;
}
})
);
} else {
this.docs = of([]);
}
}

getContextTitle(schematic: Schematic) {
Expand Down
55 changes: 55 additions & 0 deletions libs/feature-run/src/lib/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ export namespace RunNg {
};
}

export namespace SchematicDocs {
export type Variables = {
path: string;
collectionName: string;
name: string;
};

export type Query = {
__typename?: 'Query';
workspace: Workspace;
};

export type Workspace = {
__typename?: 'Workspace';
docs: Docs;
};

export type Docs = {
__typename?: 'Docs';
schematicDocs: SchematicDocs[];
};

export type SchematicDocs = {
__typename?: 'Doc';
id: string;
description?: string | null;
prop?: string | null;
};
}

export namespace WorkspaceAndProjects {
export type Variables = {
path: string;
Expand Down Expand Up @@ -264,6 +294,31 @@ export class RunNgGQL extends Apollo.Mutation<RunNg.Mutation, RunNg.Variables> {
@Injectable({
providedIn: 'root'
})
export class SchematicDocsGQL extends Apollo.Query<
SchematicDocs.Query,
SchematicDocs.Variables
> {
document: any = gql`
query SchematicDocs(
$path: String!
$collectionName: String!
$name: String!
) {
workspace(path: $path) {
docs {
schematicDocs(collectionName: $collectionName, name: $name) {
id
description
prop
}
}
}
}
`;
}
@Injectable({
providedIn: 'root'
})
export class WorkspaceAndProjectsGQL extends Apollo.Query<
WorkspaceAndProjects.Query,
WorkspaceAndProjects.Variables
Expand Down
11 changes: 11 additions & 0 deletions libs/feature-run/src/lib/graphql/schematic-docs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query SchematicDocs($path: String!, $collectionName: String!, $name: String!) {
workspace(path: $path) {
docs {
schematicDocs(collectionName: $collectionName, name: $name) {
id
description
prop
}
}
}
}
38 changes: 35 additions & 3 deletions libs/feature-run/src/lib/target/target.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
import {
IncrementalCommandOutput,
CommandRunner,
Serializer
Serializer,
Settings
} from '@angular-console/utils';
import {
ChangeDetectionStrategy,
Expand All @@ -26,7 +27,7 @@ import {
tap,
withLatestFrom
} from 'rxjs/operators';
import { ProjectsGQL, RunNgGQL } from '../generated/graphql';
import { ProjectsGQL, RunNgGQL, SchematicDocsGQL } from '../generated/graphql';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -45,6 +46,9 @@ export class TargetComponent implements OnInit {
@ViewChild(CommandOutputComponent) out: CommandOutputComponent;
@ViewChild(TaskRunnerComponent) taskRunner: TaskRunnerComponent;
@ViewChild(FlagsComponent) flags: FlagsComponent;

docs: Observable<any[]>;

private readonly ngRun$ = new Subject<any>();
private readonly ngRunDisabled$ = new BehaviorSubject(true);

Expand All @@ -54,7 +58,9 @@ export class TargetComponent implements OnInit {
private readonly serializer: Serializer,
private readonly contextActionService: ContextualActionBarService,
private readonly projectsGQL: ProjectsGQL,
private readonly runNgGQL: RunNgGQL
private readonly runNgGQL: RunNgGQL,
private readonly settings: Settings,
private readonly schematicDocsGQL: SchematicDocsGQL
) {}

ngOnInit() {
Expand Down Expand Up @@ -132,6 +138,32 @@ export class TargetComponent implements OnInit {
this.command$ = this.commandArray$.pipe(
map(c => `ng ${this.serializer.argsToString(c.commands)}`)
);

if (this.settings.showDocs) {
this.docs = targetDescription$.pipe(
switchMap(d => {
if (d === null) {
return of(null);
} else {
const [collectionName, name] = d.target.split(':');
return this.schematicDocsGQL.fetch({
path: d.path,
collectionName,
name
});
}
}),
map(p => {
if (!p) {
return [];
} else {
return p.data.workspace.docs.schematicDocs;
}
})
);
} else {
this.docs = of([]);
}
}

getContextTitle(project: Project) {
Expand Down
49 changes: 49 additions & 0 deletions libs/feature-workspaces/src/lib/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ export namespace SchematicCollections {
};
}

export namespace WorkspaceDocs {
export type Variables = {
path: string;
};

export type Query = {
__typename?: 'Query';
workspace: Workspace;
};

export type Workspace = {
__typename?: 'Workspace';
docs: Docs;
};

export type Docs = {
__typename?: 'Docs';
workspaceDocs: WorkspaceDocs[];
};

export type WorkspaceDocs = {
__typename?: 'Doc';
id: string;
description?: string | null;
prop?: string | null;
};
}

export namespace Workspace {
export type Variables = {
path: string;
Expand Down Expand Up @@ -221,6 +249,27 @@ export class SchematicCollectionsGQL extends Apollo.Query<
@Injectable({
providedIn: 'root'
})
export class WorkspaceDocsGQL extends Apollo.Query<
WorkspaceDocs.Query,
WorkspaceDocs.Variables
> {
document: any = gql`
query WorkspaceDocs($path: String!) {
workspace(path: $path) {
docs {
workspaceDocs {
id
description
prop
}
}
}
}
`;
}
@Injectable({
providedIn: 'root'
})
export class WorkspaceGQL extends Apollo.Query<
Workspace.Query,
Workspace.Variables
Expand Down
11 changes: 11 additions & 0 deletions libs/feature-workspaces/src/lib/graphql/workspace-docs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query WorkspaceDocs($path: String!) {
workspace(path: $path) {
docs {
workspaceDocs {
id
description
prop
}
}
}
}
Loading

0 comments on commit 0bfae75

Please sign in to comment.