Skip to content

Commit

Permalink
feat(core): add preset generator (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Apr 12, 2023
1 parent 69068af commit 57725ea
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 51 deletions.
4 changes: 0 additions & 4 deletions docs/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ Generate a new C# project as an Nx application

Add a reference from one project to another

### [init](./generators/init.md)

init generator

### [sync](./generators/sync.md)

Synchronizes NuGet references for the workspace
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ slug: /
## [@nx-dotnet/core](./core)

- 7 Executors
- 12 Generators
- 11 Generators

## [@nx-dotnet/nx-ghpages](./nx-ghpages)

Expand Down
6 changes: 6 additions & 0 deletions packages/core/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
"schema": "./src/generators/move/schema.json",
"description": "Moves a .NET project (including updating references)",
"alias": "mv"
},
"preset": {
"factory": "./src/generators/preset/generator",
"schema": "./src/generators/preset/schema.json",
"description": "preset generator",
"hidden": true
}
}
}
23 changes: 23 additions & 0 deletions packages/core/src/generators/preset/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { formatFiles, Tree } from '@nrwl/devkit';
import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet';

import appGenerator from '../app/generator';

export default async function (tree: Tree) {
tree.write('apps/.gitkeep', '');
tree.write('libs/.gitkeep', '');
await appGenerator(
tree,
{
language: 'C#',
template: 'webapi',
name: 'api',
testTemplate: 'xunit',
pathScheme: 'nx',
skipSwaggerLib: false,
useNxPluginOpenAPI: true,
},
new DotNetClient(dotnetFactory()),
);
await formatFiles(tree);
}
3 changes: 3 additions & 0 deletions packages/core/src/generators/preset/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PresetGeneratorSchema {
name: string;
}
9 changes: 9 additions & 0 deletions packages/core/src/generators/preset/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"$id": "Preset",
"title": "",
"type": "object",
"properties": {},
"required": []
}
41 changes: 24 additions & 17 deletions packages/nxdoc/src/generators/generate-docs/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
ExecutorsJson,
formatFiles,
generateFiles,
GeneratorsJson,
getProjects,
names,
ProjectConfiguration,
Expand All @@ -9,14 +11,11 @@ import {
} from '@nrwl/devkit';

import { readFileSync } from 'fs';
import { GeneratorsJsonEntry } from 'nx/src/config/misc-interfaces';
import * as path from 'path';

import { Schema } from './schema';
import {
ExecutorsCollection,
GeneratorsCollection,
SchemaJSON,
} from './schema-json.interface';
import { SchemaJSON } from './schema-json.interface';

export default async function (host: Tree, options: Schema) {
const projects = await findProjectsWithGeneratorsOrExecutors(host);
Expand All @@ -34,7 +33,7 @@ export default async function (host: Tree, options: Schema) {
? options.exclude
: options.exclude.split(',');

projects.forEach((project) => {
for (const project of projects) {
if (excludedProjects.includes(project.name)) {
return;
}
Expand All @@ -53,15 +52,23 @@ export default async function (host: Tree, options: Schema) {
console.log('Getting started file not found');
}

const generatorsCollection: GeneratorsCollection = project.generators
? readJson<GeneratorsCollection>(host, `${project.root}/generators.json`)
: ({} as GeneratorsCollection);
const generators = generatorsCollection.generators;
const generatorsCollection: GeneratorsJson = project.generators
? readJson<GeneratorsJson>(host, `${project.root}/generators.json`)
: ({} as GeneratorsJson);
const generators = Object.fromEntries(
Object.entries(generatorsCollection.generators ?? {}).filter(
([, config]) => !config.hidden,
),
);

const executorsCollection: ExecutorsCollection = project.executors
? readJson<ExecutorsCollection>(host, `${project.root}/executors.json`)
: ({} as ExecutorsCollection);
const executors = executorsCollection.executors;
const executorsCollection: ExecutorsJson = project.executors
? readJson<ExecutorsJson>(host, `${project.root}/executors.json`)
: ({} as ExecutorsJson);
const executors = Object.fromEntries(
Object.entries(executorsCollection.executors ?? {}).filter(
([, config]) => !(config as GeneratorsJsonEntry).hidden,
),
);

const packageName = readJson(host, `${project.root}/package.json`).name;
const projectFileName = names(project.name).fileName;
Expand Down Expand Up @@ -97,7 +104,7 @@ export default async function (host: Tree, options: Schema) {
},
);

Object.entries(generators).forEach(([generatorName, config]) => {
for (const [generatorName, config] of Object.entries(generators)) {
const generatorFileName = names(generatorName).fileName;
const schema = readJson<SchemaJSON>(
host,
Expand All @@ -116,7 +123,7 @@ export default async function (host: Tree, options: Schema) {
packageName,
},
);
});
}

Object.entries(executors).forEach(([generatorName, config]) => {
const generatorFileName = names(generatorName).fileName;
Expand All @@ -138,7 +145,7 @@ export default async function (host: Tree, options: Schema) {
},
);
});
});
}

generateFiles(
host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,3 @@ export interface PropertyConfiguration {
default: boolean | string | number;
enum: string[];
}

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;
}

0 comments on commit 57725ea

Please sign in to comment.