Setting up the developer environment
Contents
In this chapter, you’ll install the Enonic CLI, start a local Enonic XP sandbox, and create and deploy the app you’ll work on for the rest of the tutorial.
Enonic CLI
The Enonic CLI (Command Line Interface) manages local XP instances, creates projects from starters, and builds and deploys your apps.
Task: Install the CLI
-
Install the command-line tool - If you have
npmon your machine, run:npm install -g @enonic/cliIf not, there are alternative ways to install the Enonic CLI.
-
Verify the installation - Run
enonic -v. The command prints the version of the installed CLI.
Run enonic without arguments to list the available commands, and enonic latest to check for a newer version of the CLI. |
Sandbox
A sandbox is a local developer instance of Enonic XP. Each sandbox is isolated from the others, with its own data and configuration, and can run a different version of XP.
Task: Create a sandbox
-
Create and start the sandbox - Run this command in your terminal:
enonic sandbox create tutorial_siteframework -t essentials -v 7.16.11 -fThis creates a sandbox called
tutorial_siteframeworkrunning Enonic XP 7.16.11, installs the applications in theessentialstemplate, including Content Studio, and starts the sandbox. -
Verify that XP is running - Wait until the terminal stops printing new log lines, then open http://localhost:8080 in your browser. You should see the XP boot page, with the title "Welcome to the Enonic SDK".
To stop the sandbox, press Ctrl+C in its terminal. To start it again, run enonic sandbox start tutorial_siteframework. Sandboxes share the same ports, so stop this one before starting the sandbox of another tutorial. |
App
Almost everything you build on XP is packaged as an application. Instead of starting from an empty folder, you’ll create your app from a starter that contains the components, content types, and sample content used in this tutorial.
Task: Create the app
Use a dedicated workspace folder for Enonic tutorials, such as enonic-tutorials/, so each tutorial’s source folder stays separate.
-
Create the app from the starter - Open a new terminal window in your tutorials workspace folder, leaving the sandbox running in the first one, and run:
enonic project create com.example.tutorial.siteframework -r tutorial-site-framework -b 7.x -s tutorial_siteframework -d tutorial-siteframework-enonic -fThis creates an app named
com.example.tutorial.siteframeworkin the foldertutorial-siteframework-enonic, using the tutorial-site-framework repository as a starter, and links the app to thetutorial_siteframeworksandbox. -
Inspect the project structure - The project folder contains a basic app structure. These are the parts you’ll meet in this tutorial:
build.gradle (1) code-samples/ (2) docs/ (3) tsup/ (4) src/ main/ resources/ import/ (5) assets/ (6) site/ content-types/ (7) country/ city/ parts/ (8) pages/ (9)1 Core build files 2 Code samples that you’ll copy into the app in later chapters 3 The documentation you are reading now 4 Build files for the TypeScript compilation 5 Sample content that is imported when the app starts 6 Location for static assets 7 Two pre-defined content types, country and city 8 Part components - leaf components to place on pages 9 Page components - the root component of a page
Task: Build and deploy the app
-
Start the development watcher - Change to the project folder and start development mode:
cd tutorial-siteframework-enonic enonic devThis builds the app, deploys it to the
tutorial_siteframeworksandbox, and then keeps watching the folder. When you save a file, your TypeScript code is compiled and the sandbox picks up the change. There is no need for manual deployments.Keep this command running in its own terminal while you follow the tutorial. Press Ctrl+C to stop watching, and run
enonic devfromtutorial-siteframework-enonicto resume later. -
Verify that the app has started - The first build downloads a few things, so give it a moment. Then look for lines like these in the terminal where the sandbox is running:
INFO com.example.tutorial.siteframework - (/main.js) Project "myfirstsite" successfully created INFO com.example.tutorial.siteframework - (/main.js) Importing "myfirstsite" data
XP admin
The sandbox has a web interface for administration, where each admin tool is its own application.
Task: Log in to XP admin
-
Open the boot page - Open http://localhost:8080 in your browser, or reload it if it is already open:
The boot page gives an overview of the sandbox, including the installed applications and the standard configuration files. Your app,
My First Site, is in the list, together with the applications that were installed when you created the sandbox. -
Log in - Click Log In as Guest to open the XP admin dashboard:
The menu on the right-hand side, the XP menu, lets you move between admin tools. Applications can add their own admin tools to it.
| If things don’t look exactly the same, don’t worry. The background picture changes between versions of XP, and the dashboard is localized to your browser’s preferred language. |
Summary
You’ve installed the Enonic CLI, created a sandbox running XP 7, and created, built, and deployed an app from a starter to that sandbox.
Next, you’ll explore the sample content in Content Studio.