@angular-cli/ast-tools

  • Version 1.0.16
  • Published
  • 4 dependencies
  • MIT license

Install

npm i @angular-cli/ast-tools
yarn add @angular-cli/ast-tools
pnpm add @angular-cli/ast-tools

Overview

CLI tool for Angular

Index

Variables

variable NodeHost

const NodeHost: Host;

    Functions

    function addDeclarationToModule

    addDeclarationToModule: (
    modulePath: string,
    classifiedName: string,
    importPath: string
    ) => Promise<Change>;
    • Custom function to insert a declaration (component, pipe, directive) into NgModule declarations. It also imports the component.

    function addExportToModule

    addExportToModule: (
    modulePath: string,
    classifiedName: string,
    importPath: string
    ) => Promise<Change>;
    • Custom function to insert an export into NgModule. It also imports it.

    function addImportToModule

    addImportToModule: (
    modulePath: string,
    classifiedName: string,
    importPath: string
    ) => Promise<Change>;
    • Custom function to insert a declaration (component, pipe, directive) into NgModule declarations. It also imports the component.

    function addItemsToRouteProperties

    addItemsToRouteProperties: (
    routesFile: string,
    routes: { [key: string]: string[] }
    ) => Change[];
    • Add more properties to the route object in routes.ts

      Parameter routesFile

      routes.ts

      Parameter routes

      Object {route: [key, value]}

    function addPathToRoutes

    addPathToRoutes: (routesFile: string, pathOptions: any) => Change[];
    • Inserts a path to the new route into src/routes.ts if it doesn't exist

      Parameter routesFile

      Parameter pathOptions

      Change[]

      Throws

      Error if routesFile has multiple export default or none.

    function addProviderToModule

    addProviderToModule: (
    modulePath: string,
    classifiedName: string,
    importPath: string
    ) => Promise<Change>;
    • Custom function to insert a provider into NgModule. It also imports it.

    function applyChanges

    applyChanges: (changes: Change[], host?: Host) => Promise<void>;
    • Sort changes in decreasing order and apply them.

      Parameter changes

      Parameter host

      Promise

    function bootstrapItem

    bootstrapItem: (
    mainFile: string,
    imports: { [key: string]: (string | boolean)[] },
    toBootstrap: string
    ) => Change[];
    • Adds imports to mainFile and adds toBootstrap to the array of providers in bootstrap, if not present

      Parameter mainFile

      main.ts

      Parameter imports

      Object { importedClass: ['path/to/import/from', defaultStyleImport?] }

      Parameter toBootstrap

    function confirmComponentExport

    confirmComponentExport: (file: string, componentName: string) => boolean;
    • Verifies that a component file exports a class of the component

      Parameter file

      Parameter componentName

      whether file exports componentName

    function findNodes

    findNodes: (node: ts.Node, kind: ts.SyntaxKind, max?: number) => ts.Node[];
    • Find all nodes from the AST in the subtree of node of SyntaxKind kind.

      Parameter node

      Parameter kind

      Parameter max

      The maximum number of items to return. all nodes of kind, or [] if none is found

    function getContentOfKeyLiteral

    getContentOfKeyLiteral: (source: ts.SourceFile, node: ts.Node) => string;

      function getDecoratorMetadata

      getDecoratorMetadata: (
      source: ts.SourceFile,
      identifier: string,
      module: string
      ) => Observable<ts.Node>;

        function getSource

        getSource: (filePath: string) => ts.SourceFile;
        • Get TS source file based on path.

          Parameter filePath

          source file of ts.SourceFile kind

        function getSourceNodes

        getSourceNodes: (sourceFile: ts.SourceFile) => Observable<ts.Node>;
        • Get all the nodes from a source, as an observable.

          Parameter sourceFile

          The source file object.

          Returns

          {Observable<ts.Node>} An observable of all the nodes in the source.

        function insertAfterLastOccurrence

        insertAfterLastOccurrence: (
        nodes: ts.Node[],
        toInsert: string,
        file: string,
        fallbackPos?: number,
        syntaxKind?: ts.SyntaxKind
        ) => Change;
        • Insert toInsert after the last occurence of ts.SyntaxKind[nodes[i].kind] or after the last of occurence of syntaxKind if the last occurence is a sub child of ts.SyntaxKind[nodes[i].kind] and save the changes in file.

          Parameter nodes

          insert after the last occurence of nodes

          Parameter toInsert

          string to insert

          Parameter file

          file to insert changes into

          Parameter fallbackPos

          position to insert if toInsert happens to be the first occurence

          Parameter syntaxKind

          the ts.SyntaxKind of the subchildren to insert after Change instance Error if toInsert is first occurence but fall back is not set

        function insertImport

        insertImport: (
        fileToEdit: string,
        symbolName: string,
        fileName: string,
        isDefault?: boolean
        ) => Change;
        • Add Import import { symbolName } from fileName if the import doesn't exit already. Assumes fileToEdit can be resolved and accessed.

          Parameter fileToEdit

          (file we want to add import to)

          Parameter symbolName

          (item to import)

          Parameter fileName

          (path to the file)

          Parameter isDefault

          (if true, import follows style for importing default exports) Change

        function removeAstNode

        removeAstNode: (node: ts.Node) => Change;

          function resolveComponentPath

          resolveComponentPath: (
          projectRoot: string,
          currentDir: string,
          filePath: string
          ) => string;
          • Resolve a path to a component file. If the path begins with path.sep, it is treated to be absolute from the app/ directory. Otherwise, it is relative to currDir

            Parameter projectRoot

            Parameter currentDir

            Parameter filePath

            componentName or path to componentName component file name Error if component file referenced by path is not found

          Classes

          class InsertChange

          class InsertChange implements Change {}
          • Will add text to the source code.

          constructor

          constructor(path: string, pos: number, toAdd: string);

            property description

            description: string;

              property order

              order: number;

                property path

                path: string;

                  method apply

                  apply: (host: Host) => Promise<any>;
                  • This method does not insert spaces if there is none in the original string.

                  class MultiChange

                  class MultiChange implements Change {}
                  • An operation that mixes two or more changes, and merge them (in order). Can only apply to a single file. Use a ChangeManager to apply changes to multiple files.

                  constructor

                  constructor(...changes: (Change | Change[])[]);

                    property description

                    readonly description: string;

                      property order

                      readonly order: number;

                        property path

                        readonly path: string;

                          method appendChange

                          appendChange: (change: Change) => void;

                            method apply

                            apply: (host: Host) => Promise<void>;

                              class NoopChange

                              class NoopChange implements Change {}
                              • An operation that does nothing.

                              property description

                              description: string;

                                property order

                                order: number;

                                  property path

                                  path: string;

                                    method apply

                                    apply: () => Promise<void>;

                                      class RemoveChange

                                      class RemoveChange implements Change {}
                                      • Will remove text from the source code.

                                      constructor

                                      constructor(path: string, pos: number, toRemove: string);

                                        property description

                                        description: string;

                                          property order

                                          order: number;

                                            property path

                                            path: string;

                                              method apply

                                              apply: (host: Host) => Promise<any>;

                                                class ReplaceChange

                                                class ReplaceChange implements Change {}
                                                • Will replace text from the source code.

                                                constructor

                                                constructor(path: string, pos: number, oldText: string, newText: string);

                                                  property description

                                                  description: string;

                                                    property order

                                                    order: number;

                                                      property path

                                                      path: string;

                                                        method apply

                                                        apply: (host: Host) => Promise<any>;

                                                          Interfaces

                                                          interface Change

                                                          interface Change {}

                                                            property description

                                                            readonly description: string;

                                                              property order

                                                              readonly order: number;

                                                                property path

                                                                readonly path: string | null;

                                                                  method apply

                                                                  apply: (host: Host) => Promise<void>;

                                                                    interface Host

                                                                    interface Host {}

                                                                      method read

                                                                      read: (path: string) => Promise<string>;

                                                                        method write

                                                                        write: (path: string, content: string) => Promise<void>;

                                                                          Package Files (5)

                                                                          Dependencies (4)

                                                                          Dev Dependencies (0)

                                                                          No dev dependencies.

                                                                          Peer Dependencies (0)

                                                                          No peer dependencies.

                                                                          Badge

                                                                          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@angular-cli/ast-tools.

                                                                          • Markdown
                                                                            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@angular-cli/ast-tools)
                                                                          • HTML
                                                                            <a href="https://www.jsdocs.io/package/@angular-cli/ast-tools"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>