How to use the @nrwl/workspace/src/utils/ast-utils.insertImport function in @nrwl/workspace

To help you get started, weโ€™ve selected a few @nrwl/workspace examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nrwl / nx / packages / angular / src / schematics / library / library.ts View on Github external
return (host: Tree) => {
    const moduleSource = host.read(options.modulePath)!.toString('utf-8');
    const sourceFile = ts.createSourceFile(
      options.modulePath,
      moduleSource,
      ts.ScriptTarget.Latest,
      true
    );
    insert(host, options.modulePath, [
      insertImport(
        sourceFile,
        options.modulePath,
        'RouterModule',
        '@angular/router'
      ),
      ...addImportToModule(
        sourceFile,
        options.modulePath,
        `
        RouterModule.forChild([
        /* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
       ]) `
      )
    ]);
    return host;
  };
github nrwl / nx / packages / angular / src / schematics / application / application.ts View on Github external
true
      );

      host.overwrite(
        componentSpecPath,
        componentSpecSource
          .replace('.content span', 'h1')
          .replace(
            `${options.name} app is running!`,
            `Welcome to ${options.name}!`
          )
      );

      if (options.routing) {
        insert(host, componentSpecPath, [
          insertImport(
            componentSpecSourceFile,
            componentSpecPath,
            'RouterTestingModule',
            '@angular/router/testing'
          ),
          ...addImportToTestBed(
            componentSpecSourceFile,
            componentSpecPath,
            `RouterTestingModule`
          )
        ]);
      }
    }

    return host;
  };
github nrwl / nx / packages / angular / src / schematics / ngrx / rules / add-imports-to-module.ts View on Github external
const addImport = (
      symbolName: string,
      fileName: string,
      isDefault = false
    ): Change => {
      return insertImport(source, modulePath, symbolName, fileName, isDefault);
    };
github nrwl / nx / packages / angular / src / schematics / library / library.ts View on Github external
return (host: Tree) => {
    const moduleSource = host.read(options.modulePath)!.toString('utf-8');
    const moduleSourceFile = ts.createSourceFile(
      options.modulePath,
      moduleSource,
      ts.ScriptTarget.Latest,
      true
    );
    const constName = `${toPropertyName(options.fileName)}Routes`;

    insert(host, options.modulePath, [
      insertImport(
        moduleSourceFile,
        options.modulePath,
        'RouterModule, Route',
        '@angular/router'
      ),
      ...addImportToModule(
        moduleSourceFile,
        options.modulePath,
        `RouterModule`
      ),
      ...addGlobal(
        moduleSourceFile,
        options.modulePath,
        `export const ${constName}: Route[] = [];`
      )
    ]);
github nrwl / nx / packages / angular / src / schematics / upgrade-module / upgrade-module.ts View on Github external
return (host: Tree) => {
    const { moduleClassName, modulePath, moduleSource } = readBootstrapInfo(
      host,
      options.project
    );

    insert(host, modulePath, [
      insertImport(
        moduleSource,
        modulePath,
        `configure${toClassName(options.name)}, upgradedComponents`,
        `../${toFileName(options.name)}-setup`
      ),
      insertImport(
        moduleSource,
        modulePath,
        'UpgradeModule',
        '@angular/upgrade/static'
      ),
      ...addImportToModule(moduleSource, modulePath, 'UpgradeModule'),
      ...addDeclarationToModule(
        moduleSource,
        modulePath,
        '...upgradedComponents'
      ),
      ...addEntryComponents(
        moduleSource,
        modulePath,
        getBootstrapComponent(moduleSource, moduleClassName)
      )