title: Custom Angular Schematics: how to modify files and create files in different locations/folders
body: <p>I've been creating a custom Angular Schematics following this article: <a href="https://medium.com/@tomastrajan/total-guide-to-custom-angular-schematics-5c50cf90cdb4" rel="noreferrer">https://medium.com/@tomastrajan/total-guide-to-custom-angular-schematics-5c50cf90cdb4</a></p>
  
  <p>Now I'm trying to find out how to modify some files (for example app-routing.module.ts, to add the route of the component created via my custom schematics). Is it possible? Could anyone provide an example?</p>
  
  <p>I also would like to create files in different locations/folders at the same time.</p>
  
  <p>This is the current structure of my custom schematics:</p>
  
  <blockquote>
    <ul>
    <li>src
    
    <ul>
    <li>table
    
    <ul>
    <li>files
    
    <ul>
    <li>__name@dasherize __-table
    
    <ul>
    <li>__name@dasherize __-table-routing.module.ts</li>
    <li>__name@dasherize __-table.component.html</li>
    <li>__name@dasherize __-table.component.scss</li>
    <li>...</li>
    </ul></li>
    <li>index.ts</li>
    <li>schema.d.ts</li>
    <li>schema.json</li>
    </ul></li>
    </ul></li>
    <li>collection.json</li>
    </ul></li>
    <li>...</li>
    </ul>
  </blockquote>
  
  <p>And this is my current code:</p>
  
  <p><strong>index.ts</strong></p>
  
  <pre><code>import { strings } from '@angular-devkit/core';
  import {
      apply, mergeWith, move, Rule, SchematicContext, SchematicsException, template, Tree, url
  } from '@angular-devkit/schematics';
  import { parseName } from '@schematics/angular/utility/parse-name';
  import { buildDefaultPath } from '@schematics/angular/utility/project';
  
  import { Schema } from './schema';
  
  export function tabla(_options: Schema): Rule {
    return (tree: Tree, _context: SchematicContext) =&gt; {
      const workspaceConfigBuffer = tree.read('angular.json');
  
      if (!workspaceConfigBuffer) {
        throw new SchematicsException('Not an Angular CLI workspace');
      }
  
      const workspaceConfig = JSON.parse(workspaceConfigBuffer.toString());
      const projectName = _options.project || workspaceConfig.defaultProject;
      const project = workspaceConfig.projects[projectName];
      const defaultProjectPath = buildDefaultPath(project);
      const parsedPath = parseName(defaultProjectPath, _options.name);
      const { name, path } = parsedPath;
      const sourceTemplate = url('./files');
  
      const sourceParametrizedTemplate = apply(sourceTemplate, [
        template({
          ..._options,
          ...strings,
          name
        }),
        move(path)
      ]);
  
      return mergeWith(sourceParametrizedTemplate)(tree, _context);
    };
  }
  </code></pre>
  
  <p><strong>schema.json</strong></p>
  
  <pre><code>{
      "$schema": "http://json-schema.org/schema",
      "id": "SchematicsTable",
      "title": "Options Table Schema",
      "type": "object",
      "description": "Creates a page with a table",
      "properties": {
          "project": {
              "type": "string",
              "description": "Generates in a specific project"
          },
          "name": {
              "type": "string",
              "description": "Component's name",
              "$default": {
                  "$source": "argv",
                  "index": 0
              }
          }
      },
      "required": [
          "name"
      ]
  }
  </code></pre>
  
  <p><strong>schema.d.ts</strong></p>
  
  <pre><code>export interface Schema {
      project?: string;
      name: string;
  }
  </code></pre>
  
  <p><strong>collection.json</strong></p>
  
  <pre><code>{
    "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
    "schematics": {
      "table": {
        "description": "Page with a table",
        "factory": "./table/index#table",
        "schema": "./table/schema.json"
      }
    }
  }
  </code></pre>
  
  <p>Now if I execute "ng g my_package_name:table --name=example" in an Angular CLI workspace a folder "example-table" is created inside "src/app" with the following files inside it:</p>
  
  <blockquote>
    <ul>
    <li>example-table-routing.module.ts</li>
    <li>example-table.component.html</li>
    <li>example-table.component.scss</li>
    <li>...</li>
    </ul>
  </blockquote>
  
  <p>This alreay works fine, but what I would like is that at the same time this folder and files are created, the "app-routing.module.ts" file is modified adding the route of the example-table page and also creates a folder with some files in the folder "src/app/services". </p>