How to use the @schematics/angular/utility/ast-utils.addSymbolToNgModuleMetadata 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 angular / components / src / material / schematics / ng-update / upgrade-rules / hammer-gestures-v9 / hammer-gestures-rule.ts View on Github external
getModuleSpecifier(gestureConfigPath, sourceFile.fileName), false,
        this._getGestureConfigIdentifiersOfFile(sourceFile));
    const hammerConfigTokenExpr = this._importManager.addImportToSourceFile(
        sourceFile, HAMMER_CONFIG_TOKEN_NAME, HAMMER_CONFIG_TOKEN_MODULE);
    const newProviderNode = ts.createObjectLiteral([
      ts.createPropertyAssignment('provide', hammerConfigTokenExpr),
      ts.createPropertyAssignment('useClass', gestureConfigExpr)
    ]);

    // If the providers field exists and already contains references to the hammer gesture
    // config token and the gesture config, we naively assume that the gesture config is
    // already set up. We only want to add the gesture config provider if it is not set up.
    if (!providerIdentifiers ||
        !(this._hammerConfigTokenReferences.some(r => providerIdentifiers.includes(r.node)) &&
          this._gestureConfigReferences.some(r => providerIdentifiers.includes(r.node)))) {
      addSymbolToNgModuleMetadata(
          sourceFile, relativePath, 'providers', this._printNode(newProviderNode, sourceFile), null)
          .forEach(change => {
            if (change instanceof InsertChange) {
              recorder.insertRight(change.pos, change.toAdd);
            }
          });
    }
  }
github SAP / cloud-commerce-spartacus-storefront / projects / schematics / src / shared / utils / module-file-utils.ts View on Github external
function addToMetadata(
  host: Tree,
  modulePath: string,
  importText: string,
  metadataType: 'imports' | 'declarations' | 'entryComponents' | 'exports',
  moduleSource?: ts.SourceFile
): InsertChange[] {
  moduleSource = moduleSource || getTsSourceFile(host, modulePath);
  return addSymbolToNgModuleMetadata(
    moduleSource,
    modulePath,
    metadataType,
    importText
  ) as InsertChange[];
}
github OnsenUI / OnsenUI / bindings / angular2 / schematics / src / 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));

    const moduleSource = getSourceFile(host, appModulePath);
    if (!moduleSource) {
        throw new SchematicsException(`Module not found: ${appModulePath}`);
    }

    const changes = addSymbolToNgModuleMetadata(moduleSource, appModulePath, 'schemas', 'CUSTOM_ELEMENTS_SCHEMA', '@angular/core');

    const declarationRecorder = host.beginUpdate(appModulePath);
    for (const change of changes) {
      if (change instanceof InsertChange) {
        declarationRecorder.insertLeft(change.pos, change.toAdd);
      }
    }
    host.commitUpdate(declarationRecorder);

    return host;
  }
}
github NativeScript / nativescript-schematics / src / generate / module / index.ts View on Github external
(tree: Tree) => {
    const moduleSource = getSourceFile(tree, modulePath);
    const recorder = tree.beginUpdate(modulePath);

    const metadataChange = addSymbolToNgModuleMetadata(
      moduleSource, modulePath,
      'schemas', 'NO_ERRORS_SCHEMA',
      '@angular/core');

    metadataChange.forEach((change: InsertChange) =>
      recorder.insertRight(change.pos, change.toAdd),
    );
    tree.commitUpdate(recorder);

    return tree;
  };
github NativeScript / nativescript-schematics / src / module / index.ts View on Github external
const addNSCommonModule = (tree: Tree, modulePath: string) => {
  const moduleSource = getSourceFile(tree, modulePath);
  const recorder = tree.beginUpdate(modulePath);

  const metadataChange = addSymbolToNgModuleMetadata(
    moduleSource, modulePath,
    'imports', 'NativeScriptCommonModule',
    'nativescript-angular/common');

  metadataChange.forEach((change: InsertChange) =>
    recorder.insertRight(change.pos, change.toAdd)
  );
  tree.commitUpdate(recorder);

  return tree;
};