<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dawid Wojda on Medium]]></title>
        <description><![CDATA[Stories by Dawid Wojda on Medium]]></description>
        <link>https://medium.com/@dawiidio?source=rss-a48e253bbd35------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Sch-Hx8xfOwUYNfBsOe-UA.jpeg</url>
            <title>Stories by Dawid Wojda on Medium</title>
            <link>https://medium.com/@dawiidio?source=rss-a48e253bbd35------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:32:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dawiidio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create CLI for your React project in 5 minutes with Pli]]></title>
            <link>https://medium.com/@dawiidio/create-cli-for-your-react-project-in-5-minutes-with-pli-b4a3f38e3f98?source=rss-a48e253bbd35------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4a3f38e3f98</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Dawid Wojda]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 13:25:33 GMT</pubDate>
            <atom:updated>2023-04-06T13:25:33.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wnXcahIpoe-ZyVah" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">CHUTTERSNAP</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you have ever worked with Nest.js (which is a backend framework for Node.js) you may know that they have a nice terminal CLI which allows creating common application components like models, controllers or decorators. I really enjoyed working with it and missed the experience later in many projects. I think especially in frontend projects with React. I love React but one of it’s downsides (and biggest advantages at the same time) is that React is a library and by itself it does not provide any tooling which for bigger projects would be very useful.</p><p>So, how can we create the nice experience of having CLI for our project while staying away from React principle of being a library? <a href="https://github.com/dawiidio/pli"><strong>Pli</strong></a><strong> </strong>can answer this question. <a href="https://github.com/dawiidio/pli">Pli</a> is a small library which will turn your files into nice terminal CLI for project in just minutes.</p><h3>How to start with Pli?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_rOfBtoJIPPcjs29r_CZQ.jpeg" /></figure><p>Pli is an NPM package, so you can easily install it by typing npm install -g @dawiidio/pli or yarn global add @dawiidio/pli in your terminal. Later create directory where you want to experiment with Pli, or choose one existing one and checkout there.</p><p>When we have Pli installed and we are in our directory run pli init . It will create a templates directory in current location with example template inside. The example template is hello.ts the below code inside it:</p><pre>export function hello(): string {<br>    return &#39;Hello $NAME$&#39;;<br>}</pre><p>As you can see it’s just a normal TypeScript function. One unusual thing about it, is $NAME$ inside of string. This is a <strong>Pli</strong> variable. Pli will extract this variable from our example file and later it will prompt for it’s value in cli to replace $NAME$ with provided value at the end. Wannt try it? Run</p><pre>pli<br># it will ask you which template you want to use<br># ? Select template (Use arrow keys)<br># ❯ hello.ts</pre><p>For now we have just one template, hello.js so let’s go with it.</p><pre># next question is about the directory where you want to save the output file<br># you can leave it empty, so the output will be saved in current directory<br>? Output directory<br><br># and the las question is about our variable $NAME$!<br>? Insert value for NAME :</pre><p>After providing values for variables Pli will replace all variables in template file and save the output in directory provided in the second question. Final message from pli is paths tree of generated result files and directories, like the below:</p><pre>Following structure was created inside directory /path/to/directory<br>├─ hello.ts</pre><p>I entered the value “Dawid” for variable $NAME$ so If I will open hello.ts it will contain the following text:</p><pre>export function hello(): string {<br>    return &#39;Hello Dawid&#39;;<br>}</pre><p>That’s it! Our most basic Pli template is ready to use 🔥</p><h3>Complex example</h3><p>As you saw in previous example, creating templates with Pli is fast and simple since they are just files and variables inside them. Nevertheless simplicity of Pli does not imply that it can’t deal with more complex tasks. Now I want to show you how to create template for React component with css modules styles.</p><p>In my application I keep components in directory src/components , each component has it’s own directory inside and in this directory I have component and it’s CSS file. What I want to do, is to create Pli template which will generate this component for me.</p><p>First, let’s create following structure in templates directory:</p><pre> <br># ├─ $COMPONENT_NAME$/<br># │  ├─ $COMPONENT_NAME$.module.css<br># │  ├─ $COMPONENT_NAME$.tsx<br><br>mkdir templates/$COMPONENT_NAME$<br>touch templates/$COMPONENT_NAME$/$COMPONENT_NAME$.module.css<br>touch templates/$COMPONENT_NAME$/$COMPONENT_NAME$.tsx</pre><p>Now, we can fill the files with content, in my case it looks like this:</p><pre>/* templates/$COMPONENT_NAME$/$COMPONENT_NAME$.module.css */<br><br>.$NAME$Root {<br><br>}</pre><pre>// templates/$COMPONENT_NAME$/$COMPONENT_NAME$.tsx<br><br>import React, { FunctionComponent } from &quot;react&quot;;<br>import styles from &#39;./$NAME$.module.css&#39;;<br><br>interface $NAME$Props {<br><br>}<br><br>export const $NAME$:FunctionComponent&lt;$NAME$Props&gt; = ({  }) =&gt; {<br><br>    return (<br>        &lt;div className={styles.$NAME$Root}&gt;<br>            Component $NAME$<br>        &lt;/&gt;<br>    )<br>};</pre><p>You can now run this template and it will create nice react component with it’s styles. One more thing we can improve is to add default output directory, so we won’t have to type src/components each time. To do it we need to add pli config file, you can do it easily by running pli init -c . File pli.config.ts will appear in current directory, to improve our template we will add to it following content:</p><pre>import { Template, IConfig } from &#39;@dawiidio/pli&#39;;<br><br>const config: IConfig = {<br>    templates: [<br>        new Template({<br>            // readable name, instead of &quot;$COMPONENT_NAME$&quot; you will see &quot;React Component&quot; in cli<br>            name: &#39;React Component&#39;,<br>            // if you want to extend from existing template in templates directory you need to provide its name<br>            id: &#39;$COMPONENT_NAME$&#39;,<br>            // all will be generated relative to src/components directory<br>            defaultOutputDirectoryPath: &#39;src/components&#39;,<br>        })<br>    ]<br>}<br><br>export default config;</pre><p>And that’s it! Our template for React component with css modules file in src/componentsis ready to run. After running it you should see the message like the below one, but with your component name (in my case is was TestFilter)</p><pre>Following structure was created inside directory /myProject/src/components<br>├─ TestFilters/<br>│  ├─ TestFilters.module.css<br>│  ├─ TestFilters.tsx</pre><p>Of course you may want to add some validation for variables, introduce new ones, create dynamic templates etc. If you want to learn more see the examples in repo <a href="https://github.com/dawiidio/pli/tree/main/examples">https://github.com/dawiidio/pli/tree/main/examples</a></p><h3>Summary</h3><p>Pli is a very simple but powerful tool, I hope it will help you maintaining your projects on daily basis. Also, as you may already noticed, Pli is language agnostic, so if you want to you can use it with any other language than just TS or JS. If you liked it or want to know more please visit the repo <a href="https://github.com/dawiidio/pli/tree/main/examples">https://github.com/dawiidio/pli</a> since Pli does not have the webpage as it’s own yet. Have a nice day ❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4a3f38e3f98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configurable frontend apps with docker and env-serve]]></title>
            <link>https://medium.com/@dawiidio/configurable-frontend-apps-with-docker-and-env-serve-a385e8527e86?source=rss-a48e253bbd35------2</link>
            <guid isPermaLink="false">https://medium.com/p/a385e8527e86</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dawid Wojda]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 23:39:16 GMT</pubDate>
            <atom:updated>2020-04-30T17:52:03.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8v7ClfIZDT8Sfz6M" /><figcaption>Photo by <a href="https://unsplash.com/@laurent_perren?utm_source=medium&amp;utm_medium=referral">Laurent Perren</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Recently everyone speaks about Docker. There is a lot of articles on the web which in brief saying how docker helps scaling, sharing and running backend apps, but what about frontend?</p><p>First big disadvantage and difference between backend and frontend is that backend, even after build to some executable, is still application. You can run it and control from outside by parameters or environment variables passed on the initial phase while frontend application is only a bunch of static files served by other app, mostly server like Nginx or Apache.</p><p>For better understanding what problem we discuss let’s say you put a variable color in index.js file which holds a primary color for UI components. When you have single version of app this is not a problem, you can change variable and it’ll affect whole interface in every app version. But it becomes a problem when app could be running at the same time in many color variants.</p><p>Let’s assume you have “Client A” and “Client B”. Client A uses green variant of your app, but here comes Client B and says “App looks great, but hey! My logo is red, I want to have your tool in my company colors!”. <br>Client A is good with green, Client B wants red. At this moment, for the purposes of experiment, we assuming that app will be served on two different ports for each client and client can’t switch between color schemes dynamically. In this situation you may think “Okay, we’ll build conditionally basing on env variables” — and it’s great move! Let’s do this, something like: EXPORT PRIMARY_COLOR=red; node scripts/build.js</p><p>Then in your build.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/510bb1ff3a250ac5ec687012e61b37da/href">https://medium.com/media/510bb1ff3a250ac5ec687012e61b37da/href</a></iframe><p>Seems legit, it works. Now you can build your frontend app in two different color variants. But there are also disadvantages of above solution:</p><ul><li>It can’t be changed without rebuild whole app</li><li>when it comes to run app in docker, you also need to install all dependencies and after that again rebuild app , in brief — it takes a lot of time to build version with only one, small change in color variable</li></ul><p>above problems are aftermath of mentioned at the beginning difference: frontend apps are only bunch of static files, you can not communicate with them at runtime like with other apps.</p><p>According to this problem I wrote small server called env-serve which helps you configure frontend apps on runtime, it may be useful especially when you work with docker.</p><h4>Example app with docker</h4><p>Full code available on GitHub: <a href="https://github.com/dawiidio/env-serve-example">https://github.com/dawiidio/env-serve-example</a></p><p>For the beginning let’s take a look on the Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c20320f205de999a53cee7d2b38cb599/href">https://medium.com/media/c20320f205de999a53cee7d2b38cb599/href</a></iframe><p>What are we doing here:</p><ol><li>declare custom env vars</li><li>copy app source code from host to container</li><li>install dependencies, env-serve then build app</li><li>expose app port (default 3000)</li><li>change directory do app/src . In real app it would be directory with output from bundler eg. app/dist</li><li>and set env-serve as entrypoint</li></ol><p>to work with env-serve you need also entry file, eg. index.html . One important thing to remember about entry file — it must contains initial shape of config object, like:</p><pre>&lt;script&gt;<br>    <strong><em>window</em></strong>.appConfig = {<br>        &quot;CLIENT_NAME&quot;: &quot;Client A&quot;,<br>        &quot;PRIMARY_COLOR&quot;: &quot;green&quot;<br>    };<br>&lt;/script&gt;</pre><p>env-serve will be looking for window.appConfig in entry file and then will try match it’s keys with env vars, if it finds for example CLIENT_NAME then replace it’s initial value with value provided in the env var. If eg.PRIMARY_COLOR wasn’t provided then it stays untouched.</p><p>Above configuration gives you ability to build your frontend once, and then configure on runtime, just like backend apps. Thanks to this you can run many variants of your app faster.</p><pre># build it once<br>docker build -t frontend:latest .</pre><pre># then run many different variants in seconds without rebuild<br>docker run -p 3000:3000 -e CLIENT_NAME=&quot;Client A&quot; frontend:latest</pre><pre>docker run -p 3001:3000 -e CLIENT_NAME=&quot;Client B&quot; frontend:latest</pre><pre>docker run -p 3002:3000 -e CLIENT_NAME=&quot;Client C&quot; frontend:latest</pre><p>I wrote a small docker-compose.yaml to put both version together and run by single docker-compose up command</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bbf892c743b3772202cffd98db780ab/href">https://medium.com/media/4bbf892c743b3772202cffd98db780ab/href</a></iframe><p>I have a few lines of JS in my index.html to pull informations from data passed by env-serve to my initial config declared also in the same file. Here’s content of it</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4c7749aa2441f5b8bbc2600a31f2f60/href">https://medium.com/media/d4c7749aa2441f5b8bbc2600a31f2f60/href</a></iframe><p>How you can see above, I’ve declared shape of my config, then I pulls needed informations from it and basing on them customize interface. Simple :)</p><p>After run docker-compose up I can see something like this in console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*qwQcaDxxCk-zV0l8XaWhJw.png" /></figure><p>And this the final result in my browser, after open localhost on declared in docker-compose.yaml ports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ezq1zDvpGGDqZGiw-fdGFw.png" /></figure><h4>When you shouldn’t use env-serve?</h4><p>There are some cases, which still should be done on the build phase. For example: if client A asks you for feature X but client B shouldn’t see it, probably because he don’t pay for it, you should add some env variable and join feature code conditionally basing on it, also you shouldn’t put any sensitive data to config (eg. passwords) because anyone can see it.</p><h4>Summary</h4><p>We discussed main difference between built backend and frontend, how it affects further work with Docker and in general how it may complicate process of adjusting and delivering app for many different clients . We also tried solution called env-serve which addresses some of the problems.</p><p>If you have any problems or suggestions please let me know here or on twitter <a href="https://twitter.com/Caridina_multid">https://twitter.com/Caridina_multid</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a385e8527e86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>