This is a React boilerplate to create the decentralize renderer.
The easiest way to install the React template for the decentralized renderer is through GitHub:
- In the repository page, click
Use this template.
Alternatively, you can also download or git clone this repository:
$ git clone https://github.com/Open-Attestation/decentralized-renderer-react-template.git my-module
$ cd my-module
$ rm -rf .git
$ npm installBe sure to edit the following files according to your module information:
package.json(module name and version)README.mdLICENSE- Add your own template (in the
src/templatesfolder) and configure the template registry (in thesrc/templates/index.tsxfile).
The following shows a list of commands for development tasks:
$ npm run storybook # open storybook and start editing your components
$ npm run storybook:build # generate docs
$ npm run test:watch # run tests with Jest
$ npm run test:coverage # run tests with coverage
$ npm run integration # run integration test with testcafe
$ npm run lint # lint code
$ npm run build # build component
$ npm run example:application # start embedded application- The
index.tsfile contains the logic to communicate with the host embedding your renderer. You might not need to update this file. - The template registry configuration is located in the
src/templates/index.tsxfile. - Templates are located in the
src/templatesfolder. You can add as many templates as required and structure the code accordingly. - Document samples contain fake data to test the templates you build. You can create a TypeScript interface to make sure that your template uses the correct expected document:
- Create a type describing the kind of document you expect to render (For instance, check
CustomTemplateCertificateinsrc/sample.tsx). - Create a template consuming that interface, using the
TemplatePropshelper from@govtechsg/decentralized-renderer-react-components(For instance, check the template in thesrc/templates/customTemplate/customTemplate.tsxfile).
- Create a type describing the kind of document you expect to render (For instance, check
- Shared components are located in the
src/corefolder. For instance, you can find a watermark example that will display while printing the document. - Examples for adding a watermark and QR code are located in the
examples/templatefolder. - You can remove anything your project won't use.
This template provides a simple application that is able to render documents built for the current renderer.
To use it, follow the steps below:
-
Open the
application/index.tsxfile and edit thedocumentsproperty of theAppcomponent depending on your needs.Provide any document that is available locally, whether it's a JavaScript, JSON, or TypeScript document.
-
Start your renderer using the command below:
npm run dev- Start the local application using the command below:
npm run example:application-
Visit
http://localhost:3010/in browser.The configured documents in Step 1 should display.
- Start your renderer using the command below:
npm run dev- Start the local HTML using the command below:
npm run example:html-
Visit
http://localhost:8080/in browser.A button for rendering the document should display. Click the button to start rendering.
This repository has been configured to run end-to-end tests using Testcafe. Visualization test is also configured through Percy and the tests run through Testcafe.
To set up Percy, you will need a token on Percy's dashboard. For local development, type export PERCY_TOKEN=<PERCY_TOKEN> before running npm run integration.
- Babel - With this tool, you can write next-generation JavaScript.
- Debug - A JS debugging utility that works in both node.js and browsers
- Emotion - A library designed for writing CSS with JavaScript
- ESLint - With this tool, you write quality code.
- Jest - A JavaScript testing framework used by Facebook
- Percy - A visualization testing tool
- Prettier - It enforces a consistent style by parsing your code and re-printing it.
- React - A JavaScript library for building user interfaces
- React testing library - Simple and complete testing utilities that encourage good testing practices
- TestCafe - A node.js tool to automate end-to-end web testing
- TypeScript - A JavaScript superset that provides optional static typing
- Storybook - A tool for developing UI components in isolation with documentation
- Webpack - A component bundler
To uninstall npm packages with emotions, use the command below:
$ npm uninstall @emotion/core @emotion/styled @emotion/babel-preset-css-prop- The uninstallation process will remove
@emotion/babel-preset-css-propfrom Babel presets (configuration is made in thepackage.jsonfile). - It will remove
@emotion/corefrom TypeScript configuration (in thetsconfig.jsonfile). - It will also remove
.storybook/webpack.config.js(a file created only for emotion CSS property support in storybook).
To uninstall npm packages with examples, use the command below:
$ npm uninstall qrcode.react @types/qrcode.react- The uninstallation process will remove the
examplesfolder completely. - It will remove line 5 with the
../examplecontext from.storybook/config.js, so that the storybook won't look for example files.
The React template for the decentralized renderer is under the Apache license, version 2.0.