<?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: Vishal Mahajan</title>
    <description>The latest articles on DEV Community by Vishal Mahajan (@vishal423).</description>
    <link>https://dev.to/vishal423</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%2F119527%2F7a9ec5e4-e986-440f-beb5-f164970b7493.png</url>
      <title>DEV Community: Vishal Mahajan</title>
      <link>https://dev.to/vishal423</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vishal423"/>
    <language>en</language>
    <item>
      <title>Generate JHipster + Svelte/Kit web applications</title>
      <dc:creator>Vishal Mahajan</dc:creator>
      <pubDate>Fri, 14 Jan 2022 18:21:17 +0000</pubDate>
      <link>https://dev.to/vishal423/generate-jhipster-sveltekit-web-applications-3b5e</link>
      <guid>https://dev.to/vishal423/generate-jhipster-sveltekit-web-applications-3b5e</guid>
      <description>&lt;p&gt;&lt;a href="(https://www.jhipster.tech/)"&gt;JHipster&lt;/a&gt; is a development platform to quickly generate, develop, &amp;amp; deploy modern web applications and micro-service architectures. The default JHipster platform supports Angular, React, and Vue as the frontend framework. &lt;/p&gt;

&lt;p&gt;The JHipster platform allows code extension and customization via blueprints. In this blog post, we look into &lt;a href="https://www.npmjs.com/package/generator-jhipster-svelte" rel="noopener noreferrer"&gt;Svelte Hipster&lt;/a&gt; blueprint that generates Svelte/Kit powered frontend applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Svelte Hipster - A JHipster blueprint
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Svelte Hipster&lt;/code&gt; is a JHipster blueprint that intends to use the following technical stack in generated applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://svelte.dev/" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt;/&lt;a href="https://kit.svelte.dev/" rel="noopener noreferrer"&gt;Kit&lt;/a&gt; - Client-side development framework&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwindcss&lt;/a&gt; - CSS utility framework&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.cypress.io/" rel="noopener noreferrer"&gt;Cypress&lt;/a&gt; - End-to-End tests framework&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jestjs.io/" rel="noopener noreferrer"&gt;Jest&lt;/a&gt; - Javascript unit tests framework&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; - Opinionated code formatter&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint&lt;/a&gt; - Javascript Lint tool&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://typicode.github.io/husky/#/" rel="noopener noreferrer"&gt;Husky&lt;/a&gt; - Git commit hooks&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Install Svelte Hipster blueprint
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NodeJS 16.x&lt;/code&gt; and &lt;code&gt;NPM 8.x&lt;/code&gt; are recommended versions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Java 11.x&lt;/code&gt; is minimum supported Java version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a very first step, we need to install the &lt;code&gt;generator-jhipster-svelte&lt;/code&gt; npm package globally. Run the below command in your favorite terminal:&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 generator-jhipster-svelte@0.7.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Generate a new monolithic application
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Svelte Hipster&lt;/code&gt; blueprint exposes a &lt;code&gt;cli&lt;/code&gt; to use the correct version of &lt;code&gt;JHipster&lt;/code&gt;. Run the below command to interactively generate an application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shipster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;shipster&lt;/code&gt; CLI prompts a series of questions to customize the generated web application. We chose the below options for our sample application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Which *type* of application would you like to create? Monolithic application (recommended for simple projects)
? What is the base name of your application? Blog
? Do you want to make it reactive with Spring WebFlux? No
? What is your default Java package name? org.github.vishal423
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
? Which *production* database would you like to use? PostgreSQL
? Which *development* database would you like to use? H2 with disk-based persistence
? Which cache do you want to use? (Spring cache abstraction) Caffeine (local cache, for a single node)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Do you want to use the JHipster Registry to configure, monitor and scale your application? No
? Which other technologies would you like to use?
? Besides Junit, which testing frameworks would you like to use?
? Would you like to install other generators from the JHipster Marketplace? (y/N) No
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;PS: Svelte Hipster blueprint is still under active development.  You can refer to the &lt;a href="https://github.com/jhipster/generator-jhipster-svelte#supported-flows-and-integrations" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; listing supported options and integrations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After successful application generation, the code is formatted with opinionated &lt;code&gt;Prettier&lt;/code&gt; configurations and stored in the local git repository with an initial commit. We can also see instructions to start the backend and frontend development servers on the console.&lt;/p&gt;

