<?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: Marek Dano</title>
    <description>The latest articles on DEV Community by Marek Dano (@marekdano).</description>
    <link>https://dev.to/marekdano</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%2F32663%2F7a93c6ba-bb36-4ffd-ba77-0c8639a9dee8.png</url>
      <title>DEV Community: Marek Dano</title>
      <link>https://dev.to/marekdano</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marekdano"/>
    <language>en</language>
    <item>
      <title>Closure in Javascript</title>
      <dc:creator>Marek Dano</dc:creator>
      <pubDate>Mon, 18 May 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/marekdano/closure-in-javascript-1gn6</link>
      <guid>https://dev.to/marekdano/closure-in-javascript-1gn6</guid>
      <description>&lt;p&gt;The closure in javascript is one of the main concepts which each javascript developer needs to grasp. It is also used in the interviews for frontend developers.&lt;/p&gt;

&lt;p&gt;So, what's the &lt;strong&gt;closure&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;We can understand it by great definition from &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures"&gt;MDN&lt;/a&gt; documentation where stays:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A closure is a special kind of object that combines two things: a function, and the environment in which the function was created. The environment consists of local variables that were in-scope at the time that the closure was created.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, the closure is created when a function is returned from another function and that returned function has access to the outer function's scope. The closure is created at the function creation time.&lt;/p&gt;

&lt;p&gt;Let say we have a function of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getFamily&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;familyName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;familyName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can create a &lt;code&gt;family&lt;/code&gt; function by calling the function &lt;code&gt;getFamily&lt;/code&gt; and passing &lt;code&gt;familyName&lt;/code&gt; into that function. Calling the function &lt;code&gt;getFamily&lt;/code&gt; returns a function. The closure is created with the scope defined. The scope contains &lt;code&gt;familyName&lt;/code&gt;. If we call that returned function (closure) from &lt;code&gt;getFamily&lt;/code&gt;, in our case &lt;code&gt;family&lt;/code&gt; and passing &lt;code&gt;firstName&lt;/code&gt; into that function we can get the full name. The reason we can get &lt;code&gt;familyName&lt;/code&gt; is that we have access to the outer scope of the returned function where &lt;code&gt;familyName&lt;/code&gt; exists. Remember the variable &lt;code&gt;familyName&lt;/code&gt; was created when the function of &lt;code&gt;family&lt;/code&gt; was created. Hopefully what I said now makes sense when we execute the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getFamily&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fatherFullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;motherFullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Emma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fatherFullName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// John Smith&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;motherFullName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Emma Smith&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The closure is also used when we want to keep the variables defined in the function private, not to be accessible outside of the scope. The variables can then be modified inside of the scope. Consider this extended code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getFamily&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;familyName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;familyMembers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addMember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;familyMembers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;listOfFamilyMembers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;familyMembers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getFamilyName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;familyName&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;addMember&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;listOfFamilyMembers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;getFamilyName&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;The variable of &lt;code&gt;familyMember&lt;/code&gt; won't be accessible. It can be called or modified in the functions which are defined in the scope when the function of &lt;code&gt;getFamily&lt;/code&gt; is created. If we want &lt;code&gt;familyMember&lt;/code&gt; to be accessible from &lt;code&gt;getFamily&lt;/code&gt; we can add it to the object returned from that function, but in this case, the variable won't be private anymore.&lt;/p&gt;

&lt;p&gt;Now please follow the code and let me know what will be logged. Try to execute the code in your head first before testing it in your preferred javascript console.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getFamily&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addMember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addMember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Emma&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addMember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Josh&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listOfFamilyMembers&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// ???&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;family&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getFamilyName&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// ???&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>javascriptfundamentals</category>
      <category>interviewing</category>
    </item>
    <item>
      <title>What platform (website) should I use to show my amazing project(s)</title>
      <dc:creator>Marek Dano</dc:creator>
      <pubDate>Wed, 06 May 2020 15:46:03 +0000</pubDate>
      <link>https://dev.to/marekdano/what-platform-website-should-i-use-to-show-my-amazing-project-s-6m3</link>
      <guid>https://dev.to/marekdano/what-platform-website-should-i-use-to-show-my-amazing-project-s-6m3</guid>
      <description>&lt;p&gt;I'd like to find if there is a platform or website somewhere, for frontend and even backend developers where they can show what they've created/built at work or during their free time. &lt;/p&gt;

&lt;p&gt;Many developers are not known very well, because they can be just out of a college, just out of dev bootcamp or they have lost their jobs. They haven't had enough time to build their personal brand and be widely seen on social media or outside of their personal network. But they can still be amazing as developers/engineers. how would you recommend for them to be seen? Where they should go to promote themselves?  &lt;/p&gt;

