Giter Site home page Giter Site logo

schematics's Introduction

Getting Started With Schematics

This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.

Testing

To test locally, install @angular-devkit/schematics globally and use the schematics command line tool. That tool acts the same as the generate command of the Angular CLI, but also has a debug mode.

Check the documentation with

schematics --help

Unit Testing

npm run test will run the unit tests, using Jasmine as a runner and test framework.

Publishing

To publish, simply do:

npm run build
npm publish

That's it!

Running a schematic while in development

schematics .:<schematic-name> --dry-run false

The dry-run false is only necessary when you're doing relative path schematics, when developing. Dry running is on by default when using relative paths.

Logs

Log 20180525 1448

I can parse and walk through a file (using .toString() and JSON.parse()). But when I want to record updates (type UpdateRecorder) I only have insertLeft and insertRight. So I think I'll have to calculate what index I have to pass it to insert it into the right spot. Kinda tricky? Maybe missing an API for mutations like this.

  • AST transformations looks like something to look into.
  • Maybe check what @angular/ did here? How they mutated the package.json etc.

Log 20180608 0952

JSON files are quite easy to parse and overwrite, looked up an example from the Angular/schematics. Looking into file manipulation that isn't JSON, seems like more of what I described in the previous log.

Diving into that right now.

Log 20180608 1138

Generated a new Angular app, ng new ng-test. Used npm link ../schematics/ to link my schematics.

Now I could run schematics schematics:packageupdate to update my package.json.

Back to other file manipulation.

Log 20180608 1550

Finished for now, got some additional file manipulation going by looking at other repositories. Copied a few utils so I could implement my own addImportStatement function which works very nicely.

Main thing is: JSON manipulation is quite easy, so files like package.json or angular.json are quite easy to test and update. It gets a bit more complex when you want to manipulate other files.

URL references:

schematics's People

Contributors

bjeaurn avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.