Skip to content

Commit

Permalink
feat(repo): schematic to generate docs #53
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 21, 2021
1 parent 45567c0 commit a7828c5
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/core/core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# core

## Generators

### lib
nx-dotnet generator

### app
Generate a new C# project.

### project-reference
Adds a reference from one project to another.

### init
init generator

### sync
sync generator

### nuget-reference
nuget-reference generator

### restore
Restores NuGet packages and .NET tools used by the workspace


## Executors

### build
build executor

### serve
serve executor

### test
test executor

### publish
publish executor

### format
Formats and lints a project using the dotnet-format tool
12 changes: 12 additions & 0 deletions docs/typescript/typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# typescript

## Generators

### typescript
typescript generator


## Executors

### build
build executor
56 changes: 56 additions & 0 deletions tools/generators/generate-docs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
Tree,
formatFiles,
installPackagesTask,
getProjects,
ProjectConfiguration,
NxJsonProjectConfiguration,
generateFiles,
names,
readJson,
} from '@nrwl/devkit';
import { libraryGenerator } from '@nrwl/workspace/generators';
import * as path from 'path';
import { ExecutorsCollection, GeneratorsCollection } from './schema-json.interface';

export default async function (host: Tree, schema: any) {
const projects = await findProjectsWithGeneratorsOrExecutors(host);
projects.forEach((p) => {
const generators = readJson<GeneratorsCollection>(host, `${p.root}/generators.json`);
const executors = readJson<ExecutorsCollection>(host, `${p.root}/executors.json`);
generateFiles(host, path.join(__dirname, 'templates'), `docs`, {
projectFileName: names(p.name).fileName,
project: p,
generators: generators.generators,
executors: executors.executors
});
});
}

export async function findProjectsWithGeneratorsOrExecutors(host: Tree) {
const projects: ({
name: string;
generators: boolean;
executors: boolean;
} & Omit<ProjectConfiguration, 'generators'>)[] = [];
getProjects(host).forEach((configuration, project) => {
const res = projectContainsGeneratorsOrExecutors(host, configuration);
if (res) {
projects.push({
...configuration,
name: project,
...res,
});
}
});
return projects;
}

export function projectContainsGeneratorsOrExecutors(
host: Tree,
project: ProjectConfiguration,
): false | { generators: boolean; executors: boolean } {
const executors = host.isFile(`${project.root}/executors.json`);
const generators = host.isFile(`${project.root}/generators.json`);
return !(executors || generators) ? false : { generators, executors };
}
30 changes: 30 additions & 0 deletions tools/generators/generate-docs/schema-json.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export interface SchemaJSON {}

export interface GeneratorsCollection {
name: string;
version: string;
generators: {
[key: string]: GeneratorConfiguration
};
}

export interface ExecutorsCollection {
executors: {
[key: string]: ExecutorConfiguration;
};
builders: {
[key: string]: ExecutorConfiguration;
};
}

export interface ExecutorConfiguration {
implementation: string;
schema: string;
description: string;
}

export interface GeneratorConfiguration {
factory: string;
schema: string;
description: string;
}
16 changes: 16 additions & 0 deletions tools/generators/generate-docs/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"cli": "nx",
"id": "generate-docs",
"type": "object",
"properties": {
// "name": {
// "type": "string",
// "description": "Library name",
// "$default": {
// "$source": "argv",
// "index": 0
// }
// }
}
// "required": ["name"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# <%= project.name %>

## Generators
<% Object.entries(generators).forEach(([key, config]) => { %>
### <%= key %>
<%= config.description %>
<% }) %>

## Executors
<% Object.entries(executors).forEach(([key, config]) => { %>
### <%= key %>
<%= config.description %>
<% }) %>

0 comments on commit a7828c5

Please sign in to comment.