-1

I am building an Angular custom schematics. I created the files directory and it looks like this:

files directory
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. 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:

side.nav.component.ts

and I don't get any warnings.

What am I missing here?

Abhishek Kumar
  • 2,501
  • 10
  • 25
Liraz Shaka Amir
  • 587
  • 9
  • 26

2 Answers2

2

Solved it. It turns out it was a problem with the publishing to npm. for some unknown reason, an .npmignore a file was created - no idea how, and inside of it I saw this:

*.ts

So basically it ignored all of the typescript files when I published.

Liraz Shaka Amir
  • 587
  • 9
  • 26
1

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. 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
Alain Boudard
  • 768
  • 6
  • 16