This project includes configuration and tooling that conforms to Crema's baseline best-practices for publishing a TypeScript library.
🧰 Tools Used
- ESLint for code linting
- Hygen for component and util generators
- Jest for unit tests
- Loki for visual testing
- Prettier for code formatting (via ESLint plugin)
- Storybook for component playground (and used by Loki)
- TypeScript for Static Typing in JavaScript (Learn)
- Install Node/NPM
- Install NVM (Node Version Manager)
nvm install 'lts/*' && nvm usenpm i(install project dependencies)- Install the ESLint plugin for
your editorVS Code - Enable "Auto-Fix on Save" in
settings.json:
{
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
]
}
Run the following scripts with npm run <SCRIPT_HERE>:
start- start compiling code insrcdirectory (output todist)new:component- generate a new componentnew:util- generate a new util(ity)new:type- generate a new typetest:analyze- run bundle analyzertest:lint:fix- run linter and fix if possibletest:lint- run lintertest:playground- run component playground (storybook)test:unit:coverage- run unit tests with coveragetest:unit- run unit teststest:visual:approve- approve visual changestest:visual:update- update or create visual referencestest:visual- run visual tests (loki)
These scripts are located in
package.jsonand do not represent the entirety of available scripts, but are the most commonly used.
The src directory contains all source files for your library. Below is a printout of its file-tree with a description for each part ().
src
├── components // Create a new one with `npm run new:component`
│ └── MyReactComponent/
├── utils // Create a new one with `npm run new:util`
│ └── MyUtil/
├── types // Centralize Type Definitions
│ └── MyType.ts
└── index.ts // Exports all types/modules for public consumption
- Ensure that you have incremented the version in
package.json - Run
npm run pack:testto see a list of files that would be included in your package - Run
npm packto generate a.tgzfile containing your package (for local testing) - Run
npm publishto publish your package (see Publish Package)
- Use the code generators:
npm run new:componentnpm run new:utilnpm run new:type- When prompted for a name, prefer
camelCasefor utils andCamelCasefor components and types
- Fill out the
README.mdto describe what your code does - Run your unit tests
npm run test:unitwhile working to see immediate feedback - If you get stuck at any point, just log an issue and we'll figure it out together 👭.