How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • // index.ts
    
    import { strings } from "@angular-devkit/core";
    import {
      Rule,
      SchematicContext,
      SchematicsException,
      Tree,
      apply,
      branchAndMerge,
      mergeWith,
      template,
      url,
    } from "@angular-devkit/schematics";
    import { Schema as ClassOptions } from "./schema";
    
    export default function (options: ClassOptions): Rule {
      return (tree: Tree, context: SchematicContext) => {
        if (!options.name) {
          throw new SchematicsException(
            "Option (name) is required."
          );
        }
    
        const templateSource = apply(url("./files"), [
          template({
            ...strings,
            ...options,
          }),
        ]);
    
        return branchAndMerge(mergeWith(templateSource));
      };
    }
    
    Docs
    0
  • // index.ts
    
    import { strings } from "@angular-devkit/core";
    import {
      Rule,
      SchematicContext,
      SchematicsException,
      Tree,
      apply,
      branchAndMerge,
      mergeWith,
      template,
      url,
    } from "@angular-devkit/schematics";
    import { Schema as ClassOptions } from "./schema";
    
    export default function (options: ClassOptions): Rule {
      return (tree: Tree, context: SchematicContext) => {
        if (!options.name) {
          throw new SchematicsException(
            "Option (name) is required."
          );
        }
    
        const templateSource = apply(url("./files"), [
          template({
            ...strings,
            ...options,
          }),
        ]);
    
        return branchAndMerge(mergeWith(templateSource));
      };
    }
    
    Docs
    0
  • import {
      Rule,
      Tree,
      SchematicsException,
      apply,
      url,
      applyTemplates,
      move,
      chain,
      mergeWith,
    } from "@angular-devkit/schematics";
    
    import {
      strings,
      normalize,
      virtualFs,
      workspaces,
    } from "@angular-devkit/core";
    
    import { Schema as MyServiceSchema } from "./schema";
    
    function createHost(tree: Tree): workspaces.WorkspaceHost {
      return {
        async readFile(path: string): Promise {
          const data = tree.read(path);
          if (!data) {
            throw new SchematicsException("File not found.");
          }
          return virtualFs.fileBufferToString(data);
        },
        async writeFile(
          path: string,
          data: string
        ): Promise {
          return tree.overwrite(path, data);
        },
        async isDirectory(path: string): Promise {
          return (
            !tree.exists(path) &&
            tree.getDir(path).subfiles.length > 0
          );
        },
        async isFile(path: string): Promise {
          return tree.exists(path);
        },
      };
    }
    
    export function myService(options: MyServiceSchema): Rule {
      return async (tree: Tree) => {
        const host = createHost(tree);
        const { workspace } = await workspaces.readWorkspace(
          "/",
          host
        );
    
        if (!options.project) {
          options.project = workspace.extensions.defaultProject;
        }
    
        const project = workspace.projects.get(options.project);
        if (!project) {
          throw new SchematicsException(
            `Invalid project name: ${options.project}`
          );
        }
    
        const projectType =
          project.extensions.projectType === "application"
            ? "app"
            : "lib";
    
        if (options.path === undefined) {
          options.path = `${project.sourceRoot}/${projectType}`;
        }
    
        const templateSource = apply(url("./files"), [
          applyTemplates({
            classify: strings.classify,
            dasherize: strings.dasherize,
            name: options.name,
          }),
          move(normalize(options.path as string)),
        ]);
    
        return chain([mergeWith(templateSource)]);
      };
    }
    
    Docs
    0
  • // index.ts
    
    import { strings } from "@angular-devkit/core";
    import {
      Rule,
      SchematicContext,
      SchematicsException,
      Tree,
      apply,
      branchAndMerge,
      mergeWith,
      template,
      url,
    } from "@angular-devkit/schematics";
    import { Schema as ClassOptions } from "./schema";
    
    export default function (options: ClassOptions): Rule {
      return (tree: Tree, context: SchematicContext) => {
        if (!options.name) {
          throw new SchematicsException(
            "Option (name) is required."
          );
        }
    
        const templateSource = apply(url("./files"), [
          template({
            ...strings,
            ...options,
          }),
        ]);
    
        return branchAndMerge(mergeWith(templateSource));
      };
    }
    
    Docs
    0
  • import {
      Rule,
      Tree,
      SchematicsException,
      apply,
      url,
      applyTemplates,
      move,
      chain,
      mergeWith,
    } from "@angular-devkit/schematics";
    
    import {
      strings,
      normalize,
      virtualFs,
      workspaces,
    } from "@angular-devkit/core";
    
    import { Schema as MyServiceSchema } from "./schema";
    
    function createHost(tree: Tree): workspaces.WorkspaceHost {
      return {
        async readFile(path: string): Promise {
          const data = tree.read(path);
          if (!data) {
            throw new SchematicsException("File not found.");
          }
          return virtualFs.fileBufferToString(data);
        },
        async writeFile(
          path: string,
          data: string
        ): Promise {
          return tree.overwrite(path, data);
        },
        async isDirectory(path: string): Promise {
          return (
            !tree.exists(path) &&
            tree.getDir(path).subfiles.length > 0
          );
        },
        async isFile(path: string): Promise {
          return tree.exists(path);
        },
      };
    }
    
    export function myService(options: MyServiceSchema): Rule {
      return async (tree: Tree) => {
        const host = createHost(tree);
        const { workspace } = await workspaces.readWorkspace(
          "/",
          host
        );
    
        if (!options.project) {
          options.project = workspace.extensions.defaultProject;
        }
    
        const project = workspace.projects.get(options.project);
        if (!project) {
          throw new SchematicsException(
            `Invalid project name: ${options.project}`
          );
        }
    
        const projectType =
          project.extensions.projectType === "application"
            ? "app"
            : "lib";
    
        if (options.path === undefined) {
          options.path = `${project.sourceRoot}/${projectType}`;
        }
    
        const templateSource = apply(url("./files"), [
          applyTemplates({
            classify: strings.classify,
            dasherize: strings.dasherize,
            name: options.name,
          }),
          move(normalize(options.path as string)),
        ]);
    
        return chain([mergeWith(templateSource)]);
      };
    }
    
    Docs
    0
  • // index.ts
    
    import { strings } from "@angular-devkit/core";
    import {
      Rule,
      SchematicContext,
      SchematicsException,
      Tree,
      apply,
      branchAndMerge,
      mergeWith,
      template,
      url,
    } from "@angular-devkit/schematics";
    import { Schema as ClassOptions } from "./schema";
    
    export default function (options: ClassOptions): Rule {
      return (tree: Tree, context: SchematicContext) => {
        if (!options.name) {
          throw new SchematicsException(
            "Option (name) is required."
          );
        }
    
        const templateSource = apply(url("./files"), [
          template({
            ...strings,
            ...options,
          }),
        ]);
    
        return branchAndMerge(mergeWith(templateSource));
      };
    }
    
    Docs
    0
  • import {
      Rule,
      Tree,
      SchematicsException,
      apply,
      url,
      applyTemplates,
      move,
      chain,
      mergeWith,
    } from "@angular-devkit/schematics";
    
    import {
      strings,
      normalize,
      virtualFs,
      workspaces,
    } from "@angular-devkit/core";
    
    import { Schema as MyServiceSchema } from "./schema";
    
    function createHost(tree: Tree): workspaces.WorkspaceHost {
      return {
        async readFile(path: string): Promise {
          const data = tree.read(path);
          if (!data) {
            throw new SchematicsException("File not found.");
          }
          return virtualFs.fileBufferToString(data);
        },
        async writeFile(
          path: string,
          data: string
        ): Promise {
          return tree.overwrite(path, data);
        },
        async isDirectory(path: string): Promise {
          return (
            !tree.exists(path) &&
            tree.getDir(path).subfiles.length > 0
          );
        },
        async isFile(path: string): Promise {
          return tree.exists(path);
        },
      };
    }
    
    export function myService(options: MyServiceSchema): Rule {
      return async (tree: Tree) => {
        const host = createHost(tree);
        const { workspace } = await workspaces.readWorkspace(
          "/",
          host
        );
    
        if (!options.project) {
          options.project = workspace.extensions.defaultProject;
        }
    
        const project = workspace.projects.get(options.project);
        if (!project) {
          throw new SchematicsException(
            `Invalid project name: ${options.project}`
          );
        }
    
        const projectType =
          project.extensions.projectType === "application"
            ? "app"
            : "lib";
    
        if (options.path === undefined) {
          options.path = `${project.sourceRoot}/${projectType}`;
        }
    
        const templateSource = apply(url("./files"), [
          applyTemplates({
            classify: strings.classify,
            dasherize: strings.dasherize,
            name: options.name,
          }),
          move(normalize(options.path as string)),
        ]);
    
        return chain([mergeWith(templateSource)]);
      };
    }
    
    Docs
    0
  • // index.ts
    
    import { strings } from "@angular-devkit/core";
    import {
      Rule,
      SchematicContext,
      SchematicsException,
      Tree,
      apply,
      branchAndMerge,
      mergeWith,
      template,
      url,
    } from "@angular-devkit/schematics";
    import { Schema as ClassOptions } from "./schema";
    
    export default function (options: ClassOptions): Rule {
      return (tree: Tree, context: SchematicContext) => {
        if (!options.name) {
          throw new SchematicsException(
            "Option (name) is required."
          );
        }
    
        const templateSource = apply(url("./files"), [
          template({
            ...strings,
            ...options,
          }),
        ]);
    
        return branchAndMerge(mergeWith(templateSource));
      };
    }
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples