Angular-cli custom schemas / collections

I am trying to create custom schemas for angular cli. Until now, I realized that the "compilation" must be compiled, cli cannot read typescript. This means that you cannot just clone https://github.com/angular/devkit/tree/master/packages/schematics/angular to change everything you need and publish it to npm, which means you need to clone all https : //github.com/angular/devkit and use it npm run build to create compiled circuits you need to run it through tsc , then you can publish these compiled files to npm and install it globally using npm, for example

npm i -g @thescrollbar/schematics

then I would have to do ng new --collection=@thescrollbar /schematics my-app , but surprisingly enough, it didn’t work and threw tree.branch is not a function .

But if you copy this globally installed package to the cli module

/usr/local/bin/node_modules/@thescrollbar/schematics/usr/local/bin/node_modules/@angular/cli/node_modules/@thescrollbar/schematics

it starts working and you can create a new application based on your circuits.

Now for a new problem, I have no workaround when I try to generate new components using

ng gc --collection=@thescrollbar /schematics logo

he creates it using the @schematics/angular template instead of my collection, even though when I specifically do

ng g shat --collection=@thescrollbar /schematics logo

it says

The shat schema was not found in the @ thescrollbar / schematics collection.

which, I think, clearly indicates that he really uses my collection?

Who managed to create custom collections? Globally and to create components / modules?

+7
angular angular-cli
source share
2 answers

/ usr / local / bin / node_modules / @ thescrollbar / schematics → / usr / local / bin / node_modules / @ angular / cli / node_modules / @ thescrollbar / schematics

Yes, this is a problem with the current implementation. This is because we (blindly) call require.resolve in the collection name, which is resolved only from the current module, which is the CLI. There is an inbound fix ( PR 163 ) to be released this week that will be resolved using the following list:

  • is it a node package regarding process.cwd ()?
  • is it a node package regarding a tool (CLI in your case)?
  • Is this a global node package?

You may notice that two missing backups are missing; is it a package compared to your schemes and is it a package for your project? It will come, it is a little harder to implement. In any case, you can install your circuit around the world, and this will work fine.

ng gc --collection = @ thescrollbar / schematics logo

he creates it using the @ schematics / angular template instead of my collection

This is a known issue, and we have a PR that captures it in the CLI. This is also a fix.

Thanks for trying out Schematics. It was a long time ago a project, and we still record a lot of things. In the near future we will also receive better documentation and tutorials (including a diagram). This is pretty much work in progress, so thank you for being so patient.

In the Angular DevKit repository you can point out problems and errors ( https://github.com/angular/devkit ).

+9
source share

A quick fix for cli 1.4.1 is to edit node_modules/@angular/cli/commands/new.js, in the run function: (commandOptions, rawArgs) change the line

commandOptions.collectionName = this.getCollectionName(rawArgs);

to

commandOptions.collectionName = commandOptions.collection || this.getCollectionName(rawArgs);

0
source share

All Articles