4

在 Angular 6.0 之前,我已经创建了一些示意图。schematic 'my-schematic' not found in collection @schematics/angular当我尝试在托管应用程序(Angular 6)上生成一些代码时,我在 Angular 5.x 中执行的相同步骤现在总是会导致错误?。

我的设置(全局 Angular 的东西):

Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64

@angular-devkit/{architect, core, schematics} 0.6.0
@schematics/angular 0.6.0
rxjs 6.1.0
typescript 2.7.2

我的步骤:

  1. schematics schematic --name=my-first-schematics。因此,它创建了一个新的原理图项目,其中包含三个示例模式。然后我导航到那个新文件夹cd my-first-schematics
  2. npm run build。它构建没有错误。
  3. schematics .:my-first-schematics。结果:"my-first-schematics" not found in collection "."我在一些博客中看到他们执行此步骤没有问题的错误。我从来没有运行过这个命令,我不确定它实际上做了什么,所以我会假设这个命令毕竟不是必需的。
  4. npm link,以便我可以在新项目中使用这个新的原理图集合。
  5. 在另一个提示窗口中,我创建了一个新应用程序:ng new schematics-consumer,然后在 npm 安装后,cd schematics-consumer.
  6. Rannpm link my-first-schematics所以我现在可以访问该原理图库。
  7. 我导航到那是src/app我要生成文件的地方。
  8. ng g my-schematic -c my-first-schematics。导致错误Schematic "my-schematic" not found in collection "@schematics/angular"。我指定了一个集合。为什么它没有看到我的新集合,并且仍然认为每个原理图都在@schematics/angular

所以,我不能用原理图生成任何东西。我没有修改schematics schematic name=my-first-schematics.

是否有一套新的命令、程序等来创建我们自己的自定义原理图?我错过了哪些步骤?我还需要安装什么?如有必要,我会提供更多信息。

目前,还没有关于原理图的新指南或博客,因为 6.0 只有几周的历史,所以我假设旧方法应该仍然有效。

4

1 回答 1

1

似乎问题最终与angular-cli,请参阅讨论:https ://github.com/angular/devkit/issues/528#issuecomment-387415646

为了解决这个问题,您可以将默认集合设置为自定义原理图:

ng config cli.defaultCollection my-first-schematics

现在您应该可以运行ng g my-schematic.

如果这不起作用,您可以发布my-first-schematics目录的文件列表吗?

于 2018-05-29T16:10:58.950 回答