Please read before contributing to Merchant Center Application Kit in order to get familiar with the guidelines for contributing to the project.
The Merchant Center is a Multi Single-Page-Application where effectively multiple applications are running within the same domain, giving it a look and feel of being one big application. In fact, sections of the Merchant Center such as Dashboard, Orders, Products, etc are all different applications. You can read more about the architecture here (coming soon).
With that in mind, developing a Merchant Center Application requires a set of tools and components that should be used across the different applications, as they share some common logic. This repository contains all the minimal packages that are necessary to do that. Some of them do not need to be used directly but are instead required by other packages. Let's have a deeper look.
This repository is managed as a monorepo, meaning it contains multiple (sub)packages located in the packages
directory.
packages/
actions-global/
application-components/
application-shell/
application-shell-connectors/
assets/
babel-preset-mc-app/
browser-history/
constants/
create-mc-app/
eslint-config-mc-app/
i18n/
jest-preset-mc-app/
jest-stylelint-runner/
l10n/
mc-dev-authentication/
mc-html-template/
mc-http-server/
mc-scripts/
notifications/
permissions/
react-notifications/
sdk/
sentry/
url-utils/
Below a short description of the most import packages:
This package contains React components for developing Merchant Center applications, similarly to what the UiKit implements.
This package is the most important one and contains the core logic of a Merchant Center application (login, intl, base layout, etc). To develop an application, you need to render the <ApplicationShell>
component first (see package documentation).
The package also initializes different things such as intl, apollo, routing, etc.
This package is a complementary package of the application-shell
and contains "connector" components that use the new React Context API. The main purpose of those "connectors" is to make it easier for the consumer to access data in any place of the application.
This package contains static assets, such as SVG images.
This package contains a set of useful constant variables.
This package contains a CLI to bootstrap a starter application based on a predefined template.
This package contains a set of linting rules useful to use as a preset of your eslint
config.
This package contains React components for accessing internationalization data such as intl messages (of the application kit packages), moment locales, etc.
This package contains a preset configuration for Jest, focused on necessary tools and transformers for a Merchant Center application code.
This package contains React components for accessing localization data such as country, currency, language, time zone, etc.
This package runs a small HTTP server to serve the index.html
, with some additional extra like CSP headers, etc. The server is meant to be used to run the application in production mode.
If you're familiar with react-scripts
, this CLI works very similarly except that it is configured to work for developing Merchant Center Applications.
This package contains React components to apply permissions in your application code (e.g. prevent access to a view if the user does not have the correct scopes, etc).
This package contains React components to render notification (e.g. error message, success message, etc).
This package contains React components to perform requests in a declarative way. Underneath it uses our js-sdk to perform the network requests.
- Clone the repository
- Run
yarn
in the root folder
Once it's done, you can run yarn start
or yarn test
(yarn test:watch
) to develop the packages.
To develop locally, you can use the playground
application to test the changes in some of the packages. Make sure to yarn build
the packages before starting the playground
app because the app consumes the packages as normal "transpiled" dependencies.
You can also run the build in watch mode yarn build:bundles:watch
alongside with yarn playground:start
to rebundle and rebuild the application on each change.
commercetools application-kit uses changesets to do versioning and creating changelogs.
As a contributor you need to add a changeset by running yarn changeset
.
The command will prompt to select the packages that should be bumped, their associated semver bump types and some markdown which will be inserted into the changelogs.
When opening a Pull Request, a changeset-bot
checks that the Pull Request contains a changeset. A changeset is NOT required, as things like documentation or other changes in the repository itself generally don't need a changeset.
By default, all releases go to the
next
distribution channel and should be considered prereleases. This gives us a chance to test out a release before marking it stable in thelatest
distribution channel.
commercetools application-kit uses changesets to do versioning and publishing a release.
A Changesets release GitHub Action opens a Version Packages
Pull Request whenever there are some changesets that have not been released yet.
When the Version Packages
Pull Request gets merged, the Changesets release GitHub Action will automatically trigger the release.
After testing the next
release on a production project, if the version is stable it can be finally movede to the latest
distribution channel.
$ yarn release:from-next-to-latest
The command will promote the version published on next
to the latest
npm dist-tag, for each package.
On master
branch, we automatically publish canary releases from CI to the canary
distribution channel, after the build runs successfully.
Canary releases are useful to test early changes that should not be released yet to next
or latest
. They are automatically triggered and released after a Pull Request merged into master
, unless the commit message contains [skip publish]
.
Note that canary releases will not create git tags and version bump commits.
In order to be able to validate GraphQL queries and mutations, defined as .graphql
files, we use the eslint-plugin-graphql, which requires introspection schemas from the different GraphQL APIs being used.
To download the remote schemas simply run yarn get-schemas
. The configuration of each schema is defined in the .graphqlconfig.yml
file, in the root directory. Running this script will download the schemas in the schemas/*.json
files.
NOTE that you need your user
mcAccessToken
to be defined as an environment variableMC_ACCESS_TOKEN
in.env
file. This will be used by the introspection queries to be able to download the schemas from the MC API. Additionally, you also need to specify one of yourCTP_PROJECT_KEY
where you have access to.
Since the MC uses multiple GraphQL APIs, we need to differentiate which queries use which schema. To do so, prefix the file extension with one of the GraphQL targets:
- mc: instead of
.graphql
use*.mc.graphql
(graphql target:mc
) - settings: instead of
.graphql
use*.settings.graphql
(graphql target:settings
) - ctp: instead of
.graphql
use*.ctp.graphql
(graphql target:ctp
) - proxy: instead of
.graphql
use*.proxy.graphql
(API in the MC frontend apps)
The regex to match the files to each project schema are defiend in the .graphqlconfig.yml
file.
The file recommended.code-workspace
contains a pre-defined VSCode configuration that is optimized for working in this repository.
It also contains the extension recommendations to effectively work with MDX, the writing style linter and more.
When opening the project folder, VSCode detects that there is a workspace configuration available and prompts the option to open it. When VSCode loads the workspace configuration, it asks to automatically install all recommended extensions.
If you wish to keep your own settings.json
config, you might consider to pick the configuration that you need from the recommended config.