@hkbn/es-header-footer 7.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of @hkbn/es-header-footer might be problematic. Click here for more details.

Files changed (4) hide show
  1. package/README.md +303 -0
  2. package/helpers.js +747 -0
  3. package/index.js +678 -0
  4. package/package.json +18 -0
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+ # CRA-MHL
2
+ ## A Professional Starter Create React App (CRA) with Must-Have Libraries (MHL) Template
3
+
4
+ [![Build Status](https://travis-ci.org/EliEladElrom/cra-template-must-have-libraries.svg?branch=main)](https://travis-ci.org/EliEladElrom/cra-template-must-have-libraries)
5
+ [![Coverage Status](https://coveralls.io/repos/github/EliEladElrom/cra-template-must-have-libraries/badge.svg?branch=main)](https://coveralls.io/github/EliEladElrom/cra-template-must-have-libraries?branch=main)
6
+ ![test](https://github.com/EliEladElrom/cra-template-must-have-libraries/workflows/test/badge.svg)
7
+ ![CI](https://github.com/EliEladElrom/cra-template-must-have-libraries/workflows/CI/badge.svg)
8
+ ![build](https://github.com/EliEladElrom/cra-template-must-have-libraries/workflows/build/badge.svg)
9
+ [![npm version](https://badge.fury.io/js/cra-template-must-have-libraries.svg)](https://badge.fury.io/js/cra-template-must-have-libraries)
10
+ [![GitHub issues](https://img.shields.io/github/issues/EliEladElrom/cra-template-must-have-libraries)](https://github.com/EliEladElrom/cra-template-must-have-libraries/issues)
11
+ [![DeepScan grade](https://deepscan.io/api/teams/11491/projects/14393/branches/266604/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=11491&pid=14393&bid=266604)
12
+ [![codecov](https://codecov.io/gh/EliEladElrom/cra-template-must-have-libraries/branch/main/graph/badge.svg?token=6HEUnw0uTD)](undefined) - [Get Badges](https://medium.com/react-courses/set-an-ultimate-react-automated-dev-ci-cycle-with-husky-jest-puppeteer-github-actions-codecov-46b923c4f8e3)
13
+
14
+ A very opinionated starter [Create React App](https://github.com/facebook/create-react-app) (CRA) _template_ with Must-Have Libraries (MHL) including:
15
+
16
+ - React v17.0.2
17
+ - Type Checker - TypeScript ^4.2.3
18
+ - Preprocessors - Sass/SCSS
19
+ - State management - Redux Toolkit, Recoil
20
+ - CSS Framework - Material-UI
21
+ - CSS-in-JS Modules — Styled Components
22
+ - Router - React Router
23
+ - Unit Testing - Jest & Enzyme + Sinon
24
+ - E2E Testing - Jest & Puppeteer
25
+ - Folder structure
26
+ - Generate templates
27
+ - Format & Lint - ESLint & Prettier
28
+ - Useful utilities - Moment, Classnames, Serve, react-snap, React-Helmet, Analyzer Bundle, react-uuid.
29
+
30
+ Custom Templates, format, and ESLint configurations.
31
+ The original Create React App README available [here](./README_CRA.md).
32
+
33
+ If you want to generate HTML in the server check [NEXT-MHL](https://github.com/EliEladElrom/next-must-have-libraries)
34
+
35
+ ## Usage
36
+
37
+ ```bash
38
+ yarn create react-app your-project-name --template must-have-libraries
39
+ ```
40
+
41
+ Or;
42
+
43
+ ```bash
44
+ npx create-react-app your-project-name --template must-have-libraries
45
+ ```
46
+
47
+ `npx` package runner tool installs the most recent stable version of CRA from npm. (npx comes out of the box with npm 5.2+)
48
+
49
+ `--template` parameter points to this template, note that `cra-template-` prefix will be omitted.
50
+
51
+ ## What are React Developer must know libraries and why do I need them?
52
+
53
+ Create-React-App (CRA) is a great starter project for React, you can be up and running quickly. It includes vanilla flavor packages and other opinionated packages. Additionally, it has an option to include templates or you can create your own template.
54
+
55
+ CRA already made some decisions for us, for example; build tools: Webpack over Rollup or Parcel. Task Runners npm scripts over gulp. CSS, JS, and Jest as the default, and so on.
56
+
57
+ After working & reviewing projects and libraries that help get the job done with React, it’s hard to stay neutral and not to form an opinion one way or another.
58
+
59
+ For example, when using the package manager what should you use: yarn or npm. When it comes to CSS preprocessor: Saas/SCSS, PostCSS, Less or Stylus, or maybe others. CSS Frameworks: use the main ones; Bootstrap or MaterialUI or a different one. The list goes on and on.
60
+
61
+ Another challenge I observe is that many libraries are not very easy to migrate to once you start without them so although you may not need them today, it may be worth looking into starting on the right foot.
62
+
63
+ The idea here is to help you set up CRA with the selection of certain opinionated libraries that will help you get the job done from a small project to a larger enterprise level.
64
+
65
+ ## Run Scripts
66
+
67
+ Inside the project directory run using `npm` or `yarn`:
68
+
69
+ - `start` - runs the app in the development mode. Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
70
+ - `test` - launches the test runner in the interactive watch mode.
71
+ - `build` - builds the app for production to the `build` folder.
72
+ - `build:serve` - run a local static build using the production build using serve library. Install `npm install -g serve`.
73
+ - `build:profile` - profiling production build.
74
+ - `eject` - exposes content of `react-script` package
75
+ - `lint` - lints project files according to Airbnb — as part of their style guide 👍 — it provides an ESLint configuration that anyone can use and it is the standard.
76
+ - `fix` - fix lints issues according to style guide set.
77
+ - `format` - will format your code prettier using opinionated settings inside `.prettierrc` file.
78
+ - `isready` - will check if the code is ready for showtime (production), run lint, format and build.
79
+ - `test:e2e` - run e2e integration testing with the help of Jest & Puppeteer.
80
+ - `test:e2e-watch` - same as test:e2e just with a watcher.
81
+ - `test:e2e-alone` - stand-alone e2e integration testing NodeJS script for testing using Puppeteer.
82
+ - `test:debug` - debug your jest tests using the debugger statement, more info [here](https://medium.com/react-courses/six-best-debugging-options-to-crush-your-reacts-bugs-like-a-champion-70b11b6a1a2d).
83
+ - `coverage` - this test is to create a coverage report at needs extra setting in order to work as expected.
84
+ - `analyze` - source-map-explorer to Analyzer Bundle.
85
+ - `analyzer` - uses cra-bundle-analyzer to Analyzer Bundle.
86
+
87
+ CRA template only support `scripts` and `dependencies` inside generated `package.json`. No `devDependencies` is possible on CRA template for now.
88
+
89
+ ## Docker
90
+
91
+ Docker hub: [https://hub.docker.com/repository/docker/elieladelrom/cra-template-must-have-libraries](https://hub.docker.com/repository/docker/elieladelrom/cra-template-must-have-libraries)
92
+
93
+ Check project running: http://localhost:8080/
94
+
95
+ ````
96
+ $ docker run -p 8080:80 elieladelrom/cra-template-must-have-libraries
97
+ ````
98
+
99
+ ## Need bootstrap?
100
+
101
+ If you need bootstrap. Just add;
102
+ ```
103
+ $ yarn add bootstrap
104
+ ```
105
+ Uncomment import in index.tsx;
106
+ ```
107
+ import 'bootstrap/dist/css/bootstrap.css';
108
+ ```
109
+
110
+ More here: https://create-react-app.dev/docs/adding-bootstrap
111
+
112
+ ## Router + State Management
113
+
114
+ Router via React Router v5.2.0 and is set on 'AppRouter.tsx' and included in 'index.tsx', read [here](https://medium.com/react-courses/how-to-integrate-routing-in-typescript-project-with-react-router-v5-2-0-a6b0ab160a1b).
115
+
116
+ The code is set for [Recoil](https://medium.com/react-courses/integrate-recoil-with-typescript-to-share-your-state-across-react-components-8cf1a3910fae) or [Redux Toolkit](https://medium.com/react-courses/instant-learn-react-redux-toolkit-with-a-simple-minimalistic-example-3c63c296ed65) you pick.
117
+
118
+ ## Unit Testing
119
+
120
+ Unit Testing supported with [Enzyme](https://airbnb.io/enzyme/) that works with [Jest](https://github.com/facebook/jest). Additionally, [Sinon](https://github.com/sinonjs/sinon) - a standalone test spies, stubs and mocks that works with Enzyme & Jest.
121
+
122
+ Jest and Sinon serve the same purpose. So why add Sinon?
123
+ The answer is that there are times that you may find one framework more natural and easier to work for the specific test you need than the other so it wouldn’t hurt to have both.
124
+
125
+ You can compare the list of APIs on Jest (https://jestjs.io/docs/en/api) and Sinon (https://sinonjs.org/releases/v9.2.0/)
126
+
127
+
128
+ The 'src/setupTests.ts' file is already configured to work with enzyme using the enzyme react adapter.
129
+
130
+ For snapshot -- update 'package.json';
131
+
132
+ ```
133
+ // package.json
134
+ "jest": {
135
+ "snapshotSerializers": ["enzyme-to-json/serializer"]
136
+ }
137
+ ```
138
+
139
+ Note: remember to update / delete 'src/App.test.tsx' in case you update 'App.tsx'
140
+
141
+ For instance to check if a component you added
142
+ include in App.tsx;
143
+
144
+ ```
145
+ import { shallow } from "enzyme";
146
+ import Calculator from "./components/SomeComponent/SomeComponent";
147
+
148
+ test('should render SomeComponent', () => {
149
+ const wrapper = shallow(<App />);
150
+ const calculator = wrapper.find(SomeComponent);
151
+ expect(calculator.exists()).toBe(true);
152
+ })
153
+ ```
154
+
155
+ You can read more about unit testing: [hello-jest-enzyme-ts](https://medium.com/react-courses/unit-testing-react-typescript-app-with-jest-jest-dom-enzyme-11f52487aa18)
156
+
157
+ To run the tests:
158
+
159
+ `$ yarn test`
160
+
161
+ ## Coverage
162
+
163
+ To set coverage we can use Jest. Jest allow us to create reports in different format and set where we want to collect these reports from (or not collect them from), as well as ensure the coverageThreshold. Take a look at my 'package.json' settings;
164
+
165
+ To get testing coverage report, you need to include the following settings in your 'package.json' file;
166
+
167
+ ```
168
+ // package.json
169
+ "jest": {
170
+ "coverageReporters": [
171
+ "json",
172
+ "text",
173
+ "html",
174
+ "lcov"
175
+ ],
176
+ "collectCoverageFrom": [
177
+ "src/**/*.{js,jsx,ts,tsx}",
178
+ "!src/**/*/*.d.ts",
179
+ "!src/**/*/Loadable.{js,jsx,ts,tsx}",
180
+ "!src/**/*/types.ts",
181
+ "!src/**/store.ts",
182
+ "!src/index.tsx",
183
+ "!src/serviceWorker.ts",
184
+ "!<rootDir>/node_modules/",
185
+ "!**/templates/**",
186
+ "!**/template/**"
187
+ ],
188
+ "coverageThreshold": {
189
+ "global": {
190
+ "branches": 50,
191
+ "functions": 50,
192
+ "lines": 50,
193
+ "statements": 50
194
+ }
195
+ }
196
+ ```
197
+
198
+ In this example, I am enforcing 50% 'coverageThreshold', when I set these it can ensure that I am testing in within my threshold or get an error. That can come handy, because we can set these setting to ensure that every single function, statement, lines and branches get at least 50% or even set it to 100% test coverage.
199
+
200
+ ## E2E Testing
201
+
202
+ E2E testing provided by Jest & Puppeteer. Check the E2E folder for stand-alone and testing app.test.tsx component. You can read more about it [here](https://medium.com/react-courses/deliver-quality-software-reduce-qa-load-integrate-end-to-end-e2e-testing-on-cra-react-a20486a39ac2?sk=c9610ea9812363b262f141f1c30ae445).
203
+
204
+ To run the E2E stand-alone and Jest & Puppeteer tests run;
205
+
206
+ `$ yarn test:e2e`
207
+
208
+ And;
209
+
210
+ `$ yarn test:e2e-alone`
211
+
212
+ ## Eslint configurations
213
+
214
+ Lint set according to Airbnb style guide — as part of their style guide. Feel free to tweak `.eslintrc`.
215
+
216
+ ## Format configurations
217
+
218
+ [Prettier](https://prettier.io/) is set using my opinionated settings, feel free to [tweak prettier rules](https://prettier.io/docs/en/configuration.html) inside config file `.prettierrc` to match your code style.
219
+
220
+ ## Configure Components Templates
221
+
222
+ [generate-react-cli](https://github.com/arminbro/generate-react-cli) help speed up productivity in React projects, feel free to tweak rules inside the config file `generate-react-cli.json` to match your needs.
223
+
224
+ ## Debugging and Profiling
225
+
226
+ There are many options to debug such as using this run script and placing `debugger` statements
227
+ ```$ yarn test:debug```. Read how on how to debug the App in [this article](https://medium.com/react-courses/six-best-debugging-options-to-crush-your-reacts-bugs-like-a-champion-70b11b6a1a2d).
228
+
229
+ For Profiling you can use methods such as Chrome DevTools or the `<Profile>` Component. Here is an example;
230
+ ````
231
+ // src/AppRouter.tsx
232
+
233
+ import { Profiler } from 'react'
234
+
235
+ const AppRouter: FunctionComponent = () => {
236
+ return (
237
+ <Profiler onRender={(id, phase, actualTime, baseTime, startTime, commitTime) => {
238
+ console.log(`${id}'s ${phase} phase:`);
239
+ console.log(`Actual time: ${actualTime}`);
240
+ console.log(`Base time: ${baseTime}`);
241
+ console.log(`Start time: ${startTime}`);
242
+ console.log(`Commit time: ${commitTime}`);
243
+ }}>
244
+ <Router>
245
+ <RecoilRoot>
246
+ <Suspense fallback={<span>Loading...</span>}>
247
+ <Switch>
248
+ <Route exact path="/" component={App} />
249
+ </Switch>
250
+ </Suspense>
251
+ </RecoilRoot>
252
+ </Router>
253
+ </Profiler>
254
+ )
255
+ }
256
+ ````
257
+
258
+ Read more about profiling options [here](https://medium.com/react-courses/4-ways-to-profile-your-react-app-75b740e39ab2?sk=9e73055e0f3d99caddb0f4f229f4b160).
259
+
260
+ ## Optimizing
261
+
262
+ - Prerender - almost static pages using `react-snap`. See comments in: `src/index.tsx`;
263
+ - Precache - src/index.tsx > `serviceWorker.register()`
264
+ - Analyzer Bundle - `yarn add -D cra-bundle-analyzer` -> Create the report: `npx cra-bundle-analyzer`
265
+
266
+ Read more about optimizing in [this article](https://medium.com/react-courses/optimize-react-app-best-optimzing-techniques-i-wish-i-knew-before-i-wrote-my-first-line-of-code-2b4651f45a48).
267
+
268
+ ## Analyzing the Bundle Size
269
+
270
+ ‘bundle-analyzer’ (https://github.com/svengau/cra-bundle-analyzer), is my prefer bundle analyzer, it's more colorful and includes all the bundles in one page instead of calling them one by one with source-map-explorer.
271
+
272
+ Install (yarn add --dev cra-bundle-analyzer) & you use the run script:
273
+ ````
274
+ $ yarn analyzer
275
+ ````
276
+
277
+ Other option is to use source-map-explorer (yarn add --dev source-map-explorer);
278
+ ````
279
+ $ yarn analyze
280
+ ````
281
+
282
+ ## Cost
283
+
284
+ Adding all these libraries from this project comes with a cost of 87 kb out of the gate (54 kb of that for Recoil).
285
+
286
+ <b>Important</b> - if you don't use Recoil - remove it:
287
+
288
+ `$ yarn remove recoil`
289
+
290
+ React v17 costs are a split between React library itself parsed cost 129.17KB that is broken down to parsed 8.67kb (or 2.4 gzipped) and the React DOM parsed 120.5kb (or 38kb gzipped).
291
+
292
+ If you can use help with your React project or have a burning question, or an issue in your project that needs help with, I invite you to hire me as your [Coach](https://elielrom.com). My strategy is 100% results-oriented. If you want to sample how I work 1-on-1, let’s schedule a one-time deep dive [Consultation](https://elielrom.com/CoachingHourly).
293
+ Additionally, [I will tutor you in react, javascript, typescript, mongodb, node, d3.](https://www.fiverr.com/elieladelrom/tutor-you-in-react-javascript-typescript-mongodb-node-d3)
294
+
295
+ ## Where to go from here?
296
+
297
+ - [Take the interactive d3 and React Course](https://www.udemy.com/course/integrating-d3js-with-react/?referralCode=4C1ADE35AB8633B90205)
298
+ - [Take the Digital Course & get a 40 pages React book](https://www.udemy.com/course/getting-started-react17-with-must-have-libraries/?referralCode=3E6A9B9D8EBB48A913A9)
299
+ - [View the article on Medium](https://medium.com/react-courses/setting-up-professional-react-project-with-must-have-reactjs-libraries-2020-9358edf9acb3)
300
+ - [Visit my site EliElrom.com](https://elielrom.com)
301
+ - [Learning React?](https://github.com/EliEladElrom/react-tutorials)
302
+
303
+ If you like this library, don't be shy to star it 🙏