Skip to content

Commit

Permalink
Lab #8
Browse files Browse the repository at this point in the history
  • Loading branch information
christianliebel committed Oct 7, 2024
1 parent b1caf67 commit 4897280
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/my-plugin/src/generators/my-generator/generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { applicationGenerator } from '@nx/angular/generators';
import { addImportToComponent } from '@nx/angular/src/utils';
import { generateFiles, joinPathFragments, readProjectConfiguration, Tree } from '@nx/devkit';
import { insertImport } from '@nx/js';
import { getSourceFile } from '../utils/get-source-file';
import { MyGeneratorGeneratorSchema } from './schema';

export async function myGeneratorGenerator(
Expand All @@ -17,6 +20,10 @@ export async function myGeneratorGenerator(
const projectDir = readProjectConfiguration(tree, options.name).root;
const destinationDir = joinPathFragments(projectDir, 'src', 'app');
generateFiles(tree, sourceDir, destinationDir, {});

const appComponentPath = joinPathFragments(destinationDir, 'app.component.ts');
addImportToComponent(tree, getSourceFile(tree, appComponentPath), appComponentPath, 'MyLibraryComponent');
insertImport(tree, getSourceFile(tree, appComponentPath), appComponentPath, 'MyLibraryComponent', '@my-workspace/my-library');
}

export default myGeneratorGenerator;

0 comments on commit 4897280

Please sign in to comment.