Skip to content

Commit

Permalink
fix(core): add @trumbitta/nx-plugin-openapi via the Tree
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Feb 24, 2023
1 parent cf8f8c3 commit c2f2781
Showing 1 changed file with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import {
joinPathFragments,
ProjectConfiguration,
readProjectConfiguration,
readWorkspaceConfiguration,
readNxJson,
Tree,
updateProjectConfiguration,
updateWorkspaceConfiguration,
updateNxJson,
addDependenciesToPackageJson,
} from '@nrwl/devkit';
import { libraryGenerator } from '@nrwl/js/src/generators/library/library';

import type NxPluginOpenAPILibGenerator = require('@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator');
import type NxPluginOpenAPIInitGenerator = require('@trumbitta/nx-plugin-openapi/src/generators/init/generator');

import { getSwaggerExecutorConfiguration } from '../../models/swagger-executor-configuration';
import { AddSwaggerJsonExecutorSchema } from './schema';

Expand Down Expand Up @@ -118,14 +122,21 @@ async function generateCodegenProject(
const nameWithDirectory = `generated-${options.codegenProject}`;
if (options.useNxPluginOpenAPI) {
ensurePackage(host, '@trumbitta/nx-plugin-openapi', '^1.12.1');
tasks.push(
addDependenciesToPackageJson(
host,
{},
{ '@trumbitta/nx-plugin-openapi': '^1.12.1' },
),
);
const {
default: nxPluginOpenAPIGenerator,
}: // eslint-disable-next-line @typescript-eslint/no-var-requires
typeof import('@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator') = require('@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator');
typeof NxPluginOpenAPILibGenerator = require('@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator');
const {
default: nxPluginOpenAPIInitGenerator,
}: // eslint-disable-next-line @typescript-eslint/no-var-requires
typeof import('@trumbitta/nx-plugin-openapi/src/generators/init/generator') = require('@trumbitta/nx-plugin-openapi/src/generators/init/generator');
typeof NxPluginOpenAPIInitGenerator = require('@trumbitta/nx-plugin-openapi/src/generators/init/generator');

tasks.push(await nxPluginOpenAPIInitGenerator(host));

Expand Down Expand Up @@ -176,7 +187,19 @@ async function generateCodegenProject(
);
}

const wc = readWorkspaceConfiguration(host);
updateNxJsonForCodegenTargets(host, options);

return tasks;
}
function updateNxJsonForCodegenTargets(
host: Tree,
options: AddSwaggerJsonExecutorSchema,
) {
const wc = readNxJson(host);

if (!wc) {
return;
}

const cacheableOperations: string[] | null =
wc.tasksRunnerOptions?.default?.options?.cacheableOperations;
Expand All @@ -190,7 +213,5 @@ async function generateCodegenProject(
wc.targetDefaults['build'].dependsOn ??= [];
wc.targetDefaults['build'].dependsOn.push(...newBuildDeps);

updateWorkspaceConfiguration(host, wc);

return tasks;
updateNxJson(host, wc);
}

0 comments on commit c2f2781

Please sign in to comment.