Gathering detailed insights and metrics for cra-template-josh-ts
Gathering detailed insights and metrics for cra-template-josh-ts
Gathering detailed insights and metrics for cra-template-josh-ts
Gathering detailed insights and metrics for cra-template-josh-ts
A create-react-app template setup with React, TypeScript, Prettier, ESLint config, Cypress automated testing, Emotion CSS-in-JS, and a readme explaining how to use each.
npm install cra-template-josh-ts
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (50.76%)
HTML (33.03%)
TypeScript (16.22%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
10 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jan 07, 2021
Latest Version
0.1.2
Package Id
cra-template-josh-ts@0.1.2
Unpacked Size
44.54 kB
Size
30.18 kB
File Count
25
NPM Version
5.8.0
Node Version
10.21.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
16
This project was bootstrapped with Create React App.
This is a template to quickly initialise a react project with, what I believe to be, best practices in mind. The technologies initialised are: React, TypeScript, ESlint, Prettier, Emotion CSS-in-JS, and Cypress automated testing. This will preconfigure ESLint, Prettier, and a tsconfig file, and also provides instruction on how to alter it to suite your needs. It also provides the useful VSCode extensions for this template. A .env
file and a cypress.env.json
file are also created, and automatically added to a .gitignore
to ensure sensitive info is not committed.
Below is a list of the VSCode extensions recommended to get the most out of this template. Note, the ones with asterixis (*) I consider required, or their equivalent if using a different IDE/editor.
This project currently uses Emotion for CSS. This allows the creation of css stylings in the same file as Components to keep things scoped nicely.
The following comment is required at the top of every file which will use css-in-js, as this tells React to grab the JSX creation from emotion instead of React.createElement.
1/** @jsxImportSource @emotion/react */
This means we can create styles like this:
1import React from "react"; 2import { css } from "@emotion/react"; 3 4const hoverColor = "green"; 5 6const styling = css` 7 color: red; 8 &:hover { 9 color: ${hoverColor}; 10 font-size: 20px; 11 } 12`;
Note, this will have syntax highlighting and autocomplete for the css when the above extensions are installed.
We then add the stylings as such using the css
property we imported.
1const Another: React.FC = (): JSX.Element => { 2 return ( 3 <div css={styling}> 4 <h2>Another thing here.</h2> 5 </div> 6 ); 7};
This uses Yarn as a package manager. If yarn has never been used, install it first (https://classic.yarnpkg.com/en/docs/install/#windows-stable).
yarn add -D <package>
for dev dependenciesyarn global add <package>
for global depsyarn install
for installing the projectyarn <script>
to run a script in package.json.This project uses ESLint as a linter, and Prettier as a code formatter. The .eslintrc.js
file handles the settings for linting, currently it just uses the default "react-app" settings. However, this can be adjusted to adhere to different rules.
1module.exports = { 2 extends: ["react-app", "react-app/jest"], 3 rules: { 4 quotes: ["error", "single"], 5 }, 6};
The above the project would need single quotes for all strings rather than double, and would throw an error if doing so. If we wanted instead a warning (could still run), we would specify to "warn".
1module.exports = { 2 extends: ["react-app", "react-app/jest"], 3 rules: { 4 quotes: ["warn", "single"], 5 }, 6};
The rules can be found on eslint.org. To make ESLint ignore some files, we can use the ignorePatterns
option in the .eslintrc.js
file to give some files to ignore:
1module.exports = { 2 extends: ["react-app", "react-app/jest"], 3 ignorePatterns: ["src/**/__tests/"], 4};
The above tells ESLint not to run on any file in a folder called __tests__
that is in any subdirectory (or a direct child of) src
.
1module.exports = { 2 extends: ["react-app", "react-app/jest"], 3 ignorePatterns: ["**/*.{js,jsx}"], 4};
The above tells ESLint not to run on any file in any directory which has the extension of .js
or .jsx
.
Finally, we add TypeScript support via a couple plugins that are already installed, and should be installed with a yarn install
command.
1module.exports = { 2 extends: [ 3 "react-app", 4 "react-app/jest", 5 "eslint:recommended", 6 "plugin:@typescript-eslint/eslint-recommended", 7 "plugin:@typescript-eslint/recommended", 8 ], 9};
Can also run yarn lint
to lint everything in src
. This will show any warnings or errors that won't be autosolved by prettier (see below).
The .prettierrc.js
file contains the formatting that prettier will automatically adhere to.
1module.exports = { 2 tabWidth: 4, 3 semi: true, 4 singleQuote: false, 5 useTabs: true, 6};
These rules again can be found online. To get prettier and eslint to work, ensure the following properties are in the VSCode user settings.
1"editor.defaultFormatter": "esbenp.prettier-vscode", 2"editor.formatOnSave": true, 3"eslint.validate": [ 4 "javascript", 5 "javascriptreact", 6 { "language": "typescript", "autoFix": true }, 7 { "language": "typescriptreact", "autoFix": true } 8 ], 9"javascript.updateImportsOnFileMove.enabled": "always",
This will cause prettier to format code on every save. This means that, if the Prettier settings and the ESLint/tsconfig are setup correctly, prettier should always cause no warnings to appear due to ESLint. But they probably still will as is the software life ¯\_(ツ)_/¯.
This project using automated testing using Cypress. This can be run from the terminal yarn cypress open
or by running the cy:dev
script with yarn cy:dev
. This opens the cypress test runner. The tests are from the cypress/integration
folder. Each can be run, or all can be run at once. To get intellisense on cypress commands, add /// <reference types="Cypress" />
to the top of each cypress test file (spec.js
). You can also write these tests in TypeScript if you want, they are in JavaScript to highlight that you can use both TS and JS in the same project without issues.
Before running the tests, ensure that the dev server is running on localhost:3000 in a separate terminal window. TO provide sensitive information in a secure way when doing automated testing (passwords etc), we use a cypress.env.json
file, in which we store our env variables for cypress testing (note: we can also use a normal .env
file and prefix our cypress env vars with CYPRESS_
too).
1{ 2 "adminUsername": "admin", 3 "adminPassword": "password444" 4} 5 6// OR in normal .env file 7CYPRESS_adminUsername=admin 8CYPRESS_adminPassword=password444
Then, in a cypress test, we would write:
1describe("First test", () => { 2 it("Admin login works", () => { 3 cy.visit("http://localhost:3000"); 4 cy.get("#login-username").type(Cypress.env(`adminUsername`)); 5 cy.get("#login-password").type(Cypress.env(`adminPassword`)); 6 }); 7});
To run these tests in headless mode, use yarn cy:run
- this is, by default, set to run with no config file (--config-file false), however this can be changed after running yarn cy:dev
once to generate a cypress.json
file, then pointing the config file at this location.
This will get cypress to select the elements on the page with a id
property of login-username/login-password
respectively, and type in each of the values found in the env variables.
NOTE - if you are using this via a Linux shell, you must install the following dependencies (as root user) before cypress will work (see https://docs.cypress.io/guides/guides/continuous-integration.html#Advanced-setup):
1apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
If this fails, you may need to update your current packages.
1sudo apt-get update
If an issue with installing xvfb
still occurs after the above, try installing it again:
1sudo apt-get install xvfb
Right now, Cypress seems to struggle functioning correctly on WSL1 distros, therefore it is recommended to upgrade to WSL2 to use Cypress correctly.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/10 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
104 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More