<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Felipe Norato Lacerda</title>
    <description>The latest articles on DEV Community by Felipe Norato Lacerda (@norato).</description>
    <link>https://dev.to/norato</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F198322%2F8b6db91b-f0a5-4910-96bc-fcc48e60b96d.jpeg</url>
      <title>DEV Community: Felipe Norato Lacerda</title>
      <link>https://dev.to/norato</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/norato"/>
    <language>en</language>
    <item>
      <title>Feature and Behavior Schematics - The Composition Approach</title>
      <dc:creator>Felipe Norato Lacerda</dc:creator>
      <pubDate>Fri, 27 Sep 2019 00:49:51 +0000</pubDate>
      <link>https://dev.to/norato/feature-and-behavior-schematics-the-composition-approach-o4e</link>
      <guid>https://dev.to/norato/feature-and-behavior-schematics-the-composition-approach-o4e</guid>
      <description>&lt;p&gt;Some weeks ago I started to study how to create schematics to deliver faster and creating code patterns. I could try lots of techniques in this meantime to make the schematics to my team, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Template files;&lt;/li&gt;
&lt;li&gt;Apply string manipulations;&lt;/li&gt;
&lt;li&gt;Path manipulation to move files;&lt;/li&gt;
&lt;li&gt;Filtering files by props.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And also my favorite one. That allows you to create complete flows, but without big complexity. This is the &lt;strong&gt;Schematic Composition&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;This technique provides you to combine the schematics you created and external ones, like Angular schematics, to build powerful schematics that could create a whole structure for a feature.&lt;/p&gt;

&lt;p&gt;It's important to alert you that this is a 20% technical and &lt;strong&gt;80% philosophic post&lt;/strong&gt;. 😂 &lt;/p&gt;

&lt;p&gt;I wrote a post explaining more about creating schematics and how to simplify that &lt;a href="https://medium.com/@felipenoratolacerda/one-line-angular-schematics-the-practical-guide-6a82ade5a94f" rel="noopener noreferrer"&gt;using just one line&lt;/a&gt;. There you can see how to apply path, templates, string manipulation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is this technique so useful?
&lt;/h3&gt;

&lt;p&gt;We can think we are using the functional programming approach. Each schematic is a function, that has its responsibility and could be joined by another Schematic to compose a big flow.&lt;/p&gt;

&lt;p&gt;Sharing the responsibility to many functions we reduce the complexity, so &lt;em&gt;it is easy to maintain and reuse&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Another big benefit in creating small schematics is when you need to create just a part of a feature or flow, &lt;em&gt;you can call this one schematic alone&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;There are some cases that you didn't have defined the design and architecture pattern at the beginning of the project. So we create some pages, start to define the patterns and, finally, create the schematics to each single component part of this pattern. When you start to revisit the old pages to apply the patterns &lt;em&gt;you can just use the schematics you need to rewrite the old component&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Basically, we can use the &lt;strong&gt;Feature Schematic&lt;/strong&gt; to create a new feature from scratch and the &lt;strong&gt;Behavior Schematic&lt;/strong&gt; to compose the Feature Schematic to apply the new code to an existent feature.&lt;/p&gt;

&lt;p&gt;I, personally, like to think in using the Feature Schematic like a &lt;strong&gt;Façade&lt;/strong&gt; to join lots of Behavior Schematics and create a complete feature or flow. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Behavior Schematics&lt;/strong&gt; needs to be &lt;em&gt;more generic as possible&lt;/em&gt; to be used alone and to compose many other Feature Schematics if it is required. &lt;/p&gt;

&lt;p&gt;It is very important to define patterns of code and layout to make these schematics really productive, but how granular and how you will implement this is up to your needs.&lt;/p&gt;

&lt;p&gt;Now I will explain to you how I implement the schematics to my current project and I defined the &lt;em&gt;Feature and Behavior Schematics&lt;/em&gt; approach.&lt;/p&gt;

&lt;p&gt;You can follow the examples on &lt;a href="https://github.com/norato/schematic-composition" rel="noopener noreferrer"&gt;schematic-composition at my github&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Behavior Schematic
&lt;/h3&gt;

&lt;p&gt;To explain the conception about this we will implement a form and a table and create one behavior schematics for each one. To make it simple, we will use the angular material schematics to create the components for us. So here, is the first example: &lt;strong&gt;How to extend an external schematics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We just use the method &lt;code&gt;externalSchematic&lt;/code&gt; with the collection name, schematic name and the options. 😄&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular-devkit/schematics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="nf"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/material&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we reuse the &lt;code&gt;@angular/material:table&lt;/code&gt; schematic and it generates some files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk3utiktik0j4fwr1sbd2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk3utiktik0j4fwr1sbd2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same we will do to create the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular-devkit/schematics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="nf"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/material&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;addressForm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For both schematics, I set the same schema just &lt;strong&gt;name and project&lt;/strong&gt; properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"http://json-schema.org/schema"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"form"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Library name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"$default"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"$source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"argv"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"index"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"project"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Library name"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"project"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Feature Schematic
&lt;/h3&gt;

&lt;p&gt;For this schematic, we can face it as the Façade to join the other schematics. The method to call the schematics from your collection is &lt;strong&gt;schematic&lt;/strong&gt;, where you only need to pass the schematic name and the options. It's easy!&lt;/p&gt;

