You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: 'Simple way to generate report from your cli using only vite and react'
5
+
description: 'Feature insight: sls-mentor awesome new report'
6
6
tags: webdev, javascript, react, tutorial
7
7
series:
8
8
canonical_url:
9
9
---
10
10
11
-
# Context
11
+
# TLDR
12
12
13
-
I work on an open source project: [sls-mentor](https://www.sls-mentor.dev/), that audits an aws stack and give advices on the best practices to configure serverless resources on AWS.
13
+
In this feature insight, we explain how we generate the new reporting feature from sls-mentor, getting inspiration from [jest-html-reporter](https://github.com/Hazyzh/jest-html-reporters). And we show you how to code your own report tool using react.
14
14
15
-
On the project, we wanted to add a feature of report generation to have a visual document with every important information at a glance and that can be shared easily.
15
+
# Getting a fresh new report for sls-mentor ?
16
16
17
-
# Requirements
17
+
With my team we have been building [sls-mentor](https://www.sls-mentor.dev/), a **free and open source** tool to audit your serverless stack on AWSand to give you tips to improve it!
18
18
19
-
- Report generation is done in a CLI ⌨️
20
-
- The report is pretty 💄
21
-
- As a fullstack developper, I wanted to use a tool that I know well to generate the report: [React](https://react.dev/)
19
+
The tool runs in the cli and outputs the result directly in the terminal. We pimped the result, and it is already quite good-looking 😎.
22
20
23
-
# Tech strategy
21
+

24
22
25
-
## Find inspiration 💡
23
+
But a cli print is not easy to share and the look still feels a bit rough! And as developers, we have to present technical concepts all the time, and we learned that the presentation is as important as the content. That's why we wanted a report that can be presented to our clients, our managers to convey the quality of our serverless infrastructures or the need for real work on it.
26
24
27
-
First, I started with a naive search on how other auditing tools were generating their reports. I found the example of [jest-html-reporter](https://github.com/Hazyzh/jest-html-reporters/tree/master)
25
+
That's why we decided to add a reporting feature to sls-mentor.
28
26
29
-
The report looks amazing ! 😍
27
+
# It does look better doesn't it ? 😍
30
28
31
-

29
+

32
30
33
-
And guess what ? It is written in react ! 🚀
31
+
The report is generated in the cli as a single html file. So you can share it and display it in any browser! Showing your audit results has never been so easy! 🚀
34
32
35
-
## Dig in how it works 🪛
33
+
Moreover tips are displayed on the bottom to help you improve your stack, and they redirect to sls-mentor website to get more details. 🤓
36
34
37
-
In the details, I didn't understand everything 🙈, but it doesn't matter! What matters is the general idea !
35
+
# What's under the hood ? 🪛
38
36
39
-
- They have a React application, the app is built into a template html file.
37
+
The report is generated in React, it is a one of most popular and well known framework in web development so it is easy to customize and to add new features. we are already working on it! 💪
40
38
41
-
- The template file contains a placeholder string, for example for jest-html-report, it is:
39
+
We actually got inspired by [jest-html-reporter](https://github.com/Hazyzh/jest-html-reporters) to generate the report.
42
40
43
-
```
41
+
First we write a template react app, and we build it into a single html file.
42
+
43
+
The template file contains a placeholder string, for example for jest-html-report, it is:
- Then at runtime, jest copies the template file, then replace the placeholder with the result of the analysis and 💥 ! It generates an html report !
49
+
Then at runtime, jest copies the template file, then replaces the placeholder with the result of the analysis and 💥! It generates an html report!
50
+
51
+
Simple isn't it ? 😎
48
52
49
-
# Let's write a report template
53
+
# Coding time 👨🏽💻! Let's write a report template
50
54
51
55
Ok, now we know the general idea, let's write our own report template.
52
56
@@ -66,7 +70,7 @@ Now you have a react app. Try to build it.
66
70
67
71
It generates a dist folder with an index.html file. But if you try to open it in your browser, you will see a blank page.
68
72
69
-
If you open the index.html in an editor, you will notice it is almost empty, it just an empty div and some scripts to js files.
73
+
If you open the index.html in an editor, you will notice it just an empty div and some scripts to js files.
70
74
71
75
That's not what we want, we want a single html file that contains everything. So it is easy to share.
72
76
@@ -89,7 +93,7 @@ export default defineConfig({
89
93
90
94
Now if you build again, you will have a single html file in the dist folder. 🎉
91
95
92
-
If you open it in your browser, you will see your app, except for a small detail: the images are not displayed! 😱 Because the images are absolute imports to other svg files in the dist folder. The issue is not problematic but a bit painful to fix: the svg must be converted into react components (but that is not the topic of this article 😜).
96
+
If you open it in your browser, you will see your app, except for a small detail: the images are not displayed! 😱 Because the images are absolute imports to other svg files in the dist folder. The issue is not problematic but a bit painful to fix: the svg must be converted into react components (which can be done using this great [tool](https://react-svgr.com/playground/)).
93
97
94
98
## Customize the report
95
99
@@ -197,7 +201,6 @@ The placeholder `<<<RESULTS_PLACEHOLDER>>>` will be replaced by the result of th
197
201
Now we have a template, we want to test it.
198
202
199
203
- First, let's build the report again and copy it to a new file report.html.
200
-
201
204
- Open the report.html in your editor, and search for `<<<RESULTS_PLACEHOLDER>>>`.
202
205
- Replace it with `{\"score\": 100}` (⚠️ don't forget to escape the quotes !).
203
206
- Save the file and open it in your browser.
@@ -213,10 +216,27 @@ In order to build the report from your cli, just automate the previous steps wit
213
216
- duplicate the template file to a new file report.html
214
217
- replace the placeholder with the result of the analysis and don't forget to escape the quotes
If you've found a typo, a sentence that could be improved or anything else that should be updated on this blog post, you can access it through a git repository and make a pull request. Instead of posting a comment, please go directly to <REPOURL> and open a new pull request with your changes.
242
+
If you've found a typo, a sentence that could be improved or anything else that should be updated on this blog post, you can access it through a git repository and make a pull request. Instead of posting a comment, please go directly to https://github.com/QuentinNativel/articles and open a new pull request with your changes.
0 commit comments