-1

我正在构建一个 Angular 自定义原理图。我创建了 files 目录,它看起来像这样:

文件目录
我正在尝试将此组件添加到最终应用程序中。我的索引文件如下所示:

function addSideNav(options: any) {
return (host: Tree, context: SchematicContext) => {
try {

  host.delete('src/app/app.component.html');

  const workspace = getWorkspace(host);
  if (!options.project) {
    options.project = Object.keys(workspace.projects)[0];
  }
  const project = getProject(host, options.project);

  if (options.path === undefined) {
    options.path = buildDefaultPath(project);
  }

  const templateSource = apply(url('./files'), [
    template({
      ...options,
      ...strings
    }),
    move(options.path)
  ]);

  // context.logger.log("info", `✅️ Added SideNav to the tree`);
  return mergeWith(templateSource);

} catch (e) {
  context.logger.log("error", ` Failed to add the SideNav to the tree`);
  throw new SchematicsException(`Error detailes: ${e}`);
}};}

之后我这样调用这个函数:

export default function (options: any): Rule {
return chain([
    addPackageJsonDependencies(),
    installPackageJsonDependencies(),
    addSideNav(options),
    addMaterialStyle(options),
    addPolyfillToScripts(options),
    addToAppModule(options)

]); }

当我在本地使用 npm 链接对其进行测试时-效果很好。一切都创建得很好。

但是当我发布它 npm 并从 npm 安装它时 - 除了 ts 文件之外的所有文件都被创建:

side.nav.component.ts

而且我没有收到任何警告。

我在这里想念什么?

4

2 回答 2

2

解决了。事实证明这是发布到 npm 的问题。由于某种未知的原因,.npmignore创建了一个文件 - 不知道如何,在其中我看到了这个:

*.ts

所以基本上它在我发布时忽略了所有的打字稿文件。

于 2019-03-22T07:09:01.373 回答
1

好吧,默认情况下它会忽略 .ts 文件,因为 shematics 在构建版本上运行,并且不需要来自原理图 api 的 index.ts 或 schema.ts 文件等源文件。所以要小心,你应该只忽略想要的目录,通过添加类似的东西:

# Ignores TypeScript files, but keeps definitions.
*.ts
!*.d.ts    
# Not ignoring component files
!src/your-schematics/files/**/*.ts
于 2020-04-01T10:11:20.730 回答