&lt;p&gt;The extra thing I add here is the module schematic for the feature.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@schematics/angular/component/schema&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;schematic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular-devkit/schematics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;chain&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="nf"&gt;externalSchematic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@schematics/angular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;routing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;schematic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;table&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;schematic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;form&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see, when we call this Feature Schematic it will call the Behavior Schematics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmhng418k8blarmy1v9j7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmhng418k8blarmy1v9j7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well done!&lt;/p&gt;

&lt;p&gt;This example is for you to think you can use schematics to create things for you. I did thought this when I realized how powerful is this and how much it could help me in other past projects.&lt;/p&gt;

</description>
      <category>schematics</category>
      <category>productivity</category>
      <category>angular</category>
      <category>nx</category>
    </item>
    <item>
      <title>Thoughts about monorepos and code-sharing</title>
      <dc:creator>Felipe Norato Lacerda</dc:creator>
      <pubDate>Sun, 15 Sep 2019 14:41:07 +0000</pubDate>
      <link>https://dev.to/norato/thoughts-about-monorepos-and-code-sharing-3gph</link>
      <guid>https://dev.to/norato/thoughts-about-monorepos-and-code-sharing-3gph</guid>
      <description>&lt;p&gt;Some weeks ago I went to a conference and I could hear more about monorepos and it makes my mind blows. The point that makes my mind blows was how to share code between applications in an easy way.&lt;/p&gt;

&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;I worked on some projects that I really want to solve the code-sharing problems across frontend, libs, and microservices.&lt;/p&gt;

&lt;p&gt;In a project, we had an Angular Web Application and many Node Microservices, each in different repositories. And it was close to impossible to share code between those applications since we did not have a private npm.&lt;/p&gt;

&lt;p&gt;In other, we had to create an Angular Web application and an Electron desktop with Angular application both using an Angular Component Library. All in the same repository, and it as really difficult to manage, but, here we could share code.&lt;/p&gt;

&lt;p&gt;For those projects, I think using monorepo could solve this kind of problems because we would have all applications in a single repository and we could painlessly share code.&lt;/p&gt;

&lt;p&gt;But, the second project example we had a monorepo and it still causing pain to manage the projects. That was because we did not use a monorepo manager, we actually we did not know that it as a monorepo.&lt;/p&gt;

&lt;h3&gt;
  
  
  A possible solution
&lt;/h3&gt;

&lt;p&gt;So, what really solves the complexity around managing multiples projects in a single repository is a monorepo manager. I have been trying &lt;a href="https://nx.dev"&gt;nx by nwrl&lt;/a&gt; since that.&lt;/p&gt;

&lt;p&gt;The NX has some commands to create, build, test and check the interdependencies between the applications and libs. It is really useful and it will keep all organized without multiple customs commands, as we need to make in the second project.&lt;/p&gt;

&lt;p&gt;In this time studying and trying NX to manage monorepos I can list some &lt;em&gt;pros&lt;/em&gt; and &lt;em&gt;cons&lt;/em&gt; to use that for a javascript monorepo.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You don't need to download tons of node modules for each project. It will be reused by all libs and applications;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All code will be in the same place, so it is easy to navigate through the project;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You don't need to duplicate or publish some code in npm to share code through the application. It makes easy to refactor and improve code;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In a private project, you only need to allow access to a single repository;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using a monorepo manager, like NX, you can use many commands from its CLI to automate the flow;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will keep all working in the same branch;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is easy to test everything together and check what artifact was affected by a change. You also can only test and build the affected artifact;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is easy to create new applications. Is easy because we can use the CLI to create it and all provisioning and libs could be reused, it will save lots of time. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;An untested change could break all project, in the same context that is easy to improve is easy to break everything;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You could not deny access to an application to a developer because you are keeping everything together in a single repository;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is not so easy to create CI/CD to deploy a specific artifact. This is a point that I am still working to find a simple solution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Considerations
&lt;/h3&gt;

&lt;p&gt;I suggest to test it a new project to check if this alternative will fit your needs. It could prevent that effect &lt;code&gt;POC to production&lt;/code&gt;! Some questions you could ask yourself to decide to move to a monorepo:&lt;/p&gt;

&lt;p&gt;1 - Do you need to share code between projects?&lt;br&gt;
2 - Do you have more applications using the same environment/language?&lt;br&gt;
3 - Do you can allow all developers to access all source code?&lt;br&gt;
5 - Do you think about to create new projects that need to reuse some existent code?&lt;br&gt;
4 - And the most important, do you really think that could help you to deliver faster?&lt;/p&gt;

&lt;p&gt;That questions I ask myself when I decided to try to use monorepo. I am working on a huge frontend application and we are going to create more projects. We started to think about speedup our delivery and reuse many features that we created in the other one. So this migration is motivated to anticipate to be productive when new projects arrive.&lt;/p&gt;

&lt;p&gt;And you?&lt;br&gt;
Do you already test monorepo? What is your experience on that?&lt;/p&gt;

</description>
      <category>monorepo</category>
      <category>productivity</category>
      <category>typescript</category>
      <category>codequality</category>
    </item>
  </channel>
</rss>