&lt;p&gt;Please share this article and left a comment below to help others to be seen ✋. &lt;/p&gt;

</description>
      <category>developers</category>
      <category>jobseekers</category>
      <category>promoteyourself</category>
    </item>
    <item>
      <title>Automate build process with the build script</title>
      <dc:creator>Marek Dano</dc:creator>
      <pubDate>Fri, 01 Nov 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/marekdano/automate-build-process-with-the-build-script-5c97</link>
      <guid>https://dev.to/marekdano/automate-build-process-with-the-build-script-5c97</guid>
      <description>&lt;p&gt;The process of building applications for production usually involves executing several steps and building angular applications is no different. The repetitive steps are in the following sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Get a tag and branch name from &lt;em&gt;git&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; Build the application for production by using &lt;strong&gt;ng build --prod&lt;/strong&gt; command&lt;/li&gt;
&lt;li&gt; Update the configuration file of &lt;strong&gt;config.json&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; Zip the build and release it&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;As I already mentioned we have the angular application. We keep the configuration settings of our application in the &lt;strong&gt;config.json&lt;/strong&gt; file. If you want to find out more about how we use the configuration file in our app, please check &lt;a href="https://marekdano.com/posts/one-configuration-for-multiple-servers/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To update the &lt;strong&gt;config.json&lt;/strong&gt; file for production we decided to use the &lt;a href="https://stedolan.github.io/jq/"&gt;&lt;code&gt;jq&lt;/code&gt; tool&lt;/a&gt; which had to be installed on a build machine. We build the application on OS X, so we installed it through &lt;code&gt;brew&lt;/code&gt;, like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install jq
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;In the script below you can see that we followed the required steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We read the latest git tag and current branch name from git and assigned it to variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We build the application by executing &lt;strong&gt;ng build --prod&lt;/strong&gt; and placed the build to the &lt;strong&gt;wwwroot&lt;/strong&gt; folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Updating &lt;strong&gt;config.json&lt;/strong&gt; under &lt;em&gt;wwwroot/assets&lt;/em&gt; folder with using &lt;strong&gt;jq&lt;/strong&gt; tool. We read the &lt;strong&gt;config.json&lt;/strong&gt; file, find a field, assign a new value to it, redirect the output content to the newly created &lt;strong&gt;temp.json&lt;/strong&gt; file, and finally replace the content in &lt;strong&gt;config.json&lt;/strong&gt; within the content in &lt;strong&gt;config.json&lt;/strong&gt; within the content in &lt;strong&gt;temp.json&lt;/strong&gt;. Something like:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;jq &lt;span class="s1"&gt;'.field = "new_value"'&lt;/span&gt; config.json &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json config.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; We zipped the build with the updated &lt;strong&gt;config.json&lt;/strong&gt; file and moved the zipped file to the root of the project.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And here is the full build script that we used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="nv"&gt;CONFIG_PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;wwwroot/assets/config.json
&lt;span class="nv"&gt;CURRENT_TAG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git describe &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;git rev-list &lt;span class="nt"&gt;--tags&lt;/span&gt; &lt;span class="nt"&gt;--max-count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# the latest tag&lt;/span&gt;
&lt;span class="nv"&gt;CURRENT_BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git rev-parse &lt;span class="nt"&gt;--abbrev-ref&lt;/span&gt; HEAD&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;ENV_TYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="s2"&gt;"production"&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"app version &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_TAG&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"building in branch &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_BRANCH&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"environment type &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$ENV_TYPE&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Start building the app..."&lt;/span&gt;
ng build &lt;span class="nt"&gt;--prod&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"End building the app!!!"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$CURRENT_BRANCH&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'master'&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nv"&gt;CURRENT_BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nv"&gt;CURRENT_BRANCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"-&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_BRANCH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi


&lt;/span&gt;jq &lt;span class="s2"&gt;".version = &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$CURRENT_TAG$CURRENT_BRANCH&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s2"&gt;".ops_environment = &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$ENV_TYPE&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.authentication = true'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.authorizationHeader = ""'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.apiUrl = "http://10.0.0.84:60820/ws"'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.tenant = ""'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.authenticationType = "windows"'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.signalr.url = "http://10.0.0.84:60820/ws/signalr"'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;
jq &lt;span class="s1"&gt;'.signalr.hubName = "OPSHub"'&lt;/span&gt; &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; temp.json &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;mv &lt;/span&gt;temp.json &lt;span class="nv"&gt;$CONFIG_PATH&lt;/span&gt;


