<?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: Ahmed Kamal</title>
    <description>The latest articles on DEV Community by Ahmed Kamal (@ahmedmkamal).</description>
    <link>https://dev.to/ahmedmkamal</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%2F125322%2Fe6ddcf60-e125-44f3-8d74-03cb3dce5129.jpeg</url>
      <title>DEV Community: Ahmed Kamal</title>
      <link>https://dev.to/ahmedmkamal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmedmkamal"/>
    <language>en</language>
    <item>
      <title>What're your strategies to upgrade a React app that's in production?</title>
      <dc:creator>Ahmed Kamal</dc:creator>
      <pubDate>Mon, 27 Jul 2020 01:06:14 +0000</pubDate>
      <link>https://dev.to/ahmedmkamal/what-re-your-strategies-to-upgrade-a-react-app-that-s-in-production-3kn0</link>
      <guid>https://dev.to/ahmedmkamal/what-re-your-strategies-to-upgrade-a-react-app-that-s-in-production-3kn0</guid>
      <description>&lt;p&gt;I moved to a new company as a full-time frontend dev, the company has a React app that works as a dashboard where their users can create/manage automated financial-workflows, now, the current codebase is "IMO" pretty messy, think of the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Some parts of the app were written in JS and others are written in TS.&lt;/li&gt;
&lt;li&gt;There're no unit tests what so ever!&lt;/li&gt;
&lt;li&gt;I'm not sure if this one is common but the backend guys are contributing to the frontend app.&lt;/li&gt;
&lt;li&gt;There's no unified code style across the codebase, every one is applying their style.&lt;/li&gt;
&lt;li&gt;The app is using multiple solutions for the same problem, for instance, they're using &lt;code&gt;styled-components&lt;/code&gt;, &lt;code&gt;antd&lt;/code&gt;, and &lt;code&gt;mat-ui&lt;/code&gt; all at the same time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;that was to give you a hint about what the codebase looks like.&lt;/p&gt;

&lt;p&gt;What I'm asking is this, if you're in my position, what would be your strategies/plans to deal with this situation?&lt;/p&gt;

</description>
      <category>react</category>
      <category>agile</category>
      <category>help</category>
    </item>
    <item>
      <title>Build Desktop apps with the power of Angular</title>
      <dc:creator>Ahmed Kamal</dc:creator>
      <pubDate>Wed, 02 Jan 2019 00:34:21 +0000</pubDate>
      <link>https://dev.to/ahmedmkamal/build-desktop-apps-with-the-power-of-angular-18g7</link>
      <guid>https://dev.to/ahmedmkamal/build-desktop-apps-with-the-power-of-angular-18g7</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xj37irwfwtwk7mo5ja2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xj37irwfwtwk7mo5ja2.png" alt="angular and electron" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If you can build a website, you can build a desktop app.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s true if you know how to write Javascript code, you can build a desktop application that looks and behaves like the native one. not just that, you also can bring the power of Angular into the world of desktop apps to make your IU look stunning 😍, enough talking, go get yourself a cup of coffee and let’s get started.&lt;/p&gt;

&lt;h1&gt;
  
  
  What are we going to do?!!
&lt;/h1&gt;

&lt;p&gt;We’re going to build a basic desktop application using &lt;a href="https://electronjs.org/" rel="noopener noreferrer"&gt;Electron&lt;/a&gt; and &lt;a href="https://angular.io/" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before we start I expect that you have some basic knowledge of NodeJs and Angular.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Set up Angular
&lt;/h1&gt;

&lt;p&gt;If you don’t have Angular cli installed already, run the following command to install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install -g @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s start a new Angular application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ng new angular-electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’ll ask you about the styles compiler you want to use and if you want to use the Angular router and so on, this configuration doesn’t matter at all select whatever you want.&lt;/p&gt;

&lt;p&gt;You can see your application now in action by running…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd angular-electron
$ ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open your browser at &lt;a href="http://localhost:4200/" rel="noopener noreferrer"&gt;http://localhost:4200/&lt;/a&gt;, anyway that’s not the funniest part, let’s move forward.&lt;/p&gt;

&lt;p&gt;We need to modify the index.html file at the src folder of our project, add a period to the base tag, so our app can find the static files, don’t skip this step it’s very important.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;base href="./"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Set up Electron
&lt;/h1&gt;

&lt;p&gt;Now we going to add Electron to our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install --save-dev electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we’ll also need some dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install --save-dev app-root-path
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s create a new folder for our Electron application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir bin &amp;amp;&amp;amp; cd bin &amp;amp;&amp;amp; touch main.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we created bin folder with a &lt;code&gt;main.ts&lt;/code&gt; file in it, and the reason we created the main file with &lt;code&gt;ts&lt;/code&gt; extension and not &lt;code&gt;js&lt;/code&gt; is that we already using Typescript for the Angular application, so why not use Typescript for the entire project?!!&lt;/p&gt;