&lt;h3&gt;
  
  
  A sneak peek into generated application
&lt;/h3&gt;

&lt;p&gt;As instructed on console, let's start the backend server with &lt;code&gt;./mvnw&lt;/code&gt; command. By default, the command also compiles and deploys the frontend code. If you would like to skip the execution of unit tests, then, you can use &lt;code&gt;./mvnw -DskipTests&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;You can browse the generated application at &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt; and log-in with default &lt;code&gt;admin&lt;/code&gt; or &lt;code&gt;user&lt;/code&gt; credentials.&lt;/p&gt;

&lt;p&gt;The default application consists of following screens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign In&lt;/li&gt;
&lt;li&gt;Sign Up&lt;/li&gt;
&lt;li&gt;Forgot Password&lt;/li&gt;
&lt;li&gt;Home&lt;/li&gt;
&lt;li&gt;Account

&lt;ul&gt;
&lt;li&gt;Change Password&lt;/li&gt;
&lt;li&gt;Settings&lt;/li&gt;
&lt;li&gt;Sign Out&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Administration

&lt;ul&gt;
&lt;li&gt;User Management (List, Create, Update, View, Delete)&lt;/li&gt;
&lt;li&gt;Loggers &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In the following screencast, we navigate through generated screens and try out different flows:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0odwdyyuk6lmok90uc0s.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0odwdyyuk6lmok90uc0s.gif" alt="Generated Application Screens"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Extend application to add business domain model
&lt;/h3&gt;

&lt;p&gt;An application without a functional domain is not much useful. Let's extend our example application to add business domain entities. We are leveraging JHipster JDL to define structure and relationships. Refer to &lt;a href="https://www.jhipster.tech/jdl/entities-fields" rel="noopener noreferrer"&gt;JDL entity fields&lt;/a&gt; documentation for all supported entity data types and constraints and &lt;a href="https://www.jhipster.tech/managing-relationships/" rel="noopener noreferrer"&gt;JDL relationships&lt;/a&gt; documentation for supported relationships and syntax.&lt;/p&gt;

&lt;p&gt;Save below entity JDL contents in a file (&lt;code&gt;entity.jdl&lt;/code&gt; in this example)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;entity Blog {
  name String required minlength(3)
  handle String required minlength(2)
}

entity Post {
  title String required
  content TextBlob required
  date Instant required
}

entity Tag {
  name String required minlength(2)
}

relationship ManyToOne {
  Blog{user(login)} to User
  Post{blog(name)} to Blog
}

relationship ManyToMany {
  Post{tag(name)} to Tag{entry}
}

paginate Post, Tag with pagination
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we define an entity named &lt;code&gt;Blog&lt;/code&gt;, &lt;code&gt;Post&lt;/code&gt;, and &lt;code&gt;Tag&lt;/code&gt;. Refer to JDL documentation for supported data types and constraints.&lt;/p&gt;

&lt;p&gt;In our domain model, a user can write multiple blogs and each blog can contain multiple posts. &lt;code&gt;User&lt;/code&gt; is a special entity supported by JHipster to model read only relationships. Further, a post can be associated with multiple tags and same tag can be used in multiple posts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Post&lt;/code&gt; and &lt;code&gt;Tag&lt;/code&gt; entities are also marked to represent data in a paginated manner.&lt;/p&gt;

&lt;p&gt;Run the below command to import entities domain model into our example application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;shipster import-jdl entity.jdl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are updating our application to include business domain model, you will notice prompts to review the updated code. For now, we accept all modifications by entering &lt;code&gt;a&lt;/code&gt; key. The new and updated files are not committed to Git and you can always review those using your favorite diff tool.&lt;/p&gt;

&lt;p&gt;Restart the application with &lt;code&gt;./mvnw&lt;/code&gt; command and log in with default &lt;code&gt;admin&lt;/code&gt; credentials. Under the &lt;code&gt;Entities&lt;/code&gt; menu, you will see &lt;code&gt;Blog&lt;/code&gt;, &lt;code&gt;Post&lt;/code&gt;, and &lt;code&gt;Tag&lt;/code&gt; menu items. In the development profile, JHipster application also uses the &lt;code&gt;faker.js&lt;/code&gt; library to generate test data.  &lt;/p&gt;

