- React PWA Reference Storefront
- Overview
- Setting up the Storefront
- Running a Linter
- Adding New Locales
- Running Unit Tests
- Configuring Jenkins Pipeline
- Terms And Conditions
This document provides guidelines for knowledgeable JavaScript developers and front-end developers to extend and customize React PWA Reference Storefront components. However, this document is not a primer for JavaScript or CSS and is intended for professionals who are familiar with the following technologies:
The REACT PWA Reference Storefront is a flexible e-commerce website built on Elastic Path’s RESTful e-commerce API, Cortex API. Through the Cortex API, the storefront uses the e-commerce capabilities provided by Elastic Path Commerce and gets data in a RESTful manner. For more information about the storefront, see REACT PWA Reference Storefront Documentation.
The Storefront is designed as an open source mobile Progressive Web Application (PWA) that has the capabilities for local browser storage page caching and persistent session management. This PWA is built using the 'React.js', Bootstrap, and Babel technologies. Webpack and node.js enable the application layer interactions through the configurable web server. For more information about the software requirements, see the Requirements and Specifications section.
Ensure that the following software are installed:
- Git
- Node.js
- Visual Studio Code with the following extensions:
- Java JDK 8 (for unit testing, optional)
- Maven 3.5.2 (for unit testing, optional)
- IntelliJ IDEA (for unit testing, optional)
- A valid Elastic Path development environment. For more information, see The Starting Construction Guide.
You must configure the following parameters in the ./src/ep.config.json
file:
Parameter | Importance | Type | Description |
---|---|---|---|
cortexApi.path |
Required | String | The URL, which is composed of the hostname and port, to access Cortex. By default, a web proxy is configured in the Webpack configuration of the project. For local development, set this value to /cortex to redirect Cortex calls to the local proxy. |
cortexApi.scope |
Required | String | Name of the store from which Cortex retrieves data. |
cortexApi.pathForProxy |
Required | String | The path to which the Webpack proxy routes the Cortex calls from the storefront. This value is a URL that consists of hostname and port of a running instance of Cortex. Leave this field blank to disable proxy. |
skuImagesUrl |
Required | String | The URL that consists of the path to catalog images hosted on an external CMS. Set this parameter to the complete URL of the images by replacing the sku/file-name with the %sku% string. This value is populated when the page is loaded with values retrieved by Cortex. |
siteImagesUrl |
Optional | String | The path to the site content and marketing images hosted on an external CMS. Set this parameter to the complete URL of the images by replacing the filename and file extension with %fileName% . This parameter is populated with the values set in the components when the page is loaded, and uses the assets locally available in the ./src/images/site-images directory. |
arKit.enable |
Optional | Boolean | Enable elements for ARKit's Quick Look capability to load on a product display page. When arKit.enable is enabled, any product images that have hosted ARKit USDZ files are wrapped with an anchor tag referencing the file hosted on an external CMS. |
arKit.skuArImagesUrl |
Optional | String | The path to the USDZ files hosted on an external CMS used for ARKit Quick Look. Set this parameter to the complete URL of the files by replacing the sku/file-name with %sku% . This value is populated when the page is loaded with values retrieved by Cortex. |
gaTrackingId |
Optional | String | The Google Analytics tracking ID to integrate with Google Analytics Suite to track enhanced e-commerce activity on the site. |
Elastic Path provides a set of sample data with the storefront project.
Note: A valid Elastic Path development environment is required to access the sample data.
- From the
react-pwa-reference-storefront/data
directory, extract the sample catalog data contents into theep-commerce/extensions/database/ext-data/src/main/resources/data
directory. - In the
ep-commerce/extensions/database/ext-data/src/main/resources/data/
directory, update theliquibase-changelog.xml
file with the following sample data:<include file="ep-blueprint-data/liquibase-changelog.xml" relativeToChangelogFile="true" />
Note: This data must be the only sample data included within the sample data block. - In the
ep-commerce/extensions/database/ext-data/src/main/resources/environments/local/data-population.properties
file, set theliquibase.contexts
property todefault,ep-blueprint
. - In the command line, navigate to the
extensions/database
module. - To run the Data Population tool, run the following command:
mvn clean install -Preset-db
. For more information about populating database, see the Populating the Database section.
- Clone or pull the
react-pwa-reference-storefront
repository to your directory. - Run the
cd react-pwa-reference-storefront
command. - To install dependencies, run the
npm install
command. - Configure the
./src/ep.config.json
file as required for the environment.
For more information, see the Configuration Parameter Descriptions section. - To start the server in development mode, run the
npm start
command. - To see the running Progressive Web Application (PWA), navigate to
http://localhost:8080/
.
-
Clone or pull the
react-pwa-reference-storefront
repository to your directory. -
Navigate to the
react-pwa-reference-storefront
directory. -
Build a Production Docker Image:
- Clone or pull the
react-pwa-reference-storefront
repository to your directory. - Run the
cd react-pwa-reference-storefront
command. - Run the
docker build -t ep-store -f ./docker/prod/Dockerfile .
command. - Push the
ep-store
image to the docker repository.
- Clone or pull the
-
Run a Production Docker Image:
- Navigate to the
docker/prod/
directory. - Copy the following files to the user home directory on the remote host:
docker-compose.yaml
nginx.conf
- In the
nginx.conf
file, update the following parameters:$CORTEX_URL
with Cortex server URL.$DOMAIN
with domain name withouthttp://
.$SSL_CERT_PATH
with the certificate file path in the remote server.
For example,/etc/letsencrypt/live/reference.elasticpath.com/fullchain.pem
.$SSL_KEY_PATH
with the path of the private key in the remote server.
For example,/etc/letsencrypt/live/reference.elasticpath.com/privkey.pem
.
Note: You can use the certificate generated by any certificate provider, such as Let's Encrypt.
- In the
docker-compose.yaml
file, update the following parameters:$DOCKER_REPO
withep-store
.$SSL_CERT_PATH
with the certificate file path in the remote server .
For example,/etc/letsencrypt/live/reference.elasticpath.com/fullchain.pem
.$SSL_KEY_PATH
with the path of the private key in the remote server.
For example,/etc/letsencrypt/live/reference.elasticpath.com/privkey.pem
.
- Run the following Docker command to start the Docker container created for the Docker image:
docker-compose up -d
- Navigate to the
The storefront project is set up with the linting utility, ESLint. For the storefront project, Elastic Path uses and extends the ESLint configuration provided by Airbnb. For more information on the style guide, see the Airbnb GitHub page.
By default, the ESLint loader is added to the webpack.config.dev.js
file. When you start the application in the development mode, the ESLint loader automatically runs.
- To run the linter from the command line, navigate to the project root directory.
- Run the following command:
./node_modules/.bin/eslint --ext .js --ext .jsx [file|dir|glob]
- Run the following command for the entire project:
./node_modules/.bin/eslint --ext .js --ext .jsx .
With the ESLint extension for Visual Studio Code, you can view feedback when you write the code in theProblems
view.
Note: When you check in the code, ensure that all linting errors are resolved.
The reference storefront supports multiple languages and currencies. Add all front-end textual data in the localization/en-CA.json
file as a resource string. By default, en-CA
and fr-FR
locales are provided in the project.
- For development purpose, run:
node tools/translate.js
.
This runs a pseudo translation fromen-CA
locale tofr-FR
. - To add a new locale, add an entry to the
supportedLocales
array in theep.config.json
file and add an appropriate.json
file to thelocalization
folder. - Configure the language and currency for all products in Commerce Manager.
Test data are provided in the tests
directory.
- To run all tests, run the following command:
mvn clean install -Dcucumber.options="--tags @smoketest"
- To run sanity test, run the following command:
mvn clean install -Dcucumber.options="--tags @sanity
Option | Description |
---|---|
-Dcucumber.options="--tags @smoketest" |
Specifies that you can replace the tag with a tag that you define. |
-Dfailsafe.fork.count="<no of testes>" |
Specifies the number of tests that can be run at the same time. The default value is 1. You can change this value depending on number of TestsIT classes. |
-Premote -Dremote.web.driver.url="<REMOTE DRIVER IP>" |
Specifies that the tests are executed using a remote VM. The remote.web.driver.url attribute specifies the URL of the remote VM. For example, http://<IP_ADDRESS>:4444/wd/hub . |
Note: You must set up the selenium grid to use this feature.For more information, see Selenium documentation.
- In the
/selenium/src/test/java/com/elasticpath/cucumber/
module, right-click a TestsIT class and click Run. You can create your own local runner class to run your own tagged tests. For example,RunLocalTestsIT.java
runs your own tagged tests at local. Note Do not commit the local runner class and tags that are only for the local testing purpose.
- Download the latest browser driver and update the
/selenium/src/test/resources/RepositoryMap.xml
file with the driver version. - Update the
RepositoryMap.xml
with the bash value of the browser driver:- To get the bash values, run the
openssl sha1 <filename>
command. The specifies the in theRepositoryMap.xml
file. For example, https://github.com/Ardesco/Selenium-Maven-Template/blob/master/src/test/resources/RepositoryMap.xml
- To get the bash values, run the
The storefront project includes a Jenkinsfile template to configure a Jenkins job to build a Docker image for store from the project, deploy the Docker image to AWS, and run the unit tests.
- Ensure that an AWS EC2 instance is created for the pipeline to deploy the store and Cortex.
- Open the Jenkisfile included in the project directory.
- Configure Jenkins job with the required parameters as described in the Jenkins Pipeline Parameter Descriptions section.
- Save the changes.
Parameter | Description |
---|---|
DOCKER_REGISTRY_ADDRESS |
The path to AWS ECR. For example, ${awsAccountID}.dkr.ecr.${region}.amazonaws.com . |
CORTEX_NAMESPACE |
The namespace for the Cortex images, such as Activemq, batch server, integration server, search server ,and Cortex server. |
DOCKER_IMAGE_TAG |
The tag used for the Cortex images. |
STORE_NAMESPACE |
The namespace for the store image and database image. |
STORE_IMAGE_TAG |
The tag for the store images, which are store image and database image. |
STORE_NAME |
The name of the store. For example, vestri . |
EC2_INSTANCE_HOST |
The IP address of the AWS EC2 host to deploy Jenkins pipeline. |
EC2_INSTANCE_USER |
The user credentials of the AWS EC2 instance. |
EC2_INSTANCE_SSH_KEY |
The path in Jenkins node that redirects to ec2.pem file . |
SOLR_HOME_GIT_URL |
The git URL to the project containing the solr home configuration. |
SOLR_HOME_BRANCH |
The branch name of the solr home configuration. |
SOLR_HOME_PATH |
The path to the solr home configuration that is provided in the git project. |
- Navigate to the Jenkins job console and select the Jenkins job to configure.
- In the left pane, select Configuration.
- In the Build Triggers tab, select Poll SCM.
The Schedule field is displayed. - In the Schedule field, set the time to run the job periodically.
The default setting is1 min
. - In the Advanced Project Options tab, do the following:
- In the Definition field, select Pipeline script from SCM.
- In the SCM field, select Git.
- In the Repository URL and Branches to build fields, enter the appropriate settings.
- In the Script Path filed, select Jenkinsfile
- Click Apply.
- Click Save.
You can configure all other setting as required for the project. This Jenkins job triggers commits to the master at the scheduled time. For more information about the pipeline, see the Jenkins Pipeline Workflow section.
When you run the the Jenkins job, the job operates in the following sequence:
SETUP
- Pulls the project and the project containing solr home configuration to a repository.BUILD
- Builds the store Docker image from thedocker/dev/Dockerfile
directory in the project and pushes the changes to AWS.- The development Docker runs the
entrypoint.sh
script to replace the path to Cortex and the store in theep.config.json
file and starts the project in development by running thenpm start
command.
- The development Docker runs the
UNDEPLOY_EXISTING
- Cleans up the working directory and removes docker containers and images, if any.DEPLOY
- Creates the working directory, copies the files from the project and solr home configuration, exports the environment variables used in the compose file, and deploys the store and Cortex with Docker-compose.TEST
- Sets the environment variables for JAVA_HOME and adds Java and Maven to the path. The variables are pulled from the Jenkins tools. For headless tests, installs Google Chrome by running the script at intoli and downloadinggoogle-chrome-stable
and renames it togoogle-chrome
to enable chromedriver to find it for tests. Before you run the tests, replace theselenium.session.baseurl
in thepom.xml
. For viewing reports in Jenkins UI, Jenkins Cucumber plugin is used.
- Any changes to this project must be reviewed and approved by the repository owner. For more information about contributing, see the Contribution Guide.
- For more information about the license, see GPLv3 License.