The main idea of this project is to define some standards for all AIME platforms. Here you'll find design definitions and React components which are used across all the platforms.
Run the following command:
yarn add aime-blueprint
or npm i aime-blueprint --save
.
Now import the component/components in the file you will use it:
import { Button, Input } from 'aime-blueprint
;
Now you are ready to use them :)!
- Every component we use in more than one project should be here, so we can reuse code.
- Every component we are not still using in a project, but it is useful as a UI Design reference, and we will add in one or multiple project should be here.
- Every function we use in more than one project should be here, inside utils, so we don't maintain same function in multiple places.
- Really big component we know is specific for a project.
- Things we know are temporal and we are not going to add unit test, and this kind of things.
To begin you will need to navigate to the folder named commands, this can be done via vscode build in terminal (Windows: command line with the command instruction
cd commands
.
Once you are in the commands
folder you can run all the following command instructions from this folder.
All naming conventions for Blueprint folders
and files
are: camelCase
To automatically create the files required to add components to blueprint you can run the following command sh createComponent [yourComponent]
replacing [yourComponent]
with the name of your new component.
Automating the initial creation process is preferred but not a must the files can be manually created also. (Manual creation for Windows is the only option)
The files that are expected in a component folder when creating a new component, are listed below;
yourComponent.js
yourComponent.md
yourComponent.module.scss
yourComponent.test.js
index.js
After you run your initial test you will also see the folder __snapshots__
this folder is where all the test snapshots of your component live.
All component files are located in src/lib/components/yourComponent folder.
Filename | Description |
---|---|
yourComponent.module.scss | SASS file for your component styles |
yourComponent.test.js | Unit tests for your component. Includes some default settings, but you have to update with your component props, and you should add custom unit test there (Please, it's important you add those unit test) |
yourComponent.md | Used by styleguide to generate the example of your component. Fill this file with a complete example of the usage of your component. |
yourComponent.js | Rhe React component itself, should contain all the logic of your component. |
index.js | File responsible for exporting your component โ you probably don't need to change anything here. |
After your component has been created and all supporting files along with it. After writing the unit test, your full react component and you have added the markdown example. We are ready to test everything, so we go to the next step
Nice, so your new component is ready for testing ๐, that is great! It's time to check if everything works as expected.
If you want to locally test a component from within your project. See How to locally test blueprint library in your project Otherwise, read on to test your built component in blueprint.
- First we should check if unit test are passing, so we run
yarn test
. It will create by default a snapshot folder inside our component folder. This folder is used by jest to speed up unit test, and check that everything is working as it is expected. Also this command will show you the whole project test coverage, and it will show an error if any unit test detect an error. - Now we generate our build package. Read How to build library for that.
- Also it's time to build the styleguide docs, and we can read how to do it in How to build styleguide
When all unit test are passing, we are closer to see our component working. Now we have to run a command to generate the library we will import from different projects, and the command is yarn build:lib
.
If your javascript is ok (and it should be ok because unit tests are passing), it will run completely without problems.
It's time to generate styleguide documentation, and the command is yarn build:styleguide
(this command generates automatically styleguide folder)
Lets see our component!!! ๐ We run serve -s styleguide
(you have to previously install serve command, you can use npm i serve -g
if you don't have it). This command loads your styleguide folder, and copies in your clipboard the url to open the project...so you can open now your browser and paste the url. You should find in components list the component you created, with the example you wrote in markdown file, proptypes specs and example code.
Does it work? ๐๐
Execute command yarn build:sassdoc
Does it work? ๐๐
Ohhh, you are ready to deploy...that's amazing!:muscle: Steps for deploy are:
- If you didn't follow previous steps (How to test components, How to build styleguide, How to build library), you can run
yarn deploy
command, which basically runs unit test, generate the library package and create styleguide docs. It's important to check that all unit tests are passing, and to open styleguide to confirm your component is there and it works as expected. - Add your updated files you want to commit with
git add /file1 /file2 ...
. - Run commit command to save los changes on git
git commit -m "COMMENTS OF THE CHANGE"
adding a comment of what have you updated, changed or fixed. - Push your changes to your branch
git push origin BRANCH_NAME
. - Create a PR to master.
- After PR is approved and merged to master, we are ready to run generate the new version. We have inside commands folder a command to do that. We only need to know current version of aime-blueprint, and we should define if our change is a MINOR, MAJOR or PATCH change, to upgrade our library version. Version number has the format PATCH.MAJOR.MINOR. To do the update we run on terminal inside commands folder the command
sh publish VERSION
. And that's it. Now we have to wait maybe 2 minutes, maybe 30 minutes until new version appear on npm library and it's ready to be used.
Some examples about how to increase versions are:
- MINOR change: We are on version
1.0.3
and we just fixed an existing component, so it's a minor version we need to publish, we have to run the commandsh publish 1.0.4
. - MAYOR change: Ohhh, we change the structure of some components, and added a new theme, so we think it's a major version. Library is in version
1.0.4
. So now we have to runsh publish 1.1.0
. - PATCH change: It's less common to to have this kind of change, but we updated mostly all components, it was a big refactor, and we upgrade versions of some dependencies we have in the project, so it's a big change. We are in version
1.1.8
so the command we run issh publish 2.0.0
.
- In blueprint, make sure you're on the branch that includes the updates you're wanting to test in your local project.
- Run
yarn
in case you need to update your install. - Test blueprint is loading properly by building the styleguide locally with
yarn start:styleguide
. - If having errors, you might need to switch your node version. See Troubleshooting.
- If everything is looking good in blueprint, you're ready! Run
yarn link
to set it up for linking with your local project. - Now time to build it. Run
yarn build:lib
- Now time for you to switch to your local project where you're wanting to link blueprint. Let's say it's the website. Open up a new tab in your terminal and go to your local
website
folder. Again, make sure you're on the branch that you want to test blueprint with. - Run
yarn link "aime-blueprint"
to link to your local blueprint build. - Now run
yarn dev
or whatever command builds your local project. That's it ๐ Now you should be seeing your local blueprint components within your project!
- Same as steps 1-3 above
- Now that you're happy with everything on your local branch, you need to run
yarn build:lib
to build your blueprint library - Then you need to commit and push all your blueprint lib files to your remote branch
- Now switch to your local project you want to link with blueprint. Let's say it's the website. Open up a new tab in your terminal and go to your local
website
folder. Again, make sure you're on the branch that you want to test blueprint with. - Run
yarn add git://github.com/aimementoring/blueprint.git#feature/title-improvements --save
but swap outfeature/title-improvements
with the name of the branch you're wanting to test in your project. - Now run
yarn dev
or whatever command builds your local project. That's it ๐ Now you should be seeing your local blueprint components within your project!
NB: Blueprint will be linked until you runโฆyarn unlink
in your blueprint
terminal as well as yarn unlink โaime-blueprintโ
in your local project (website
or portal
)
Having issues? Try one of the Troubleshooting tips below.
Command | Description |
---|---|
yarn run build:styleguide |
Generates styleguide folder with all project documentation |
yarn run build:lib |
Generates lib folder with all components to be imported from projects which use the library |
yarn run build |
Build styleguide and lib folder |
yarn run lint-staged |
Validate javascript code style only on files you have changed |
yarn run lint |
Validate javascript code style in the whole project |
yarn run fix-lint |
Fixes some lint errors (not complex ones) |
yarn run fix-code |
Fixes javascript lint errors using prettier (only to be used from VSCode) |
yarn run fix-styles |
Fixes scss lint errors using prettier (only to be used from VSCode) |
yarn run start |
Start project for development process in localhost |
yarn run test |
Run all unit tests, and generates coverage report |
yarn run deploy |
Execute all unit test and run build to generate lib and styleguide folder |
yarn run release |
Generate a release with a new version (Still not ready to use) |
- Run
nvm list
to see what node version your local blueprint is currently using. Right now, we're usingv12+
. - If you don't have a version of
v12
, you will need to install it. To do this runnvm install [version number]
. - Now you can switch to the right version by
nvm use [version number]
- Run
yarn
again to install what you need with the new node switch. The end!
- Checkout
.env.example
and copy in any new variables you might need in.env
- Delete your local
node_modules
folder (on the project you might be testing with too). - Empty your local trashcan
- Start fresh by installing
yarn
again.