&lt;p&gt;In the following screencast, we navigate through newly generated entity screens and create a new blog post:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewnsyx9nhnmw7e7emk06.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fewnsyx9nhnmw7e7emk06.gif" alt="Blog Entities"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Validate generated application code
&lt;/h3&gt;

&lt;p&gt;So far we have generated an application and extended it to add a business domain model. However, we still haven't looked into the verification of generated code. &lt;/p&gt;

&lt;p&gt;Svelte Hipster blueprint supports validation of generated code via two means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jest + Svelte Testing Library to validate an individual svelte component&lt;/li&gt;
&lt;li&gt;Cypress tests to validate end to end business flow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the current release, we generate a limited set of unit tests. In the current form, these help to assert all associated library integrations. However, there is a ticket to improve overall unit test coverage and ensure the robustness of generated code.&lt;/p&gt;

&lt;p&gt;Run the below command to execute unit tests:&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 test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You might observe a unit test failure. We have addressed that issue in the main code and the fix should be available in the next release.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We generate an exhaustive suite of end-to-end tests to ensure generated code meets functional requirements. Run the below command to execute cypress tests:&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 e2e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completion, you can see a summary report like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  account/change-password.spec.js          00:12        7        7        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  account/register.spec.js                 00:15       10       10        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  account/reset/init-password.spec.js      00:04        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  account/settings.spec.js                 00:10        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/logger.spec.js                     00:11        7        7        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/user-management/user-create.s      00:15        7        7        -        -        - │
  │    pec.js                                                                                      │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/user-management/user-delete.s      00:06        3        3        -        -        - │
  │    pec.js                                                                                      │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/user-management/user-list.spe      00:12        7        7        -        -        - │
  │    c.js                                                                                        │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/user-management/user-update.s      00:16        7        7        -        -        - │
  │    pec.js                                                                                      │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  admin/user-management/user-view.spe      00:03        2        2        -        -        - │
  │    c.js                                                                                        │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/blog/blog-create.spec.js        00:05        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/blog/blog-delete.spec.js        00:06        3        3        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/blog/blog-list.spec.js          00:04        3        3        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/blog/blog-update.spec.js        00:11        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/blog/blog-view.spec.js          00:03        2        2        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/post/post-create.spec.js        00:12        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/post/post-delete.spec.js        00:07        3        3        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/post/post-list.spec.js          00:06        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/post/post-update.spec.js        00:09        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/post/post-view.spec.js          00:02        2        2        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/tag/tag-create.spec.js          00:04        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/tag/tag-delete.spec.js          00:05        3        3        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/tag/tag-list.spec.js            00:06        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/tag/tag-update.spec.js          00:05        5        5        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  entities/tag/tag-view.spec.js            00:02        2        2        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  footer.spec.js                           550ms        1        1        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  home.spec.js                             00:03        4        4        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  login.spec.js                            00:06        8        8        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  navbar.spec.js                           00:11       14       14        -        -        - │
  ├────────────────────────────────────────────────────────────────────────────────────────────────┤
  │ ✔  routes.spec.js                           00:04        7        7        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        03:47      148      148        -        -        -

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping things up
&lt;/h2&gt;

&lt;p&gt;In this post, we looked into an interactive way to generate an application and use entity JDL extend to add business domain models. We also looked into generated UI and approaches to validate the generated code. As Svelte Hipster blueprint is an open-source project and under active development, you can also contribute to its growth. &lt;/p&gt;

&lt;p&gt;If you have a suggestion then, feel free to raise a &lt;a href="https://github.com/jhipster/generator-jhipster-svelte/issues" rel="noopener noreferrer"&gt;ticket&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you like the Svelte Hipster project then, give it a star on &lt;a href="https://github.com/jhipster/generator-jhipster-svelte" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and retweet this blog.&lt;/p&gt;

&lt;p&gt;You can follow me on &lt;a href="https://twitter.com/vishal423" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>jhipster</category>
      <category>svelte</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
