-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo): schematic to generate docs #53
- Loading branch information
1 parent
45567c0
commit a7828c5
Showing
6 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# typescript | ||
|
||
## Generators | ||
|
||
### typescript | ||
typescript generator | ||
|
||
|
||
## Executors | ||
|
||
### build | ||
build executor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
13 changes: 13 additions & 0 deletions
13
...s/generators/generate-docs/templates/__projectFileName__/__projectFileName__.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> | ||
<% }) %> |