Skip to content

Instantly share code, notes, and snippets.

@MSakamaki
Last active March 30, 2018 06:48
Show Gist options
  • Save MSakamaki/f11ab492bf449bd8dbc47103b838614c to your computer and use it in GitHub Desktop.
Save MSakamaki/f11ab492bf449bd8dbc47103b838614c to your computer and use it in GitHub Desktop.
@angular/devkit

command

generate schematics and development

# generate new schematics project
schematics blank --name=[schematics Name]

# add collection
schematics blank --name=[collenction Name]

# building
npm run build

# local checking
schematics .:[collenction名] [--Options]

create new project (ng new)

In ng-new, use workspace, application.

# Run on exists project
schematics blank --name=application
# global link
npm link ${generate schematics project path}

./src/application/index.ts

import { Rule, SchematicContext, Tree, chain, externalSchematic } from '@angular-devkit/schematics';

export function application(options: any): Rule {
  return chain([
    externalSchematic('@schematics/angular', 'application', options),
  ]);
}
  • generate my project
ng new --collection=[schematics Name] [application name]

file generate / update

# angular-cli initialize
ng new my-project
cd my-project
# global link
npm link ${generate schematics project path}

# generate my collection
ng g [schematics名]:[Collection名] [--Options]

Code Chips

Update existing code

function readTypeScript(options: any): Rule {
  return (host: Tree, context: SchematicContext) => {
    host.getDir('/files').visit(filePath => {
      if (!filePath.endsWith('.ts')) {
        return ;
      }
      const text = host.read(filePath);
      if (text === null) {
        throw new SchematicsException(`File ${filePath} does not exist.`);
      }

      const declarationRecorder = host.beginUpdate(filePath);
      /** 
       * Update existing code
      **/
      host.commitUpdate(declarationRecorder);

    });

    return host;
  };
}

export function updateCode(options: any): Rule {
  return branchAndMerge(chain([
    readTypeScript(options),
  ]));
}

readme

sample of how to make

Links

tutorial

AsT Explorer

@MSakamaki
Copy link
Author

MSakamaki commented Mar 30, 2018

take a look

  • use ng new --collenction [SchematicsName]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment