1

I want to create a CLI based on schematics to improve projects creation for my job and I want to scaffold an Angular Application AND an Angular Library in one command. So I tried to use externalSchematic and it works perfectly for the application but when I want to add the library using another externalSchematic, it throws an error because it cannot find the angular.json file. So I would like to know if there is a way that I can navigate (cd command equivalent) to my newly created project, please if someone has the answer ! :pray:

Here my code:

export const ngLibrary = (options: Schema): Rule =>
  chain([
    externalSchematic('@schematics/angular', 'ng-new', options),
    externalSchematic('@schematics/angular', 'library', options)
  ]);

Error:

An error occured:
Error: Path "/angular.json" does not exist.
  at HostTree.readText()

1 Answer 1

1

I found a solution. Instead of navigating in the Tree, you can execute a schematic from a scope (path).

externalSchematic('@schematics/angular', 'library', options, { scope: 'my/path' });
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, after trying 101 ways not to do it this way worked! And it's even elegant. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.