Happeo component library for React Apps. This is the public version.
- lerna
- Node version: 16.13.2
- IMPORTANT: This repository uses
lerna
andyarn workspaces
. For this reason don't use npm!!!. It would mix things up as yarn is taking care of the npm functionality.
If you are running into issues when initialising lerna for the first time, try the following:
- Check your .npmrc file, verify that the registry urls match with package urls. For example that the ending is /npm-local in package and auth
- Do npm login
- Delete yarn.lock
- Check node version
How to test your work without needing to open a PR or change directly your node_modules in bridge/admin/etc.
In the folder of the package - for example buttons
NODE_ENV=production BABEL_ENV=production chokidar ./src -c "npx babel --root-mode upward src -d dist; yalc push"
chokidar
-> can be replaced by any watcher than can run a command after a file changes
npx babel
-> can be replaced by babel
if you have it installed locally
npm run link --package=@happeouikit/buttons
Replace buttons
by any package you would need.
Then run npm install. You need to do it only once.
Follow https://divotion.com/blog/yalc-npm-link-alternative-that-does-work
There is a nifty generator tool for this. Which should get you going easily. Just run the following:
yarn run generate
The code for the generator can be found from scripts
directory. If there is something wrong with the templates,
you can go and change them. The tool under the hood is called plop and the
inspiration is from react-boilerplate.
The idea of the component library is to develop isolated components that could be placed anywhere in React applications. This way we get reusable, self-contained and easy to test components.
That's why the preferred development flow is:
- Install all packages by running:
lerna bootstrap
- If a new dependency is used in only one package of the kit, it'd be added to the
package.json
of that specific package. Otherwise it can be added to the rootpackage.json
by runningyarn add -W package-name
. - The kit packages are linked straight from their source files and there's no need to run
build
script for development. - Start the documentation engine at the repo root:
yarn start
. - Create new component with:
yarn run generate
. - Develop your component.
- Update the document file as you need, you can also use the Playground component.
- Make sure all the exported components have Props component in the documentation.
- Make sure all your edits are documented in the docs, i.e. the new props are in the
Props
and new additions have examples. - Publish your edits: follow the "Publishing a Package" guide below.
- Read the "Writing Docs" -part
- Install all packages by running:
lerna bootstrap
- Add svg file to the folder
packages/icons/svgs
- Inside the icons package run
yarn run prebuild
to generate the icon. - Start the documentation engine on the repo root:
yarn start
. - Publish your edits: follow the "Publishing a Package" guide below.
The documentation engine used is Docz.
- Try to write the docs as you develop, documenting all the use cases the component is made for.
- If another component is shown only in the documentation, like a button in a card. The other package needs to be included as a dependency of the package you are writing. So for example
@happeouikit/button
needs to be a dependency of@happeouikit/card
. - Sometimes the page just doesn't refresh or shows old stuff. This is the time to restart the
yarn start
. Also runningrm -rf .docz/
might help to clear some caches. - If you get an error of a module cannot be found. Just stop the
dev
process and runlerna bootstrap
. This will make sure all the dependencies are symlinked to the packages. - Try writing all the needed example code into the .mdx files, so the source code is easily seen from the built documentation. If really need then add a separate file for example configuration. But then add it to the package
docs
folder. Don't make the example components available in the published package, in other words, newer into thesrc
folder.
See the below example for using state inside the playground component
import { useState } from "react";
import { LoadingModal } from "../src/index";
<Playground>
{() => {
const [modalIsOpen, setModalIsOpen] = useState(false);
return (
<div style={{ padding: "32px" }}>
<button onClick={() => setModalIsOpen(true)}>Open modal</button>
<LoadingModal
isOpen={modalIsOpen}
title={"Hahaa! You cannot close me"}
description={"You fool! You need to refresh this page now. Hahaha!"}
state={"loading"}
/>
</div>
);
}}
</Playground>;
- Think about the version increase (major, minor or patch) your edits require. Don't hesitate about releasing major if it really is a breaking change. However avoid making breaking changes too often in the first place.
Note: if a major version of the UI kit is released, that means that all the packages have to be updated to the next major version (the version doesn't have to be the same for all of them). It can be easily done via
lerna publish major
. - Make sure you have written notes into the package's �
�CHANGELOG.md
. Especially if you have added components write each additions. Breaking changes of course should be written loud and clear. - When all the above is done, run
yarn run publish
in the root and follow the instructions. This will make a git commit and publish your package. It will build all packages, but should only publish packages that have new git commits with versions. - In case there's a need to publish single package only, there's a script
publish:single
, which will have the same workflow as before the kit upgrade and will usenpm
to publish specified package.
- If the changes to a package aren't visible after it has been published, make sure that the files in the package's
dist
folder have the new changes. If yes you might need to publish it again, since for some reason the changes aren't picked up sometimes. - If the files were not build, execute
yarn run build
�. - If
lerna bootstrap
fails (either locally or in the pipeline) with this error“https://universe.jfrog.io/artifactory/api/npm/npm-local/@universe/frontend-utils/-/@universe/frontend-utils-0.35.1.tgz: Request failed \“401 Unauthorized\“”.
Delete youryarn.lock
file. - If
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Don't remove yarn.lock file, and make sure that node version - 10.22.0 - if you have an authentication error with publishing to npm - check if you a part of
happeouikit
organization in npm. - If you have an error related to github when running
yarn run publish:single
then you can finish the publish withlerna publish from-package
- Each created/updated PR will create a container hosting the newly introduced changes.
- The url pointing to this container can be found at the end of the build pipeline (check
Live Draft Url
field). - The url can be shared with other devs/designers to speed up the testing/reviewing process.
styled-components/styled-components#1305
That depends entirely on your build setup. How are you building the component library? Also make sure the component library only has the dependency in peerDependencies and in devDependencies, and that both the app and the lib allow the same version.
If you have this error
warning [email protected]: Invalid bin field for "url-loader".
warning [email protected]: Invalid bin entry for "sha.js" (in "sha.js").
error An unexpected error occurred: "https://universe.jfrog.io/artifactory/api/npm/npm-local/@universe/react-translations/-/@universe/react-translations-1.2.0.tgz: Request failed \"401 Unauthorized\"".
info If you think this is a bug, please open a bug report with the information provided in "/opt/atlassian/pipelines/agent/build/yarn-error.log".
Revert your yarn.lock
e.g git checkout origin/master yarn.lock