&lt;p&gt;Now let’s add some code to our &lt;code&gt;main.ts&lt;/code&gt; file (lastly we writing some code 😅)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { app, BrowserWindow } from 'electron';
import { resolve } from 'app-root-path';

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win: BrowserWindow;

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({
    width: 800,
    height: 600
  });

  // Load the angular app.
  // Make sure that this path targets the index.html of the
  // angular application (the distribution).
  win.loadFile(resolve('dist/angular-electron/index.html'));

  // Emitted when the window is closed.
  win.on('closed', () =&amp;gt; {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi-windows, this is the time
    // when you should delete the corresponding element.
    win = null;
  });
}

// This method will be called when the Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () =&amp;gt; {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () =&amp;gt; {
  // On macOS, it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow();
  }
});

// In this file, you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above is exactly the same as mentioned at the &lt;a href="https://electronjs.org/docs/tutorial/first-app" rel="noopener noreferrer"&gt;official website&lt;/a&gt; but in Typescript syntax, also note that the &lt;code&gt;win.loadFile&lt;/code&gt; function linking to the entry file of the Angular application “we didn’t build it yet”.&lt;/p&gt;

&lt;p&gt;Okay, we need to check if what we are doing is even working, right!!&lt;/p&gt;

&lt;p&gt;Let’s add a script to our &lt;code&gt;package.json&lt;/code&gt; file so we can build and run this application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"main" : "bin/main.js",
"scripts": {
 ...
   “electron”: “tsc bin/main.ts &amp;amp;&amp;amp; ng build &amp;amp;&amp;amp; electron bin/main.js”
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now let’s see it in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm run electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now, you should see the application up and running with the angular logo in it, so far so good 😉.&lt;/p&gt;

&lt;p&gt;Okay, now we have our application running, but who could we use the Electron API within the Angular application itself?!!&lt;/p&gt;

&lt;p&gt;Don’t panic it’s as easy as running…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install --save-dev ngx-electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Access Electron API from within the Angular application.
&lt;/h1&gt;

&lt;p&gt;We just installed &lt;a href="https://github.com/ThorstenHans/ngx-electron" rel="noopener noreferrer"&gt;ngx-electron&lt;/a&gt; which going to make our life a lot easier, so let’s see how to use it.&lt;/p&gt;

&lt;p&gt;We need to import this module like any other module we used to use with Angular inside &lt;code&gt;app.module.ts&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgxElectronModule } from 'ngx-electron';
@NgModule({
imports: [
  ...
  NgxElectronModule
]
})
export class AppModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it now we can use it in our components like…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ElectronService } from 'ngx-electron';
export class AppComponent {
   constructor(private _electronService: ElectronService) {
   // now we have access to electron api through this service
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s see if we really have access to Electron API.&lt;/p&gt;

&lt;p&gt;Replace the content of your &lt;code&gt;app.component.ts&lt;/code&gt; file with the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';
import { ElectronService } from 'ngx-electron';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'angular-electron';

  versions = { node: '', chrome: '', electron: '' };

  constructor(private _electronService: ElectronService) {
    // Make sure that app is being executed inside of electron.
    if (this._electronService.isElectronApp) {
      // We have access to node process.
      this.versions.node = this._electronService.process.versions.node;
      this.versions.chrome = this._electronService.process.versions.chrome;
      this.versions.electron = this._electronService.process.versions.electron;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And replace the content of the &lt;code&gt;app.component.html&lt;/code&gt; file with the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--The content below is only a placeholder and can be replaced.--&amp;gt;

&amp;lt;div style="text-align:center"&amp;gt;

  &amp;lt;h1&amp;gt;Welcome to {{ title }}!&amp;lt;/h1&amp;gt;

  &amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;Node version {{ versions.node }}&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;Chrome version {{ versions.chrome }}&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;Electron version {{ versions.electron }}&amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;So, what do you think? don’t think a lot let’s see it in action 😅.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm run electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now, you should see the application up and running with the versions of code, chrome, and electron we using, hmmm we did it 😉.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Building desktop apps isn’t that hard, and we can use some powerful tools like node, angular, electron, and typescript to do awesome work, and you know what? even if you're web developer it’s not bad to try some new techs in your free time, I'm pretty sure that you going to learn something new from trying new techs 😉.&lt;/p&gt;

&lt;p&gt;I may add a new post to write some unit tests for our application if I have free time.&lt;/p&gt;

&lt;p&gt;And if you stuck you can always refer to the &lt;a href="https://github.com/AhmedMKamal/angular-electron" rel="noopener noreferrer"&gt;Github repo&lt;/a&gt; of this application.&lt;/p&gt;

&lt;p&gt;This post was originally published at &lt;a href="https://medium.com/@en.ahmed.mk/build-desktop-apps-with-the-power-of-angular-1e44d13d77a4" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>electron</category>
      <category>angular</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
