This is the early access documentation preview for Custom Views. This documentation might not be in sync with our official documentation.
Set up a custom Git repository
Set up a custom Git repository for your commercetools Frontend project.
Prerequisites
To set up a Git repository for your commercetools Frontend project, you need the following:
- The latest version of the CLI installed
- Git installed
- A Studio API key with the
build-upload
scope
Set up a new project
To set up a Git repository for your commercetools Frontend project, follow these steps:
Create a directory for your project using the terminal by running the following command:
Create project directoryTerminalmkdir PROJECT_NAMEChange the working directory to the new directory by running the following command:
Move into project directoryTerminalcd PROJECT_NAMEInitialize the Git repository by running the following command:
Initialize Git repositoryTerminalgit initScaffold your commercetools Frontend project by running the following command:
Scaffold your commercetools Frontend projectTerminalfrontastic scaffold CUSTOMER_NAME PROJECT_NAMEAdd and commit your code by running the following commands:
Create your first commitTerminalgit add . && git commit -m "Initial commit"Create the remote repository using git remote.
You can now push, pull, and fetch to or from your remote repository.
Build your project
To deploy your project, you need to build the application into JavaScript bundles. You can do this locally or in a Continuous Integration (CI) environment.
Backend extensions
To build the backend extensions, follow these steps:
- Run
yarn install
in thepackages/PROJECT_NAME/backend
directory. - Run
yarn build
in thepackages/PROJECT_NAME/backend
directory.
After the yarn build
command has finished executing, the build artifacts bundle.min.js
and bundle.min.js.map
will be available at this path packages/PROJECT_NAME/backend/build/
.
Frontend website
Netlify builds and deploys your frontend website separately from the backend extensions. For further information about Netlify deployments, see Deploy frontend.
Deploy your project
Deploy backend extensions
To deploy your backend extensions, you need the following information:
PROJECT
: the name of your commercetools Frontend project.BRANCH
: the name of the Git branch to deploy.REVISION
: the full commit hash of the current HEAD.VERSION
: the current time represented in the formatYYYY.MM.DD.HH.mm
. This value must be unique and sortable.NODE_JS_VERSION
: the Node.js version for the Extension runner. The default value is18
.BUILD_SUCCESSFUL
: set it totrue
if the build was successful. Otherwise, set it tofalse
. Only successful builds are stored in the Studio.BUILD_TIME
: the date and time of the build in the RFC3339 format. For example,2023-11-21T08:14:31.830Z
.. For example,2023-11-21T08:14:31.830Z
.BUILD_DURATION
: a numeric value for the build duration in seconds.BUILD_LOG
: the CI execution logs.BUNDLE_PATH
: the path to thebundle.min.js
file.BUNDLE_MAP_PATH
: the path to thebundle.min.js.map
file.SHOULD_DEPLOY
: set it totrue
to deploy the build to the staging environment, or set it tofalse
if you only want to upload the build.STUDIO_URL
: your Studio URL, in the formatCUSTOMER_ID.frontastic.io
.API_ID
: the Studio API key ID.API_KEY
: the Studio API key.
You can deploy your commercetools Frontend project when uploading the build (by setting shouldDeploy
to true
) or manually using the Studio (by setting shouldDeploy
to false
).
Upload the build
To upload the build using the CLI, follow these steps:
To protect the Studio API key from being exposed in the shell logs, set the API credentials as environment variables by running the following commands.
Set environment variables in the shell for authenticationTerminalexport FRONTASTIC_CLI_CLIENT_ID=<API_ID>export FRONTASTIC_CLI_CLIENT_SECRET=<API_KEY>Run the
upload
command from your project directory.Upload the build using the upload commandTerminalfrontastic upload \--project PROJECT \--branch BRANCH \--revision REVISION \--versionNumber VERSION \--nodeJsVersion NODE_JS_VERSION \--buildSuccessful BUILD_SUCCESSFUL \--buildTime BUILD_TIME \--buildDuration BUILD_DURATION \--buildLog BUILD_LOG \--deploy SHOULD_DEPLOY \--extensionBundleFilePath BUNDLE_PATH \--extensionBundleMapFilePath BUNDLE_MAP_PATH \--url STUDIO_URL \/
If you face issues when installing the CLI on your CI, you can use the CLI without installation.
Deploy frontend
To deploy your frontend, you must connect your Git repository to Netlify. To do so, follow these steps:
Set the following values for the build settings.
- Runtime:
Next.js
- Base directory:
packages/PROJECT_NAME/frontend
- Build command:
yarn build
- Publish directory:
packages/PROJECT_NAME/frontend/.next
- Runtime:
Set the following values for the environment variables in your Netlify site settings:
NETLIFY_USE_YARN
:true
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
:CLOUDINARY_CLOUD_NAME
NEXT_PUBLIC_FRONTASTIC_HOST
:https://PROJECT_NAME-CUSTOMER_NAME.frontastic.io/frontastic