&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Config file has been set up !!!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;

&lt;span class="nb"&gt;cd &lt;/span&gt;wwwroot

zip &lt;span class="nt"&gt;-r&lt;/span&gt; Apps-&lt;span class="nv"&gt;$CURRENT_TAG&lt;/span&gt;.zip &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="c"&gt;# move file to the root of this project&lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;Apps-rc-&lt;span class="nv"&gt;$CURRENT_TAG&lt;/span&gt;.zip ../

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Release folder zipped."&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;

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



&lt;h2&gt;
  
  
  Executing script
&lt;/h2&gt;

&lt;p&gt;The build is saved as &lt;strong&gt;release_script.sh&lt;/strong&gt; and is placed under the root of our project. Before executing the script we added the permission to the file by running following command in the folder where our script exists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 755 release_script.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The file permission can be different in your case.&lt;/p&gt;

&lt;p&gt;Executing the file, navigate to the folder where script file exists and execute the script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./release_script.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If everything is set up correctly in the script, the zip file with build and the updated &lt;strong&gt;config.json&lt;/strong&gt; file will be created under the root of the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hopefully sharing this can encourage others to think and move from repetitive tasks to fully automated ones.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>bash</category>
      <category>scripting</category>
    </item>
    <item>
      <title>One configuration for multiple servers</title>
      <dc:creator>Marek Dano</dc:creator>
      <pubDate>Sun, 01 Sep 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/marekdano/one-configuration-for-multiple-servers-49mc</link>
      <guid>https://dev.to/marekdano/one-configuration-for-multiple-servers-49mc</guid>
      <description>&lt;p&gt;&lt;em&gt;Have you ever asked yourself how to deploy the same application onto different servers with different settings? We asked the same question when we started developing our frontend application.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirement
&lt;/h2&gt;

&lt;p&gt;In my company, we develop web applications. One of the applications is written in the Angular 8 and had to be deployed to our several customers, on their local in-house server or Azure one. The application had to be configured to communicate with our web API and also to have global settings defined. The place where web API is live is different for each application. Therefore we decided to have one local configuration file with all settings required in the app. Those settings should have been used in our application.&lt;/p&gt;

&lt;p&gt;The similar file that we have is like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"v1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ops_environment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"production"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"authentication"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"authenticationType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"azure"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"apiUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://sample-app.azurewebsites.net/ws"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tenant"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sample-tenant.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"signalr"&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;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://sample-app.azurewebsites.net/ws/signalr"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"hubName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SampleHub"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Where&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;authenticationType&lt;/strong&gt; can be &lt;strong&gt;azure&lt;/strong&gt; or &lt;strong&gt;windows&lt;/strong&gt; depending on where the app is deployed - options are to Azure or IIS on the Windows server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;apiUrl&lt;/strong&gt; and &lt;strong&gt;singlar.url&lt;/strong&gt; is the URL of the required web API.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Our implementation
&lt;/h2&gt;

&lt;p&gt;After researching we found that the best solution for us was to build and do a release of the application once for all our clients and have a configuration file of &lt;strong&gt;config.json&lt;/strong&gt; somewhere in the app with the settings already defined above.&lt;/p&gt;

&lt;p&gt;We decided to put the config.json file under &lt;strong&gt;assets&lt;/strong&gt; folder rather than having it under the build root or somewhere else. If we didn't have it under the &lt;strong&gt;assets&lt;/strong&gt; folder then we would have had to create the web API for getting the configuration file and reading settings at the start of initializing the whole application. Since we had it under assets, the config.json file loaded every time into the browser when the app started and we could set the required settings in our application.&lt;/p&gt;

&lt;p&gt;The setting of &lt;strong&gt;apiUrl&lt;/strong&gt; is used in angular services, &lt;strong&gt;authenticationType&lt;/strong&gt; in the authentication process and &lt;strong&gt;signalr&lt;/strong&gt; to set signal-R client in our app.&lt;/p&gt;

&lt;p&gt;The part of our application structure with the location of config.json file is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;...

├── SampleApp
|   ├── src
|   |   ├── app
|   |   |   ├── pages
|   |   |   ├── shared

...

|   |   ├── assets
|   |   |   └── config.json
|   |   ├── environments

...

|   |   └── index.html

...

|   ├── package.json
|   └── angular.json

...

└── README.md

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



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We believe that there might be a better solution to handle our problem. If you think we could have done it in a different way, please let us know ;)&lt;/p&gt;

</description>
      <category>configuration</category>
      <category>angular</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
