How to use the @schematics/angular/utility/ng-ast-utils.getAppModulePath function in @schematics/angular

To help you get started, we’ve selected a few @schematics/angular 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 ng-matero / ng-matero / schematics / ng-add / setup-project.ts View on Github external
return (host: Tree) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const appModulePath = getAppModulePath(host, getProjectMainFile(project));

    if (options.animations) {
      // In case the project explicitly uses the NoopAnimationsModule, we should print a warning
      // message that makes the user aware of the fact that we won't automatically set up
      // animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
      // is already configured, we would cause unexpected behavior and runtime exceptions.
      if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
        return console.warn(
          chalk.red(
            `Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
              `because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please ` +
              `manually set up browser animations.`
          )
        );
      }
github positive-js / mosaic / packages / mosaic / schematics / ng-add / setup-project.ts View on Github external
return (host: Tree) => {

        const workspace = getWorkspace(host);
        const project = getProjectFromWorkspace(workspace, options.project);

        const appModulePath = getAppModulePath(host, getProjectMainFile(project));

        if (options.animations) {
            if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
                console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
                    `because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
                    `set up browser animations.`));

                return;
            }

            addModuleImportToRootModule(host, browserAnimationsModuleName,
                '@angular/platform-browser/animations', project);
        } else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
            // Do not add the NoopAnimationsModule module if the project already explicitly uses
            // the BrowserAnimationsModule.
            addModuleImportToRootModule(host, noopAnimationsModuleName,
github angular / components / src / material / schematics / ng-add / setup-project.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project);
    const appModulePath = getAppModulePath(host, getProjectMainFile(project));

    if (options.animations) {
      // In case the project explicitly uses the NoopAnimationsModule, we should print a warning
      // message that makes the user aware of the fact that we won't automatically set up
      // animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
      // is already configured, we would cause unexpected behavior and runtime exceptions.
      if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
        context.logger.error(
            `Could not set up "${browserAnimationsModuleName}" ` +
            `because "${noopAnimationsModuleName}" is already imported.`);
        context.logger.info(`Please manually set up browser animations.`);
        return;
      }

      addModuleImportToRootModule(host, browserAnimationsModuleName,
          '@angular/platform-browser/animations', project);
github cyrilletuzi / angular-async-local-storage / projects / ngx-pwa / local-storage / schematics / utility / module.ts View on Github external
function getAppModule(host: Tree, mainPath: string): { appModulePath: string; appModuleFile: string; } {

  const appModulePath = getAppModulePath(host, mainPath);

  if (!host.exists(appModulePath)) {
    throw new SchematicsException(`Can't find AppModule`);
  }

  const appModuleFile = (host.read(appModulePath) as Buffer).toString('utf-8');

  return { appModulePath, appModuleFile };

}
github NG-ZORRO / ng-zorro-antd / schematics / ng-add / setup-project / add-required-modules.ts View on Github external
return (host: Tree) => {
    const workspace = getWorkspace(host);
    const project = getProjectFromWorkspace(workspace, options.project) as WorkspaceProject;
    const appModulePath = getAppModulePath(host, getProjectMainFile(project));

    for (const module in modulesMap) {
      addModuleImportToApptModule(host, module, modulesMap[ module ],
        project, appModulePath, options);
    }

    return host;
  };
}
github valor-software / ngx-bootstrap / schematics / src / utils / index.ts View on Github external
export function addModuleImportToRootModule(host: Tree, moduleName: string, src: string, project: WorkspaceProject) {
  const modulePath = getAppModulePath(host, getProjectMainFile(project));
  addModuleImportToModule(host, modulePath, moduleName, src);
}
github FortAwesome / angular-fontawesome / projects / schematics / src / ng-add / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    const workspace = getWorkspace(host);
    const project = workspace.projects[projectName || workspace.defaultProject!];
    const buildOptions = getProjectTargetOptions(project, 'build');
    const modulePath = getAppModulePath(host, buildOptions.main);
    const moduleSource = getSourceFile(host, modulePath);
    const changes = addImportToModule(
      moduleSource,
      modulePath,
      'FontAwesomeModule',
      '@fortawesome/angular-fontawesome',
    );
    const recorder = host.beginUpdate(modulePath);
    changes.forEach((change) => {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    });
    host.commitUpdate(recorder);

    context.addTask(new TslintFixTask(modulePath, {}));
github ngx-meta / rules / libs / schematics / ng-generate / m-page / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {

    try {
      const matButton = ['MatButtonModule', '@angular/material'];
      const modulePath = getAppModulePath(host, getMainProjectPath(host, options));
      const relativePath = buildRelativePath(modulePath, componentPath);

      const srcPath = getSourceFile(host, modulePath);
      const compName = strings.classify(`${options.name}Component`);

      if (!isImported(srcPath, compName, relativePath)) {
        let changes = addDeclarationToModule(srcPath, modulePath, compName, relativePath);

        if (options.uiLib === 'material') {
          changes = [...changes, ...addImportToModule(srcPath, modulePath, matButton[0],
            matButton[1])];
        }

        const recorder = host.beginUpdate(modulePath);
        changes.forEach((change) => {
          if (change instanceof InsertChange) {
github articodeltd / angular-cesium / projects / angular-cesium / schematics / ng-add / index.ts View on Github external
return (tree: Tree, _context: SchematicContext) => {
    const workspace = getWorkspace(tree);
    const project = workspace.projects[workspace.defaultProject];

    const modulePath = getAppModulePath(tree, getProjectMainFile(project));
    const moduleSource = getSourceFile(tree, modulePath);

    const changes = addImportToModule(moduleSource, modulePath, 'AngularCesiumModule.forRoot()', 'angular-cesium')
      .concat(addImportToModule(moduleSource, modulePath, 'AngularCesiumWidgetsModule', 'angular-cesium'));
    const recorder = tree.beginUpdate(modulePath);

    changes.forEach((change) => {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    });

    tree.commitUpdate(recorder);

    return tree;
  };
github NarikMe / narik-angular / projects / narik-cli / schematics / ng-add / index.ts View on Github external
export function addModuleImportToRootModule(
  host: Tree,
  moduleName: string,
  src: string,
  project: WorkspaceProject,
  isModuleImport: boolean = true
) {
  const modulePath = getAppModulePath(host, getProjectMainFile(project));
  addModuleImportToModule(host, modulePath, moduleName, src, isModuleImport);
}