简体   繁体   English

角度原理图 - 文件未安装

[英]Angular schematics - file not installing

I am building an Angular custom schematics.我正在构建一个 Angular 自定义原理图。 I created the files directory and it looks like this:我创建了文件目录,它看起来像这样:

文件目录
I am trying to add this component to the final app.我正在尝试将此组件添加到最终应用程序中。 my index file looks like this:我的索引文件如下所示:

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}`);
}};}

afterwards I'm calling this function like this:之后我像这样调用这个函数:

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

]); ]); } }

when I test it with npm link locally - it works great.当我在本地使用 npm link 对其进行测试时-效果很好。 everything is created just fine.一切都很好。

but when i publish it npm and install it from npm - all of the files are created except for the ts file:但是当我发布它 npm 并从 npm 安装它时 - 除了 ts 文件之外,所有文件都被创建:

side.nav.component.ts

and I don't get any warnings.我没有收到任何警告。

What am I missing here?我在这里缺少什么?

Solved it.解决了。 It turns out it was a problem with the publishing to npm.事实证明这是发布到 npm 的问题。 for some unknown reason, an .npmignore a file was created - no idea how, and inside of it I saw this:出于某种未知原因,创建了一个.npmignore文件 - 不知道如何,在其中我看到了这个:

*.ts

So basically it ignored all of the typescript files when I published.所以基本上它在我发布时忽略了所有的打字稿文件。

Well it's ignoring .ts files by default because shematics run on built version, and don't need the source files like index.ts or schema.ts files from schematics api.好吧,它默认忽略 .ts 文件,因为 shematics 在构建版本上运行,并且不需要来自 schemas api 的 index.ts 或 schema.ts 文件等源文件。 So be careful, you should only ignore the wanted directories, by adding something like that :所以要小心,你应该只忽略想要的目录,通过添加类似的东西:

# Ignores TypeScript files, but keeps definitions.
*.ts
!*.d.ts    
# Not ignoring component files
!src/your-schematics/files/**/*.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM