How to Install the Development version of Directus Locally

Shariq Shahab
Shariq Shahab
发布于 2023-09-15 / 104 阅读
0
0

How to Install the Development version of Directus Locally

This guide explains how to install the Development version of Directus locally so that you can work on the platform's source code.

Minimum Requirements

You will need to have the latest version of Node to build a Development version of Directus.

You will also need to have the package manager pnpm installed.

1. Fork the Directus repository

Go to the repository and fork it to your GitHub account. A fork is your copy of the Directus repository which allows you to freely experiment with changes without affecting the original project.

2. Clone from your repository

git clone [email protected]:YOUR-USERNAME/directus.git

3. Make a new branch

git checkout -b YOUR-BRANCH-NAME

4. Install the dependencies and build the project

pnpm install
pnpm build

5. Setup Local Configuration

Create a .env file in /api

Create an .env file under the api folder using vars from the online config help.

Config Values
The KEY& SECRET config options from Security are mandatory.

Also the Database Configuration must be specified. You might want to use the docker-compose.yml file to spin up a test database.

KEY: '255d861b-5ea1-5996-9aa3-922530ec40b1'
SECRET: '6116487b-cda1-52c2-b5b5-c8022c45e263'

HOST="0.0.0.0" # REPLACE WITH DOMAIN/IP ADDRESS
PORT=8055
DB_CLIENT="mysql"
DB_HOST="localhost"
DB_PORT=3306
DB_DATABASE=DATABASE_NAME
DB_USER=YOUR_DATABASE_USER
DB_PASSWORD=YOUR_DATABASE_USER_PASSWORD

Upload/Extensions Folder

If you are using the local storage driver, your files will upload to /api/uploads. If you are locally developing extensions from the extensions folder, that folder should be located at /api/extensions.

6. Initialize the database

For this step, you'll need to already have a SQL database up-and-running, except if you're using the SQLite driver, which will create the database (file) for you.

Admin Account

Adding the ADMIN_EMAIL & ADMIN_PASSWORD to the .env file before running the bootstrap command, will populate the admin user with the provided credentials instead of random values.

To start the initialization run the following command:

pnpm --filter api cli bootstrap

This will set-up the required tables for Directus and make sure all the migrations have run.

7. Start the development server

You can run all packages in development with the following command:

bash

pnpm --recursive dev

Race Conditions

When running multiple or all packages, sometimes ts-node may not start up the API properly because of race conditions due to changes happening to other packages. You can either rerun the command to restart the API or opt to choose what packages to work on as described below.

If you wish to choose what packages to work on, you should run the dev script for that package. You can see their names and list of scripts in their related package.json.

Example of running the API only:

pnpm --filter api dev

If you want to work on multiple packages at once, you should create a new instance of your terminal for each package. Example of running both the API and App at the same time:

Terminal 1 [Api]

Terminal 2 [App]

pnpm --filter api dev

pnpm --filter app dev


评论